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