Mercurial > geeqie.yaz
annotate src/ui_pathsel.c @ 764:ae618ebec3e9
Save properties window width and height to rc file and restore
them on next session if layout.save_window_positions is set to TRUE.
author | zas_ |
---|---|
date | Thu, 29 May 2008 07:52:05 +0000 |
parents | a1dcef8cd1ae |
children | 1698baa37871 |
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' |
726 | 187 && pathl[0] == G_DIR_SEPARATOR && 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; | |
717 | 192 gchar *filepath = g_build_filename(pathl, name, NULL); |
9 | 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 { | |
702
e07895754e65
Drop concat_dir_and_file() and use g_build_filename() instead.
zas_
parents:
605
diff
changeset
|
234 filepath = g_build_filename(path, list->data, NULL); |
9 | 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 | |
702
e07895754e65
Drop concat_dir_and_file() and use g_build_filename() instead.
zas_
parents:
605
diff
changeset
|
259 filepath = g_build_filename(path, name, NULL); |
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 { | |
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
|
277 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
|
278 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
|
279 gchar *new_directory; |
9 | 280 |
281 if (retain_name) | |
282 { | |
283 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
|
284 |
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 if (!isdir(buf)) old_name = filename_from_path(buf); |
9 | 286 } |
287 | |
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
|
288 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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 |
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 gtk_entry_set_text(GTK_ENTRY(dd->entry), full_path); |
9 | 295 |
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
|
296 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
|
297 g_free(new_directory); |
9 | 298 |
299 if (old_name) | |
300 { | |
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
|
301 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
|
302 |
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 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
|
304 g_free(basename); |
9 | 305 } |
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
|
306 |
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 g_free(full_path); |
9 | 308 } |
309 | |
310 /* | |
311 *----------------------------------------------------------------------------- | |
312 * drag and drop | |
313 *----------------------------------------------------------------------------- | |
314 */ | |
315 | |
316 enum { | |
317 TARGET_URI_LIST, | |
318 TARGET_TEXT_PLAIN | |
319 }; | |
320 | |
321 static GtkTargetEntry dest_drag_types[] = { | |
322 { "text/uri-list", 0, TARGET_URI_LIST }, | |
323 { "text/plain", 0, TARGET_TEXT_PLAIN } | |
324 }; | |
325 #define dest_drag_types_n 2 | |
326 | |
327 | |
328 static void dest_dnd_set_data(GtkWidget *view, | |
329 GdkDragContext *context, GtkSelectionData *selection_data, | |
330 guint info, guint time, gpointer data) | |
331 { | |
332 gchar *path = NULL; | |
333 gchar *uri_text = NULL; | |
334 GList *list = NULL; | |
335 gint length = 0; | |
336 GtkTreeModel *model; | |
337 GtkTreeSelection *selection; | |
338 GtkTreeIter iter; | |
339 | |
340 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); | |
341 if (!gtk_tree_selection_get_selected(selection, &model, &iter)) return; | |
342 | |
343 gtk_tree_model_get(model, &iter, 1, &path, -1); | |
344 if (!path) return; | |
345 | |
346 list = g_list_append(list, path); | |
347 | |
348 switch (info) | |
349 { | |
350 case TARGET_URI_LIST: | |
351 uri_text = uri_text_from_list(list, &length, FALSE); | |
352 break; | |
353 case TARGET_TEXT_PLAIN: | |
354 uri_text = uri_text_from_list(list, &length, TRUE); | |
355 break; | |
356 } | |
357 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
513
diff
changeset
|
358 string_list_free(list); |
9 | 359 |
360 if (!uri_text) return; | |
361 | |
362 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
|
363 8, (guchar *)uri_text, length); |
9 | 364 g_free(uri_text); |
365 } | |
366 | |
367 static void dest_dnd_init(Dest_Data *dd) | |
368 { | |
369 gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(dd->d_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->d_view), "drag_data_get", | |
373 G_CALLBACK(dest_dnd_set_data), dd); | |
374 | |
375 if (dd->f_view) | |
376 { | |
377 gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(dd->f_view), GDK_BUTTON1_MASK, | |
378 dest_drag_types, dest_drag_types_n, | |
379 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK); | |
380 g_signal_connect(G_OBJECT(dd->f_view), "drag_data_get", | |
381 G_CALLBACK(dest_dnd_set_data), dd); | |
382 } | |
383 } | |
384 | |
385 | |
386 /* | |
387 *----------------------------------------------------------------------------- | |
388 * destination widget file management utils | |
389 *----------------------------------------------------------------------------- | |
390 */ | |
391 | |
392 static void dest_view_store_selection(Dest_Data *dd, GtkTreeView *view) | |
393 { | |
394 GtkTreeModel *model; | |
395 GtkTreeSelection *selection; | |
396 GtkTreeIter iter; | |
397 | |
398 if (dd->right_click_path) gtk_tree_path_free(dd->right_click_path); | |
399 dd->right_click_path = NULL; | |
400 | |
401 selection = gtk_tree_view_get_selection(view); | |
402 if (!gtk_tree_selection_get_selected(selection, &model, &iter)) | |
403 { | |
404 return; | |
405 } | |
406 | |
407 dd->right_click_path = gtk_tree_model_get_path(model, &iter); | |
408 } | |
409 | |
410 static gint dest_view_rename_cb(TreeEditData *ted, const gchar *old, const gchar *new, gpointer data) | |
411 { | |
412 Dest_Data *dd = data; | |
413 GtkTreeModel *model; | |
414 GtkTreeIter iter; | |
415 gchar *buf; | |
416 gchar *old_path; | |
417 gchar *new_path; | |
418 | |
419 model = gtk_tree_view_get_model(GTK_TREE_VIEW(ted->tree)); | |
420 gtk_tree_model_get_iter(model, &iter, dd->right_click_path); | |
421 | |
422 gtk_tree_model_get(model, &iter, 1, &old_path, -1); | |
423 if (!old_path) return FALSE; | |
424 | |
425 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
|
426 new_path = g_build_filename(buf, new, NULL); |
9 | 427 g_free(buf); |
428 | |
429 if (isname(new_path)) | |
430 { | |
431 buf = g_strdup_printf(_("A file with name %s already exists."), new); | |
432 warning_dialog("Rename failed", buf, GTK_STOCK_DIALOG_INFO, dd->entry); | |
433 g_free(buf); | |
434 } | |
435 else if (!rename_file(old_path, new_path)) | |
436 { | |
437 buf = g_strdup_printf(_("Failed to rename %s to %s."), old, new); | |
438 warning_dialog("Rename failed", buf, GTK_STOCK_DIALOG_ERROR, dd->entry); | |
439 g_free(buf); | |
440 } | |
441 else | |
442 { | |
443 const gchar *text; | |
444 | |
445 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, new, 1, new_path, -1); | |
446 | |
447 text = gtk_entry_get_text(GTK_ENTRY(dd->entry)); | |
448 if (text && old_path && strcmp(text, old_path) == 0) | |
449 { | |
450 gtk_entry_set_text(GTK_ENTRY(dd->entry), new_path); | |
451 } | |
452 } | |
453 | |
454 g_free(old_path); | |
455 g_free(new_path); | |
456 | |
457 return TRUE; | |
458 } | |
459 | |
460 static void dest_view_rename(Dest_Data *dd, GtkTreeView *view) | |
461 { | |
462 GtkTreeModel *model; | |
463 GtkTreeIter iter; | |
464 gchar *text; | |
465 | |
466 if (!dd->right_click_path) return; | |
467 | |
468 model = gtk_tree_view_get_model(view); | |
469 gtk_tree_model_get_iter(model, &iter, dd->right_click_path); | |
470 gtk_tree_model_get(model, &iter, 0, &text, -1); | |
471 | |
472 tree_edit_by_path(view, dd->right_click_path, 0, text, | |
473 dest_view_rename_cb, dd); | |
474 | |
475 g_free(text); | |
476 } | |
477 | |
478 static void dest_view_delete_dlg_cancel(GenericDialog *gd, gpointer data) | |
479 { | |
480 DestDel_Data *dl = data; | |
481 | |
482 dl->dd->gd = NULL; | |
483 g_free(dl->path); | |
484 g_free(dl); | |
485 } | |
486 | |
487 static void dest_view_delete_dlg_ok_cb(GenericDialog *gd, gpointer data) | |
488 { | |
489 DestDel_Data *dl = data; | |
490 | |
491 if (!unlink_file(dl->path)) | |
492 { | |
493 gchar *text = g_strdup_printf(_("Unable to delete file:\n%s"), dl->path); | |
494 warning_dialog(_("File deletion failed"), text, GTK_STOCK_DIALOG_WARNING, dl->dd->entry); | |
495 g_free(text); | |
496 } | |
497 else if (dl->dd->path) | |
498 { | |
499 /* refresh list */ | |
500 gchar *path = g_strdup(dl->dd->path); | |
501 dest_populate(dl->dd, path); | |
502 g_free(path); | |
503 } | |
504 | |
505 dest_view_delete_dlg_cancel(gd, data); | |
506 } | |
507 | |
508 static void dest_view_delete(Dest_Data *dd, GtkTreeView *view) | |
509 { | |
510 gchar *path; | |
511 gchar *text; | |
512 DestDel_Data *dl; | |
513 GtkTreeModel *model; | |
514 GtkTreeIter iter; | |
515 | |
516 if (view != GTK_TREE_VIEW(dd->f_view)) return; | |
517 if (!dd->right_click_path) return; | |
518 | |
519 model = gtk_tree_view_get_model(view); | |
520 gtk_tree_model_get_iter(model, &iter, dd->right_click_path); | |
521 gtk_tree_model_get(model, &iter, 1, &path, -1); | |
442 | 522 |
9 | 523 if (!path) return; |
524 | |
525 dl = g_new(DestDel_Data, 1); | |
526 dl->dd = dd; | |
527 dl->path = path; | |
528 | |
529 if (dd->gd) | |
530 { | |
531 GenericDialog *gd = dd->gd; | |
532 dest_view_delete_dlg_cancel(dd->gd, dd->gd->data); | |
533 generic_dialog_close(gd); | |
534 } | |
535 | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
138
diff
changeset
|
536 dd->gd = generic_dialog_new(_("Delete file"), GQ_WMCLASS, "dlg_confirm", |
9 | 537 dd->entry, TRUE, |
538 dest_view_delete_dlg_cancel, dl); | |
539 | |
540 generic_dialog_add_button(dd->gd, GTK_STOCK_DELETE, NULL, dest_view_delete_dlg_ok_cb, TRUE); | |
541 | |
542 text = g_strdup_printf(_("About to delete the file:\n %s"), path); | |
543 generic_dialog_add_message(dd->gd, GTK_STOCK_DIALOG_QUESTION, | |
544 _("Delete file"), text); | |
545 g_free(text); | |
546 | |
547 gtk_widget_show(dd->gd->dialog); | |
548 } | |
549 | |
550 static void dest_view_bookmark(Dest_Data *dd, GtkTreeView *view) | |
551 { | |
552 GtkTreeModel *model; | |
553 GtkTreeIter iter; | |
554 gchar *path; | |
555 | |
556 if (!dd->right_click_path) return; | |
557 | |
558 model = gtk_tree_view_get_model(view); | |
559 gtk_tree_model_get_iter(model, &iter, dd->right_click_path); | |
560 gtk_tree_model_get(model, &iter, 1, &path, -1); | |
561 | |
562 bookmark_list_add(dd->bookmark_list, filename_from_path(path), path); | |
563 g_free(path); | |
564 } | |
565 | |
566 static void dest_popup_dir_rename_cb(GtkWidget *widget, gpointer data) | |
567 { | |
568 Dest_Data *dd = data; | |
569 dest_view_rename(dd, GTK_TREE_VIEW(dd->d_view)); | |
570 } | |
571 | |
572 static void dest_popup_dir_bookmark_cb(GtkWidget *widget, gpointer data) | |
573 { | |
574 Dest_Data *dd = data; | |
575 dest_view_bookmark(dd, GTK_TREE_VIEW(dd->d_view)); | |
576 } | |
577 | |
578 static void dest_popup_file_rename_cb(GtkWidget *widget, gpointer data) | |
579 { | |
580 Dest_Data *dd = data; | |
581 dest_view_rename(dd, GTK_TREE_VIEW(dd->f_view)); | |
582 } | |
583 | |
584 static void dest_popup_file_delete_cb(GtkWidget *widget, gpointer data) | |
585 { | |
586 Dest_Data *dd = data; | |
587 dest_view_delete(dd, GTK_TREE_VIEW(dd->f_view)); | |
588 } | |
589 | |
590 static void dest_popup_file_bookmark_cb(GtkWidget *widget, gpointer data) | |
591 { | |
592 Dest_Data *dd = data; | |
593 dest_view_bookmark(dd, GTK_TREE_VIEW(dd->f_view)); | |
594 } | |
595 | |
596 static void dest_popup_position_cb(GtkMenu *menu, gint *x, gint *y, | |
597 gboolean *push_in, gpointer data) | |
598 { | |
599 Dest_Data *dd = data; | |
600 GtkTreeView *view; | |
601 gint cw, ch; | |
602 | |
603 view = g_object_get_data(G_OBJECT(menu), "active_view"); | |
604 | |
605 tree_view_get_cell_clamped(view, dd->right_click_path, 0, TRUE, x, y, &cw, &ch); | |
606 *y += ch; | |
607 popup_menu_position_clamp(menu, x, y, 0); | |
608 } | |
609 | |
610 static gint dest_popup_menu(Dest_Data *dd, GtkTreeView *view, | |
611 gint button, guint32 time, gint local) | |
612 { | |
613 GtkWidget *menu; | |
614 | |
615 if (!dd->right_click_path) return FALSE; | |
616 | |
617 if (view == GTK_TREE_VIEW(dd->d_view)) | |
618 { | |
619 GtkTreeModel *model; | |
620 GtkTreeIter iter; | |
621 gchar *text; | |
622 gint normal_dir; | |
623 | |
624 model = gtk_tree_view_get_model(view); | |
625 gtk_tree_model_get_iter(model, &iter, dd->right_click_path); | |
626 gtk_tree_model_get(model, &iter, 0, &text, -1); | |
627 | |
628 if (!text) return FALSE; | |
442 | 629 |
9 | 630 normal_dir = (strcmp(text, ".") == 0 || strcmp(text, "..") == 0); |
631 | |
632 menu = popup_menu_short_lived(); | |
633 menu_item_add_sensitive(menu, _("_Rename"), !normal_dir, | |
634 G_CALLBACK(dest_popup_dir_rename_cb), dd); | |
635 menu_item_add_stock(menu, _("Add _Bookmark"), GTK_STOCK_JUMP_TO, | |
636 G_CALLBACK(dest_popup_dir_bookmark_cb), dd); | |
637 } | |
638 else | |
639 { | |
640 menu = popup_menu_short_lived(); | |
641 menu_item_add(menu, _("_Rename"), | |
642 G_CALLBACK(dest_popup_file_rename_cb), dd); | |
643 menu_item_add_stock(menu, _("_Delete"), GTK_STOCK_DELETE, | |
644 G_CALLBACK(dest_popup_file_delete_cb), dd); | |
645 menu_item_add_stock(menu, _("Add _Bookmark"), GTK_STOCK_JUMP_TO, | |
646 G_CALLBACK(dest_popup_file_bookmark_cb), dd); | |
647 } | |
648 | |
649 if (local) | |
650 { | |
651 g_object_set_data(G_OBJECT(menu), "active_view", view); | |
652 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, | |
653 dest_popup_position_cb, dd, button, time); | |
654 } | |
655 else | |
656 { | |
657 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, time); | |
658 } | |
659 | |
660 return TRUE; | |
661 } | |
662 | |
663 static gint dest_press_cb(GtkWidget *view, GdkEventButton *event, gpointer data) | |
664 { | |
665 Dest_Data *dd = data; | |
666 GtkTreePath *tpath; | |
667 GtkTreeViewColumn *column; | |
668 gint cell_x, cell_y; | |
669 GtkTreeModel *model; | |
670 GtkTreeIter iter; | |
671 GtkTreeSelection *selection; | |
672 | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
673 if (event->button != MOUSE_BUTTON_RIGHT || |
9 | 674 !gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(view), event->x, event->y, |
675 &tpath, &column, &cell_x, &cell_y)) | |
676 { | |
677 return FALSE; | |
678 } | |
679 | |
680 model = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); | |
681 gtk_tree_model_get_iter(model, &iter, tpath); | |
682 | |
683 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); | |
684 gtk_tree_selection_select_iter(selection, &iter); | |
685 | |
686 if (dd->right_click_path) gtk_tree_path_free(dd->right_click_path); | |
687 dd->right_click_path = tpath; | |
688 | |
689 return dest_popup_menu(dd, GTK_TREE_VIEW(view), 0, event->time, FALSE); | |
690 } | |
691 | |
692 static gboolean dest_keypress_cb(GtkWidget *view, GdkEventKey *event, gpointer data) | |
693 { | |
694 Dest_Data *dd = data; | |
695 | |
696 switch (event->keyval) | |
697 { | |
698 case GDK_F10: | |
699 if (!(event->state & GDK_CONTROL_MASK)) return FALSE; | |
700 case GDK_Menu: | |
701 dest_view_store_selection(dd, GTK_TREE_VIEW(view)); | |
702 dest_popup_menu(dd, GTK_TREE_VIEW(view), 0, event->time, TRUE); | |
703 return TRUE; | |
704 break; | |
705 case 'R': case 'r': | |
706 if (event->state & GDK_CONTROL_MASK) | |
707 { | |
708 dest_view_store_selection(dd, GTK_TREE_VIEW(view)); | |
709 dest_view_rename(dd, GTK_TREE_VIEW(view)); | |
710 return TRUE; | |
711 } | |
712 break; | |
713 case GDK_Delete: | |
714 dest_view_store_selection(dd, GTK_TREE_VIEW(view)); | |
715 dest_view_delete(dd, GTK_TREE_VIEW(view)); | |
716 return TRUE; | |
717 break; | |
718 case 'B' : case 'b': | |
719 if (event->state & GDK_CONTROL_MASK) | |
720 { | |
721 dest_view_store_selection(dd, GTK_TREE_VIEW(view)); | |
722 dest_view_bookmark(dd, GTK_TREE_VIEW(view)); | |
723 return TRUE; | |
724 } | |
725 break; | |
726 } | |
727 | |
728 return FALSE; | |
729 } | |
442 | 730 |
9 | 731 static void dest_new_dir_cb(GtkWidget *widget, gpointer data) |
732 { | |
733 Dest_Data *dd = data; | |
734 gchar *path; | |
735 gchar *buf; | |
736 const gchar *tmp; | |
737 gint from_text = FALSE; | |
738 | |
739 tmp = gtk_entry_get_text(GTK_ENTRY(dd->entry)); | |
740 if (!isname(tmp)) | |
741 { | |
742 path = g_strdup(tmp); | |
743 from_text = TRUE; | |
744 } | |
745 else | |
746 { | |
702
e07895754e65
Drop concat_dir_and_file() and use g_build_filename() instead.
zas_
parents:
605
diff
changeset
|
747 buf = g_build_filename(dd->path, _("New folder"), NULL); |
9 | 748 path = unique_filename(buf, NULL, " ", FALSE); |
749 g_free(buf); | |
750 } | |
751 | |
752 if (!mkdir_utf8(path, 0755)) | |
753 { | |
754 /* failed */ | |
755 gchar *text; | |
756 | |
757 text = g_strdup_printf(_("Unable to create folder:\n%s"), filename_from_path(path)); | |
758 warning_dialog(_("Error creating folder"), text, GTK_STOCK_DIALOG_ERROR, dd->entry); | |
759 g_free(text); | |
760 } | |
761 else | |
762 { | |
763 GtkTreeIter iter; | |
764 GtkListStore *store; | |
765 const gchar *text; | |
766 | |
767 if (from_text) gtk_entry_set_text(GTK_ENTRY(dd->entry), dd->path); | |
768 | |
769 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dd->d_view))); | |
770 | |
771 text = filename_from_path(path); | |
772 | |
773 gtk_list_store_append(store, &iter); | |
774 gtk_list_store_set(store, &iter, 0, text, 1, path, -1); | |
775 | |
776 if (dd->right_click_path) gtk_tree_path_free(dd->right_click_path); | |
777 dd->right_click_path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); | |
778 | |
779 tree_edit_by_path(GTK_TREE_VIEW(dd->d_view), dd->right_click_path, 0, text, | |
780 dest_view_rename_cb, dd); | |
781 } | |
782 | |
783 g_free(path); | |
784 } | |
785 | |
786 /* | |
787 *----------------------------------------------------------------------------- | |
788 * destination widget file selection, traversal, view options | |
789 *----------------------------------------------------------------------------- | |
442 | 790 */ |
9 | 791 |
792 static void dest_select_cb(GtkTreeSelection *selection, gpointer data) | |
793 { | |
794 Dest_Data *dd = data; | |
795 GtkTreeView *view; | |
796 GtkTreeModel *store; | |
797 GtkTreeIter iter; | |
798 gchar *path; | |
799 | |
800 if (!gtk_tree_selection_get_selected(selection, NULL, &iter)) return; | |
801 | |
802 view = gtk_tree_selection_get_tree_view(selection); | |
803 store = gtk_tree_view_get_model(view); | |
804 gtk_tree_model_get(store, &iter, 1, &path, -1); | |
805 | |
806 if (view == GTK_TREE_VIEW(dd->d_view)) | |
807 { | |
808 dest_change_dir(dd, path, (dd->f_view != NULL)); | |
809 } | |
810 else | |
811 { | |
812 gtk_entry_set_text(GTK_ENTRY(dd->entry), path); | |
813 } | |
814 | |
815 g_free(path); | |
816 } | |
817 | |
818 static void dest_activate_cb(GtkWidget *view, GtkTreePath *tpath, GtkTreeViewColumn *column, gpointer data) | |
819 { | |
820 Dest_Data *dd = data; | |
821 GtkTreeModel *store; | |
822 GtkTreeIter iter; | |
823 gchar *path; | |
824 | |
825 store = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); | |
826 gtk_tree_model_get_iter(store, &iter, tpath); | |
827 gtk_tree_model_get(store, &iter, 1, &path, -1); | |
828 | |
829 if (view == dd->d_view) | |
830 { | |
831 dest_change_dir(dd, path, (dd->f_view != NULL)); | |
832 } | |
833 else | |
834 { | |
835 if (dd->select_func) | |
836 { | |
837 dd->select_func(path, dd->select_data); | |
838 } | |
839 } | |
840 | |
841 g_free(path); | |
842 } | |
843 | |
844 static void dest_home_cb(GtkWidget *widget, gpointer data) | |
845 { | |
846 Dest_Data *dd = data; | |
847 | |
848 dest_change_dir(dd, homedir(), (dd->f_view != NULL)); | |
849 } | |
850 | |
851 static void dest_show_hidden_cb(GtkWidget *widget, gpointer data) | |
852 { | |
853 Dest_Data *dd = data; | |
854 gchar *buf; | |
855 | |
856 dd->show_hidden = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dd->hidden_button)); | |
857 | |
858 buf = g_strdup(dd->path); | |
859 dest_populate(dd, buf); | |
860 g_free(buf); | |
861 } | |
862 | |
863 static void dest_entry_changed_cb(GtkEditable *editable, gpointer data) | |
864 { | |
865 Dest_Data *dd = data; | |
866 const gchar *path; | |
867 gchar *buf; | |
868 | |
869 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
|
870 if (dd->path && strcmp(path, dd->path) == 0) return; |
9 | 871 |
872 buf = remove_level_from_path(path); | |
873 | |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
874 if (buf && (!dd->path || strcmp(buf, dd->path) != 0)) |
9 | 875 { |
876 gchar *tmp = remove_trailing_slash(path); | |
877 if (isdir(tmp)) | |
878 { | |
879 dest_populate(dd, tmp); | |
880 } | |
881 else if (isdir(buf)) | |
882 { | |
883 dest_populate(dd, buf); | |
884 } | |
885 g_free(tmp); | |
886 } | |
887 g_free(buf); | |
888 } | |
889 | |
890 static void dest_filter_list_sync(Dest_Data *dd) | |
891 { | |
892 GtkWidget *entry; | |
893 GtkListStore *store; | |
894 gchar *old_text; | |
895 GList *fwork; | |
896 GList *twork; | |
897 | |
898 if (!dd->filter_list || !dd->filter_combo) return; | |
899 | |
900 entry = GTK_BIN(dd->filter_combo)->child; | |
901 old_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry))); | |
902 | |
903 store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(dd->filter_combo))); | |
904 gtk_list_store_clear(store); | |
905 | |
906 fwork = dd->filter_list; | |
907 twork = dd->filter_text_list; | |
908 while (fwork && twork) | |
909 { | |
910 GtkTreeIter iter; | |
911 gchar *name; | |
912 gchar *filter; | |
913 | |
914 name = twork->data; | |
915 filter = fwork->data; | |
916 | |
917 gtk_list_store_append(store, &iter); | |
918 gtk_list_store_set(store, &iter, FILTER_COLUMN_NAME, name, | |
919 FILTER_COLUMN_FILTER, filter, -1); | |
920 | |
921 if (strcmp(old_text, filter) == 0) | |
922 { | |
923 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(dd->filter_combo), &iter); | |
924 } | |
925 | |
926 fwork = fwork->next; | |
927 twork = twork->next; | |
928 } | |
929 | |
930 g_free(old_text); | |
931 } | |
932 | |
933 static void dest_filter_add(Dest_Data *dd, const gchar *filter, const gchar *description, gint set) | |
934 { | |
935 GList *work; | |
936 gchar *buf; | |
937 gint c = 0; | |
938 | |
939 if (!filter) return; | |
940 | |
941 work = dd->filter_list; | |
942 while (work) | |
943 { | |
944 gchar *f = work->data; | |
945 | |
946 if (strcmp(f, filter) == 0) | |
947 { | |
948 if (set) gtk_combo_box_set_active(GTK_COMBO_BOX(dd->filter_combo), c); | |
949 return; | |
950 } | |
951 work = work->next; | |
952 c++; | |
953 } | |
954 | |
955 dd->filter_list = uig_list_insert_link(dd->filter_list, g_list_last(dd->filter_list), g_strdup(filter)); | |
956 | |
957 if (description) | |
958 { | |
959 buf = g_strdup_printf("%s ( %s )", description, filter); | |
960 } | |
961 else | |
962 { | |
963 buf = g_strdup_printf("( %s )", filter); | |
964 } | |
965 dd->filter_text_list = uig_list_insert_link(dd->filter_text_list, g_list_last(dd->filter_text_list), buf); | |
966 | |
967 if (set) gtk_entry_set_text(GTK_ENTRY(GTK_BIN(dd->filter_combo)->child), filter); | |
968 dest_filter_list_sync(dd); | |
969 } | |
970 | |
971 static void dest_filter_clear(Dest_Data *dd) | |
972 { | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
513
diff
changeset
|
973 string_list_free(dd->filter_list); |
9 | 974 dd->filter_list = NULL; |
975 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
513
diff
changeset
|
976 string_list_free(dd->filter_text_list); |
9 | 977 dd->filter_text_list = NULL; |
978 | |
979 dest_filter_add(dd, "*", _("All Files"), TRUE); | |
980 } | |
981 | |
982 static void dest_filter_changed_cb(GtkEditable *editable, gpointer data) | |
983 { | |
984 Dest_Data *dd = data; | |
985 GtkWidget *entry; | |
986 const gchar *buf; | |
987 gchar *path; | |
988 | |
989 entry = GTK_BIN(dd->filter_combo)->child; | |
990 buf = gtk_entry_get_text(GTK_ENTRY(entry)); | |
991 | |
992 g_free(dd->filter); | |
993 dd->filter = NULL; | |
994 if (strlen(buf) > 0) dd->filter = g_strdup(buf); | |
995 | |
996 path = g_strdup(dd->path); | |
997 dest_populate(dd, path); | |
998 g_free(path); | |
999 } | |
1000 | |
1001 static void dest_bookmark_select_cb(const gchar *path, gpointer data) | |
1002 { | |
1003 Dest_Data *dd = data; | |
1004 | |
1005 if (isdir(path)) | |
1006 { | |
1007 dest_change_dir(dd, path, (dd->f_view != NULL)); | |
1008 } | |
1009 else if (isfile(path) && dd->f_view) | |
1010 { | |
1011 gtk_entry_set_text(GTK_ENTRY(dd->entry), path); | |
442 | 1012 } |
9 | 1013 } |
1014 | |
1015 /* | |
1016 *----------------------------------------------------------------------------- | |
1017 * destination widget setup routines (public) | |
1018 *----------------------------------------------------------------------------- | |
442 | 1019 */ |
9 | 1020 |
1021 GtkWidget *path_selection_new_with_files(GtkWidget *entry, const gchar *path, | |
1022 const gchar *filter, const gchar *filter_desc) | |
1023 { | |
1024 GtkWidget *hbox2; | |
1025 Dest_Data *dd; | |
1026 GtkWidget *scrolled; | |
1027 GtkWidget *table; | |
1028 GtkWidget *paned; | |
1029 GtkListStore *store; | |
1030 GtkTreeSelection *selection; | |
1031 GtkTreeViewColumn *column; | |
1032 GtkCellRenderer *renderer; | |
1033 | |
1034 dd = g_new0(Dest_Data, 1); | |
1035 dd->show_hidden = FALSE; | |
1036 dd->select_func = NULL; | |
1037 dd->select_data = NULL; | |
1038 dd->gd = NULL; | |
1039 | |
1040 table = gtk_table_new(4, (filter != NULL) ? 3 : 1, FALSE); | |
1041 gtk_table_set_col_spacings(GTK_TABLE(table), PREF_PAD_GAP); | |
1042 gtk_table_set_row_spacing(GTK_TABLE(table), 0, PREF_PAD_GAP); | |
1043 gtk_widget_show(table); | |
1044 | |
1045 dd->entry = entry; | |
1046 g_object_set_data(G_OBJECT(dd->entry), "destination_data", dd); | |
1047 | |
1048 hbox2 = pref_table_box(table, 0, 0, GTK_ORIENTATION_HORIZONTAL, NULL); | |
1049 gtk_box_set_spacing(GTK_BOX(hbox2), PREF_PAD_BUTTON_GAP); | |
1050 pref_button_new(hbox2, NULL, _("Home"), FALSE, | |
1051 G_CALLBACK(dest_home_cb), dd); | |
1052 pref_button_new(hbox2, NULL, _("New folder"), FALSE, | |
1053 G_CALLBACK(dest_new_dir_cb), dd); | |
1054 | |
1055 dd->hidden_button = gtk_check_button_new_with_label(_("Show hidden")); | |
1056 g_signal_connect(G_OBJECT(dd->hidden_button), "clicked", | |
1057 G_CALLBACK(dest_show_hidden_cb), dd); | |
1058 gtk_box_pack_end(GTK_BOX(hbox2), dd->hidden_button, FALSE, FALSE, 0); | |
1059 gtk_widget_show(dd->hidden_button); | |
1060 | |
1061 hbox2 = gtk_hbox_new(FALSE, PREF_PAD_GAP); | |
1062 if (filter) | |
1063 { | |
1064 paned = gtk_hpaned_new(); | |
1065 gtk_table_attach(GTK_TABLE(table), paned, 0, 3, 1, 2, | |
1066 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); | |
1067 gtk_widget_show(paned); | |
1068 gtk_paned_add1(GTK_PANED(paned), hbox2); | |
1069 } | |
1070 else | |
1071 { | |
1072 paned = NULL; | |
1073 gtk_table_attach(GTK_TABLE(table), hbox2, 0, 1, 1, 2, | |
1074 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); | |
1075 } | |
1076 gtk_widget_show(hbox2); | |
1077 | |
1078 /* bookmarks */ | |
1079 scrolled = bookmark_list_new(NULL, dest_bookmark_select_cb, dd); | |
1080 gtk_box_pack_start(GTK_BOX(hbox2), scrolled, FALSE, FALSE, 0); | |
1081 gtk_widget_show(scrolled); | |
1082 | |
1083 dd->bookmark_list = scrolled; | |
1084 | |
1085 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
1086 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
|
1087 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
|
1088 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); |
9 | 1089 gtk_box_pack_start(GTK_BOX(hbox2), scrolled, TRUE, TRUE, 0); |
1090 gtk_widget_show(scrolled); | |
1091 | |
1092 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); | |
1093 dd->d_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
1094 g_object_unref(store); | |
1095 | |
1096 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(dd->d_view), PATH_SEL_USE_HEADINGS); | |
1097 | |
1098 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dd->d_view)); | |
1099 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_SINGLE); | |
1100 | |
1101 column = gtk_tree_view_column_new(); | |
1102 gtk_tree_view_column_set_title(column, _("Folders")); | |
1103 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
1104 | |
1105 renderer = gtk_cell_renderer_text_new(); | |
1106 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1107 gtk_tree_view_column_add_attribute(column, renderer, "text", 0); | |
1108 | |
1109 gtk_tree_view_append_column(GTK_TREE_VIEW(dd->d_view), column); | |
1110 | |
1111 #if 0 | |
1112 /* only for debugging */ | |
1113 column = gtk_tree_view_column_new(); | |
1114 gtk_tree_view_column_set_title(column, _("Path")); | |
1115 renderer = gtk_cell_renderer_text_new(); | |
1116 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1117 gtk_tree_view_column_add_attribute(column, renderer, "text", 1); | |
1118 gtk_tree_view_append_column(GTK_TREE_VIEW(dd->d_view), column); | |
1119 #endif | |
1120 | |
1121 gtk_widget_set_size_request(dd->d_view, DEST_WIDTH, DEST_HEIGHT); | |
1122 gtk_container_add(GTK_CONTAINER(scrolled), dd->d_view); | |
1123 gtk_widget_show(dd->d_view); | |
1124 | |
1125 g_signal_connect(G_OBJECT(dd->d_view), "button_press_event", | |
1126 G_CALLBACK(dest_press_cb), dd); | |
1127 g_signal_connect(G_OBJECT(dd->d_view), "key_press_event", | |
1128 G_CALLBACK(dest_keypress_cb), dd); | |
1129 g_signal_connect(G_OBJECT(dd->d_view), "row_activated", | |
1130 G_CALLBACK(dest_activate_cb), dd); | |
1131 g_signal_connect(G_OBJECT(dd->d_view), "destroy", | |
1132 G_CALLBACK(dest_free_data), dd); | |
442 | 1133 |
9 | 1134 if (filter) |
1135 { | |
1136 GtkListStore *store; | |
1137 | |
1138 hbox2 = pref_table_box(table, 2, 0, GTK_ORIENTATION_HORIZONTAL, NULL); | |
1139 pref_label_new(hbox2, _("Filter:")); | |
1140 | |
1141 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); | |
1142 | |
1143 dd->filter_combo = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(store), | |
1144 FILTER_COLUMN_FILTER); | |
1145 g_object_unref(store); | |
1146 gtk_cell_layout_clear(GTK_CELL_LAYOUT(dd->filter_combo)); | |
1147 renderer = gtk_cell_renderer_text_new(); | |
1148 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dd->filter_combo), renderer, TRUE); | |
1149 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dd->filter_combo), renderer, | |
1150 "text", FILTER_COLUMN_NAME, NULL); | |
1151 #if 0 | |
1152 gtk_combo_set_case_sensitive(GTK_COMBO(dd->filter_combo), TRUE); | |
1153 #endif | |
1154 gtk_box_pack_start(GTK_BOX(hbox2), dd->filter_combo, TRUE, TRUE, 0); | |
1155 gtk_widget_show(dd->filter_combo); | |
1156 | |
1157 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
1158 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
|
1159 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
|
1160 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); |
9 | 1161 if (paned) |
1162 { | |
1163 gtk_paned_add2(GTK_PANED(paned), scrolled); | |
1164 } | |
1165 else | |
1166 { | |
1167 gtk_table_attach(GTK_TABLE(table), scrolled, 2, 3, 1, 2, | |
1168 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); | |
1169 } | |
1170 gtk_widget_show(scrolled); | |
1171 | |
1172 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); | |
1173 dd->f_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
1174 g_object_unref(store); | |
1175 | |
1176 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(dd->f_view), PATH_SEL_USE_HEADINGS); | |
1177 | |
1178 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dd->f_view)); | |
1179 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_SINGLE); | |
1180 | |
1181 column = gtk_tree_view_column_new(); | |
1182 gtk_tree_view_column_set_title(column, _("Files")); | |
1183 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
1184 | |
1185 renderer = gtk_cell_renderer_text_new(); | |
1186 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1187 gtk_tree_view_column_add_attribute(column, renderer, "text", 0); | |
1188 | |
1189 gtk_tree_view_append_column(GTK_TREE_VIEW(dd->f_view), column); | |
1190 | |
1191 gtk_widget_set_size_request(dd->f_view, DEST_WIDTH, DEST_HEIGHT); | |
1192 gtk_container_add(GTK_CONTAINER(scrolled), dd->f_view); | |
1193 gtk_widget_show(dd->f_view); | |
1194 | |
1195 g_signal_connect(G_OBJECT(dd->f_view), "button_press_event", | |
1196 G_CALLBACK(dest_press_cb), dd); | |
1197 g_signal_connect(G_OBJECT(dd->f_view), "key_press_event", | |
1198 G_CALLBACK(dest_keypress_cb), dd); | |
1199 g_signal_connect(G_OBJECT(dd->f_view), "row_activated", | |
1200 G_CALLBACK(dest_activate_cb), dd); | |
1201 g_signal_connect(selection, "changed", | |
1202 G_CALLBACK(dest_select_cb), dd); | |
1203 | |
1204 dest_filter_clear(dd); | |
1205 dest_filter_add(dd, filter, filter_desc, TRUE); | |
1206 | |
1207 dd->filter = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_BIN(dd->filter_combo)->child))); | |
1208 } | |
1209 | |
726 | 1210 if (path && path[0] == G_DIR_SEPARATOR && isdir(path)) |
9 | 1211 { |
1212 dest_populate(dd, path); | |
1213 } | |
1214 else | |
1215 { | |
1216 gchar *buf = remove_level_from_path(path); | |
725 | 1217 if (buf && buf[0] == G_DIR_SEPARATOR && isdir(buf)) |
9 | 1218 { |
1219 dest_populate(dd, buf); | |
1220 } | |
1221 else | |
1222 { | |
1223 gint pos = -1; | |
1224 | |
1225 dest_populate(dd, (gchar *)homedir()); | |
725 | 1226 if (path) gtk_editable_insert_text(GTK_EDITABLE(dd->entry), G_DIR_SEPARATOR_S, -1, &pos); |
9 | 1227 if (path) gtk_editable_insert_text(GTK_EDITABLE(dd->entry), path, -1, &pos); |
1228 } | |
1229 g_free(buf); | |
1230 } | |
1231 | |
1232 if (dd->filter_combo) | |
1233 { | |
1234 g_signal_connect(G_OBJECT(GTK_BIN(dd->filter_combo)->child), "changed", | |
1235 G_CALLBACK(dest_filter_changed_cb), dd); | |
1236 } | |
1237 g_signal_connect(G_OBJECT(dd->entry), "changed", | |
1238 G_CALLBACK(dest_entry_changed_cb), dd); | |
1239 | |
1240 dest_dnd_init(dd); | |
1241 | |
1242 return table; | |
1243 } | |
1244 | |
1245 GtkWidget *path_selection_new(const gchar *path, GtkWidget *entry) | |
1246 { | |
1247 return path_selection_new_with_files(entry, path, NULL, NULL); | |
1248 } | |
1249 | |
1250 void path_selection_sync_to_entry(GtkWidget *entry) | |
1251 { | |
1252 Dest_Data *dd = g_object_get_data(G_OBJECT(entry), "destination_data"); | |
1253 const gchar *path; | |
1254 | |
1255 if (!dd) return; | |
1256 | |
1257 path = gtk_entry_get_text(GTK_ENTRY(entry)); | |
442 | 1258 |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1259 if (isdir(path) && (!dd->path || strcmp(path, dd->path) != 0)) |
9 | 1260 { |
1261 dest_populate(dd, path); | |
1262 } | |
1263 else | |
1264 { | |
1265 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
|
1266 if (isdir(buf) && (!dd->path || strcmp(buf, dd->path) != 0)) |
9 | 1267 { |
1268 dest_populate(dd, buf); | |
1269 } | |
1270 g_free(buf); | |
1271 } | |
1272 } | |
1273 | |
1274 void path_selection_add_select_func(GtkWidget *entry, | |
1275 void (*func)(const gchar *, gpointer), gpointer data) | |
1276 { | |
1277 Dest_Data *dd = g_object_get_data(G_OBJECT(entry), "destination_data"); | |
1278 | |
1279 if (!dd) return; | |
1280 | |
1281 dd->select_func = func; | |
1282 dd->select_data = data; | |
1283 } | |
1284 | |
1285 void path_selection_add_filter(GtkWidget *entry, const gchar *filter, const gchar *description, gint set) | |
1286 { | |
1287 Dest_Data *dd = g_object_get_data(G_OBJECT(entry), "destination_data"); | |
1288 | |
1289 if (!dd) return; | |
1290 if (!filter) return; | |
1291 | |
1292 dest_filter_add(dd, filter, description, set); | |
1293 } | |
1294 | |
1295 void path_selection_clear_filter(GtkWidget *entry) | |
1296 { | |
1297 Dest_Data *dd = g_object_get_data(G_OBJECT(entry), "destination_data"); | |
1298 | |
1299 if (!dd) return; | |
1300 | |
1301 dest_filter_clear(dd); | |
1302 } |