Mercurial > geeqie.yaz
annotate src/ui_pathsel.c @ 653:e06947d07086
Expand tilde with file: and view: remote parameters.
Now these are working:
geeqie -r file:~/dir
geeqie -r view:~user/file
author | zas_ |
---|---|
date | Tue, 13 May 2008 16:09:43 +0000 |
parents | 651ae2be1031 |
children | e07895754e65 |
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 |
475 | 4 * Copyright (C) 2008 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" | |
42 | |
43 | |
44 #define DEST_WIDTH 250 | |
45 #define DEST_HEIGHT 210 | |
46 | |
47 #define RENAME_PRESS_DELAY 333 /* 1/3 second, to allow double clicks */ | |
48 | |
49 #define PATH_SEL_USE_HEADINGS FALSE | |
50 | |
51 enum { | |
52 FILTER_COLUMN_NAME = 0, | |
53 FILTER_COLUMN_FILTER | |
54 }; | |
55 | |
56 typedef struct _Dest_Data Dest_Data; | |
57 struct _Dest_Data | |
58 { | |
59 GtkWidget *d_view; | |
60 GtkWidget *f_view; | |
61 GtkWidget *entry; | |
62 gchar *filter; | |
63 gchar *path; | |
64 | |
65 GList *filter_list; | |
66 GList *filter_text_list; | |
67 GtkWidget *filter_combo; | |
68 | |
69 gint show_hidden; | |
70 GtkWidget *hidden_button; | |
71 | |
72 GtkWidget *bookmark_list; | |
73 | |
74 GtkTreePath *right_click_path; | |
75 | |
76 void (*select_func)(const gchar *path, gpointer data); | |
77 gpointer select_data; | |
78 | |
79 GenericDialog *gd; /* any open confirm dialogs ? */ | |
80 }; | |
81 | |
82 typedef struct _DestDel_Data DestDel_Data; | |
83 struct _DestDel_Data | |
84 { | |
85 Dest_Data *dd; | |
86 gchar *path; | |
87 }; | |
88 | |
89 | |
90 static void dest_view_delete_dlg_cancel(GenericDialog *gd, gpointer data); | |
91 | |
92 | |
93 /* | |
94 *----------------------------------------------------------------------------- | |
95 * (private) | |
96 *----------------------------------------------------------------------------- | |
442 | 97 */ |
9 | 98 |
99 static void dest_free_data(GtkWidget *widget, gpointer data) | |
100 { | |
101 Dest_Data *dd = data; | |
102 | |
103 if (dd->gd) | |
104 { | |
105 GenericDialog *gd = dd->gd; | |
106 dest_view_delete_dlg_cancel(dd->gd, dd->gd->data); | |
107 generic_dialog_close(gd); | |
108 } | |
109 if (dd->right_click_path) gtk_tree_path_free(dd->right_click_path); | |
110 | |
111 g_free(dd->filter); | |
112 g_free(dd->path); | |
113 g_free(dd); | |
114 } | |
115 | |
116 static gint dest_check_filter(const gchar *filter, const gchar *file) | |
117 { | |
118 const gchar *f_ptr = filter; | |
119 const gchar *strt_ptr; | |
120 gint i; | |
121 gint l; | |
122 | |
123 l = strlen(file); | |
124 | |
125 if (filter[0] == '*') return TRUE; | |
126 while (f_ptr < filter + strlen(filter)) | |
127 { | |
128 strt_ptr = f_ptr; | |
129 i=0; | |
130 while (*f_ptr != ';' && *f_ptr != '\0') | |
131 { | |
132 f_ptr++; | |
133 i++; | |
134 } | |
135 if (*f_ptr != '\0' && f_ptr[1] == ' ') f_ptr++; /* skip space immediately after separator */ | |
136 f_ptr++; | |
605
651ae2be1031
Use g_ascii_strncasecmp() instead of strncasecmp() where applicable.
zas_
parents:
576
diff
changeset
|
137 /* FIXME: utf8 */ |
9 | 138 if (l >= i && strncasecmp(file + l - i, strt_ptr, i) == 0) return TRUE; |
139 } | |
140 return FALSE; | |
141 } | |
142 | |
143 #ifndef CASE_SORT | |
144 #define CASE_SORT strcmp | |
145 #endif | |
146 | |
147 static gint dest_sort_cb(void *a, void *b) | |
148 { | |
149 return CASE_SORT((gchar *)a, (gchar *)b); | |
150 } | |
151 | |
152 static gint is_hidden(const gchar *name) | |
153 { | |
154 if (name[0] != '.') return FALSE; | |
155 if (name[1] == '\0') return FALSE; | |
156 if (name[1] == '.' && name[2] == '\0') return FALSE; | |
157 return TRUE; | |
158 } | |
159 | |
160 static void dest_populate(Dest_Data *dd, const gchar *path) | |
161 { | |
162 DIR *dp; | |
163 struct dirent *dir; | |
164 struct stat ent_sbuf; | |
165 GList *path_list = NULL; | |
166 GList *file_list = NULL; | |
167 GList *list; | |
168 GtkListStore *store; | |
169 gchar *pathl; | |
170 | |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
171 if (!path) return; |
9 | 172 |
173 pathl = path_from_utf8(path); | |
174 dp = opendir(pathl); | |
175 if (!dp) | |
176 { | |
177 /* dir not found */ | |
178 g_free(pathl); | |
179 return; | |
180 } | |
181 while ((dir = readdir(dp)) != NULL) | |
182 { | |
373
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
281
diff
changeset
|
183 if (!options->file_filter.show_dot_directory |
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
281
diff
changeset
|
184 && dir->d_name[0] == '.' && dir->d_name[1] == '\0') |
442 | 185 continue; |
373
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
281
diff
changeset
|
186 if (dir->d_name[0] == '.' && dir->d_name[1] == '.' && dir->d_name[2] == '\0' |
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
281
diff
changeset
|
187 && pathl[0] == '/' && pathl[1] == '\0') |
442 | 188 continue; /* no .. for root directory */ |
69
31759d770628
Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
189 if (dd->show_hidden || !is_hidden(dir->d_name)) |
9 | 190 { |
191 gchar *name = dir->d_name; | |
192 gchar *filepath = g_strconcat(pathl, "/", name, NULL); | |
193 if (stat(filepath, &ent_sbuf) >= 0 && S_ISDIR(ent_sbuf.st_mode)) | |
194 { | |
195 path_list = g_list_prepend(path_list, path_to_utf8(name)); | |
196 } | |
197 else if (dd->f_view) | |
198 { | |
199 if (!dd->filter || (dd->filter && dest_check_filter(dd->filter, name))) | |
200 file_list = g_list_prepend(file_list, path_to_utf8(name)); | |
201 } | |
202 g_free(filepath); | |
203 } | |
204 } | |
205 closedir(dp); | |
206 g_free(pathl); | |
207 | |
208 path_list = g_list_sort(path_list, (GCompareFunc) dest_sort_cb); | |
209 file_list = g_list_sort(file_list, (GCompareFunc) dest_sort_cb); | |
210 | |
211 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dd->d_view))); | |
212 gtk_list_store_clear(store); | |
213 | |
214 list = path_list; | |
215 while (list) | |
216 { | |
217 GtkTreeIter iter; | |
218 gchar *filepath; | |
219 | |
220 if (strcmp(list->data, ".") == 0) | |
221 { | |
222 filepath = g_strdup(path); | |
223 } | |
224 else if (strcmp(list->data, "..") == 0) | |
225 { | |
226 gchar *p; | |
227 filepath = g_strdup(path); | |
228 p = (gchar *)filename_from_path(filepath); | |
229 if (p - 1 != filepath) p--; | |
230 p[0] = '\0'; | |
231 } | |
232 else | |
233 { | |
234 filepath = concat_dir_and_file(path, list->data); | |
235 } | |
442 | 236 |
9 | 237 gtk_list_store_append(store, &iter); |
238 gtk_list_store_set(store, &iter, 0, list->data, 1, filepath, -1); | |
239 | |
240 g_free(filepath); | |
241 list = list->next; | |
242 } | |
243 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
513
diff
changeset
|
244 string_list_free(path_list); |
9 | 245 |
246 | |
247 if (dd->f_view) | |
248 { | |
249 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dd->f_view))); | |
250 gtk_list_store_clear(store); | |
251 | |
252 list = file_list; | |
253 while (list) | |
442 | 254 { |
9 | 255 GtkTreeIter iter; |
256 gchar *filepath; | |
257 const gchar *name = list->data; | |
258 | |
259 filepath = concat_dir_and_file(path, name); | |
442 | 260 |
9 | 261 gtk_list_store_append(store, &iter); |
262 gtk_list_store_set(store, &iter, 0, name, 1, filepath, -1); | |
263 | |
264 g_free(filepath); | |
265 list = list->next; | |
266 } | |
267 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
513
diff
changeset
|
268 string_list_free(file_list); |
9 | 269 } |
270 | |
271 g_free(dd->path); | |
272 dd->path = g_strdup(path); | |
273 } | |
274 | |
275 static void dest_change_dir(Dest_Data *dd, const gchar *path, gint retain_name) | |
276 { | |
277 gchar *old_name = NULL; | |
278 gint s = 0; | |
279 | |
280 if (retain_name) | |
281 { | |
282 const gchar *buf = gtk_entry_get_text(GTK_ENTRY(dd->entry)); | |
283 if (!isdir(buf)) | |
284 { | |
285 if (path && strcmp(path, "/") == 0) | |
286 { | |
287 old_name = g_strdup(filename_from_path(buf)); | |
288 } | |
289 else | |
290 { | |
291 old_name = g_strconcat("/", filename_from_path(buf), NULL); | |
292 s = 1; | |
293 } | |
294 } | |
295 } | |
296 | |
297 gtk_entry_set_text(GTK_ENTRY(dd->entry), path); | |
298 | |
299 dest_populate(dd, path); | |
300 | |
301 /* remember filename */ | |
302 if (old_name) | |
303 { | |
304 gint pos = -1; | |
305 gtk_editable_insert_text(GTK_EDITABLE(dd->entry), old_name, -1, &pos); | |
306 gtk_editable_select_region(GTK_EDITABLE(dd->entry), strlen(path) + s, strlen(path) + strlen(old_name)); | |
307 g_free(old_name); | |
308 } | |
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); | |
427 new_path = concat_dir_and_file(buf, new); | |
428 g_free(buf); | |
429 | |
430 if (isname(new_path)) | |
431 { | |
432 buf = g_strdup_printf(_("A file with name %s already exists."), new); | |
433 warning_dialog("Rename failed", buf, GTK_STOCK_DIALOG_INFO, dd->entry); | |
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); | |
439 warning_dialog("Rename failed", buf, GTK_STOCK_DIALOG_ERROR, dd->entry); | |
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 | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
138
diff
changeset
|
537 dd->gd = generic_dialog_new(_("Delete file"), GQ_WMCLASS, "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 | |
611 static gint dest_popup_menu(Dest_Data *dd, GtkTreeView *view, | |
612 gint button, guint32 time, gint local) | |
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; | |
623 gint normal_dir; | |
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 | |
664 static gint dest_press_cb(GtkWidget *view, GdkEventButton *event, gpointer data) | |
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; | |
738 gint from_text = FALSE; | |
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 { | |
748 buf = concat_dir_and_file(dd->path, _("New folder")); | |
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 | |
934 static void dest_filter_add(Dest_Data *dd, const gchar *filter, const gchar *description, gint set) | |
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 dd->show_hidden = FALSE; | |
1037 dd->select_func = NULL; | |
1038 dd->select_data = NULL; | |
1039 dd->gd = NULL; | |
1040 | |
1041 table = gtk_table_new(4, (filter != NULL) ? 3 : 1, FALSE); | |
1042 gtk_table_set_col_spacings(GTK_TABLE(table), PREF_PAD_GAP); | |
1043 gtk_table_set_row_spacing(GTK_TABLE(table), 0, PREF_PAD_GAP); | |
1044 gtk_widget_show(table); | |
1045 | |
1046 dd->entry = entry; | |
1047 g_object_set_data(G_OBJECT(dd->entry), "destination_data", dd); | |
1048 | |
1049 hbox2 = pref_table_box(table, 0, 0, GTK_ORIENTATION_HORIZONTAL, NULL); | |
1050 gtk_box_set_spacing(GTK_BOX(hbox2), PREF_PAD_BUTTON_GAP); | |
1051 pref_button_new(hbox2, NULL, _("Home"), FALSE, | |
1052 G_CALLBACK(dest_home_cb), dd); | |
1053 pref_button_new(hbox2, NULL, _("New folder"), FALSE, | |
1054 G_CALLBACK(dest_new_dir_cb), dd); | |
1055 | |
1056 dd->hidden_button = gtk_check_button_new_with_label(_("Show hidden")); | |
1057 g_signal_connect(G_OBJECT(dd->hidden_button), "clicked", | |
1058 G_CALLBACK(dest_show_hidden_cb), dd); | |
1059 gtk_box_pack_end(GTK_BOX(hbox2), dd->hidden_button, FALSE, FALSE, 0); | |
1060 gtk_widget_show(dd->hidden_button); | |
1061 | |
1062 hbox2 = gtk_hbox_new(FALSE, PREF_PAD_GAP); | |
1063 if (filter) | |
1064 { | |
1065 paned = gtk_hpaned_new(); | |
1066 gtk_table_attach(GTK_TABLE(table), paned, 0, 3, 1, 2, | |
1067 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); | |
1068 gtk_widget_show(paned); | |
1069 gtk_paned_add1(GTK_PANED(paned), hbox2); | |
1070 } | |
1071 else | |
1072 { | |
1073 paned = NULL; | |
1074 gtk_table_attach(GTK_TABLE(table), hbox2, 0, 1, 1, 2, | |
1075 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); | |
1076 } | |
1077 gtk_widget_show(hbox2); | |
1078 | |
1079 /* bookmarks */ | |
1080 scrolled = bookmark_list_new(NULL, dest_bookmark_select_cb, dd); | |
1081 gtk_box_pack_start(GTK_BOX(hbox2), scrolled, FALSE, FALSE, 0); | |
1082 gtk_widget_show(scrolled); | |
1083 | |
1084 dd->bookmark_list = scrolled; | |
1085 | |
1086 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
1087 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
|
1088 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
|
1089 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); |
9 | 1090 gtk_box_pack_start(GTK_BOX(hbox2), scrolled, TRUE, TRUE, 0); |
1091 gtk_widget_show(scrolled); | |
1092 | |
1093 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); | |
1094 dd->d_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
1095 g_object_unref(store); | |
1096 | |
1097 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(dd->d_view), PATH_SEL_USE_HEADINGS); | |
1098 | |
1099 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dd->d_view)); | |
1100 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_SINGLE); | |
1101 | |
1102 column = gtk_tree_view_column_new(); | |
1103 gtk_tree_view_column_set_title(column, _("Folders")); | |
1104 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
1105 | |
1106 renderer = gtk_cell_renderer_text_new(); | |
1107 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1108 gtk_tree_view_column_add_attribute(column, renderer, "text", 0); | |
1109 | |
1110 gtk_tree_view_append_column(GTK_TREE_VIEW(dd->d_view), column); | |
1111 | |
1112 #if 0 | |
1113 /* only for debugging */ | |
1114 column = gtk_tree_view_column_new(); | |
1115 gtk_tree_view_column_set_title(column, _("Path")); | |
1116 renderer = gtk_cell_renderer_text_new(); | |
1117 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1118 gtk_tree_view_column_add_attribute(column, renderer, "text", 1); | |
1119 gtk_tree_view_append_column(GTK_TREE_VIEW(dd->d_view), column); | |
1120 #endif | |
1121 | |
1122 gtk_widget_set_size_request(dd->d_view, DEST_WIDTH, DEST_HEIGHT); | |
1123 gtk_container_add(GTK_CONTAINER(scrolled), dd->d_view); | |
1124 gtk_widget_show(dd->d_view); | |
1125 | |
1126 g_signal_connect(G_OBJECT(dd->d_view), "button_press_event", | |
1127 G_CALLBACK(dest_press_cb), dd); | |
1128 g_signal_connect(G_OBJECT(dd->d_view), "key_press_event", | |
1129 G_CALLBACK(dest_keypress_cb), dd); | |
1130 g_signal_connect(G_OBJECT(dd->d_view), "row_activated", | |
1131 G_CALLBACK(dest_activate_cb), dd); | |
1132 g_signal_connect(G_OBJECT(dd->d_view), "destroy", | |
1133 G_CALLBACK(dest_free_data), dd); | |
442 | 1134 |
9 | 1135 if (filter) |
1136 { | |
1137 GtkListStore *store; | |
1138 | |
1139 hbox2 = pref_table_box(table, 2, 0, GTK_ORIENTATION_HORIZONTAL, NULL); | |
1140 pref_label_new(hbox2, _("Filter:")); | |
1141 | |
1142 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); | |
1143 | |
1144 dd->filter_combo = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(store), | |
1145 FILTER_COLUMN_FILTER); | |
1146 g_object_unref(store); | |
1147 gtk_cell_layout_clear(GTK_CELL_LAYOUT(dd->filter_combo)); | |
1148 renderer = gtk_cell_renderer_text_new(); | |
1149 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dd->filter_combo), renderer, TRUE); | |
1150 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dd->filter_combo), renderer, | |
1151 "text", FILTER_COLUMN_NAME, NULL); | |
1152 #if 0 | |
1153 gtk_combo_set_case_sensitive(GTK_COMBO(dd->filter_combo), TRUE); | |
1154 #endif | |
1155 gtk_box_pack_start(GTK_BOX(hbox2), dd->filter_combo, TRUE, TRUE, 0); | |
1156 gtk_widget_show(dd->filter_combo); | |
1157 | |
1158 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
1159 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
|
1160 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
|
1161 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); |
9 | 1162 if (paned) |
1163 { | |
1164 gtk_paned_add2(GTK_PANED(paned), scrolled); | |
1165 } | |
1166 else | |
1167 { | |
1168 gtk_table_attach(GTK_TABLE(table), scrolled, 2, 3, 1, 2, | |
1169 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); | |
1170 } | |
1171 gtk_widget_show(scrolled); | |
1172 | |
1173 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); | |
1174 dd->f_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
1175 g_object_unref(store); | |
1176 | |
1177 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(dd->f_view), PATH_SEL_USE_HEADINGS); | |
1178 | |
1179 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dd->f_view)); | |
1180 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_SINGLE); | |
1181 | |
1182 column = gtk_tree_view_column_new(); | |
1183 gtk_tree_view_column_set_title(column, _("Files")); | |
1184 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
1185 | |
1186 renderer = gtk_cell_renderer_text_new(); | |
1187 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1188 gtk_tree_view_column_add_attribute(column, renderer, "text", 0); | |
1189 | |
1190 gtk_tree_view_append_column(GTK_TREE_VIEW(dd->f_view), column); | |
1191 | |
1192 gtk_widget_set_size_request(dd->f_view, DEST_WIDTH, DEST_HEIGHT); | |
1193 gtk_container_add(GTK_CONTAINER(scrolled), dd->f_view); | |
1194 gtk_widget_show(dd->f_view); | |
1195 | |
1196 g_signal_connect(G_OBJECT(dd->f_view), "button_press_event", | |
1197 G_CALLBACK(dest_press_cb), dd); | |
1198 g_signal_connect(G_OBJECT(dd->f_view), "key_press_event", | |
1199 G_CALLBACK(dest_keypress_cb), dd); | |
1200 g_signal_connect(G_OBJECT(dd->f_view), "row_activated", | |
1201 G_CALLBACK(dest_activate_cb), dd); | |
1202 g_signal_connect(selection, "changed", | |
1203 G_CALLBACK(dest_select_cb), dd); | |
1204 | |
1205 dest_filter_clear(dd); | |
1206 dest_filter_add(dd, filter, filter_desc, TRUE); | |
1207 | |
1208 dd->filter = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_BIN(dd->filter_combo)->child))); | |
1209 } | |
1210 | |
1211 if (path && path[0] == '/' && isdir(path)) | |
1212 { | |
1213 dest_populate(dd, path); | |
1214 } | |
1215 else | |
1216 { | |
1217 gchar *buf = remove_level_from_path(path); | |
1218 if (buf && buf[0] == '/' && isdir(buf)) | |
1219 { | |
1220 dest_populate(dd, buf); | |
1221 } | |
1222 else | |
1223 { | |
1224 gint pos = -1; | |
1225 | |
1226 dest_populate(dd, (gchar *)homedir()); | |
1227 if (path) gtk_editable_insert_text(GTK_EDITABLE(dd->entry), "/", -1, &pos); | |
1228 if (path) gtk_editable_insert_text(GTK_EDITABLE(dd->entry), path, -1, &pos); | |
1229 } | |
1230 g_free(buf); | |
1231 } | |
1232 | |
1233 if (dd->filter_combo) | |
1234 { | |
1235 g_signal_connect(G_OBJECT(GTK_BIN(dd->filter_combo)->child), "changed", | |
1236 G_CALLBACK(dest_filter_changed_cb), dd); | |
1237 } | |
1238 g_signal_connect(G_OBJECT(dd->entry), "changed", | |
1239 G_CALLBACK(dest_entry_changed_cb), dd); | |
1240 | |
1241 dest_dnd_init(dd); | |
1242 | |
1243 return table; | |
1244 } | |
1245 | |
1246 GtkWidget *path_selection_new(const gchar *path, GtkWidget *entry) | |
1247 { | |
1248 return path_selection_new_with_files(entry, path, NULL, NULL); | |
1249 } | |
1250 | |
1251 void path_selection_sync_to_entry(GtkWidget *entry) | |
1252 { | |
1253 Dest_Data *dd = g_object_get_data(G_OBJECT(entry), "destination_data"); | |
1254 const gchar *path; | |
1255 | |
1256 if (!dd) return; | |
1257 | |
1258 path = gtk_entry_get_text(GTK_ENTRY(entry)); | |
442 | 1259 |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1260 if (isdir(path) && (!dd->path || strcmp(path, dd->path) != 0)) |
9 | 1261 { |
1262 dest_populate(dd, path); | |
1263 } | |
1264 else | |
1265 { | |
1266 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
|
1267 if (isdir(buf) && (!dd->path || strcmp(buf, dd->path) != 0)) |
9 | 1268 { |
1269 dest_populate(dd, buf); | |
1270 } | |
1271 g_free(buf); | |
1272 } | |
1273 } | |
1274 | |
1275 void path_selection_add_select_func(GtkWidget *entry, | |
1276 void (*func)(const gchar *, gpointer), gpointer data) | |
1277 { | |
1278 Dest_Data *dd = g_object_get_data(G_OBJECT(entry), "destination_data"); | |
1279 | |
1280 if (!dd) return; | |
1281 | |
1282 dd->select_func = func; | |
1283 dd->select_data = data; | |
1284 } | |
1285 | |
1286 void path_selection_add_filter(GtkWidget *entry, const gchar *filter, const gchar *description, gint set) | |
1287 { | |
1288 Dest_Data *dd = g_object_get_data(G_OBJECT(entry), "destination_data"); | |
1289 | |
1290 if (!dd) return; | |
1291 if (!filter) return; | |
1292 | |
1293 dest_filter_add(dd, filter, description, set); | |
1294 } | |
1295 | |
1296 void path_selection_clear_filter(GtkWidget *entry) | |
1297 { | |
1298 Dest_Data *dd = g_object_get_data(G_OBJECT(entry), "destination_data"); | |
1299 | |
1300 if (!dd) return; | |
1301 | |
1302 dest_filter_clear(dd); | |
1303 } |