Mercurial > geeqie
annotate src/bar_sort.c @ 1344:3f9be528787c
show histogram label in the title
adjusted label texts
author | nadvornik |
---|---|
date | Sat, 28 Feb 2009 20:13:11 +0000 |
parents | 055ed09d5a03 |
children | 3bc4967aaa57 |
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; | |
1272 | 69 const gchar *filter_key; |
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 { | |
134 gint folder_mode; | |
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 = ""; | |
358 sd->filter_key = filter_key; | |
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; | |
419 const gchar *name; | |
420 | |
421 name = gtk_entry_get_text(GTK_ENTRY(sd->dialog_name_entry)); | |
422 if (sd->mode == BAR_SORT_MODE_FOLDER) | |
423 { | |
424 if (strlen(name) == 0) | |
425 { | |
426 name = filename_from_path(fd->dest_path); | |
427 } | |
428 | |
429 bookmark_list_add(sd->bookmarks, name, fd->dest_path); | |
430 } | |
431 else | |
432 { | |
433 gchar *path; | |
700 | 434 |
9 | 435 if (strlen(name) == 0) return; |
436 | |
781
2d2cca2bceb0
Replace hardcoded collection filename extension by a macro (GQ_COLLECTION_EXT).
zas_
parents:
780
diff
changeset
|
437 if (!file_extension_match(name, GQ_COLLECTION_EXT)) |
9 | 438 { |
781
2d2cca2bceb0
Replace hardcoded collection filename extension by a macro (GQ_COLLECTION_EXT).
zas_
parents:
780
diff
changeset
|
439 gchar *tmp = g_strconcat(name, GQ_COLLECTION_EXT, NULL); |
700 | 440 g_free((gpointer) name); |
441 name = tmp; | |
9 | 442 } |
443 | |
1145
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
444 path = g_build_filename(get_collections_dir(), name, NULL); |
9 | 445 if (isfile(path)) |
446 { | |
447 gchar *text = g_strdup_printf(_("The collection:\n%s\nalready exists."), name); | |
448 file_util_warning_dialog(_("Collection exists"), text, GTK_STOCK_DIALOG_INFO, NULL); | |
449 g_free(text); | |
450 } | |
451 else | |
452 { | |
453 CollectionData *cd; | |
454 | |
455 cd = collection_new(path); | |
456 if (collection_save(cd, path)) | |
457 { | |
458 bar_sort_collection_list_build(sd->bookmarks); | |
459 } | |
460 else | |
461 { | |
462 gchar *text = g_strdup_printf(_("Failed to save the collection:\n%s"), path); | |
463 file_util_warning_dialog(_("Save Failed"), text, | |
464 GTK_STOCK_DIALOG_ERROR, GENERIC_DIALOG(fd)->dialog); | |
465 g_free(text); | |
466 } | |
467 collection_unref(cd); | |
468 } | |
469 | |
470 g_free(path); | |
471 } | |
472 | |
473 bar_sort_add_close(sd); | |
474 } | |
475 | |
476 static void bar_sort_add_cancel_cb(FileDialog *fd, gpointer data) | |
477 { | |
478 SortData *sd = data; | |
479 | |
480 bar_sort_add_close(sd); | |
481 } | |
482 | |
483 static void bar_sort_add_cb(GtkWidget *button, gpointer data) | |
484 { | |
485 SortData *sd = data; | |
486 GtkWidget *hbox; | |
487 const gchar *title; | |
488 | |
489 if (sd->dialog) | |
490 { | |
491 gtk_window_present(GTK_WINDOW(GENERIC_DIALOG(sd->dialog)->dialog)); | |
492 return; | |
493 } | |
494 | |
495 if (sd->mode == BAR_SORT_MODE_FOLDER) | |
496 { | |
497 title = _("Add Bookmark"); | |
498 } | |
499 else | |
500 { | |
501 title = _("Add Collection"); | |
502 } | |
503 | |
504 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
|
505 "add_bookmark", button, |
9 | 506 bar_sort_add_cancel_cb, sd); |
507 file_dialog_add_button(sd->dialog, GTK_STOCK_OK, NULL, bar_sort_add_ok_cb, TRUE); | |
508 | |
509 generic_dialog_add_message(GENERIC_DIALOG(sd->dialog), NULL, title, NULL); | |
510 | |
511 if (sd->mode == BAR_SORT_MODE_FOLDER) | |
512 { | |
513 file_dialog_add_path_widgets(sd->dialog, NULL, NULL, "add_bookmark", NULL, NULL); | |
514 } | |
515 | |
516 hbox = pref_box_new(GENERIC_DIALOG(sd->dialog)->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP); | |
517 | |
518 pref_label_new(hbox, _("Name:")); | |
519 | |
520 sd->dialog_name_entry = gtk_entry_new(); | |
521 gtk_box_pack_start(GTK_BOX(hbox), sd->dialog_name_entry, TRUE, TRUE, 0); | |
522 generic_dialog_attach_default(GENERIC_DIALOG(sd->dialog), sd->dialog_name_entry); | |
523 gtk_widget_show(sd->dialog_name_entry); | |
524 | |
525 if (sd->mode == BAR_SORT_MODE_COLLECTION) | |
526 { | |
527 gtk_widget_grab_focus(sd->dialog_name_entry); | |
528 } | |
529 | |
530 gtk_widget_show(GENERIC_DIALOG(sd->dialog)->dialog); | |
531 } | |
532 | |
533 void bar_sort_close(GtkWidget *bar) | |
534 { | |
535 SortData *sd; | |
536 | |
537 sd = g_object_get_data(G_OBJECT(bar), "bar_sort_data"); | |
538 if (!sd) return; | |
539 | |
540 gtk_widget_destroy(sd->vbox); | |
541 } | |
542 | |
543 static void bar_sort_destroy(GtkWidget *widget, gpointer data) | |
544 { | |
545 SortData *sd = data; | |
546 | |
547 bar_sort_add_close(sd); | |
548 | |
549 g_free(sd->undo_src); | |
550 g_free(sd->undo_dest); | |
551 g_free(sd); | |
552 } | |
553 | |
1320 | 554 static GtkWidget *bar_sort_new(LayoutWindow *lw, SortActionType action, SortModeType mode, SortSelectionType selection, const gchar *filter_key) |
9 | 555 { |
556 SortData *sd; | |
557 GtkWidget *buttongrp; | |
558 GtkWidget *label; | |
559 GtkWidget *tbar; | |
560 GtkWidget *combo; | |
1272 | 561 GList *editors_list, *work; |
562 gboolean have_filter; | |
9 | 563 |
564 if (!lw) return NULL; | |
565 | |
566 sd = g_new0(SortData, 1); | |
567 | |
568 sd->lw = lw; | |
491 | 569 |
1320 | 570 sd->action = action; |
753 | 571 |
1320 | 572 if (sd->action == BAR_SORT_FILTER && (!filter_key || !filter_key[0])) |
573 { | |
1272 | 574 sd->action = BAR_SORT_COPY; |
1320 | 575 } |
753 | 576 |
1320 | 577 sd->selection = selection; |
9 | 578 sd->undo_src = NULL; |
579 sd->undo_dest = NULL; | |
580 | |
581 sd->vbox = gtk_vbox_new(FALSE, PREF_PAD_GAP); | |
582 g_object_set_data(G_OBJECT(sd->vbox), "bar_sort_data", sd); | |
583 g_signal_connect(G_OBJECT(sd->vbox), "destroy", | |
584 G_CALLBACK(bar_sort_destroy), sd); | |
585 | |
586 label = gtk_label_new(_("Sort Manager")); | |
587 pref_label_bold(label, TRUE, FALSE); | |
588 gtk_box_pack_start(GTK_BOX(sd->vbox), label, FALSE, FALSE, 0); | |
589 gtk_widget_show(label); | |
590 | |
591 combo = gtk_combo_box_new_text(); | |
592 gtk_box_pack_start(GTK_BOX(sd->vbox), combo, FALSE, FALSE, 0); | |
593 gtk_widget_show(combo); | |
594 | |
595 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("Folders")); | |
596 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("Collections")); | |
597 | |
598 g_signal_connect(G_OBJECT(combo), "changed", | |
599 G_CALLBACK(bar_sort_mode_cb), sd); | |
600 | |
601 sd->folder_group = pref_box_new(sd->vbox, FALSE, GTK_ORIENTATION_VERTICAL, 0); | |
602 | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
603 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
|
604 _("Copy"), (sd->action == BAR_SORT_COPY), |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
605 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
|
606 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
|
607 _("Move"), (sd->action == BAR_SORT_MOVE), |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
608 G_CALLBACK(bar_sort_set_move_cb), sd); |
753 | 609 |
610 | |
1272 | 611 have_filter = FALSE; |
612 editors_list = editor_list_get(); | |
613 work = editors_list; | |
614 while (work) | |
753 | 615 { |
616 GtkWidget *button; | |
1272 | 617 EditorDescription *editor = work->data; |
618 work = work->next; | |
619 gboolean select = FALSE; | |
620 | |
621 if (!editor_is_filter(editor->key)) continue; | |
753 | 622 |
1320 | 623 if (sd->action == BAR_SORT_FILTER && strcmp(editor->key, filter_key) == 0) |
1272 | 624 { |
625 bar_sort_set_action(sd, sd->action, editor->key); | |
626 select = TRUE; | |
627 have_filter = TRUE; | |
628 } | |
753 | 629 |
630 button = pref_radiobutton_new(sd->folder_group, buttongrp, | |
1272 | 631 editor->name, select, |
753 | 632 G_CALLBACK(bar_sort_set_filter_cb), sd); |
633 | |
634 | |
1272 | 635 g_object_set_data(G_OBJECT(button), "filter_key", editor->key); |
753 | 636 } |
1272 | 637 g_list_free(editors_list); |
638 | |
639 if (sd->action == BAR_SORT_FILTER && !have_filter) sd->action = BAR_SORT_COPY; | |
9 | 640 |
641 sd->collection_group = pref_box_new(sd->vbox, FALSE, GTK_ORIENTATION_VERTICAL, 0); | |
642 | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
643 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
|
644 _("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
|
645 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
|
646 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
|
647 _("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
|
648 G_CALLBACK(bar_sort_set_selection_selected_cb), sd); |
9 | 649 |
650 sd->bookmarks = bookmark_list_new(SORT_KEY_FOLDERS, bar_sort_bookmark_select, sd); | |
651 gtk_box_pack_start(GTK_BOX(sd->vbox), sd->bookmarks, TRUE, TRUE, 0); | |
652 gtk_widget_show(sd->bookmarks); | |
653 | |
654 tbar = pref_toolbar_new(sd->vbox, GTK_TOOLBAR_ICONS); | |
655 | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
656 sd->add_button = pref_toolbar_button(tbar, GTK_STOCK_ADD, NULL, FALSE, |
9 | 657 _("Add Bookmark"), |
658 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
|
659 sd->undo_button = pref_toolbar_button(tbar, GTK_STOCK_UNDO, NULL, FALSE, |
9 | 660 _("Undo last image"), |
661 G_CALLBACK(bar_sort_undo_cb), sd); | |
662 | |
663 sd->mode = -1; | |
491 | 664 bar_sort_mode_sync(sd, mode); |
9 | 665 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), sd->mode); |
442 | 666 |
9 | 667 return sd->vbox; |
668 } | |
1320 | 669 |
670 GtkWidget *bar_sort_new_from_config(LayoutWindow *lw, const gchar **attribute_names, const gchar **attribute_values) | |
671 { | |
672 GtkWidget *bar; | |
673 | |
674 gboolean enabled = TRUE; | |
675 gint action = 0; | |
676 gint mode = 0; | |
677 gint selection = 0; | |
678 gchar *filter_key = NULL; | |
679 | |
680 while (attribute_names && *attribute_names) | |
681 { | |
682 const gchar *option = *attribute_names++; | |
683 const gchar *value = *attribute_values++; | |
684 | |
685 if (READ_BOOL_FULL("enabled", enabled)) continue; | |
686 if (READ_INT_CLAMP_FULL("action", action, 0, BAR_SORT_ACTION_COUNT - 1)) continue; | |
687 if (READ_INT_CLAMP_FULL("mode", mode, 0, BAR_SORT_MODE_COUNT - 1)) continue; | |
688 if (READ_INT_CLAMP_FULL("selection", selection, 0, BAR_SORT_SELECTION_COUNT - 1)) continue; | |
689 if (READ_CHAR_FULL("filter_key", filter_key)) continue; | |
690 | |
691 DEBUG_1("unknown attribute %s = %s", option, value); | |
692 } | |
693 bar = bar_sort_new(lw, action, mode, selection, filter_key); | |
694 | |
695 g_free(filter_key); | |
696 if (enabled) gtk_widget_show(bar); | |
697 return bar; | |
698 } | |
699 | |
700 GtkWidget *bar_sort_new_default(LayoutWindow *lw) | |
701 { | |
702 return bar_sort_new_from_config(lw, NULL, NULL); | |
703 } | |
704 | |
705 void bar_sort_write_config(GtkWidget *bar, GString *outstr, gint indent) | |
706 { | |
707 SortData *sd; | |
708 | |
709 if (!bar) return; | |
710 sd = g_object_get_data(G_OBJECT(bar), "bar_sort_data"); | |
711 if (!sd) return; | |
712 | |
713 WRITE_STRING("<bar_sort\n"); | |
714 indent++; | |
715 write_bool_option(outstr, indent, "enabled", GTK_WIDGET_VISIBLE(bar)); | |
716 WRITE_INT(*sd, mode); | |
717 WRITE_INT(*sd, action); | |
718 WRITE_INT(*sd, selection); | |
719 WRITE_CHAR(*sd, filter_key); | |
720 indent--; | |
721 WRITE_STRING("/>\n"); | |
722 } | |
723 | |
724 | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
995
diff
changeset
|
725 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |