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