Mercurial > geeqie
annotate src/ui_pathsel.c @ 1808:6c61c246506b
Fix a small issue with strptime
strptime do not initialize all fields. So the undefined fields could end
in crash later on.
author | mow |
---|---|
date | Sun, 28 Feb 2010 15:17:12 +0000 |
parents | 956aab097ea7 |
children |
rev | line source |
---|---|
9 | 1 /* |
2 * (SLIK) SimpLIstic sKin functions | |
69
31759d770628
Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
3 * (C) 2006 John Ellis |
1802 | 4 * Copyright (C) 2008 - 2010 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
13 #ifdef HAVE_CONFIG_H | |
14 # include "config.h" | |
15 #endif | |
16 #include "intl.h" | |
17 | |
18 #include <stdio.h> | |
19 #include <stdlib.h> | |
20 #include <string.h> | |
21 | |
22 #include <dirent.h> | |
23 #include <fcntl.h> | |
24 #include <unistd.h> | |
25 #include <sys/types.h> | |
26 #include <sys/stat.h> | |
27 | |
28 #include <gtk/gtk.h> | |
29 | |
30 #include <gdk/gdkkeysyms.h> /* for key values */ | |
31 | |
281 | 32 #include "main.h" |
9 | 33 #include "ui_pathsel.h" |
34 | |
35 #include "ui_bookmark.h" | |
36 #include "ui_fileops.h" | |
37 #include "ui_menu.h" | |
38 #include "ui_misc.h" | |
39 #include "ui_utildlg.h" | |
40 #include "ui_tabcomp.h" | |
41 #include "ui_tree_edit.h" | |
904
1698baa37871
Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
726
diff
changeset
|
42 #include "uri_utils.h" |
9 | 43 |
44 | |
45 #define DEST_WIDTH 250 | |
46 #define DEST_HEIGHT 210 | |
47 | |
48 #define RENAME_PRESS_DELAY 333 /* 1/3 second, to allow double clicks */ | |
49 | |
50 #define PATH_SEL_USE_HEADINGS FALSE | |
51 | |
52 enum { | |
53 FILTER_COLUMN_NAME = 0, | |
54 FILTER_COLUMN_FILTER | |
55 }; | |
56 | |
57 typedef struct _Dest_Data Dest_Data; | |
58 struct _Dest_Data | |
59 { | |
60 GtkWidget *d_view; | |
61 GtkWidget *f_view; | |
62 GtkWidget *entry; | |
63 gchar *filter; | |
64 gchar *path; | |
65 | |
66 GList *filter_list; | |
67 GList *filter_text_list; | |
68 GtkWidget *filter_combo; | |
69 | |
1448 | 70 gboolean show_hidden; |
9 | 71 GtkWidget *hidden_button; |
72 | |
73 GtkWidget *bookmark_list; | |
74 | |
75 GtkTreePath *right_click_path; | |
76 | |
77 void (*select_func)(const gchar *path, gpointer data); | |
78 gpointer select_data; | |
79 | |
80 GenericDialog *gd; /* any open confirm dialogs ? */ | |
81 }; | |
82 | |
83 typedef struct _DestDel_Data DestDel_Data; | |
84 struct _DestDel_Data | |
85 { | |
86 Dest_Data *dd; | |
87 gchar *path; | |
88 }; | |
89 | |
90 | |
91 static void dest_view_delete_dlg_cancel(GenericDialog *gd, gpointer data); | |
92 | |
93 | |
94 /* | |
95 *----------------------------------------------------------------------------- | |
96 * (private) | |
97 *----------------------------------------------------------------------------- | |
442 | 98 */ |
9 | 99 |
100 static void dest_free_data(GtkWidget *widget, gpointer data) | |
101 { | |
102 Dest_Data *dd = data; | |
103 | |
104 if (dd->gd) | |
105 { | |
106 GenericDialog *gd = dd->gd; | |
107 dest_view_delete_dlg_cancel(dd->gd, dd->gd->data); | |
108 generic_dialog_close(gd); | |
109 } | |
110 if (dd->right_click_path) gtk_tree_path_free(dd->right_click_path); | |
111 | |
112 g_free(dd->filter); | |
113 g_free(dd->path); | |
114 g_free(dd); | |
115 } | |
116 | |
1448 | 117 static gboolean dest_check_filter(const gchar *filter, const gchar *file) |
9 | 118 { |
119 const gchar *f_ptr = filter; | |
120 const gchar *strt_ptr; | |
121 gint i; | |
122 gint l; | |
123 | |
124 l = strlen(file); | |
125 | |
126 if (filter[0] == '*') return TRUE; | |
127 while (f_ptr < filter + strlen(filter)) | |
128 { | |
129 strt_ptr = f_ptr; | |
130 i=0; | |
131 while (*f_ptr != ';' && *f_ptr != '\0') | |
132 { | |
133 f_ptr++; | |
134 i++; | |
135 } | |
136 if (*f_ptr != '\0' && f_ptr[1] == ' ') f_ptr++; /* skip space immediately after separator */ | |
137 f_ptr++; | |
605
651ae2be1031
Use g_ascii_strncasecmp() instead of strncasecmp() where applicable.
zas_
parents:
576
diff
changeset
|
138 /* FIXME: utf8 */ |
1307 | 139 if (l >= i && g_ascii_strncasecmp(file + l - i, strt_ptr, i) == 0) return TRUE; |
9 | 140 } |
141 return FALSE; | |
142 } | |
143 | |
144 #ifndef CASE_SORT | |
145 #define CASE_SORT strcmp | |
146 #endif | |
147 | |
1002 | 148 static gint dest_sort_cb(gpointer a, gpointer b) |
9 | 149 { |
150 return CASE_SORT((gchar *)a, (gchar *)b); | |
151 } | |
152 | |
1448 | 153 static gboolean is_hidden(const gchar *name) |
9 | 154 { |
155 if (name[0] != '.') return FALSE; | |
156 if (name[1] == '\0') return FALSE; | |
157 if (name[1] == '.' && name[2] == '\0') return FALSE; | |
158 return TRUE; | |
159 } | |
160 | |
161 static void dest_populate(Dest_Data *dd, const gchar *path) | |
162 { | |
163 DIR *dp; | |
164 struct dirent *dir; | |
165 struct stat ent_sbuf; | |
166 GList *path_list = NULL; | |
167 GList *file_list = NULL; | |
168 GList *list; | |
169 GtkListStore *store; | |
170 gchar *pathl; | |
171 | |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
172 if (!path) return; |
9 | 173 |
174 pathl = path_from_utf8(path); | |
175 dp = opendir(pathl); | |
176 if (!dp) | |
177 { | |
178 /* dir not found */ | |
179 g_free(pathl); | |
180 return; | |
181 } | |
182 while ((dir = readdir(dp)) != NULL) | |
183 { | |
373
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
281
diff
changeset
|
184 if (!options->file_filter.show_dot_directory |
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
281
diff
changeset
|
185 && dir->d_name[0] == '.' && dir->d_name[1] == '\0') |
442 | 186 continue; |
373
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
281
diff
changeset
|
187 if (dir->d_name[0] == '.' && dir->d_name[1] == '.' && dir->d_name[2] == '\0' |
726 | 188 && pathl[0] == G_DIR_SEPARATOR && pathl[1] == '\0') |
442 | 189 continue; /* no .. for root directory */ |
69
31759d770628
Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
190 if (dd->show_hidden || !is_hidden(dir->d_name)) |
9 | 191 { |
192 gchar *name = dir->d_name; | |
717 | 193 gchar *filepath = g_build_filename(pathl, name, NULL); |
9 | 194 if (stat(filepath, &ent_sbuf) >= 0 && S_ISDIR(ent_sbuf.st_mode)) |
195 { | |
196 path_list = g_list_prepend(path_list, path_to_utf8(name)); | |
197 } | |
198 else if (dd->f_view) | |
199 { | |
200 if (!dd->filter || (dd->filter && dest_check_filter(dd->filter, name))) | |
201 file_list = g_list_prepend(file_list, path_to_utf8(name)); | |
202 } | |
203 g_free(filepath); | |
204 } | |
205 } | |
206 closedir(dp); | |
207 g_free(pathl); | |
208 | |
209 path_list = g_list_sort(path_list, (GCompareFunc) dest_sort_cb); | |
210 file_list = g_list_sort(file_list, (GCompareFunc) dest_sort_cb); | |
211 | |
212 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dd->d_view))); | |
213 gtk_list_store_clear(store); | |
214 | |
215 list = path_list; | |
216 while (list) | |
217 { | |
218 GtkTreeIter iter; | |
219 gchar *filepath; | |
220 | |
221 if (strcmp(list->data, ".") == 0) | |
222 { | |
223 filepath = g_strdup(path); | |
224 } | |
225 else if (strcmp(list->data, "..") == 0) | |
226 { | |
227 gchar *p; | |
228 filepath = g_strdup(path); | |
229 p = (gchar *)filename_from_path(filepath); | |
230 if (p - 1 != filepath) p--; | |
231 p[0] = '\0'; | |
232 } | |
233 else | |
234 { | |
702
e07895754e65
Drop concat_dir_and_file() and use g_build_filename() instead.
zas_
parents:
605
diff
changeset
|
235 filepath = g_build_filename(path, list->data, NULL); |
9 | 236 } |
442 | 237 |
9 | 238 gtk_list_store_append(store, &iter); |
239 gtk_list_store_set(store, &iter, 0, list->data, 1, filepath, -1); | |
240 | |
241 g_free(filepath); | |
242 list = list->next; | |
243 } | |
244 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
513
diff
changeset
|
245 string_list_free(path_list); |
9 | 246 |
247 | |
248 if (dd->f_view) | |
249 { | |
250 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dd->f_view))); | |
251 gtk_list_store_clear(store); | |
252 | |
253 list = file_list; | |
254 while (list) | |
442 | 255 { |
9 | 256 GtkTreeIter iter; |
257 gchar *filepath; | |
258 const gchar *name = list->data; | |
259 | |
702
e07895754e65
Drop concat_dir_and_file() and use g_build_filename() instead.
zas_
parents:
605
diff
changeset
|
260 filepath = g_build_filename(path, name, NULL); |
442 | 261 |
9 | 262 gtk_list_store_append(store, &iter); |
263 gtk_list_store_set(store, &iter, 0, name, 1, filepath, -1); | |
264 | |
265 g_free(filepath); | |
266 list = list->next; | |
267 } | |
268 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
513
diff
changeset
|
269 string_list_free(file_list); |
9 | 270 } |
271 | |
272 g_free(dd->path); | |
273 dd->path = g_strdup(path); | |
274 } | |
275 | |
1448 | 276 static void dest_change_dir(Dest_Data *dd, const gchar *path, gboolean retain_name) |
9 | 277 { |
719
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
278 const gchar *old_name = NULL; |
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
279 gchar *full_path; |
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
280 gchar *new_directory; |
9 | 281 |
282 if (retain_name) | |
283 { | |
284 const gchar *buf = gtk_entry_get_text(GTK_ENTRY(dd->entry)); | |
719
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
285 |
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
286 if (!isdir(buf)) old_name = filename_from_path(buf); |
9 | 287 } |
288 | |
719
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
289 full_path = g_build_filename(path, old_name, NULL); |
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
290 if (old_name) |
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
291 new_directory = g_path_get_dirname(full_path); |
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
292 else |
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
293 new_directory = g_strdup(full_path); |
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
294 |
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
295 gtk_entry_set_text(GTK_ENTRY(dd->entry), full_path); |
9 | 296 |
719
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
297 dest_populate(dd, new_directory); |
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
298 g_free(new_directory); |
9 | 299 |
300 if (old_name) | |
301 { | |
719
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
302 gchar *basename = g_path_get_basename(full_path); |
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
303 |
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
304 gtk_editable_select_region(GTK_EDITABLE(dd->entry), strlen(full_path) - strlen(basename), strlen(full_path)); |
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
305 g_free(basename); |
9 | 306 } |
719
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
307 |
ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
zas_
parents:
717
diff
changeset
|
308 g_free(full_path); |
9 | 309 } |
310 | |
311 /* | |
312 *----------------------------------------------------------------------------- | |
313 * drag and drop | |
314 *----------------------------------------------------------------------------- | |
315 */ | |
316 | |
317 enum { | |
318 TARGET_URI_LIST, | |
319 TARGET_TEXT_PLAIN | |
320 }; | |
321 | |
322 static GtkTargetEntry dest_drag_types[] = { | |
323 { "text/uri-list", 0, TARGET_URI_LIST }, | |
324 { "text/plain", 0, TARGET_TEXT_PLAIN } | |
325 }; | |
326 #define dest_drag_types_n 2 | |
327 | |
328 | |
329 static void dest_dnd_set_data(GtkWidget *view, | |
330 GdkDragContext *context, GtkSelectionData *selection_data, | |
331 guint info, guint time, gpointer data) | |
332 { | |
333 gchar *path = NULL; | |
334 gchar *uri_text = NULL; | |
335 GList *list = NULL; | |
336 gint length = 0; | |
337 GtkTreeModel *model; | |
338 GtkTreeSelection *selection; | |
339 GtkTreeIter iter; | |
340 | |
341 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); | |
342 if (!gtk_tree_selection_get_selected(selection, &model, &iter)) return; | |
343 | |
344 gtk_tree_model_get(model, &iter, 1, &path, -1); | |
345 if (!path) return; | |
346 | |
347 list = g_list_append(list, path); | |
348 | |
349 switch (info) | |
350 { | |
351 case TARGET_URI_LIST: | |
352 uri_text = uri_text_from_list(list, &length, FALSE); | |
353 break; | |
354 case TARGET_TEXT_PLAIN: | |
355 uri_text = uri_text_from_list(list, &length, TRUE); | |
356 break; | |
357 } | |
358 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
513
diff
changeset
|
359 string_list_free(list); |
9 | 360 |
361 if (!uri_text) return; | |
362 | |
363 gtk_selection_data_set(selection_data, selection_data->target, | |
64
04ff0df3ad2f
Mon Aug 15 17:13:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
364 8, (guchar *)uri_text, length); |
9 | 365 g_free(uri_text); |
366 } | |
367 | |
368 static void dest_dnd_init(Dest_Data *dd) | |
369 { | |
370 gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(dd->d_view), GDK_BUTTON1_MASK, | |
371 dest_drag_types, dest_drag_types_n, | |
372 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK); | |
373 g_signal_connect(G_OBJECT(dd->d_view), "drag_data_get", | |
374 G_CALLBACK(dest_dnd_set_data), dd); | |
375 | |
376 if (dd->f_view) | |
377 { | |
378 gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(dd->f_view), GDK_BUTTON1_MASK, | |
379 dest_drag_types, dest_drag_types_n, | |
380 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK); | |
381 g_signal_connect(G_OBJECT(dd->f_view), "drag_data_get", | |
382 G_CALLBACK(dest_dnd_set_data), dd); | |
383 } | |
384 } | |
385 | |
386 | |
387 /* | |
388 *----------------------------------------------------------------------------- | |
389 * destination widget file management utils | |
390 *----------------------------------------------------------------------------- | |
391 */ | |
392 | |
393 static void dest_view_store_selection(Dest_Data *dd, GtkTreeView *view) | |
394 { | |
395 GtkTreeModel *model; | |
396 GtkTreeSelection *selection; | |
397 GtkTreeIter iter; | |
398 | |
399 if (dd->right_click_path) gtk_tree_path_free(dd->right_click_path); | |
400 dd->right_click_path = NULL; | |
401 | |
402 selection = gtk_tree_view_get_selection(view); | |
403 if (!gtk_tree_selection_get_selected(selection, &model, &iter)) | |
404 { | |
405 return; | |
406 } | |
407 | |
408 dd->right_click_path = gtk_tree_model_get_path(model, &iter); | |
409 } | |
410 | |
411 static gint dest_view_rename_cb(TreeEditData *ted, const gchar *old, const gchar *new, gpointer data) | |
412 { | |
413 Dest_Data *dd = data; | |
414 GtkTreeModel *model; | |
415 GtkTreeIter iter; | |
416 gchar *buf; | |
417 gchar *old_path; | |
418 gchar *new_path; | |
419 | |
420 model = gtk_tree_view_get_model(GTK_TREE_VIEW(ted->tree)); | |
421 gtk_tree_model_get_iter(model, &iter, dd->right_click_path); | |
422 | |
423 gtk_tree_model_get(model, &iter, 1, &old_path, -1); | |
424 if (!old_path) return FALSE; | |
425 | |
426 buf = remove_level_from_path(old_path); | |
702
e07895754e65
Drop concat_dir_and_file() and use g_build_filename() instead.
zas_
parents:
605
diff
changeset
|
427 new_path = g_build_filename(buf, new, NULL); |
9 | 428 g_free(buf); |
429 | |
430 if (isname(new_path)) | |
431 { | |
432 buf = g_strdup_printf(_("A file with name %s already exists."), new); | |
989
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
904
diff
changeset
|
433 warning_dialog(_("Rename failed"), buf, GTK_STOCK_DIALOG_INFO, dd->entry); |
9 | 434 g_free(buf); |
435 } | |
436 else if (!rename_file(old_path, new_path)) | |
437 { | |
438 buf = g_strdup_printf(_("Failed to rename %s to %s."), old, new); | |
989
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
904
diff
changeset
|
439 warning_dialog(_("Rename failed"), buf, GTK_STOCK_DIALOG_ERROR, dd->entry); |
9 | 440 g_free(buf); |
441 } | |
442 else | |
443 { | |
444 const gchar *text; | |
445 | |
446 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, new, 1, new_path, -1); | |
447 | |
448 text = gtk_entry_get_text(GTK_ENTRY(dd->entry)); | |
449 if (text && old_path && strcmp(text, old_path) == 0) | |
450 { | |
451 gtk_entry_set_text(GTK_ENTRY(dd->entry), new_path); | |
452 } | |
453 } | |
454 | |
455 g_free(old_path); | |
456 g_free(new_path); | |
457 | |
458 return TRUE; | |
459 } | |
460 | |
461 static void dest_view_rename(Dest_Data *dd, GtkTreeView *view) | |
462 { | |
463 GtkTreeModel *model; | |
464 GtkTreeIter iter; | |
465 gchar *text; | |
466 | |
467 if (!dd->right_click_path) return; | |
468 | |
469 model = gtk_tree_view_get_model(view); | |
470 gtk_tree_model_get_iter(model, &iter, dd->right_click_path); | |
471 gtk_tree_model_get(model, &iter, 0, &text, -1); | |
472 | |
473 tree_edit_by_path(view, dd->right_click_path, 0, text, | |
474 dest_view_rename_cb, dd); | |
475 | |
476 g_free(text); | |
477 } | |
478 | |
479 static void dest_view_delete_dlg_cancel(GenericDialog *gd, gpointer data) | |
480 { | |
481 DestDel_Data *dl = data; | |
482 | |
483 dl->dd->gd = NULL; | |
484 g_free(dl->path); | |
485 g_free(dl); | |
486 } | |
487 | |
488 static void dest_view_delete_dlg_ok_cb(GenericDialog *gd, gpointer data) | |
489 { | |
490 DestDel_Data *dl = data; | |
491 | |
492 if (!unlink_file(dl->path)) | |
493 { | |
494 gchar *text = g_strdup_printf(_("Unable to delete file:\n%s"), dl->path); | |
495 warning_dialog(_("File deletion failed"), text, GTK_STOCK_DIALOG_WARNING, dl->dd->entry); | |
496 g_free(text); | |
497 } | |
498 else if (dl->dd->path) | |
499 { | |
500 /* refresh list */ | |
501 gchar *path = g_strdup(dl->dd->path); | |
502 dest_populate(dl->dd, path); | |
503 g_free(path); | |
504 } | |
505 | |
506 dest_view_delete_dlg_cancel(gd, data); | |
507 } | |
508 | |
509 static void dest_view_delete(Dest_Data *dd, GtkTreeView *view) | |
510 { | |
511 gchar *path; | |
512 gchar *text; | |
513 DestDel_Data *dl; | |
514 GtkTreeModel *model; | |
515 GtkTreeIter iter; | |
516 | |
517 if (view != GTK_TREE_VIEW(dd->f_view)) return; | |
518 if (!dd->right_click_path) return; | |
519 | |
520 model = gtk_tree_view_get_model(view); | |
521 gtk_tree_model_get_iter(model, &iter, dd->right_click_path); | |
522 gtk_tree_model_get(model, &iter, 1, &path, -1); | |
442 | 523 |
9 | 524 if (!path) return; |
525 | |
526 dl = g_new(DestDel_Data, 1); | |
527 dl->dd = dd; | |
528 dl->path = path; | |
529 | |
530 if (dd->gd) | |
531 { | |
532 GenericDialog *gd = dd->gd; | |
533 dest_view_delete_dlg_cancel(dd->gd, dd->gd->data); | |
534 generic_dialog_close(gd); | |
535 } | |
536 | |
1174
0bea79d87065
Drop useless wmclass stuff. Gtk will take care of it and as said in the documentation using gtk_window_set_wmclass() is sort of pointless.
zas_
parents:
1055
diff
changeset
|
537 dd->gd = generic_dialog_new(_("Delete file"), "dlg_confirm", |
9 | 538 dd->entry, TRUE, |
539 dest_view_delete_dlg_cancel, dl); | |
540 | |
541 generic_dialog_add_button(dd->gd, GTK_STOCK_DELETE, NULL, dest_view_delete_dlg_ok_cb, TRUE); | |
542 | |
543 text = g_strdup_printf(_("About to delete the file:\n %s"), path); | |
544 generic_dialog_add_message(dd->gd, GTK_STOCK_DIALOG_QUESTION, | |
545 _("Delete file"), text); | |
546 g_free(text); | |
547 | |
548 gtk_widget_show(dd->gd->dialog); | |
549 } | |
550 | |
551 static void dest_view_bookmark(Dest_Data *dd, GtkTreeView *view) | |
552 { | |
553 GtkTreeModel *model; | |
554 GtkTreeIter iter; | |
555 gchar *path; | |
556 | |
557 if (!dd->right_click_path) return; | |
558 | |
559 model = gtk_tree_view_get_model(view); | |
560 gtk_tree_model_get_iter(model, &iter, dd->right_click_path); | |
561 gtk_tree_model_get(model, &iter, 1, &path, -1); | |
562 | |
563 bookmark_list_add(dd->bookmark_list, filename_from_path(path), path); | |
564 g_free(path); | |
565 } | |
566 | |
567 static void dest_popup_dir_rename_cb(GtkWidget *widget, gpointer data) | |
568 { | |
569 Dest_Data *dd = data; | |
570 dest_view_rename(dd, GTK_TREE_VIEW(dd->d_view)); | |
571 } | |
572 | |
573 static void dest_popup_dir_bookmark_cb(GtkWidget *widget, gpointer data) | |
574 { | |
575 Dest_Data *dd = data; | |
576 dest_view_bookmark(dd, GTK_TREE_VIEW(dd->d_view)); | |
577 } | |
578 | |
579 static void dest_popup_file_rename_cb(GtkWidget *widget, gpointer data) | |
580 { | |
581 Dest_Data *dd = data; | |
582 dest_view_rename(dd, GTK_TREE_VIEW(dd->f_view)); | |
583 } | |
584 | |
585 static void dest_popup_file_delete_cb(GtkWidget *widget, gpointer data) | |
586 { | |
587 Dest_Data *dd = data; | |
588 dest_view_delete(dd, GTK_TREE_VIEW(dd->f_view)); | |
589 } | |
590 | |
591 static void dest_popup_file_bookmark_cb(GtkWidget *widget, gpointer data) | |
592 { | |
593 Dest_Data *dd = data; | |
594 dest_view_bookmark(dd, GTK_TREE_VIEW(dd->f_view)); | |
595 } | |
596 | |
597 static void dest_popup_position_cb(GtkMenu *menu, gint *x, gint *y, | |
598 gboolean *push_in, gpointer data) | |
599 { | |
600 Dest_Data *dd = data; | |
601 GtkTreeView *view; | |
602 gint cw, ch; | |
603 | |
604 view = g_object_get_data(G_OBJECT(menu), "active_view"); | |
605 | |
606 tree_view_get_cell_clamped(view, dd->right_click_path, 0, TRUE, x, y, &cw, &ch); | |
607 *y += ch; | |
608 popup_menu_position_clamp(menu, x, y, 0); | |
609 } | |
610 | |
1448 | 611 static gboolean dest_popup_menu(Dest_Data *dd, GtkTreeView *view, |
612 guint button, guint32 time, gboolean local) | |
9 | 613 { |
614 GtkWidget *menu; | |
615 | |
616 if (!dd->right_click_path) return FALSE; | |
617 | |
618 if (view == GTK_TREE_VIEW(dd->d_view)) | |
619 { | |
620 GtkTreeModel *model; | |
621 GtkTreeIter iter; | |
622 gchar *text; | |
1448 | 623 gboolean normal_dir; |
9 | 624 |
625 model = gtk_tree_view_get_model(view); | |
626 gtk_tree_model_get_iter(model, &iter, dd->right_click_path); | |
627 gtk_tree_model_get(model, &iter, 0, &text, -1); | |
628 | |
629 if (!text) return FALSE; | |
442 | 630 |
9 | 631 normal_dir = (strcmp(text, ".") == 0 || strcmp(text, "..") == 0); |
632 | |
633 menu = popup_menu_short_lived(); | |
634 menu_item_add_sensitive(menu, _("_Rename"), !normal_dir, | |
635 G_CALLBACK(dest_popup_dir_rename_cb), dd); | |
636 menu_item_add_stock(menu, _("Add _Bookmark"), GTK_STOCK_JUMP_TO, | |
637 G_CALLBACK(dest_popup_dir_bookmark_cb), dd); | |
638 } | |
639 else | |
640 { | |
641 menu = popup_menu_short_lived(); | |
642 menu_item_add(menu, _("_Rename"), | |
643 G_CALLBACK(dest_popup_file_rename_cb), dd); | |
644 menu_item_add_stock(menu, _("_Delete"), GTK_STOCK_DELETE, | |
645 G_CALLBACK(dest_popup_file_delete_cb), dd); | |
646 menu_item_add_stock(menu, _("Add _Bookmark"), GTK_STOCK_JUMP_TO, | |
647 G_CALLBACK(dest_popup_file_bookmark_cb), dd); | |
648 } | |
649 | |
650 if (local) | |
651 { | |
652 g_object_set_data(G_OBJECT(menu), "active_view", view); | |
653 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, | |
654 dest_popup_position_cb, dd, button, time); | |
655 } | |
656 else | |
657 { | |
658 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, time); | |
659 } | |
660 | |
661 return TRUE; | |
662 } | |
663 | |
1448 | 664 static gboolean dest_press_cb(GtkWidget *view, GdkEventButton *event, gpointer data) |
9 | 665 { |
666 Dest_Data *dd = data; | |
667 GtkTreePath *tpath; | |
668 GtkTreeViewColumn *column; | |
669 gint cell_x, cell_y; | |
670 GtkTreeModel *model; | |
671 GtkTreeIter iter; | |
672 GtkTreeSelection *selection; | |
673 | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
674 if (event->button != MOUSE_BUTTON_RIGHT || |
9 | 675 !gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(view), event->x, event->y, |
676 &tpath, &column, &cell_x, &cell_y)) | |
677 { | |
678 return FALSE; | |
679 } | |
680 | |
681 model = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); | |
682 gtk_tree_model_get_iter(model, &iter, tpath); | |
683 | |
684 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); | |
685 gtk_tree_selection_select_iter(selection, &iter); | |
686 | |
687 if (dd->right_click_path) gtk_tree_path_free(dd->right_click_path); | |
688 dd->right_click_path = tpath; | |
689 | |
690 return dest_popup_menu(dd, GTK_TREE_VIEW(view), 0, event->time, FALSE); | |
691 } | |
692 | |
693 static gboolean dest_keypress_cb(GtkWidget *view, GdkEventKey *event, gpointer data) | |
694 { | |
695 Dest_Data *dd = data; | |
696 | |
697 switch (event->keyval) | |
698 { | |
699 case GDK_F10: | |
700 if (!(event->state & GDK_CONTROL_MASK)) return FALSE; | |
701 case GDK_Menu: | |
702 dest_view_store_selection(dd, GTK_TREE_VIEW(view)); | |
703 dest_popup_menu(dd, GTK_TREE_VIEW(view), 0, event->time, TRUE); | |
704 return TRUE; | |
705 break; | |
706 case 'R': case 'r': | |
707 if (event->state & GDK_CONTROL_MASK) | |
708 { | |
709 dest_view_store_selection(dd, GTK_TREE_VIEW(view)); | |
710 dest_view_rename(dd, GTK_TREE_VIEW(view)); | |
711 return TRUE; | |
712 } | |
713 break; | |
714 case GDK_Delete: | |
715 dest_view_store_selection(dd, GTK_TREE_VIEW(view)); | |
716 dest_view_delete(dd, GTK_TREE_VIEW(view)); | |
717 return TRUE; | |
718 break; | |
719 case 'B' : case 'b': | |
720 if (event->state & GDK_CONTROL_MASK) | |
721 { | |
722 dest_view_store_selection(dd, GTK_TREE_VIEW(view)); | |
723 dest_view_bookmark(dd, GTK_TREE_VIEW(view)); | |
724 return TRUE; | |
725 } | |
726 break; | |
727 } | |
728 | |
729 return FALSE; | |
730 } | |
442 | 731 |
9 | 732 static void dest_new_dir_cb(GtkWidget *widget, gpointer data) |
733 { | |
734 Dest_Data *dd = data; | |
735 gchar *path; | |
736 gchar *buf; | |
737 const gchar *tmp; | |
1437 | 738 gboolean from_text = FALSE; |
9 | 739 |
740 tmp = gtk_entry_get_text(GTK_ENTRY(dd->entry)); | |
741 if (!isname(tmp)) | |
742 { | |
743 path = g_strdup(tmp); | |
744 from_text = TRUE; | |
745 } | |
746 else | |
747 { | |
702
e07895754e65
Drop concat_dir_and_file() and use g_build_filename() instead.
zas_
parents:
605
diff
changeset
|
748 buf = g_build_filename(dd->path, _("New folder"), NULL); |
9 | 749 path = unique_filename(buf, NULL, " ", FALSE); |
750 g_free(buf); | |
751 } | |
752 | |
753 if (!mkdir_utf8(path, 0755)) | |
754 { | |
755 /* failed */ | |
756 gchar *text; | |
757 | |
758 text = g_strdup_printf(_("Unable to create folder:\n%s"), filename_from_path(path)); | |
759 warning_dialog(_("Error creating folder"), text, GTK_STOCK_DIALOG_ERROR, dd->entry); | |
760 g_free(text); | |
761 } | |
762 else | |
763 { | |
764 GtkTreeIter iter; | |
765 GtkListStore *store; | |
766 const gchar *text; | |
767 | |
768 if (from_text) gtk_entry_set_text(GTK_ENTRY(dd->entry), dd->path); | |
769 | |
770 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dd->d_view))); | |
771 | |
772 text = filename_from_path(path); | |
773 | |
774 gtk_list_store_append(store, &iter); | |
775 gtk_list_store_set(store, &iter, 0, text, 1, path, -1); | |
776 | |
777 if (dd->right_click_path) gtk_tree_path_free(dd->right_click_path); | |
778 dd->right_click_path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); | |
779 | |
780 tree_edit_by_path(GTK_TREE_VIEW(dd->d_view), dd->right_click_path, 0, text, | |
781 dest_view_rename_cb, dd); | |
782 } | |
783 | |
784 g_free(path); | |
785 } | |
786 | |
787 /* | |
788 *----------------------------------------------------------------------------- | |
789 * destination widget file selection, traversal, view options | |
790 *----------------------------------------------------------------------------- | |
442 | 791 */ |
9 | 792 |
793 static void dest_select_cb(GtkTreeSelection *selection, gpointer data) | |
794 { | |
795 Dest_Data *dd = data; | |
796 GtkTreeView *view; | |
797 GtkTreeModel *store; | |
798 GtkTreeIter iter; | |
799 gchar *path; | |
800 | |
801 if (!gtk_tree_selection_get_selected(selection, NULL, &iter)) return; | |
802 | |
803 view = gtk_tree_selection_get_tree_view(selection); | |
804 store = gtk_tree_view_get_model(view); | |
805 gtk_tree_model_get(store, &iter, 1, &path, -1); | |
806 | |
807 if (view == GTK_TREE_VIEW(dd->d_view)) | |
808 { | |
809 dest_change_dir(dd, path, (dd->f_view != NULL)); | |
810 } | |
811 else | |
812 { | |
813 gtk_entry_set_text(GTK_ENTRY(dd->entry), path); | |
814 } | |
815 | |
816 g_free(path); | |
817 } | |
818 | |
819 static void dest_activate_cb(GtkWidget *view, GtkTreePath *tpath, GtkTreeViewColumn *column, gpointer data) | |
820 { | |
821 Dest_Data *dd = data; | |
822 GtkTreeModel *store; | |
823 GtkTreeIter iter; | |
824 gchar *path; | |
825 | |
826 store = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); | |
827 gtk_tree_model_get_iter(store, &iter, tpath); | |
828 gtk_tree_model_get(store, &iter, 1, &path, -1); | |
829 | |
830 if (view == dd->d_view) | |
831 { | |
832 dest_change_dir(dd, path, (dd->f_view != NULL)); | |
833 } | |
834 else | |
835 { | |
836 if (dd->select_func) | |
837 { | |
838 dd->select_func(path, dd->select_data); | |
839 } | |
840 } | |
841 | |
842 g_free(path); | |
843 } | |
844 | |
845 static void dest_home_cb(GtkWidget *widget, gpointer data) | |
846 { | |
847 Dest_Data *dd = data; | |
848 | |
849 dest_change_dir(dd, homedir(), (dd->f_view != NULL)); | |
850 } | |
851 | |
852 static void dest_show_hidden_cb(GtkWidget *widget, gpointer data) | |
853 { | |
854 Dest_Data *dd = data; | |
855 gchar *buf; | |
856 | |
857 dd->show_hidden = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dd->hidden_button)); | |
858 | |
859 buf = g_strdup(dd->path); | |
860 dest_populate(dd, buf); | |
861 g_free(buf); | |
862 } | |
863 | |
864 static void dest_entry_changed_cb(GtkEditable *editable, gpointer data) | |
865 { | |
866 Dest_Data *dd = data; | |
867 const gchar *path; | |
868 gchar *buf; | |
869 | |
870 path = gtk_entry_get_text(GTK_ENTRY(dd->entry)); | |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
871 if (dd->path && strcmp(path, dd->path) == 0) return; |
9 | 872 |
873 buf = remove_level_from_path(path); | |
874 | |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
875 if (buf && (!dd->path || strcmp(buf, dd->path) != 0)) |
9 | 876 { |
877 gchar *tmp = remove_trailing_slash(path); | |
878 if (isdir(tmp)) | |
879 { | |
880 dest_populate(dd, tmp); | |
881 } | |
882 else if (isdir(buf)) | |
883 { | |
884 dest_populate(dd, buf); | |
885 } | |
886 g_free(tmp); | |
887 } | |
888 g_free(buf); | |
889 } | |
890 | |
891 static void dest_filter_list_sync(Dest_Data *dd) | |
892 { | |
893 GtkWidget *entry; | |
894 GtkListStore *store; | |
895 gchar *old_text; | |
896 GList *fwork; | |
897 GList *twork; | |
898 | |
899 if (!dd->filter_list || !dd->filter_combo) return; | |
900 | |
901 entry = GTK_BIN(dd->filter_combo)->child; | |
902 old_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry))); | |
903 | |
904 store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(dd->filter_combo))); | |
905 gtk_list_store_clear(store); | |
906 | |
907 fwork = dd->filter_list; | |
908 twork = dd->filter_text_list; | |
909 while (fwork && twork) | |
910 { | |
911 GtkTreeIter iter; | |
912 gchar *name; | |
913 gchar *filter; | |
914 | |
915 name = twork->data; | |
916 filter = fwork->data; | |
917 | |
918 gtk_list_store_append(store, &iter); | |
919 gtk_list_store_set(store, &iter, FILTER_COLUMN_NAME, name, | |
920 FILTER_COLUMN_FILTER, filter, -1); | |
921 | |
922 if (strcmp(old_text, filter) == 0) | |
923 { | |
924 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(dd->filter_combo), &iter); | |
925 } | |
926 | |
927 fwork = fwork->next; | |
928 twork = twork->next; | |
929 } | |
930 | |
931 g_free(old_text); | |
932 } | |
933 | |
1448 | 934 static void dest_filter_add(Dest_Data *dd, const gchar *filter, const gchar *description, gboolean set) |
9 | 935 { |
936 GList *work; | |
937 gchar *buf; | |
938 gint c = 0; | |
939 | |
940 if (!filter) return; | |
941 | |
942 work = dd->filter_list; | |
943 while (work) | |
944 { | |
945 gchar *f = work->data; | |
946 | |
947 if (strcmp(f, filter) == 0) | |
948 { | |
949 if (set) gtk_combo_box_set_active(GTK_COMBO_BOX(dd->filter_combo), c); | |
950 return; | |
951 } | |
952 work = work->next; | |
953 c++; | |
954 } | |
955 | |
956 dd->filter_list = uig_list_insert_link(dd->filter_list, g_list_last(dd->filter_list), g_strdup(filter)); | |
957 | |
958 if (description) | |
959 { | |
960 buf = g_strdup_printf("%s ( %s )", description, filter); | |
961 } | |
962 else | |
963 { | |
964 buf = g_strdup_printf("( %s )", filter); | |
965 } | |
966 dd->filter_text_list = uig_list_insert_link(dd->filter_text_list, g_list_last(dd->filter_text_list), buf); | |
967 | |
968 if (set) gtk_entry_set_text(GTK_ENTRY(GTK_BIN(dd->filter_combo)->child), filter); | |
969 dest_filter_list_sync(dd); | |
970 } | |
971 | |
972 static void dest_filter_clear(Dest_Data *dd) | |
973 { | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
513
diff
changeset
|
974 string_list_free(dd->filter_list); |
9 | 975 dd->filter_list = NULL; |
976 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
513
diff
changeset
|
977 string_list_free(dd->filter_text_list); |
9 | 978 dd->filter_text_list = NULL; |
979 | |
980 dest_filter_add(dd, "*", _("All Files"), TRUE); | |
981 } | |
982 | |
983 static void dest_filter_changed_cb(GtkEditable *editable, gpointer data) | |
984 { | |
985 Dest_Data *dd = data; | |
986 GtkWidget *entry; | |
987 const gchar *buf; | |
988 gchar *path; | |
989 | |
990 entry = GTK_BIN(dd->filter_combo)->child; | |
991 buf = gtk_entry_get_text(GTK_ENTRY(entry)); | |
992 | |
993 g_free(dd->filter); | |
994 dd->filter = NULL; | |
995 if (strlen(buf) > 0) dd->filter = g_strdup(buf); | |
996 | |
997 path = g_strdup(dd->path); | |
998 dest_populate(dd, path); | |
999 g_free(path); | |
1000 } | |
1001 | |
1002 static void dest_bookmark_select_cb(const gchar *path, gpointer data) | |
1003 { | |
1004 Dest_Data *dd = data; | |
1005 | |
1006 if (isdir(path)) | |
1007 { | |
1008 dest_change_dir(dd, path, (dd->f_view != NULL)); | |
1009 } | |
1010 else if (isfile(path) && dd->f_view) | |
1011 { | |
1012 gtk_entry_set_text(GTK_ENTRY(dd->entry), path); | |
442 | 1013 } |
9 | 1014 } |
1015 | |
1016 /* | |
1017 *----------------------------------------------------------------------------- | |
1018 * destination widget setup routines (public) | |
1019 *----------------------------------------------------------------------------- | |
442 | 1020 */ |
9 | 1021 |
1022 GtkWidget *path_selection_new_with_files(GtkWidget *entry, const gchar *path, | |
1023 const gchar *filter, const gchar *filter_desc) | |
1024 { | |
1025 GtkWidget *hbox2; | |
1026 Dest_Data *dd; | |
1027 GtkWidget *scrolled; | |
1028 GtkWidget *table; | |
1029 GtkWidget *paned; | |
1030 GtkListStore *store; | |
1031 GtkTreeSelection *selection; | |
1032 GtkTreeViewColumn *column; | |
1033 GtkCellRenderer *renderer; | |
1034 | |
1035 dd = g_new0(Dest_Data, 1); | |
1036 | |
1037 table = gtk_table_new(4, (filter != NULL) ? 3 : 1, FALSE); | |
1038 gtk_table_set_col_spacings(GTK_TABLE(table), PREF_PAD_GAP); | |
1039 gtk_table_set_row_spacing(GTK_TABLE(table), 0, PREF_PAD_GAP); | |
1040 gtk_widget_show(table); | |
1041 | |
1042 dd->entry = entry; | |
1043 g_object_set_data(G_OBJECT(dd->entry), "destination_data", dd); | |
1044 | |
1045 hbox2 = pref_table_box(table, 0, 0, GTK_ORIENTATION_HORIZONTAL, NULL); | |
1046 gtk_box_set_spacing(GTK_BOX(hbox2), PREF_PAD_BUTTON_GAP); | |
1047 pref_button_new(hbox2, NULL, _("Home"), FALSE, | |
1048 G_CALLBACK(dest_home_cb), dd); | |
1049 pref_button_new(hbox2, NULL, _("New folder"), FALSE, | |
1050 G_CALLBACK(dest_new_dir_cb), dd); | |
1051 | |
1052 dd->hidden_button = gtk_check_button_new_with_label(_("Show hidden")); | |
1053 g_signal_connect(G_OBJECT(dd->hidden_button), "clicked", | |
1054 G_CALLBACK(dest_show_hidden_cb), dd); | |
1055 gtk_box_pack_end(GTK_BOX(hbox2), dd->hidden_button, FALSE, FALSE, 0); | |
1056 gtk_widget_show(dd->hidden_button); | |
1057 | |
1058 hbox2 = gtk_hbox_new(FALSE, PREF_PAD_GAP); | |
1059 if (filter) | |
1060 { | |
1061 paned = gtk_hpaned_new(); | |
1062 gtk_table_attach(GTK_TABLE(table), paned, 0, 3, 1, 2, | |
1063 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); | |
1064 gtk_widget_show(paned); | |
1065 gtk_paned_add1(GTK_PANED(paned), hbox2); | |
1066 } | |
1067 else | |
1068 { | |
1069 paned = NULL; | |
1070 gtk_table_attach(GTK_TABLE(table), hbox2, 0, 1, 1, 2, | |
1071 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); | |
1072 } | |
1073 gtk_widget_show(hbox2); | |
1074 | |
1075 /* bookmarks */ | |
1076 scrolled = bookmark_list_new(NULL, dest_bookmark_select_cb, dd); | |
1077 gtk_box_pack_start(GTK_BOX(hbox2), scrolled, FALSE, FALSE, 0); | |
1078 gtk_widget_show(scrolled); | |
1079 | |
1080 dd->bookmark_list = scrolled; | |
1081 | |
1082 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
1083 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
512
diff
changeset
|
1084 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
475
diff
changeset
|
1085 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); |
9 | 1086 gtk_box_pack_start(GTK_BOX(hbox2), scrolled, TRUE, TRUE, 0); |
1087 gtk_widget_show(scrolled); | |
1088 | |
1089 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); | |
1090 dd->d_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
1091 g_object_unref(store); | |
1092 | |
1093 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(dd->d_view), PATH_SEL_USE_HEADINGS); | |
1094 | |
1095 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dd->d_view)); | |
1096 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_SINGLE); | |
1097 | |
1098 column = gtk_tree_view_column_new(); | |
1099 gtk_tree_view_column_set_title(column, _("Folders")); | |
1100 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
1101 | |
1102 renderer = gtk_cell_renderer_text_new(); | |
1103 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1104 gtk_tree_view_column_add_attribute(column, renderer, "text", 0); | |
1105 | |
1106 gtk_tree_view_append_column(GTK_TREE_VIEW(dd->d_view), column); | |
1107 | |
1108 #if 0 | |
1109 /* only for debugging */ | |
1110 column = gtk_tree_view_column_new(); | |
1111 gtk_tree_view_column_set_title(column, _("Path")); | |
1112 renderer = gtk_cell_renderer_text_new(); | |
1113 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1114 gtk_tree_view_column_add_attribute(column, renderer, "text", 1); | |
1115 gtk_tree_view_append_column(GTK_TREE_VIEW(dd->d_view), column); | |
1116 #endif | |
1117 | |
1118 gtk_widget_set_size_request(dd->d_view, DEST_WIDTH, DEST_HEIGHT); | |
1119 gtk_container_add(GTK_CONTAINER(scrolled), dd->d_view); | |
1120 gtk_widget_show(dd->d_view); | |
1121 | |
1122 g_signal_connect(G_OBJECT(dd->d_view), "button_press_event", | |
1123 G_CALLBACK(dest_press_cb), dd); | |
1124 g_signal_connect(G_OBJECT(dd->d_view), "key_press_event", | |
1125 G_CALLBACK(dest_keypress_cb), dd); | |
1126 g_signal_connect(G_OBJECT(dd->d_view), "row_activated", | |
1127 G_CALLBACK(dest_activate_cb), dd); | |
1128 g_signal_connect(G_OBJECT(dd->d_view), "destroy", | |
1129 G_CALLBACK(dest_free_data), dd); | |
442 | 1130 |
9 | 1131 if (filter) |
1132 { | |
1133 GtkListStore *store; | |
1134 | |
1135 hbox2 = pref_table_box(table, 2, 0, GTK_ORIENTATION_HORIZONTAL, NULL); | |
1136 pref_label_new(hbox2, _("Filter:")); | |
1137 | |
1138 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); | |
1139 | |
1140 dd->filter_combo = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(store), | |
1141 FILTER_COLUMN_FILTER); | |
1142 g_object_unref(store); | |
1143 gtk_cell_layout_clear(GTK_CELL_LAYOUT(dd->filter_combo)); | |
1144 renderer = gtk_cell_renderer_text_new(); | |
1145 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dd->filter_combo), renderer, TRUE); | |
1146 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dd->filter_combo), renderer, | |
1147 "text", FILTER_COLUMN_NAME, NULL); | |
1148 #if 0 | |
1149 gtk_combo_set_case_sensitive(GTK_COMBO(dd->filter_combo), TRUE); | |
1150 #endif | |
1151 gtk_box_pack_start(GTK_BOX(hbox2), dd->filter_combo, TRUE, TRUE, 0); | |
1152 gtk_widget_show(dd->filter_combo); | |
1153 | |
1154 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
1155 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
512
diff
changeset
|
1156 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
475
diff
changeset
|
1157 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); |
9 | 1158 if (paned) |
1159 { | |
1160 gtk_paned_add2(GTK_PANED(paned), scrolled); | |
1161 } | |
1162 else | |
1163 { | |
1164 gtk_table_attach(GTK_TABLE(table), scrolled, 2, 3, 1, 2, | |
1165 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); | |
1166 } | |
1167 gtk_widget_show(scrolled); | |
1168 | |
1169 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); | |
1170 dd->f_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
1171 g_object_unref(store); | |
1172 | |
1173 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(dd->f_view), PATH_SEL_USE_HEADINGS); | |
1174 | |
1175 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dd->f_view)); | |
1176 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_SINGLE); | |
1177 | |
1178 column = gtk_tree_view_column_new(); | |
1179 gtk_tree_view_column_set_title(column, _("Files")); | |
1180 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
1181 | |
1182 renderer = gtk_cell_renderer_text_new(); | |
1183 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1184 gtk_tree_view_column_add_attribute(column, renderer, "text", 0); | |
1185 | |
1186 gtk_tree_view_append_column(GTK_TREE_VIEW(dd->f_view), column); | |
1187 | |
1188 gtk_widget_set_size_request(dd->f_view, DEST_WIDTH, DEST_HEIGHT); | |
1189 gtk_container_add(GTK_CONTAINER(scrolled), dd->f_view); | |
1190 gtk_widget_show(dd->f_view); | |
1191 | |
1192 g_signal_connect(G_OBJECT(dd->f_view), "button_press_event", | |
1193 G_CALLBACK(dest_press_cb), dd); | |
1194 g_signal_connect(G_OBJECT(dd->f_view), "key_press_event", | |
1195 G_CALLBACK(dest_keypress_cb), dd); | |
1196 g_signal_connect(G_OBJECT(dd->f_view), "row_activated", | |
1197 G_CALLBACK(dest_activate_cb), dd); | |
1198 g_signal_connect(selection, "changed", | |
1199 G_CALLBACK(dest_select_cb), dd); | |
1200 | |
1201 dest_filter_clear(dd); | |
1202 dest_filter_add(dd, filter, filter_desc, TRUE); | |
1203 | |
1204 dd->filter = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_BIN(dd->filter_combo)->child))); | |
1205 } | |
1206 | |
726 | 1207 if (path && path[0] == G_DIR_SEPARATOR && isdir(path)) |
9 | 1208 { |
1209 dest_populate(dd, path); | |
1210 } | |
1211 else | |
1212 { | |
1213 gchar *buf = remove_level_from_path(path); | |
725 | 1214 if (buf && buf[0] == G_DIR_SEPARATOR && isdir(buf)) |
9 | 1215 { |
1216 dest_populate(dd, buf); | |
1217 } | |
1218 else | |
1219 { | |
1220 gint pos = -1; | |
1221 | |
1222 dest_populate(dd, (gchar *)homedir()); | |
725 | 1223 if (path) gtk_editable_insert_text(GTK_EDITABLE(dd->entry), G_DIR_SEPARATOR_S, -1, &pos); |
9 | 1224 if (path) gtk_editable_insert_text(GTK_EDITABLE(dd->entry), path, -1, &pos); |
1225 } | |
1226 g_free(buf); | |
1227 } | |
1228 | |
1229 if (dd->filter_combo) | |
1230 { | |
1231 g_signal_connect(G_OBJECT(GTK_BIN(dd->filter_combo)->child), "changed", | |
1232 G_CALLBACK(dest_filter_changed_cb), dd); | |
1233 } | |
1234 g_signal_connect(G_OBJECT(dd->entry), "changed", | |
1235 G_CALLBACK(dest_entry_changed_cb), dd); | |
1236 | |
1237 dest_dnd_init(dd); | |
1238 | |
1239 return table; | |
1240 } | |
1241 | |
1242 GtkWidget *path_selection_new(const gchar *path, GtkWidget *entry) | |
1243 { | |
1244 return path_selection_new_with_files(entry, path, NULL, NULL); | |
1245 } | |
1246 | |
1247 void path_selection_sync_to_entry(GtkWidget *entry) | |
1248 { | |
1249 Dest_Data *dd = g_object_get_data(G_OBJECT(entry), "destination_data"); | |
1250 const gchar *path; | |
1251 | |
1252 if (!dd) return; | |
1253 | |
1254 path = gtk_entry_get_text(GTK_ENTRY(entry)); | |
442 | 1255 |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1256 if (isdir(path) && (!dd->path || strcmp(path, dd->path) != 0)) |
9 | 1257 { |
1258 dest_populate(dd, path); | |
1259 } | |
1260 else | |
1261 { | |
1262 gchar *buf = remove_level_from_path(path); | |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1263 if (isdir(buf) && (!dd->path || strcmp(buf, dd->path) != 0)) |
9 | 1264 { |
1265 dest_populate(dd, buf); | |
1266 } | |
1267 g_free(buf); | |
1268 } | |
1269 } | |
1270 | |
1271 void path_selection_add_select_func(GtkWidget *entry, | |
1272 void (*func)(const gchar *, gpointer), gpointer data) | |
1273 { | |
1274 Dest_Data *dd = g_object_get_data(G_OBJECT(entry), "destination_data"); | |
1275 | |
1276 if (!dd) return; | |
1277 | |
1278 dd->select_func = func; | |
1279 dd->select_data = data; | |
1280 } | |
1281 | |
1448 | 1282 void path_selection_add_filter(GtkWidget *entry, const gchar *filter, const gchar *description, gboolean set) |
9 | 1283 { |
1284 Dest_Data *dd = g_object_get_data(G_OBJECT(entry), "destination_data"); | |
1285 | |
1286 if (!dd) return; | |
1287 if (!filter) return; | |
1288 | |
1289 dest_filter_add(dd, filter, description, set); | |
1290 } | |
1291 | |
1292 void path_selection_clear_filter(GtkWidget *entry) | |
1293 { | |
1294 Dest_Data *dd = g_object_get_data(G_OBJECT(entry), "destination_data"); | |
1295 | |
1296 if (!dd) return; | |
1297 | |
1298 dest_filter_clear(dd); | |
1299 } | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1002
diff
changeset
|
1300 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |