Mercurial > geeqie
annotate src/bar_sort.c @ 1710:fce6debc934e
updated czech translation
author | nadvornik |
---|---|
date | Wed, 29 Jul 2009 21:03:38 +0000 |
parents | 1b3751ac4743 |
children | 956aab097ea7 |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
67
f63ecca6c087
Fri Oct 13 05:22:43 2006 John Ellis <johne@verizon.net>
gqview
parents:
41
diff
changeset
|
3 * (C) 2006 John Ellis |
1284 | 4 * Copyright (C) 2008 - 2009 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 | |
281 | 14 #include "main.h" |
9 | 15 #include "bar_sort.h" |
16 | |
17 #include "collect.h" | |
18 #include "collect-io.h" | |
586 | 19 #include "filedata.h" |
902 | 20 #include "history_list.h" |
9 | 21 #include "layout.h" |
22 #include "layout_image.h" | |
23 #include "utilops.h" | |
753 | 24 #include "editors.h" |
9 | 25 #include "ui_bookmark.h" |
26 #include "ui_fileops.h" | |
27 #include "ui_menu.h" | |
28 #include "ui_misc.h" | |
1320 | 29 #include "rcfile.h" |
9 | 30 |
31 | |
32 /* | |
33 *------------------------------------------------------------------- | |
34 * sort bar | |
35 *------------------------------------------------------------------- | |
36 */ | |
37 | |
38 typedef enum { | |
39 BAR_SORT_MODE_FOLDER = 0, | |
491 | 40 BAR_SORT_MODE_COLLECTION, |
41 BAR_SORT_MODE_COUNT | |
9 | 42 } SortModeType; |
43 | |
44 typedef enum { | |
491 | 45 BAR_SORT_COPY = 0, |
9 | 46 BAR_SORT_MOVE, |
753 | 47 BAR_SORT_FILTER, |
1272 | 48 BAR_SORT_ACTION_COUNT |
9 | 49 } SortActionType; |
50 | |
51 typedef enum { | |
491 | 52 BAR_SORT_SELECTION_IMAGE = 0, |
53 BAR_SORT_SELECTION_SELECTED, | |
54 BAR_SORT_SELECTION_COUNT | |
9 | 55 } SortSelectionType; |
56 | |
57 typedef struct _SortData SortData; | |
58 struct _SortData | |
59 { | |
60 GtkWidget *vbox; | |
61 GtkWidget *bookmarks; | |
62 LayoutWindow *lw; | |
63 | |
64 FileDialog *dialog; | |
65 GtkWidget *dialog_name_entry; | |
66 | |
67 SortModeType mode; | |
68 SortActionType action; | |
1413
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1320
diff
changeset
|
69 gchar *filter_key; |
1272 | 70 |
9 | 71 SortSelectionType selection; |
72 | |
73 GtkWidget *folder_group; | |
74 GtkWidget *collection_group; | |
75 | |
76 GtkWidget *add_button; | |
77 GtkWidget *undo_button; | |
78 SortActionType undo_action; | |
79 GList *undo_src_list; | |
80 gchar *undo_src; | |
81 gchar *undo_dest; | |
82 }; | |
83 | |
84 | |
85 #define SORT_KEY_FOLDERS "sort_manager" | |
86 #define SORT_KEY_COLLECTIONS "sort_manager_collections" | |
87 | |
88 | |
138 | 89 static void bar_sort_undo_set(SortData *sd, GList *src_list, FileData *src, const gchar *dest); |
9 | 90 static void bar_sort_add_close(SortData *sd); |
91 | |
92 | |
93 static void bar_sort_collection_list_build(GtkWidget *bookmarks) | |
94 { | |
783 | 95 FileData *dir_fd; |
780
44128da39e13
Drop initialization to NULL since filelist_read() will take care of it.
zas_
parents:
754
diff
changeset
|
96 GList *list; |
9 | 97 GList *work; |
98 | |
99 history_list_free_key(SORT_KEY_COLLECTIONS); | |
100 bookmark_list_set_key(bookmarks, SORT_KEY_COLLECTIONS); | |
101 | |
1145
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
102 dir_fd = file_data_new_simple(get_collections_dir()); |
783 | 103 filelist_read(dir_fd, &list, NULL); |
104 file_data_unref(dir_fd); | |
9 | 105 |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
521
diff
changeset
|
106 list = filelist_sort_path(list); |
9 | 107 |
108 work = list; | |
109 while (work) | |
110 { | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
521
diff
changeset
|
111 FileData *fd; |
9 | 112 gchar *name; |
113 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
521
diff
changeset
|
114 fd = work->data; |
9 | 115 work = work->next; |
116 | |
781
2d2cca2bceb0
Replace hardcoded collection filename extension by a macro (GQ_COLLECTION_EXT).
zas_
parents:
780
diff
changeset
|
117 if (file_extension_match(fd->path, GQ_COLLECTION_EXT)) |
9 | 118 { |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
521
diff
changeset
|
119 name = remove_extension_from_path(fd->name); |
9 | 120 } |
121 else | |
122 { | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
521
diff
changeset
|
123 name = g_strdup(fd->name); |
9 | 124 } |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
521
diff
changeset
|
125 bookmark_list_add(bookmarks, name, fd->path); |
9 | 126 g_free(name); |
127 } | |
128 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
521
diff
changeset
|
129 filelist_free(list); |
9 | 130 } |
131 | |
132 static void bar_sort_mode_sync(SortData *sd, SortModeType mode) | |
133 { | |
1418
1817f5178db3
Fix bug when adding a new collection through sort manager. Tidy up.
zas_
parents:
1413
diff
changeset
|
134 gboolean folder_mode; |
9 | 135 |
136 if (sd->mode == mode) return; | |
137 sd->mode = mode; | |
138 | |
139 folder_mode = (sd->mode == BAR_SORT_MODE_FOLDER); | |
140 | |
141 bookmark_list_set_no_defaults(sd->bookmarks, !folder_mode); | |
142 bookmark_list_set_editable(sd->bookmarks, folder_mode); | |
521
57007e49d767
Do not allow to add anything but directories to sort bar in
zas_
parents:
512
diff
changeset
|
143 bookmark_list_set_only_directories(sd->bookmarks, folder_mode); |
9 | 144 |
145 if (folder_mode) | |
146 { | |
147 gtk_widget_hide(sd->collection_group); | |
148 gtk_widget_show(sd->folder_group); | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
491
diff
changeset
|
149 bookmark_list_set_key(sd->bookmarks, SORT_KEY_FOLDERS); |
9 | 150 } |
151 else | |
152 { | |
153 gtk_widget_hide(sd->folder_group); | |
154 gtk_widget_show(sd->collection_group); | |
155 bar_sort_collection_list_build(sd->bookmarks); | |
156 } | |
157 | |
158 bar_sort_add_close(sd); | |
159 | |
160 bar_sort_undo_set(sd, NULL, NULL, NULL); | |
161 } | |
162 | |
163 static void bar_sort_mode_cb(GtkWidget *combo, gpointer data) | |
164 { | |
165 SortData *sd = data; | |
166 | |
167 if (gtk_combo_box_get_active(GTK_COMBO_BOX(combo)) == BAR_SORT_MODE_FOLDER) | |
168 { | |
169 bar_sort_mode_sync(sd, BAR_SORT_MODE_FOLDER); | |
170 } | |
171 else | |
172 { | |
173 bar_sort_mode_sync(sd, BAR_SORT_MODE_COLLECTION); | |
174 } | |
175 } | |
176 | |
177 /* this takes control of src_list */ | |
138 | 178 static void bar_sort_undo_set(SortData *sd, GList *src_list, FileData *src, const gchar *dest) |
9 | 179 { |
138 | 180 string_list_free(sd->undo_src_list); |
181 sd->undo_src_list = filelist_to_path_list(src_list); | |
9 | 182 |
183 g_free(sd->undo_src); | |
138 | 184 sd->undo_src = src ? g_strdup(src->path) : NULL; |
9 | 185 g_free(sd->undo_dest); |
186 sd->undo_dest = g_strdup(dest); | |
187 | |
188 sd->undo_action = sd->action; | |
189 | |
190 if (sd->undo_button) | |
191 { | |
192 gtk_widget_set_sensitive(sd->undo_button, | |
193 ((sd->undo_src_list || sd->undo_src) && sd->undo_dest) ); | |
194 } | |
195 } | |
196 | |
197 static void bar_sort_undo_folder(SortData *sd, GtkWidget *button) | |
198 { | |
199 if (!sd->undo_src || !sd->undo_dest) return; | |
200 | |
201 switch (sd->undo_action) | |
202 { | |
203 case BAR_SORT_MOVE: | |
204 { | |
205 GList *list; | |
206 gchar *src_dir; | |
207 | |
138 | 208 list = g_list_append(NULL, file_data_new_simple(sd->undo_dest)); |
9 | 209 src_dir = remove_level_from_path(sd->undo_src); |
753 | 210 file_util_move_simple(list, src_dir, sd->lw->window); |
9 | 211 g_free(src_dir); |
212 } | |
213 break; | |
214 case BAR_SORT_COPY: | |
138 | 215 file_util_delete(file_data_new_simple(sd->undo_dest), NULL, button); |
9 | 216 break; |
995 | 217 default: |
753 | 218 /* undo external command */ |
219 file_util_delete(file_data_new_simple(sd->undo_dest), NULL, button); | |
491 | 220 break; |
9 | 221 } |
222 | |
223 layout_refresh(sd->lw); | |
224 | |
225 if (isfile(sd->undo_src)) | |
226 { | |
138 | 227 layout_image_set_fd(sd->lw, file_data_new_simple(sd->undo_src)); |
9 | 228 } |
229 | |
230 bar_sort_undo_set(sd, NULL, NULL, NULL); | |
231 } | |
232 | |
233 static void bar_sort_undo_collection(SortData *sd) | |
234 { | |
235 GList *work; | |
236 | |
237 work = sd->undo_src_list; | |
238 while (work) | |
239 { | |
240 gchar *source; | |
241 | |
242 source = work->data; | |
243 work = work->next; | |
138 | 244 collect_manager_remove(file_data_new_simple(source), sd->undo_dest); |
9 | 245 } |
246 | |
247 bar_sort_undo_set(sd, NULL, NULL, NULL); | |
248 } | |
249 | |
250 static void bar_sort_undo_cb(GtkWidget *button, gpointer data) | |
251 { | |
252 SortData *sd = data; | |
253 | |
254 if (sd->mode == BAR_SORT_MODE_FOLDER) | |
255 { | |
256 bar_sort_undo_folder(sd, button); | |
257 } | |
258 else | |
259 { | |
260 bar_sort_undo_collection(sd); | |
261 } | |
262 } | |
263 | |
138 | 264 static void bar_sort_bookmark_select_folder(SortData *sd, FileData *source, const gchar *path) |
9 | 265 { |
266 GList *list; | |
267 gchar *dest_path; | |
268 | |
269 if (!isdir(path)) return; | |
270 | |
702
e07895754e65
Drop concat_dir_and_file() and use g_build_filename() instead.
zas_
parents:
700
diff
changeset
|
271 dest_path = g_build_filename(path, source->name, NULL); |
9 | 272 bar_sort_undo_set(sd, NULL, source, dest_path); |
273 | |
138 | 274 list = g_list_append(NULL, file_data_ref(source)); |
9 | 275 |
276 switch (sd->action) | |
277 { | |
278 case BAR_SORT_COPY: | |
753 | 279 file_util_copy_simple(list, path, sd->lw->window); |
9 | 280 list = NULL; |
281 layout_image_next(sd->lw); | |
282 break; | |
283 case BAR_SORT_MOVE: | |
753 | 284 file_util_move_simple(list, path, sd->lw->window); |
9 | 285 list = NULL; |
286 break; | |
1272 | 287 case BAR_SORT_FILTER: |
288 file_util_start_filter_from_filelist(sd->filter_key, list, path, sd->lw->window); | |
289 list = NULL; | |
290 layout_image_next(sd->lw); | |
291 break; | |
753 | 292 default: |
491 | 293 break; |
9 | 294 } |
295 | |
296 g_list_free(list); | |
297 g_free(dest_path); | |
298 } | |
299 | |
138 | 300 static void bar_sort_bookmark_select_collection(SortData *sd, FileData *source, const gchar *path) |
9 | 301 { |
302 GList *list = NULL; | |
303 | |
304 switch (sd->selection) | |
305 { | |
306 case BAR_SORT_SELECTION_IMAGE: | |
138 | 307 list = g_list_append(NULL, file_data_ref(source)); |
9 | 308 break; |
309 case BAR_SORT_SELECTION_SELECTED: | |
310 list = layout_selection_list(sd->lw); | |
311 break; | |
491 | 312 default: |
313 break; | |
9 | 314 } |
315 | |
316 if (!list) | |
317 { | |
318 bar_sort_undo_set(sd, NULL, NULL, NULL); | |
319 return; | |
320 } | |
321 | |
322 bar_sort_undo_set(sd, list, NULL, path); | |
323 | |
324 while (list) | |
325 { | |
138 | 326 FileData *image_fd; |
9 | 327 |
138 | 328 image_fd = list->data; |
9 | 329 list = list->next; |
138 | 330 collect_manager_add(image_fd, path); |
9 | 331 } |
332 } | |
333 | |
334 static void bar_sort_bookmark_select(const gchar *path, gpointer data) | |
335 { | |
336 SortData *sd = data; | |
138 | 337 FileData *source; |
9 | 338 |
138 | 339 source = layout_image_get_fd(sd->lw); |
9 | 340 if (!path || !source) return; |
341 | |
342 if (sd->mode == BAR_SORT_MODE_FOLDER) | |
343 { | |
344 bar_sort_bookmark_select_folder(sd, source, path); | |
345 } | |
346 else | |
347 { | |
348 bar_sort_bookmark_select_collection(sd, source, path); | |
349 } | |
350 } | |
351 | |
1272 | 352 static void bar_sort_set_action(SortData *sd, SortActionType action, const gchar *filter_key) |
491 | 353 { |
1320 | 354 sd->action = action; |
1272 | 355 if (action == BAR_SORT_FILTER) |
356 { | |
357 if (!filter_key) filter_key = ""; | |
1413
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1320
diff
changeset
|
358 sd->filter_key = g_strdup(filter_key); |
1272 | 359 } |
360 else | |
361 { | |
362 sd->filter_key = NULL; | |
363 } | |
491 | 364 } |
365 | |
9 | 366 static void bar_sort_set_copy_cb(GtkWidget *button, gpointer data) |
367 { | |
368 SortData *sd = data; | |
369 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) return; | |
1272 | 370 bar_sort_set_action(sd, BAR_SORT_COPY, NULL); |
9 | 371 } |
372 | |
373 static void bar_sort_set_move_cb(GtkWidget *button, gpointer data) | |
374 { | |
375 SortData *sd = data; | |
376 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) return; | |
1272 | 377 bar_sort_set_action(sd, BAR_SORT_MOVE, NULL); |
9 | 378 } |
379 | |
753 | 380 static void bar_sort_set_filter_cb(GtkWidget *button, gpointer data) |
9 | 381 { |
382 SortData *sd = data; | |
1272 | 383 const gchar *key; |
754
7dbdd80610a3
bar_sort_set_filter_cb(): filter_idx was set as uint so get it as uint.
zas_
parents:
753
diff
changeset
|
384 |
9 | 385 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) return; |
1272 | 386 key = g_object_get_data(G_OBJECT(button), "filter_key"); |
387 bar_sort_set_action(sd, BAR_SORT_FILTER, key); | |
491 | 388 } |
389 | |
390 static void bar_sort_set_selection(SortData *sd, SortSelectionType selection) | |
391 { | |
1320 | 392 sd->selection = selection; |
9 | 393 } |
394 | |
395 static void bar_sort_set_selection_image_cb(GtkWidget *button, gpointer data) | |
396 { | |
397 SortData *sd = data; | |
398 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) return; | |
491 | 399 bar_sort_set_selection(sd, BAR_SORT_SELECTION_IMAGE); |
9 | 400 } |
401 | |
402 static void bar_sort_set_selection_selected_cb(GtkWidget *button, gpointer data) | |
403 { | |
404 SortData *sd = data; | |
405 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) return; | |
491 | 406 bar_sort_set_selection(sd, BAR_SORT_SELECTION_SELECTED); |
9 | 407 } |
408 | |
409 static void bar_sort_add_close(SortData *sd) | |
410 { | |
411 if (sd->dialog) file_dialog_close(sd->dialog); | |
412 sd->dialog_name_entry = NULL; | |
413 sd->dialog = NULL; | |
414 } | |
415 | |
416 static void bar_sort_add_ok_cb(FileDialog *fd, gpointer data) | |
417 { | |
418 SortData *sd = data; | |
1418
1817f5178db3
Fix bug when adding a new collection through sort manager. Tidy up.
zas_
parents:
1413
diff
changeset
|
419 const gchar *name = gtk_entry_get_text(GTK_ENTRY(sd->dialog_name_entry)); |
1817f5178db3
Fix bug when adding a new collection through sort manager. Tidy up.
zas_
parents:
1413
diff
changeset
|
420 gboolean empty_name = (name[0] == '\0'); |
9 | 421 |
422 name = gtk_entry_get_text(GTK_ENTRY(sd->dialog_name_entry)); | |
423 if (sd->mode == BAR_SORT_MODE_FOLDER) | |
424 { | |
1418
1817f5178db3
Fix bug when adding a new collection through sort manager. Tidy up.
zas_
parents:
1413
diff
changeset
|
425 if (empty_name) |
9 | 426 { |
427 name = filename_from_path(fd->dest_path); | |
428 } | |
429 | |
430 bookmark_list_add(sd->bookmarks, name, fd->dest_path); | |
431 } | |
432 else | |
433 { | |
434 gchar *path; | |
1418
1817f5178db3
Fix bug when adding a new collection through sort manager. Tidy up.
zas_
parents:
1413
diff
changeset
|
435 gboolean has_extension; |
1817f5178db3
Fix bug when adding a new collection through sort manager. Tidy up.
zas_
parents:
1413
diff
changeset
|
436 gchar *filename = (gchar *) name; |
1817f5178db3
Fix bug when adding a new collection through sort manager. Tidy up.
zas_
parents:
1413
diff
changeset
|
437 |
1817f5178db3
Fix bug when adding a new collection through sort manager. Tidy up.
zas_
parents:
1413
diff
changeset
|
438 if (empty_name) return; |
9 | 439 |
1418
1817f5178db3
Fix bug when adding a new collection through sort manager. Tidy up.
zas_
parents:
1413
diff
changeset
|
440 has_extension = file_extension_match(name, GQ_COLLECTION_EXT); |
1817f5178db3
Fix bug when adding a new collection through sort manager. Tidy up.
zas_
parents:
1413
diff
changeset
|
441 if (!has_extension) |
9 | 442 { |
1418
1817f5178db3
Fix bug when adding a new collection through sort manager. Tidy up.
zas_
parents:
1413
diff
changeset
|
443 filename = g_strconcat(name, GQ_COLLECTION_EXT, NULL); |
9 | 444 } |
445 | |
1418
1817f5178db3
Fix bug when adding a new collection through sort manager. Tidy up.
zas_
parents:
1413
diff
changeset
|
446 path = g_build_filename(get_collections_dir(), filename, NULL); |
9 | 447 if (isfile(path)) |
448 { | |
1418
1817f5178db3
Fix bug when adding a new collection through sort manager. Tidy up.
zas_
parents:
1413
diff
changeset
|
449 gchar *text = g_strdup_printf(_("The collection:\n%s\nalready exists."), filename); |
9 | 450 file_util_warning_dialog(_("Collection exists"), text, GTK_STOCK_DIALOG_INFO, NULL); |
451 g_free(text); | |
452 } | |
453 else | |
454 { | |
455 CollectionData *cd; | |
456 | |
457 cd = collection_new(path); | |
458 if (collection_save(cd, path)) | |
459 { | |
460 bar_sort_collection_list_build(sd->bookmarks); | |
461 } | |
462 else | |
463 { | |
464 gchar *text = g_strdup_printf(_("Failed to save the collection:\n%s"), path); | |
465 file_util_warning_dialog(_("Save Failed"), text, | |
466 GTK_STOCK_DIALOG_ERROR, GENERIC_DIALOG(fd)->dialog); | |
467 g_free(text); | |
468 } | |
469 collection_unref(cd); | |
470 } | |
471 | |
1418
1817f5178db3
Fix bug when adding a new collection through sort manager. Tidy up.
zas_
parents:
1413
diff
changeset
|
472 if (!has_extension) g_free(filename); |
9 | 473 g_free(path); |
474 } | |
475 | |
476 bar_sort_add_close(sd); | |
477 } | |
478 | |
479 static void bar_sort_add_cancel_cb(FileDialog *fd, gpointer data) | |
480 { | |
481 SortData *sd = data; | |
482 | |
483 bar_sort_add_close(sd); | |
484 } | |
485 | |
486 static void bar_sort_add_cb(GtkWidget *button, gpointer data) | |
487 { | |
488 SortData *sd = data; | |
489 GtkWidget *hbox; | |
490 const gchar *title; | |
491 | |
492 if (sd->dialog) | |
493 { | |
494 gtk_window_present(GTK_WINDOW(GENERIC_DIALOG(sd->dialog)->dialog)); | |
495 return; | |
496 } | |
497 | |
498 if (sd->mode == BAR_SORT_MODE_FOLDER) | |
499 { | |
500 title = _("Add Bookmark"); | |
501 } | |
502 else | |
503 { | |
504 title = _("Add Collection"); | |
505 } | |
506 | |
507 sd->dialog = file_util_file_dlg(title, | |
1174
0bea79d87065
Drop useless wmclass stuff. Gtk will take care of it and as said in the documentation using gtk_window_set_wmclass() is sort of pointless.
zas_
parents:
1145
diff
changeset
|
508 "add_bookmark", button, |
9 | 509 bar_sort_add_cancel_cb, sd); |
510 file_dialog_add_button(sd->dialog, GTK_STOCK_OK, NULL, bar_sort_add_ok_cb, TRUE); | |
511 | |
512 generic_dialog_add_message(GENERIC_DIALOG(sd->dialog), NULL, title, NULL); | |
513 | |
514 if (sd->mode == BAR_SORT_MODE_FOLDER) | |
515 { | |
516 file_dialog_add_path_widgets(sd->dialog, NULL, NULL, "add_bookmark", NULL, NULL); | |
517 } | |
518 | |
519 hbox = pref_box_new(GENERIC_DIALOG(sd->dialog)->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP); | |
520 | |
521 pref_label_new(hbox, _("Name:")); | |
522 | |
523 sd->dialog_name_entry = gtk_entry_new(); | |
524 gtk_box_pack_start(GTK_BOX(hbox), sd->dialog_name_entry, TRUE, TRUE, 0); | |
525 generic_dialog_attach_default(GENERIC_DIALOG(sd->dialog), sd->dialog_name_entry); | |
526 gtk_widget_show(sd->dialog_name_entry); | |
527 | |
528 if (sd->mode == BAR_SORT_MODE_COLLECTION) | |
529 { | |
530 gtk_widget_grab_focus(sd->dialog_name_entry); | |
531 } | |
532 | |
533 gtk_widget_show(GENERIC_DIALOG(sd->dialog)->dialog); | |
534 } | |
535 | |
536 void bar_sort_close(GtkWidget *bar) | |
537 { | |
538 SortData *sd; | |
539 | |
540 sd = g_object_get_data(G_OBJECT(bar), "bar_sort_data"); | |
541 if (!sd) return; | |
542 | |
543 gtk_widget_destroy(sd->vbox); | |
544 } | |
545 | |
546 static void bar_sort_destroy(GtkWidget *widget, gpointer data) | |
547 { | |
548 SortData *sd = data; | |
549 | |
550 bar_sort_add_close(sd); | |
551 | |
1413
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1320
diff
changeset
|
552 g_free(sd->filter_key); |
9 | 553 g_free(sd->undo_src); |
554 g_free(sd->undo_dest); | |
555 g_free(sd); | |
556 } | |
557 | |
1413
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1320
diff
changeset
|
558 static void bar_sort_edit_button_free(gpointer data) |
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1320
diff
changeset
|
559 { |
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1320
diff
changeset
|
560 g_free(data); |
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1320
diff
changeset
|
561 } |
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1320
diff
changeset
|
562 |
1418
1817f5178db3
Fix bug when adding a new collection through sort manager. Tidy up.
zas_
parents:
1413
diff
changeset
|
563 static GtkWidget *bar_sort_new(LayoutWindow *lw, SortActionType action, |
1817f5178db3
Fix bug when adding a new collection through sort manager. Tidy up.
zas_
parents:
1413
diff
changeset
|
564 SortModeType mode, SortSelectionType selection, |
1817f5178db3
Fix bug when adding a new collection through sort manager. Tidy up.
zas_
parents:
1413
diff
changeset
|
565 const gchar *filter_key) |
9 | 566 { |
567 SortData *sd; | |
568 GtkWidget *buttongrp; | |
569 GtkWidget *label; | |
570 GtkWidget *tbar; | |
571 GtkWidget *combo; | |
1272 | 572 GList *editors_list, *work; |
573 gboolean have_filter; | |
9 | 574 |
575 if (!lw) return NULL; | |
576 | |
577 sd = g_new0(SortData, 1); | |
578 | |
579 sd->lw = lw; | |
491 | 580 |
1320 | 581 sd->action = action; |
753 | 582 |
1320 | 583 if (sd->action == BAR_SORT_FILTER && (!filter_key || !filter_key[0])) |
584 { | |
1272 | 585 sd->action = BAR_SORT_COPY; |
1320 | 586 } |
753 | 587 |
1320 | 588 sd->selection = selection; |
9 | 589 sd->undo_src = NULL; |
590 sd->undo_dest = NULL; | |
591 | |
592 sd->vbox = gtk_vbox_new(FALSE, PREF_PAD_GAP); | |
593 g_object_set_data(G_OBJECT(sd->vbox), "bar_sort_data", sd); | |
594 g_signal_connect(G_OBJECT(sd->vbox), "destroy", | |
595 G_CALLBACK(bar_sort_destroy), sd); | |
596 | |
597 label = gtk_label_new(_("Sort Manager")); | |
598 pref_label_bold(label, TRUE, FALSE); | |
599 gtk_box_pack_start(GTK_BOX(sd->vbox), label, FALSE, FALSE, 0); | |
600 gtk_widget_show(label); | |
601 | |
602 combo = gtk_combo_box_new_text(); | |
603 gtk_box_pack_start(GTK_BOX(sd->vbox), combo, FALSE, FALSE, 0); | |
604 gtk_widget_show(combo); | |
605 | |
606 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("Folders")); | |
607 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("Collections")); | |
608 | |
609 g_signal_connect(G_OBJECT(combo), "changed", | |
610 G_CALLBACK(bar_sort_mode_cb), sd); | |
611 | |
612 sd->folder_group = pref_box_new(sd->vbox, FALSE, GTK_ORIENTATION_VERTICAL, 0); | |
613 | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
614 buttongrp = pref_radiobutton_new(sd->folder_group, NULL, |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
615 _("Copy"), (sd->action == BAR_SORT_COPY), |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
616 G_CALLBACK(bar_sort_set_copy_cb), sd); |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
617 pref_radiobutton_new(sd->folder_group, buttongrp, |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
618 _("Move"), (sd->action == BAR_SORT_MOVE), |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
619 G_CALLBACK(bar_sort_set_move_cb), sd); |
753 | 620 |
621 | |
1272 | 622 have_filter = FALSE; |
623 editors_list = editor_list_get(); | |
624 work = editors_list; | |
625 while (work) | |
753 | 626 { |
627 GtkWidget *button; | |
1272 | 628 EditorDescription *editor = work->data; |
1413
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1320
diff
changeset
|
629 gchar *key; |
1272 | 630 gboolean select = FALSE; |
1413
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1320
diff
changeset
|
631 |
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1320
diff
changeset
|
632 work = work->next; |
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1320
diff
changeset
|
633 |
1272 | 634 if (!editor_is_filter(editor->key)) continue; |
1413
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1320
diff
changeset
|
635 |
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1320
diff
changeset
|
636 key = g_strdup(editor->key); |
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1320
diff
changeset
|
637 if (sd->action == BAR_SORT_FILTER && strcmp(key, filter_key) == 0) |
1272 | 638 { |
1413
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1320
diff
changeset
|
639 bar_sort_set_action(sd, sd->action, key); |
1272 | 640 select = TRUE; |
641 have_filter = TRUE; | |
642 } | |
1413
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1320
diff
changeset
|
643 |
753 | 644 button = pref_radiobutton_new(sd->folder_group, buttongrp, |
1272 | 645 editor->name, select, |
753 | 646 G_CALLBACK(bar_sort_set_filter_cb), sd); |
647 | |
1413
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1320
diff
changeset
|
648 g_object_set_data_full(G_OBJECT(button), "filter_key", key, bar_sort_edit_button_free); |
753 | 649 } |
1272 | 650 g_list_free(editors_list); |
651 | |
652 if (sd->action == BAR_SORT_FILTER && !have_filter) sd->action = BAR_SORT_COPY; | |
9 | 653 |
654 sd->collection_group = pref_box_new(sd->vbox, FALSE, GTK_ORIENTATION_VERTICAL, 0); | |
655 | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
656 buttongrp = pref_radiobutton_new(sd->collection_group, NULL, |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
657 _("Add image"), (sd->selection == BAR_SORT_SELECTION_IMAGE), |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
658 G_CALLBACK(bar_sort_set_selection_image_cb), sd); |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
659 pref_radiobutton_new(sd->collection_group, buttongrp, |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
660 _("Add selection"), (sd->selection == BAR_SORT_SELECTION_SELECTED), |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
661 G_CALLBACK(bar_sort_set_selection_selected_cb), sd); |
9 | 662 |
663 sd->bookmarks = bookmark_list_new(SORT_KEY_FOLDERS, bar_sort_bookmark_select, sd); | |
664 gtk_box_pack_start(GTK_BOX(sd->vbox), sd->bookmarks, TRUE, TRUE, 0); | |
665 gtk_widget_show(sd->bookmarks); | |
666 | |
667 tbar = pref_toolbar_new(sd->vbox, GTK_TOOLBAR_ICONS); | |
668 | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
669 sd->add_button = pref_toolbar_button(tbar, GTK_STOCK_ADD, NULL, FALSE, |
9 | 670 _("Add Bookmark"), |
671 G_CALLBACK(bar_sort_add_cb), sd); | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
672 sd->undo_button = pref_toolbar_button(tbar, GTK_STOCK_UNDO, NULL, FALSE, |
9 | 673 _("Undo last image"), |
674 G_CALLBACK(bar_sort_undo_cb), sd); | |
675 | |
676 sd->mode = -1; | |
491 | 677 bar_sort_mode_sync(sd, mode); |
9 | 678 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), sd->mode); |
442 | 679 |
9 | 680 return sd->vbox; |
681 } | |
1320 | 682 |
683 GtkWidget *bar_sort_new_from_config(LayoutWindow *lw, const gchar **attribute_names, const gchar **attribute_values) | |
684 { | |
685 GtkWidget *bar; | |
686 | |
687 gboolean enabled = TRUE; | |
688 gint action = 0; | |
689 gint mode = 0; | |
690 gint selection = 0; | |
691 gchar *filter_key = NULL; | |
692 | |
693 while (attribute_names && *attribute_names) | |
694 { | |
695 const gchar *option = *attribute_names++; | |
696 const gchar *value = *attribute_values++; | |
697 | |
698 if (READ_BOOL_FULL("enabled", enabled)) continue; | |
699 if (READ_INT_CLAMP_FULL("action", action, 0, BAR_SORT_ACTION_COUNT - 1)) continue; | |
700 if (READ_INT_CLAMP_FULL("mode", mode, 0, BAR_SORT_MODE_COUNT - 1)) continue; | |
701 if (READ_INT_CLAMP_FULL("selection", selection, 0, BAR_SORT_SELECTION_COUNT - 1)) continue; | |
702 if (READ_CHAR_FULL("filter_key", filter_key)) continue; | |
703 | |
1464 | 704 log_printf("unknown attribute %s = %s\n", option, value); |
1320 | 705 } |
706 bar = bar_sort_new(lw, action, mode, selection, filter_key); | |
707 | |
708 g_free(filter_key); | |
709 if (enabled) gtk_widget_show(bar); | |
710 return bar; | |
711 } | |
712 | |
713 GtkWidget *bar_sort_new_default(LayoutWindow *lw) | |
714 { | |
715 return bar_sort_new_from_config(lw, NULL, NULL); | |
716 } | |
717 | |
718 void bar_sort_write_config(GtkWidget *bar, GString *outstr, gint indent) | |
719 { | |
720 SortData *sd; | |
721 | |
722 if (!bar) return; | |
723 sd = g_object_get_data(G_OBJECT(bar), "bar_sort_data"); | |
724 if (!sd) return; | |
725 | |
1461 | 726 WRITE_NL(); WRITE_STRING("<bar_sort "); |
1320 | 727 write_bool_option(outstr, indent, "enabled", GTK_WIDGET_VISIBLE(bar)); |
728 WRITE_INT(*sd, mode); | |
729 WRITE_INT(*sd, action); | |
730 WRITE_INT(*sd, selection); | |
731 WRITE_CHAR(*sd, filter_key); | |
1461 | 732 WRITE_STRING("/>"); |
1320 | 733 } |
734 | |
735 | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
995
diff
changeset
|
736 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |