2 * Copyright (C) 2004 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "layout-util.h"
33 #include <glib-object.h>
37 #include "advanced-exif.h"
39 #include "bar-keywords.h"
42 #include "cache-maint.h"
43 #include "collect-io.h"
45 #include "color-man.h"
48 #include "desktop-file.h"
52 #include "fullscreen.h"
53 #include "histogram.h"
54 #include "history-list.h"
55 #include "image-overlay.h"
59 #include "keymap-template.h"
60 #include "layout-image.h"
62 #include "logwindow.h"
63 #include "main-defines.h"
69 #include "pixbuf-renderer.h"
70 #include "pixbuf-util.h"
71 #include "preferences.h"
74 #include "search-and-run.h"
76 #include "slideshow.h"
77 #include "ui-fileops.h"
80 #include "ui-utildlg.h"
83 #include "view-file.h"
86 static gboolean layout_bar_enabled(LayoutWindow *lw);
87 static gboolean layout_bar_sort_enabled(LayoutWindow *lw);
88 static void layout_bars_hide_toggle(LayoutWindow *lw);
89 static void layout_util_sync_views(LayoutWindow *lw);
90 static void layout_search_and_run_window_new(LayoutWindow *lw);
93 *-----------------------------------------------------------------------------
95 *-----------------------------------------------------------------------------
98 static guint tree_key_overrides[] = {
99 GDK_KEY_Page_Up, GDK_KEY_KP_Page_Up,
100 GDK_KEY_Page_Down, GDK_KEY_KP_Page_Down,
101 GDK_KEY_Home, GDK_KEY_KP_Home,
102 GDK_KEY_End, GDK_KEY_KP_End
105 static gboolean layout_key_match(guint keyval)
109 for (i = 0; i < sizeof(tree_key_overrides) / sizeof(guint); i++)
111 if (keyval == tree_key_overrides[i]) return TRUE;
117 void keyboard_scroll_calc(gint &x, gint &y, const GdkEventKey *event)
119 static gint delta = 0;
120 static guint32 time_old = 0;
121 static guint keyval_old = 0;
123 if (event->state & GDK_SHIFT_MASK)
129 if (event->state & GDK_CONTROL_MASK)
131 if (x < 0) x = G_MININT / 2;
132 if (x > 0) x = G_MAXINT / 2;
133 if (y < 0) y = G_MININT / 2;
134 if (y > 0) y = G_MAXINT / 2;
139 if (options->progressive_key_scrolling)
143 time_diff = event->time - time_old;
145 /* key pressed within 125ms ? (1/8 second) */
146 if (time_diff > 125 || event->keyval != keyval_old) delta = 0;
148 time_old = event->time;
149 keyval_old = event->keyval;
158 x *= delta * options->keyboard_scroll_step;
159 y *= delta * options->keyboard_scroll_step;
162 gboolean layout_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
164 auto lw = static_cast<LayoutWindow *>(data);
166 gboolean stop_signal = FALSE;
170 if (lw->path_entry && gtk_widget_has_focus(lw->path_entry))
172 if (event->keyval == GDK_KEY_Escape && lw->dir_fd)
174 gq_gtk_entry_set_text(GTK_ENTRY(lw->path_entry), lw->dir_fd->path);
177 /* the gtkaccelgroup of the window is stealing presses before they get to the entry (and more),
178 * so when the some widgets have focus, give them priority (HACK)
180 if (gtk_widget_event(lw->path_entry, reinterpret_cast<GdkEvent *>(event)))
186 if (lw->vf->file_filter.combo && gtk_widget_has_focus(gtk_bin_get_child(GTK_BIN(lw->vf->file_filter.combo))))
188 if (gtk_widget_event(gtk_bin_get_child(GTK_BIN(lw->vf->file_filter.combo)), reinterpret_cast<GdkEvent *>(event)))
194 if (lw->vd && lw->options.dir_view_type == DIRVIEW_TREE && gtk_widget_has_focus(lw->vd->view) &&
195 !layout_key_match(event->keyval) &&
196 gtk_widget_event(lw->vd->view, reinterpret_cast<GdkEvent *>(event)))
201 bar_event(lw->bar, reinterpret_cast<GdkEvent *>(event)))
206 focused = gtk_container_get_focus_child(GTK_CONTAINER(lw->image->widget));
208 ((focused && gtk_widget_has_focus(focused)) || (lw->tools && widget == lw->window) || lw->full_screen) )
211 switch (event->keyval)
213 case GDK_KEY_Left: case GDK_KEY_KP_Left:
216 case GDK_KEY_Right: case GDK_KEY_KP_Right:
219 case GDK_KEY_Up: case GDK_KEY_KP_Up:
222 case GDK_KEY_Down: case GDK_KEY_KP_Down:
231 !(event->state & GDK_CONTROL_MASK))
234 switch (event->keyval)
237 layout_image_menu_popup(lw);
248 keyboard_scroll_calc(x, y, event);
249 layout_image_scroll(lw, x, y, (event->state & GDK_SHIFT_MASK));
255 void layout_keyboard_init(LayoutWindow *lw, GtkWidget *window)
257 g_signal_connect(G_OBJECT(window), "key_press_event",
258 G_CALLBACK(layout_key_press_cb), lw);
262 *-----------------------------------------------------------------------------
264 *-----------------------------------------------------------------------------
268 static GtkWidget *layout_window(LayoutWindow *lw)
270 return lw->full_screen ? lw->full_screen->window : lw->window;
273 static void layout_exit_fullscreen(LayoutWindow *lw)
275 if (!lw->full_screen) return;
276 layout_image_full_screen_stop(lw);
279 static void clear_marks_cancel_cb(GenericDialog *gd, gpointer)
281 generic_dialog_close(gd);
284 static void clear_marks_help_cb(GenericDialog *, gpointer)
286 help_window_show("GuideMainWindowMenus.html");
289 void layout_menu_clear_marks_ok_cb(GenericDialog *gd, gpointer)
292 generic_dialog_close(gd);
295 static void layout_menu_clear_marks_cb(GtkAction *, gpointer)
299 gd = generic_dialog_new(_("Clear Marks"),
300 "marks_clear", nullptr, FALSE, clear_marks_cancel_cb, nullptr);
301 generic_dialog_add_message(gd, GQ_ICON_DIALOG_QUESTION, _("Clear all marks?"), _("This will clear all marks for all images,\nincluding those linked to keywords"), TRUE);
302 generic_dialog_add_button(gd, GQ_ICON_OK, "OK", layout_menu_clear_marks_ok_cb, TRUE);
303 generic_dialog_add_button(gd, GQ_ICON_HELP, _("Help"),
304 clear_marks_help_cb, FALSE);
306 gtk_widget_show(gd->dialog);
309 static void layout_menu_new_cb(GtkAction *, gpointer data)
311 auto lw = static_cast<LayoutWindow *>(data);
313 layout_exit_fullscreen(lw);
314 collection_window_new(nullptr);
317 static void layout_menu_open_cb(GtkAction *widget, gpointer data)
319 auto lw = static_cast<LayoutWindow *>(data);
322 GList *collection_list = nullptr;
324 layout_exit_fullscreen(lw);
326 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "recent_index"));
327 collect_manager_list(nullptr, nullptr, &collection_list);
329 path = static_cast<gchar *>(g_list_nth_data(collection_list, n));
333 /* make a copy of it */
334 path = g_strdup(path);
335 collection_window_new(path);
339 string_list_free(collection_list);
342 static void layout_menu_search_cb(GtkAction *, gpointer data)
344 auto lw = static_cast<LayoutWindow *>(data);
346 layout_exit_fullscreen(lw);
347 search_new(lw->dir_fd, layout_image_get_fd(lw));
350 static void layout_menu_dupes_cb(GtkAction *, gpointer data)
352 auto lw = static_cast<LayoutWindow *>(data);
354 layout_exit_fullscreen(lw);
358 static void layout_menu_pan_cb(GtkAction *, gpointer data)
360 auto lw = static_cast<LayoutWindow *>(data);
362 layout_exit_fullscreen(lw);
363 pan_window_new(lw->dir_fd);
366 static void layout_menu_print_cb(GtkAction *, gpointer data)
368 auto lw = static_cast<LayoutWindow *>(data);
370 print_window_new(layout_image_get_fd(lw), layout_selection_list(lw), layout_list(lw), layout_window(lw));
373 static void layout_menu_dir_cb(GtkAction *, gpointer data)
375 auto lw = static_cast<LayoutWindow *>(data);
377 if (lw->vd) vd_new_folder(lw->vd, lw->dir_fd);
380 static void layout_menu_copy_cb(GtkAction *, gpointer data)
382 auto lw = static_cast<LayoutWindow *>(data);
384 file_util_copy(nullptr, layout_selection_list(lw), nullptr, layout_window(lw));
387 static void layout_menu_copy_path_cb(GtkAction *, gpointer data)
389 auto lw = static_cast<LayoutWindow *>(data);
391 file_util_path_list_to_clipboard(layout_selection_list(lw), TRUE, TRUE);
394 static void layout_menu_copy_path_unquoted_cb(GtkAction *, gpointer data)
396 auto lw = static_cast<LayoutWindow *>(data);
398 file_util_path_list_to_clipboard(layout_selection_list(lw), FALSE, TRUE);
401 static void layout_menu_cut_path_cb(GtkAction *, gpointer data)
403 auto lw = static_cast<LayoutWindow *>(data);
405 file_util_path_list_to_clipboard(layout_selection_list(lw), FALSE, FALSE);
408 static void layout_menu_move_cb(GtkAction *, gpointer data)
410 auto lw = static_cast<LayoutWindow *>(data);
412 file_util_move(nullptr, layout_selection_list(lw), nullptr, layout_window(lw));
415 static void layout_menu_rename_cb(GtkAction *, gpointer data)
417 auto lw = static_cast<LayoutWindow *>(data);
419 file_util_rename(nullptr, layout_selection_list(lw), layout_window(lw));
422 static void layout_menu_delete_cb(GtkAction *, gpointer data)
424 auto lw = static_cast<LayoutWindow *>(data);
426 options->file_ops.safe_delete_enable = FALSE;
427 file_util_delete(nullptr, layout_selection_list(lw), layout_window(lw));
430 static void layout_menu_move_to_trash_cb(GtkAction *, gpointer data)
432 auto lw = static_cast<LayoutWindow *>(data);
434 options->file_ops.safe_delete_enable = TRUE;
435 file_util_delete(nullptr, layout_selection_list(lw), layout_window(lw));
438 static void layout_menu_move_to_trash_key_cb(GtkAction *, gpointer data)
440 auto lw = static_cast<LayoutWindow *>(data);
442 if (options->file_ops.enable_delete_key)
444 options->file_ops.safe_delete_enable = TRUE;
445 file_util_delete(nullptr, layout_selection_list(lw), layout_window(lw));
449 static void layout_menu_disable_grouping_cb(GtkAction *, gpointer data)
451 auto lw = static_cast<LayoutWindow *>(data);
453 file_data_disable_grouping_list(layout_selection_list(lw), TRUE);
456 static void layout_menu_enable_grouping_cb(GtkAction *, gpointer data)
458 auto lw = static_cast<LayoutWindow *>(data);
460 file_data_disable_grouping_list(layout_selection_list(lw), FALSE);
463 void layout_menu_close_cb(GtkAction *, gpointer data)
465 auto lw = static_cast<LayoutWindow *>(data);
467 layout_exit_fullscreen(lw);
471 static void layout_menu_exit_cb(GtkAction *, gpointer)
476 static void layout_menu_alter_90_cb(GtkAction *, gpointer data)
478 auto lw = static_cast<LayoutWindow *>(data);
480 layout_image_alter_orientation(lw, ALTER_ROTATE_90);
483 static void layout_menu_rating_0_cb(GtkAction *, gpointer data)
485 auto lw = static_cast<LayoutWindow *>(data);
487 layout_image_rating(lw, "0");
490 static void layout_menu_rating_1_cb(GtkAction *, gpointer data)
492 auto lw = static_cast<LayoutWindow *>(data);
494 layout_image_rating(lw, "1");
497 static void layout_menu_rating_2_cb(GtkAction *, gpointer data)
499 auto lw = static_cast<LayoutWindow *>(data);
501 layout_image_rating(lw, "2");
504 static void layout_menu_rating_3_cb(GtkAction *, gpointer data)
506 auto lw = static_cast<LayoutWindow *>(data);
508 layout_image_rating(lw, "3");
511 static void layout_menu_rating_4_cb(GtkAction *, gpointer data)
513 auto lw = static_cast<LayoutWindow *>(data);
515 layout_image_rating(lw, "4");
518 static void layout_menu_rating_5_cb(GtkAction *, gpointer data)
520 auto lw = static_cast<LayoutWindow *>(data);
522 layout_image_rating(lw, "5");
525 static void layout_menu_rating_m1_cb(GtkAction *, gpointer data)
527 auto lw = static_cast<LayoutWindow *>(data);
529 layout_image_rating(lw, "-1");
532 static void layout_menu_alter_90cc_cb(GtkAction *, gpointer data)
534 auto lw = static_cast<LayoutWindow *>(data);
536 layout_image_alter_orientation(lw, ALTER_ROTATE_90_CC);
539 static void layout_menu_alter_180_cb(GtkAction *, gpointer data)
541 auto lw = static_cast<LayoutWindow *>(data);
543 layout_image_alter_orientation(lw, ALTER_ROTATE_180);
546 static void layout_menu_alter_mirror_cb(GtkAction *, gpointer data)
548 auto lw = static_cast<LayoutWindow *>(data);
550 layout_image_alter_orientation(lw, ALTER_MIRROR);
553 static void layout_menu_alter_flip_cb(GtkAction *, gpointer data)
555 auto lw = static_cast<LayoutWindow *>(data);
557 layout_image_alter_orientation(lw, ALTER_FLIP);
560 static void layout_menu_alter_desaturate_cb(GtkToggleAction *action, gpointer data)
562 auto lw = static_cast<LayoutWindow *>(data);
564 layout_image_set_desaturate(lw, gtk_toggle_action_get_active(action));
567 static void layout_menu_alter_ignore_alpha_cb(GtkToggleAction *action, gpointer data)
569 auto lw = static_cast<LayoutWindow *>(data);
571 if (lw->options.ignore_alpha == gtk_toggle_action_get_active(action)) return;
573 layout_image_set_ignore_alpha(lw, gtk_toggle_action_get_active(action));
576 static void layout_menu_alter_none_cb(GtkAction *, gpointer data)
578 auto lw = static_cast<LayoutWindow *>(data);
580 layout_image_alter_orientation(lw, ALTER_NONE);
583 static void layout_menu_exif_rotate_cb(GtkToggleAction *action, gpointer data)
585 auto lw = static_cast<LayoutWindow *>(data);
587 options->image.exif_rotate_enable = gtk_toggle_action_get_active(action);
588 layout_image_reset_orientation(lw);
591 static void layout_menu_select_rectangle_cb(GtkToggleAction *action, gpointer)
593 options->draw_rectangle = gtk_toggle_action_get_active(action);
596 static void layout_menu_split_pane_sync_cb(GtkToggleAction *action, gpointer data)
598 auto lw = static_cast<LayoutWindow *>(data);
600 lw->options.split_pane_sync = gtk_toggle_action_get_active(action);
603 static void layout_menu_select_overunderexposed_cb(GtkToggleAction *action, gpointer data)
605 auto lw = static_cast<LayoutWindow *>(data);
607 layout_image_set_overunderexposed(lw, gtk_toggle_action_get_active(action));
610 static void layout_menu_write_rotate(GtkToggleAction *, gpointer data, gboolean keep_date)
612 auto lw = static_cast<LayoutWindow *>(data);
614 if (!layout_valid(&lw)) return;
615 if (!lw || !lw->vf) return;
617 const gchar *keep_date_arg = keep_date ? "-t" : "";
619 vf_selection_foreach(lw->vf, [keep_date_arg](FileData *fd_n)
621 gchar *command = g_strdup_printf("%s/geeqie-rotate -r %d %s \"%s\"",
622 gq_bindir, fd_n->user_orientation, keep_date_arg, fd_n->path);
623 int cmdstatus = runcmd(command);
624 gint run_result = WEXITSTATUS(cmdstatus);
627 fd_n->user_orientation = 0;
631 GString *message = g_string_new(_("Operation failed:\n"));
634 message = g_string_append(message, _("No file extension\n"));
635 else if (run_result == 3)
636 message = g_string_append(message, _("Cannot create tmp file\n"));
637 else if (run_result == 4)
638 message = g_string_append(message, _("Operation not supported for filetype\n"));
639 else if (run_result == 5)
640 message = g_string_append(message, _("File is not writable\n"));
641 else if (run_result == 6)
642 message = g_string_append(message, _("Exiftran error\n"));
643 else if (run_result == 7)
644 message = g_string_append(message, _("Mogrify error\n"));
646 message = g_string_append(message, fd_n->name);
648 GenericDialog *gd = generic_dialog_new(_("Image orientation"), "image_orientation", nullptr, TRUE, nullptr, nullptr);
649 generic_dialog_add_message(gd, GQ_ICON_DIALOG_ERROR, _("Image orientation"), message->str, TRUE);
650 generic_dialog_add_button(gd, GQ_ICON_OK, "OK", nullptr, TRUE);
652 gtk_widget_show(gd->dialog);
654 g_string_free(message, TRUE);
661 static void layout_menu_write_rotate_keep_date_cb(GtkToggleAction *action, gpointer data)
663 layout_menu_write_rotate(action, data, TRUE);
666 static void layout_menu_write_rotate_cb(GtkToggleAction *action, gpointer data)
668 layout_menu_write_rotate(action, data, FALSE);
671 static void layout_menu_config_cb(GtkAction *, gpointer data)
673 auto lw = static_cast<LayoutWindow *>(data);
675 layout_exit_fullscreen(lw);
676 show_config_window(lw);
679 static void layout_menu_editors_cb(GtkAction *, gpointer data)
681 auto lw = static_cast<LayoutWindow *>(data);
683 layout_exit_fullscreen(lw);
684 show_editor_list_window();
687 static void layout_menu_layout_config_cb(GtkAction *, gpointer data)
689 auto lw = static_cast<LayoutWindow *>(data);
691 layout_exit_fullscreen(lw);
692 layout_show_config_window(lw);
695 static void layout_menu_remove_thumb_cb(GtkAction *, gpointer data)
697 auto lw = static_cast<LayoutWindow *>(data);
699 layout_exit_fullscreen(lw);
700 cache_manager_show();
703 static void layout_menu_wallpaper_cb(GtkAction *, gpointer data)
705 auto lw = static_cast<LayoutWindow *>(data);
707 layout_image_to_root(lw);
710 /* single window zoom */
711 static void layout_menu_zoom_in_cb(GtkAction *, gpointer data)
713 auto lw = static_cast<LayoutWindow *>(data);
715 layout_image_zoom_adjust(lw, get_zoom_increment(), FALSE);
718 static void layout_menu_zoom_out_cb(GtkAction *, gpointer data)
720 auto lw = static_cast<LayoutWindow *>(data);
722 layout_image_zoom_adjust(lw, -get_zoom_increment(), FALSE);
725 static void layout_menu_zoom_1_1_cb(GtkAction *, gpointer data)
727 auto lw = static_cast<LayoutWindow *>(data);
729 layout_image_zoom_set(lw, 1.0, FALSE);
732 static void layout_menu_zoom_fit_cb(GtkAction *, gpointer data)
734 auto lw = static_cast<LayoutWindow *>(data);
736 layout_image_zoom_set(lw, 0.0, FALSE);
739 static void layout_menu_zoom_fit_hor_cb(GtkAction *, gpointer data)
741 auto lw = static_cast<LayoutWindow *>(data);
743 layout_image_zoom_set_fill_geometry(lw, FALSE, FALSE);
746 static void layout_menu_zoom_fit_vert_cb(GtkAction *, gpointer data)
748 auto lw = static_cast<LayoutWindow *>(data);
750 layout_image_zoom_set_fill_geometry(lw, TRUE, FALSE);
753 static void layout_menu_zoom_2_1_cb(GtkAction *, gpointer data)
755 auto lw = static_cast<LayoutWindow *>(data);
757 layout_image_zoom_set(lw, 2.0, FALSE);
760 static void layout_menu_zoom_3_1_cb(GtkAction *, gpointer data)
762 auto lw = static_cast<LayoutWindow *>(data);
764 layout_image_zoom_set(lw, 3.0, FALSE);
766 static void layout_menu_zoom_4_1_cb(GtkAction *, gpointer data)
768 auto lw = static_cast<LayoutWindow *>(data);
770 layout_image_zoom_set(lw, 4.0, FALSE);
773 static void layout_menu_zoom_1_2_cb(GtkAction *, gpointer data)
775 auto lw = static_cast<LayoutWindow *>(data);
777 layout_image_zoom_set(lw, -2.0, FALSE);
780 static void layout_menu_zoom_1_3_cb(GtkAction *, gpointer data)
782 auto lw = static_cast<LayoutWindow *>(data);
784 layout_image_zoom_set(lw, -3.0, FALSE);
787 static void layout_menu_zoom_1_4_cb(GtkAction *, gpointer data)
789 auto lw = static_cast<LayoutWindow *>(data);
791 layout_image_zoom_set(lw, -4.0, FALSE);
795 static void layout_menu_connect_zoom_in_cb(GtkAction *, gpointer data)
797 auto lw = static_cast<LayoutWindow *>(data);
799 layout_image_zoom_adjust(lw, get_zoom_increment(), TRUE);
802 static void layout_menu_connect_zoom_out_cb(GtkAction *, gpointer data)
804 auto lw = static_cast<LayoutWindow *>(data);
806 layout_image_zoom_adjust(lw, -get_zoom_increment(), TRUE);
809 static void layout_menu_connect_zoom_1_1_cb(GtkAction *, gpointer data)
811 auto lw = static_cast<LayoutWindow *>(data);
813 layout_image_zoom_set(lw, 1.0, TRUE);
816 static void layout_menu_connect_zoom_fit_cb(GtkAction *, gpointer data)
818 auto lw = static_cast<LayoutWindow *>(data);
820 layout_image_zoom_set(lw, 0.0, TRUE);
823 static void layout_menu_connect_zoom_fit_hor_cb(GtkAction *, gpointer data)
825 auto lw = static_cast<LayoutWindow *>(data);
827 layout_image_zoom_set_fill_geometry(lw, FALSE, TRUE);
830 static void layout_menu_connect_zoom_fit_vert_cb(GtkAction *, gpointer data)
832 auto lw = static_cast<LayoutWindow *>(data);
834 layout_image_zoom_set_fill_geometry(lw, TRUE, TRUE);
837 static void layout_menu_connect_zoom_2_1_cb(GtkAction *, gpointer data)
839 auto lw = static_cast<LayoutWindow *>(data);
841 layout_image_zoom_set(lw, 2.0, TRUE);
844 static void layout_menu_connect_zoom_3_1_cb(GtkAction *, gpointer data)
846 auto lw = static_cast<LayoutWindow *>(data);
848 layout_image_zoom_set(lw, 3.0, TRUE);
850 static void layout_menu_connect_zoom_4_1_cb(GtkAction *, gpointer data)
852 auto lw = static_cast<LayoutWindow *>(data);
854 layout_image_zoom_set(lw, 4.0, TRUE);
857 static void layout_menu_connect_zoom_1_2_cb(GtkAction *, gpointer data)
859 auto lw = static_cast<LayoutWindow *>(data);
861 layout_image_zoom_set(lw, -2.0, TRUE);
864 static void layout_menu_connect_zoom_1_3_cb(GtkAction *, gpointer data)
866 auto lw = static_cast<LayoutWindow *>(data);
868 layout_image_zoom_set(lw, -3.0, TRUE);
871 static void layout_menu_connect_zoom_1_4_cb(GtkAction *, gpointer data)
873 auto lw = static_cast<LayoutWindow *>(data);
875 layout_image_zoom_set(lw, -4.0, TRUE);
878 static void layout_menu_zoom_to_rectangle_cb(GtkAction *, gpointer data)
880 auto lw = static_cast<LayoutWindow *>(data);
897 image_get_rectangle(&x1, &y1, &x2, &y2);
899 pr = reinterpret_cast<PixbufRenderer *>(lw->image->pr);
901 vis_width = pr->vis_width;
902 vis_height = pr->vis_height;
903 zoom_width = (gdouble(vis_width) / (x2 - x1));
904 zoom_height = (gdouble(vis_height) / (y2 - y1));
906 pr_coords_map_orientation_reverse(pr->orientation, x1, y1, pr->image_width, pr->image_height, x2 - x1, y2 - y1, &x, &y, &width, &height);
908 center_x = (width / 2) + x;
909 center_y = (height / 2) + y;
911 layout_image_zoom_set(lw, zoom_width > zoom_height ? zoom_height : zoom_width, FALSE);
912 image_scroll_to_point(lw->image, center_x, center_y, 0.5, 0.5);
915 static void layout_menu_split_cb(GtkRadioAction *action, GtkRadioAction *, gpointer data)
917 auto lw = static_cast<LayoutWindow *>(data);
920 layout_exit_fullscreen(lw);
921 mode = static_cast<ImageSplitMode>(gtk_radio_action_get_current_value(action));
922 layout_split_change(lw, mode);
926 static void layout_menu_thumb_cb(GtkToggleAction *action, gpointer data)
928 auto lw = static_cast<LayoutWindow *>(data);
930 layout_thumb_set(lw, gtk_toggle_action_get_active(action));
934 static void layout_menu_list_cb(GtkRadioAction *action, GtkRadioAction *, gpointer data)
936 auto lw = static_cast<LayoutWindow *>(data);
938 layout_exit_fullscreen(lw);
939 layout_views_set(lw, lw->options.dir_view_type, static_cast<FileViewType>(gtk_radio_action_get_current_value(action)));
942 static void layout_menu_view_dir_as_cb(GtkToggleAction *action, gpointer data)
944 auto lw = static_cast<LayoutWindow *>(data);
946 layout_exit_fullscreen(lw);
948 if (gtk_toggle_action_get_active(action))
950 layout_views_set(lw, DIRVIEW_TREE, lw->options.file_view_type);
954 layout_views_set(lw, DIRVIEW_LIST, lw->options.file_view_type);
958 static void layout_menu_view_in_new_window_cb(GtkAction *, gpointer data)
960 auto lw = static_cast<LayoutWindow *>(data);
962 layout_exit_fullscreen(lw);
963 view_window_new(layout_image_get_fd(lw));
968 GAppInfo *application;
970 GtkWidget *app_chooser_dialog;
973 void open_with_response_cb(GtkDialog *, gint response_id, gpointer data)
975 GError *error = nullptr;
976 auto open_with_data = static_cast<OpenWithData *>(data);
978 if (response_id == GTK_RESPONSE_OK)
980 g_app_info_launch(open_with_data->application, open_with_data->g_file_list, nullptr, &error);
984 log_printf("Error launching app: %s\n", error->message);
989 g_object_unref(open_with_data->application);
990 g_object_unref(g_list_first(open_with_data->g_file_list)->data);
991 g_list_free(open_with_data->g_file_list);
992 gtk_widget_destroy(GTK_WIDGET(open_with_data->app_chooser_dialog));
993 g_free(open_with_data);
996 static void open_with_application_selected_cb(GtkAppChooserWidget *, GAppInfo *application, gpointer data)
998 auto open_with_data = static_cast<OpenWithData *>(data);
1000 g_object_unref(open_with_data->application);
1002 open_with_data->application = g_app_info_dup(application);
1005 static void open_with_application_activated_cb(GtkAppChooserWidget *, GAppInfo *application, gpointer data)
1007 GError *error = nullptr;
1008 auto open_with_data = static_cast<OpenWithData *>(data);
1010 g_app_info_launch(application, open_with_data->g_file_list, nullptr, &error);
1014 log_printf("Error launching app.: %s\n", error->message);
1015 g_error_free(error);
1018 g_object_unref(open_with_data->application);
1019 g_object_unref(g_list_first(open_with_data->g_file_list)->data);
1020 g_list_free(open_with_data->g_file_list);
1021 gtk_widget_destroy(GTK_WIDGET(open_with_data->app_chooser_dialog));
1022 g_free(open_with_data);
1025 static void layout_menu_open_with_cb(GtkAction *, gpointer data)
1027 auto lw = static_cast<LayoutWindow *>(data);
1030 OpenWithData *open_with_data;
1032 if (layout_selection_list(lw))
1034 open_with_data = g_new(OpenWithData, 1);
1036 fd = static_cast<FileData *>(g_list_first(layout_selection_list(lw))->data);
1038 open_with_data->g_file_list = g_list_append(nullptr, g_file_new_for_path(fd->path));
1040 open_with_data->app_chooser_dialog = gtk_app_chooser_dialog_new(nullptr, GTK_DIALOG_DESTROY_WITH_PARENT, G_FILE(g_list_first(open_with_data->g_file_list)->data));
1042 widget = gtk_app_chooser_dialog_get_widget(GTK_APP_CHOOSER_DIALOG(open_with_data->app_chooser_dialog));
1044 open_with_data->application = gtk_app_chooser_get_app_info(GTK_APP_CHOOSER(open_with_data->app_chooser_dialog));
1046 g_signal_connect(G_OBJECT(widget), "application-selected", G_CALLBACK(open_with_application_selected_cb), open_with_data);
1047 g_signal_connect(G_OBJECT(widget), "application-activated", G_CALLBACK(open_with_application_activated_cb), open_with_data);
1048 g_signal_connect(G_OBJECT(open_with_data->app_chooser_dialog), "response", G_CALLBACK(open_with_response_cb), open_with_data);
1049 g_signal_connect(G_OBJECT(open_with_data->app_chooser_dialog), "close", G_CALLBACK(open_with_response_cb), open_with_data);
1051 gtk_widget_show(open_with_data->app_chooser_dialog);
1055 static void layout_menu_open_archive_cb(GtkAction *, gpointer data)
1057 auto lw = static_cast<LayoutWindow *>(data);
1058 LayoutWindow *lw_new;
1062 layout_exit_fullscreen(lw);
1063 fd = layout_image_get_fd(lw);
1065 if (fd->format_class == FORMAT_CLASS_ARCHIVE)
1067 dest_dir = open_archive(layout_image_get_fd(lw));
1070 lw_new = layout_new_from_default();
1071 layout_set_path(lw_new, dest_dir);
1076 warning_dialog(_("Cannot open archive file"), _("See the Log Window"), GQ_ICON_DIALOG_WARNING, nullptr);
1081 static void layout_menu_fullscreen_cb(GtkAction *, gpointer data)
1083 auto lw = static_cast<LayoutWindow *>(data);
1085 layout_image_full_screen_toggle(lw);
1088 static void layout_menu_escape_cb(GtkAction *, gpointer data)
1090 auto lw = static_cast<LayoutWindow *>(data);
1092 layout_exit_fullscreen(lw);
1095 static void layout_menu_overlay_toggle_cb(GtkAction *, gpointer data)
1097 auto lw = static_cast<LayoutWindow *>(data);
1099 image_osd_toggle(lw->image);
1100 layout_util_sync_views(lw);
1104 static void layout_menu_overlay_cb(GtkToggleAction *action, gpointer data)
1106 auto lw = static_cast<LayoutWindow *>(data);
1108 if (gtk_toggle_action_get_active(action))
1110 OsdShowFlags flags = image_osd_get(lw->image);
1112 if ((flags | OSD_SHOW_INFO | OSD_SHOW_STATUS) != flags)
1113 image_osd_set(lw->image, static_cast<OsdShowFlags>(flags | OSD_SHOW_INFO | OSD_SHOW_STATUS));
1117 GtkToggleAction *histogram_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(lw->action_group, "ImageHistogram"));
1119 image_osd_set(lw->image, OSD_SHOW_NOTHING);
1120 gtk_toggle_action_set_active(histogram_action, FALSE); /* this calls layout_menu_histogram_cb */
1124 static void layout_menu_histogram_cb(GtkToggleAction *action, gpointer data)
1126 auto lw = static_cast<LayoutWindow *>(data);
1128 if (gtk_toggle_action_get_active(action))
1130 image_osd_set(lw->image, static_cast<OsdShowFlags>(OSD_SHOW_INFO | OSD_SHOW_STATUS | OSD_SHOW_HISTOGRAM));
1131 layout_util_sync_views(lw); /* show the overlay state, default channel and mode in the menu */
1135 OsdShowFlags flags = image_osd_get(lw->image);
1136 if (flags & OSD_SHOW_HISTOGRAM)
1137 image_osd_set(lw->image, static_cast<OsdShowFlags>(flags & ~OSD_SHOW_HISTOGRAM));
1141 static void layout_menu_animate_cb(GtkToggleAction *action, gpointer data)
1143 auto lw = static_cast<LayoutWindow *>(data);
1145 if (lw->options.animate == gtk_toggle_action_get_active(action)) return;
1146 layout_image_animate_toggle(lw);
1149 static void layout_menu_rectangular_selection_cb(GtkToggleAction *action, gpointer)
1151 options->collections.rectangular_selection = gtk_toggle_action_get_active(action);
1154 static void layout_menu_histogram_toggle_channel_cb(GtkAction *, gpointer data)
1156 auto lw = static_cast<LayoutWindow *>(data);
1158 image_osd_histogram_toggle_channel(lw->image);
1159 layout_util_sync_views(lw);
1162 static void layout_menu_histogram_toggle_mode_cb(GtkAction *, gpointer data)
1164 auto lw = static_cast<LayoutWindow *>(data);
1166 image_osd_histogram_toggle_mode(lw->image);
1167 layout_util_sync_views(lw);
1170 static void layout_menu_histogram_channel_cb(GtkRadioAction *action, GtkRadioAction *, gpointer data)
1172 auto lw = static_cast<LayoutWindow *>(data);
1173 gint channel = gtk_radio_action_get_current_value(action);
1174 GtkToggleAction *histogram_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(lw->action_group, "ImageHistogram"));
1176 if (channel < 0 || channel >= HCHAN_COUNT) return;
1178 gtk_toggle_action_set_active(histogram_action, TRUE); /* this calls layout_menu_histogram_cb */
1179 image_osd_histogram_set_channel(lw->image, channel);
1182 static void layout_menu_histogram_mode_cb(GtkRadioAction *action, GtkRadioAction *, gpointer data)
1184 auto lw = static_cast<LayoutWindow *>(data);
1185 gint mode = gtk_radio_action_get_current_value(action);
1186 GtkToggleAction *histogram_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(lw->action_group, "ImageHistogram"));
1188 if (mode < 0 || mode > 1) return;
1190 gtk_toggle_action_set_active(histogram_action, TRUE); /* this calls layout_menu_histogram_cb */
1191 image_osd_histogram_set_mode(lw->image, mode);
1194 static void layout_menu_refresh_cb(GtkAction *, gpointer data)
1196 auto lw = static_cast<LayoutWindow *>(data);
1201 static void layout_menu_bar_exif_cb(GtkAction *, gpointer data)
1203 auto lw = static_cast<LayoutWindow *>(data);
1205 layout_exit_fullscreen(lw);
1206 layout_exif_window_new(lw);
1209 static void layout_menu_search_and_run_cb(GtkAction *, gpointer data)
1211 auto lw = static_cast<LayoutWindow *>(data);
1213 layout_exit_fullscreen(lw);
1214 layout_search_and_run_window_new(lw);
1218 static void layout_menu_float_cb(GtkToggleAction *action, gpointer data)
1220 auto lw = static_cast<LayoutWindow *>(data);
1222 if (lw->options.tools_float == gtk_toggle_action_get_active(action)) return;
1224 layout_exit_fullscreen(lw);
1225 layout_tools_float_toggle(lw);
1228 static void layout_menu_hide_cb(GtkAction *, gpointer data)
1230 auto lw = static_cast<LayoutWindow *>(data);
1232 layout_exit_fullscreen(lw);
1233 layout_tools_hide_toggle(lw);
1236 static void layout_menu_selectable_toolbars_cb(GtkToggleAction *action, gpointer data)
1238 auto lw = static_cast<LayoutWindow *>(data);
1240 if (lw->options.selectable_toolbars_hidden == gtk_toggle_action_get_active(action)) return;
1242 layout_exit_fullscreen(lw);
1243 layout_selectable_toolbars_toggle(lw);
1246 static void layout_menu_info_pixel_cb(GtkToggleAction *action, gpointer data)
1248 auto lw = static_cast<LayoutWindow *>(data);
1250 if (lw->options.show_info_pixel == gtk_toggle_action_get_active(action)) return;
1252 layout_exit_fullscreen(lw);
1253 layout_info_pixel_set(lw, !lw->options.show_info_pixel);
1256 /* NOTE: these callbacks are called also from layout_util_sync_views */
1257 static void layout_menu_bar_cb(GtkToggleAction *action, gpointer data)
1259 auto lw = static_cast<LayoutWindow *>(data);
1261 if (layout_bar_enabled(lw) == gtk_toggle_action_get_active(action)) return;
1263 layout_exit_fullscreen(lw);
1264 layout_bar_toggle(lw);
1267 static void layout_menu_bar_sort_cb(GtkToggleAction *action, gpointer data)
1269 auto lw = static_cast<LayoutWindow *>(data);
1271 if (layout_bar_sort_enabled(lw) == gtk_toggle_action_get_active(action)) return;
1273 layout_exit_fullscreen(lw);
1274 layout_bar_sort_toggle(lw);
1277 static void layout_menu_hide_bars_cb(GtkToggleAction *action, gpointer data)
1279 auto lw = static_cast<LayoutWindow *>(data);
1281 if (lw->options.bars_state.hidden == gtk_toggle_action_get_active(action))
1285 layout_bars_hide_toggle(lw);
1288 static void layout_menu_slideshow_cb(GtkToggleAction *action, gpointer data)
1290 auto lw = static_cast<LayoutWindow *>(data);
1292 if (layout_image_slideshow_active(lw) == gtk_toggle_action_get_active(action)) return;
1293 layout_image_slideshow_toggle(lw);
1296 static void layout_menu_slideshow_pause_cb(GtkAction *, gpointer data)
1298 auto lw = static_cast<LayoutWindow *>(data);
1300 layout_image_slideshow_pause_toggle(lw);
1303 static void layout_menu_slideshow_slower_cb(GtkAction *, gpointer)
1305 options->slideshow.delay = options->slideshow.delay + 5;
1306 if (options->slideshow.delay > SLIDESHOW_MAX_SECONDS)
1307 options->slideshow.delay = SLIDESHOW_MAX_SECONDS;
1310 static void layout_menu_slideshow_faster_cb(GtkAction *, gpointer)
1312 options->slideshow.delay = options->slideshow.delay - 5;
1313 if (options->slideshow.delay < SLIDESHOW_MIN_SECONDS * 10)
1314 options->slideshow.delay = SLIDESHOW_MIN_SECONDS * 10;
1318 static void layout_menu_stereo_mode_next_cb(GtkAction *, gpointer data)
1320 auto lw = static_cast<LayoutWindow *>(data);
1321 gint mode = layout_image_stereo_pixbuf_get(lw);
1323 /* 0->1, 1->2, 2->3, 3->1 - disable auto, then cycle */
1324 mode = mode % 3 + 1;
1326 GtkAction *radio = gtk_action_group_get_action(lw->action_group, "StereoAuto");
1327 gtk_radio_action_set_current_value(GTK_RADIO_ACTION(radio), mode);
1330 this is called via fallback in layout_menu_stereo_mode_cb
1331 layout_image_stereo_pixbuf_set(lw, mode);
1336 static void layout_menu_stereo_mode_cb(GtkRadioAction *action, GtkRadioAction *, gpointer data)
1338 auto lw = static_cast<LayoutWindow *>(data);
1339 gint mode = gtk_radio_action_get_current_value(action);
1340 layout_image_stereo_pixbuf_set(lw, mode);
1343 static void layout_menu_help_cb(GtkAction *, gpointer data)
1345 auto lw = static_cast<LayoutWindow *>(data);
1347 layout_exit_fullscreen(lw);
1348 help_window_show("index.html");
1351 static void layout_menu_help_search_cb(GtkAction *, gpointer data)
1353 auto lw = static_cast<LayoutWindow *>(data);
1355 layout_exit_fullscreen(lw);
1356 help_search_window_show();
1359 static void layout_menu_help_keys_cb(GtkAction *, gpointer data)
1361 auto lw = static_cast<LayoutWindow *>(data);
1363 layout_exit_fullscreen(lw);
1364 help_window_show("GuideReferenceKeyboardShortcuts.html");
1367 static void layout_menu_notes_cb(GtkAction *, gpointer data)
1369 auto lw = static_cast<LayoutWindow *>(data);
1371 layout_exit_fullscreen(lw);
1372 help_window_show("release_notes");
1375 static void layout_menu_changelog_cb(GtkAction *, gpointer data)
1377 auto lw = static_cast<LayoutWindow *>(data);
1379 layout_exit_fullscreen(lw);
1380 help_window_show("changelog");
1383 static constexpr const char *keyboard_map_hardcoded[][2] = {
1385 {"FastScroll", "<Shift>Left"},
1386 {"Left Border", "<Primary>Left"},
1387 {"Left Border", "<Primary><Shift>Left"},
1388 {"Scroll", "Right"},
1389 {"FastScroll", "<Shift>Right"},
1390 {"Right Border", "<Primary>Right"},
1391 {"Right Border", "<Primary><Shift>Right"},
1393 {"FastScroll", "<Shift>Up"},
1394 {"Upper Border", "<Primary>Up"},
1395 {"Upper Border", "<Primary><Shift>Up"},
1397 {"FastScroll", "<Shift>Down"},
1398 {"Lower Border", "<Primary>Down"},
1399 {"Lower Border", "<Primary><Shift>Down"},
1400 {"Next/Drag", "M1"},
1401 {"FastDrag", "<Shift>M1"},
1402 {"DnD Start", "M2"},
1404 {"PrevImage", "MW4"},
1405 {"NextImage", "MW5"},
1406 {"ScrollUp", "<Shift>MW4"},
1407 {"ScrollDown", "<Shift>MW5"},
1408 {"ZoomIn", "<Primary>MW4"},
1409 {"ZoomOut", "<Primary>MW5"},
1412 static void layout_menu_foreach_func(
1414 const gchar *accel_path,
1416 GdkModifierType accel_mods,
1423 gchar **subset_lt_arr;
1424 gchar **subset_gt_arr;
1426 gchar *converted_name;
1427 auto array = static_cast<GPtrArray *>(data);
1429 path = g_strescape(accel_path, nullptr);
1430 name = gtk_accelerator_name(accel_key, accel_mods);
1432 menu_name = g_strdup(g_strrstr(path, "/")+1);
1434 if (g_strrstr(name, ">"))
1436 subset_lt_arr = g_strsplit_set(name,"<", 4);
1437 subset_lt = g_strjoinv("<", subset_lt_arr);
1438 subset_gt_arr = g_strsplit_set(subset_lt,">", 4);
1439 converted_name = g_strjoinv(">", subset_gt_arr);
1440 key_name = g_strdup(converted_name);
1442 g_free(converted_name);
1444 g_strfreev(subset_lt_arr);
1445 g_strfreev(subset_gt_arr);
1448 key_name = g_strdup(name);
1450 g_ptr_array_add(array, menu_name);
1451 g_ptr_array_add(array, key_name);
1457 static void layout_menu_kbd_map_cb(GtkAction *, gpointer)
1462 GError *error = nullptr;
1463 GIOChannel *channel;
1466 const char *key_name;
1467 char *converted_line;
1471 fd = g_file_open_tmp("geeqie_keymap_XXXXXX.svg", &tmp_file, &error);
1474 log_printf("Error: Keyboard Map - cannot create file:%s\n",error->message);
1475 g_error_free(error);
1479 array = g_ptr_array_new();
1481 gtk_accel_map_foreach(array, layout_menu_foreach_func);
1483 channel = g_io_channel_unix_new(fd);
1486 while (keymap_template[keymap_index])
1488 if (g_strrstr(keymap_template[keymap_index], ">key:"))
1490 pre_key = g_strsplit(keymap_template[keymap_index],">key:",2);
1491 post_key = g_strsplit(pre_key[1],"<",2);
1495 for (index=0; index < array->len-2; index=index+2)
1497 if (!(g_ascii_strcasecmp(static_cast<const gchar *>(g_ptr_array_index(array,index+1)), post_key[0])))
1499 key_name = static_cast<const gchar *>(g_ptr_array_index(array,index+0));
1504 for (const auto& m : keyboard_map_hardcoded)
1506 if (!(g_strcmp0(m[1], post_key[0])))
1513 converted_line = g_strconcat(pre_key[0], ">", key_name, "<", post_key[1], "\n", NULL);
1514 g_io_channel_write_chars(channel, converted_line, -1, nullptr, &error);
1515 if (error) {log_printf("Warning: Keyboard Map:%s\n",error->message); g_error_free(error);}
1517 g_free(converted_line);
1518 g_strfreev(pre_key);
1519 g_strfreev(post_key);
1523 g_io_channel_write_chars(channel, keymap_template[keymap_index], -1, nullptr, &error);
1524 if (error) {log_printf("Warning: Keyboard Map:%s\n",error->message); g_error_free(error);}
1525 g_io_channel_write_chars(channel, "\n", -1, nullptr, &error);
1526 if (error) {log_printf("Warning: Keyboard Map:%s\n",error->message); g_error_free(error);}
1531 g_io_channel_flush(channel, &error);
1532 if (error) {log_printf("Warning: Keyboard Map:%s\n",error->message); g_error_free(error);}
1533 g_io_channel_unref(channel);
1536 for (index=0; index < array->len-2; index=index+2)
1538 g_free(g_ptr_array_index(array,index));
1539 g_free(g_ptr_array_index(array,index+1));
1541 g_ptr_array_unref(array);
1543 view_window_new(file_data_new_simple(tmp_file));
1548 static void layout_menu_about_cb(GtkAction *, gpointer data)
1550 auto lw = static_cast<LayoutWindow *>(data);
1552 layout_exit_fullscreen(lw);
1553 show_about_window(lw);
1556 static void layout_menu_log_window_cb(GtkAction *, gpointer data)
1558 auto lw = static_cast<LayoutWindow *>(data);
1560 layout_exit_fullscreen(lw);
1566 *-----------------------------------------------------------------------------
1568 *-----------------------------------------------------------------------------
1571 static void layout_menu_select_all_cb(GtkAction *, gpointer data)
1573 auto lw = static_cast<LayoutWindow *>(data);
1575 layout_select_all(lw);
1578 static void layout_menu_unselect_all_cb(GtkAction *, gpointer data)
1580 auto lw = static_cast<LayoutWindow *>(data);
1582 layout_select_none(lw);
1585 static void layout_menu_invert_selection_cb(GtkAction *, gpointer data)
1587 auto lw = static_cast<LayoutWindow *>(data);
1589 layout_select_invert(lw);
1592 static void layout_menu_file_filter_cb(GtkToggleAction *action, gpointer data)
1594 auto lw = static_cast<LayoutWindow *>(data);
1596 layout_file_filter_set(lw, gtk_toggle_action_get_active(action));
1599 static void layout_menu_marks_cb(GtkToggleAction *action, gpointer data)
1601 auto lw = static_cast<LayoutWindow *>(data);
1603 layout_marks_set(lw, gtk_toggle_action_get_active(action));
1607 static void layout_menu_set_mark_sel_cb(GtkAction *action, gpointer data)
1609 auto lw = static_cast<LayoutWindow *>(data);
1610 gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1611 g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1613 layout_selection_to_mark(lw, mark, STM_MODE_SET);
1616 static void layout_menu_res_mark_sel_cb(GtkAction *action, gpointer data)
1618 auto lw = static_cast<LayoutWindow *>(data);
1619 gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1620 g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1622 layout_selection_to_mark(lw, mark, STM_MODE_RESET);
1625 static void layout_menu_toggle_mark_sel_cb(GtkAction *action, gpointer data)
1627 auto lw = static_cast<LayoutWindow *>(data);
1628 gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1629 g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1631 layout_selection_to_mark(lw, mark, STM_MODE_TOGGLE);
1634 static void layout_menu_sel_mark_cb(GtkAction *action, gpointer data)
1636 auto lw = static_cast<LayoutWindow *>(data);
1637 gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1638 g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1640 layout_mark_to_selection(lw, mark, MTS_MODE_SET);
1643 static void layout_menu_sel_mark_or_cb(GtkAction *action, gpointer data)
1645 auto lw = static_cast<LayoutWindow *>(data);
1646 gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1647 g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1649 layout_mark_to_selection(lw, mark, MTS_MODE_OR);
1652 static void layout_menu_sel_mark_and_cb(GtkAction *action, gpointer data)
1654 auto lw = static_cast<LayoutWindow *>(data);
1655 gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1656 g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1658 layout_mark_to_selection(lw, mark, MTS_MODE_AND);
1661 static void layout_menu_sel_mark_minus_cb(GtkAction *action, gpointer data)
1663 auto lw = static_cast<LayoutWindow *>(data);
1664 gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1665 g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1667 layout_mark_to_selection(lw, mark, MTS_MODE_MINUS);
1670 static void layout_menu_mark_filter_toggle_cb(GtkAction *action, gpointer data)
1672 auto lw = static_cast<LayoutWindow *>(data);
1673 gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1674 g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1676 layout_marks_set(lw, TRUE);
1677 layout_mark_filter_toggle(lw, mark);
1682 *-----------------------------------------------------------------------------
1684 *-----------------------------------------------------------------------------
1687 static void layout_menu_image_first_cb(GtkAction *, gpointer data)
1689 auto lw = static_cast<LayoutWindow *>(data);
1690 layout_image_first(lw);
1693 static void layout_menu_image_prev_cb(GtkAction *, gpointer data)
1695 auto lw = static_cast<LayoutWindow *>(data);
1698 if (lw->options.split_pane_sync)
1700 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1702 if (lw->split_images[i])
1706 DEBUG_1("image activate scroll %d", i);
1707 layout_image_activate(lw, i, FALSE);
1708 layout_image_prev(lw);
1715 layout_image_prev(lw);
1719 static void layout_menu_image_next_cb(GtkAction *, gpointer data)
1721 auto lw = static_cast<LayoutWindow *>(data);
1724 if (lw->options.split_pane_sync)
1726 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1728 if (lw->split_images[i])
1732 DEBUG_1("image activate scroll %d", i);
1733 layout_image_activate(lw, i, FALSE);
1734 layout_image_next(lw);
1741 layout_image_next(lw);
1745 static void layout_menu_page_first_cb(GtkAction *, gpointer data)
1747 auto lw = static_cast<LayoutWindow *>(data);
1748 FileData *fd = layout_image_get_fd(lw);
1750 if (fd->page_total > 0)
1752 file_data_set_page_num(fd, 1);
1756 static void layout_menu_page_last_cb(GtkAction *, gpointer data)
1758 auto lw = static_cast<LayoutWindow *>(data);
1759 FileData *fd = layout_image_get_fd(lw);
1761 if (fd->page_total > 0)
1763 file_data_set_page_num(fd, -1);
1767 static void layout_menu_page_next_cb(GtkAction *, gpointer data)
1769 auto lw = static_cast<LayoutWindow *>(data);
1770 FileData *fd = layout_image_get_fd(lw);
1772 if (fd->page_total > 0)
1774 file_data_inc_page_num(fd);
1778 static void layout_menu_page_previous_cb(GtkAction *, gpointer data)
1780 auto lw = static_cast<LayoutWindow *>(data);
1781 FileData *fd = layout_image_get_fd(lw);
1783 if (fd->page_total > 0)
1785 file_data_dec_page_num(fd);
1789 static void layout_menu_image_forward_cb(GtkAction *, gpointer data)
1791 auto lw = static_cast<LayoutWindow *>(data);
1793 /* Obtain next image */
1794 layout_set_path(lw, image_chain_forward());
1797 static void layout_menu_image_back_cb(GtkAction *, gpointer data)
1799 auto lw = static_cast<LayoutWindow *>(data);
1801 /* Obtain previous image */
1802 layout_set_path(lw, image_chain_back());
1805 static void layout_menu_split_pane_next_cb(GtkAction *, gpointer data)
1807 auto lw = static_cast<LayoutWindow *>(data);
1810 active_frame = lw->active_split_image;
1812 if (active_frame < MAX_SPLIT_IMAGES-1 && lw->split_images[active_frame+1] )
1820 layout_image_activate(lw, active_frame, FALSE);
1823 static void layout_menu_split_pane_prev_cb(GtkAction *, gpointer data)
1825 auto lw = static_cast<LayoutWindow *>(data);
1828 active_frame = lw->active_split_image;
1830 if (active_frame >=1 && lw->split_images[active_frame-1] )
1836 active_frame = MAX_SPLIT_IMAGES-1;
1837 while (!lw->split_images[active_frame])
1842 layout_image_activate(lw, active_frame, FALSE);
1845 static void layout_menu_split_pane_updown_cb(GtkAction *, gpointer data)
1847 auto lw = static_cast<LayoutWindow *>(data);
1850 active_frame = lw->active_split_image;
1852 if (lw->split_images[MAX_SPLIT_IMAGES-1] )
1854 active_frame = active_frame ^ 2;
1858 active_frame = active_frame ^ 1;
1860 layout_image_activate(lw, active_frame, FALSE);
1863 static void layout_menu_image_last_cb(GtkAction *, gpointer data)
1865 auto lw = static_cast<LayoutWindow *>(data);
1866 layout_image_last(lw);
1869 static void layout_menu_back_cb(GtkAction *, gpointer data)
1871 auto lw = static_cast<LayoutWindow *>(data);
1874 /* Obtain previous path */
1875 dir_fd = file_data_new_dir(history_chain_back());
1876 layout_set_fd(lw, dir_fd);
1877 file_data_unref(dir_fd);
1880 static void layout_menu_forward_cb(GtkAction *, gpointer data)
1882 auto lw = static_cast<LayoutWindow *>(data);
1885 /* Obtain next path */
1886 dir_fd = file_data_new_dir(history_chain_forward());
1887 layout_set_fd(lw, dir_fd);
1888 file_data_unref(dir_fd);
1891 static void layout_menu_home_cb(GtkAction *, gpointer data)
1893 auto lw = static_cast<LayoutWindow *>(data);
1896 if (lw->options.home_path && *lw->options.home_path)
1897 path = lw->options.home_path;
1903 FileData *dir_fd = file_data_new_dir(path);
1904 layout_set_fd(lw, dir_fd);
1905 file_data_unref(dir_fd);
1909 static void layout_menu_up_cb(GtkAction *, gpointer data)
1911 auto lw = static_cast<LayoutWindow *>(data);
1912 ViewDir *vd = lw->vd;
1915 if (!vd->dir_fd || strcmp(vd->dir_fd->path, G_DIR_SEPARATOR_S) == 0) return;
1916 path = remove_level_from_path(vd->dir_fd->path);
1918 if (vd->select_func)
1920 FileData *fd = file_data_new_dir(path);
1921 vd->select_func(vd, fd, vd->select_data);
1922 file_data_unref(fd);
1930 *-----------------------------------------------------------------------------
1932 *-----------------------------------------------------------------------------
1935 static void layout_menu_edit_cb(GtkAction *action, gpointer data)
1937 auto lw = static_cast<LayoutWindow *>(data);
1938 const gchar *key = gtk_action_get_name(action);
1940 if (!editor_window_flag_set(key))
1941 layout_exit_fullscreen(lw);
1943 file_util_start_editor_from_filelist(key, layout_selection_list(lw), layout_get_path(lw), lw->window);
1947 static void layout_menu_metadata_write_cb(GtkAction *, gpointer)
1949 metadata_write_queue_confirm(TRUE, nullptr, nullptr);
1952 static GtkWidget *last_focussed = nullptr;
1953 static void layout_menu_keyword_autocomplete_cb(GtkAction *, gpointer data)
1955 auto lw = static_cast<LayoutWindow *>(data);
1957 gboolean auto_has_focus;
1959 tmp = gtk_window_get_focus(GTK_WINDOW(lw->window));
1960 auto_has_focus = bar_keywords_autocomplete_focus(lw);
1964 gtk_widget_grab_focus(last_focussed);
1968 last_focussed = tmp;
1973 *-----------------------------------------------------------------------------
1974 * color profile button (and menu)
1975 *-----------------------------------------------------------------------------
1978 static void layout_color_menu_enable_cb(GtkToggleAction *action, gpointer data)
1980 auto lw = static_cast<LayoutWindow *>(data);
1982 if (layout_image_color_profile_get_use(lw) == gtk_toggle_action_get_active(action)) return;
1984 layout_image_color_profile_set_use(lw, gtk_toggle_action_get_active(action));
1985 layout_util_sync_color(lw);
1986 layout_image_refresh(lw);
1989 static void layout_color_menu_use_image_cb(GtkToggleAction *action, gpointer data)
1991 auto lw = static_cast<LayoutWindow *>(data);
1995 if (!layout_image_color_profile_get(lw, &input, &use_image)) return;
1996 if (use_image == gtk_toggle_action_get_active(action)) return;
1997 layout_image_color_profile_set(lw, input, gtk_toggle_action_get_active(action));
1998 layout_util_sync_color(lw);
1999 layout_image_refresh(lw);
2002 static void layout_color_menu_input_cb(GtkRadioAction *action, GtkRadioAction *, gpointer data)
2004 auto lw = static_cast<LayoutWindow *>(data);
2009 type = gtk_radio_action_get_current_value(action);
2010 if (type < 0 || type >= COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS) return;
2012 if (!layout_image_color_profile_get(lw, &input, &use_image)) return;
2013 if (type == input) return;
2015 layout_image_color_profile_set(lw, type, use_image);
2016 layout_image_refresh(lw);
2019 static void layout_color_menu_enable_cb()
2023 static void layout_color_menu_use_image_cb()
2027 static void layout_color_menu_input_cb()
2034 *-----------------------------------------------------------------------------
2036 *-----------------------------------------------------------------------------
2039 static void layout_menu_recent_cb(GtkWidget *widget, gpointer)
2044 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "recent_index"));
2046 path = static_cast<gchar *>(g_list_nth_data(history_list_get_by_key("recent"), n));
2050 /* make a copy of it */
2051 path = g_strdup(path);
2052 collection_window_new(path);
2056 static void layout_menu_collection_recent_update(LayoutWindow *lw)
2064 if (!lw->ui_manager) return;
2066 list = history_list_get_by_key("recent");
2069 menu = gtk_menu_new();
2073 const gchar *filename = filename_from_path(static_cast<gchar *>(list->data));
2075 gboolean free_name = FALSE;
2077 if (file_extension_match(filename, GQ_COLLECTION_EXT))
2079 name = remove_extension_from_path(filename);
2084 name = const_cast<gchar *>(filename);
2087 item = menu_item_add_simple(menu, name, G_CALLBACK(layout_menu_recent_cb), lw);
2088 if (free_name) g_free(name);
2089 g_object_set_data(G_OBJECT(item), "recent_index", GINT_TO_POINTER(n));
2096 menu_item_add(menu, _("Empty"), nullptr, nullptr);
2099 recent = gtk_ui_manager_get_widget(lw->ui_manager, options->hamburger_menu ? "/MainMenu/OpenMenu/FileMenu/OpenRecent" : "/MainMenu/FileMenu/OpenRecent");
2100 gtk_menu_item_set_submenu(GTK_MENU_ITEM(recent), menu);
2101 gtk_widget_set_sensitive(recent, (n != 0));
2104 static void layout_menu_collection_open_update(LayoutWindow *lw)
2106 gboolean free_name = FALSE;
2109 GList *collection_list = nullptr;
2115 if (!lw->ui_manager) return;
2117 collect_manager_list(&collection_list, nullptr, nullptr);
2121 menu = gtk_menu_new();
2123 work = collection_list;
2126 const gchar *filename = static_cast<gchar *>(work->data);
2128 if (file_extension_match(filename, GQ_COLLECTION_EXT))
2130 name = remove_extension_from_path(filename);
2135 name = const_cast<gchar *>(filename);
2138 item = menu_item_add_simple(menu, name, G_CALLBACK(layout_menu_open_cb), lw);
2143 g_object_set_data(G_OBJECT(item), "recent_index", GINT_TO_POINTER(n));
2148 string_list_free(collection_list);
2152 menu_item_add(menu, _("Empty"), nullptr, nullptr);
2155 recent = gtk_ui_manager_get_widget(lw->ui_manager, options->hamburger_menu ? "/MainMenu/OpenMenu/FileMenu/OpenCollection" : "/MainMenu/FileMenu/OpenCollection");
2156 gtk_menu_item_set_submenu(GTK_MENU_ITEM(recent), menu);
2157 gtk_widget_set_sensitive(recent, (n != 0));
2160 void layout_recent_update_all()
2164 work = layout_window_list;
2167 auto lw = static_cast<LayoutWindow *>(work->data);
2170 layout_menu_collection_recent_update(lw);
2171 layout_menu_collection_open_update(lw);
2175 void layout_recent_add_path(const gchar *path)
2179 history_list_add_to_key("recent", path, options->open_recent_list_maxsize);
2181 layout_recent_update_all();
2185 *-----------------------------------------------------------------------------
2186 * window layout menu
2187 *-----------------------------------------------------------------------------
2201 GtkWidget *button_ok;
2202 GtkWidget *window_name_entry;
2210 GtkWidget *button_ok;
2214 static gint layout_window_menu_list_sort_cb(gconstpointer a, gconstpointer b)
2216 auto wna = static_cast<const WindowNames *>(a);
2217 auto wnb = static_cast<const WindowNames *>(b);
2219 return g_strcmp0(wna->name, wnb->name);
2222 static GList *layout_window_menu_list(GList *listin)
2231 pathl = path_from_utf8(get_window_layouts_dir());
2232 dp = opendir(pathl);
2240 while ((dir = readdir(dp)) != nullptr)
2242 gchar *name_file = dir->d_name;
2244 if (g_str_has_suffix(name_file, ".xml"))
2246 LayoutWindow *lw_tmp ;
2247 gchar *name_utf8 = path_to_utf8(name_file);
2248 gchar *name_base = g_strndup(name_utf8, strlen(name_utf8) - 4);
2249 list = layout_window_list;
2253 lw_tmp = static_cast<LayoutWindow *>(list->data);
2254 if (g_strcmp0(lw_tmp->options.id, name_base) == 0)
2260 gchar *dpath = g_build_filename(pathl, name_utf8, NULL);
2261 wn = g_new0(WindowNames, 1);
2262 wn->displayed = dupe;
2263 wn->name = g_strdup(name_base);
2264 wn->path = g_strdup(dpath);
2265 listin = g_list_append(listin, wn);
2276 return g_list_sort(listin, layout_window_menu_list_sort_cb);
2279 static void layout_menu_new_window_cb(GtkWidget *, gpointer data)
2283 n = GPOINTER_TO_INT(data);
2284 GList *menulist = nullptr;
2286 menulist = layout_window_menu_list(menulist);
2287 auto wn = static_cast<WindowNames *>(g_list_nth(menulist, n )->data);
2291 load_config_from_file(wn->path, FALSE);
2295 log_printf(_("Error: window layout name: %s does not exist\n"), wn->path);
2299 static void layout_menu_new_window_update(LayoutWindow *lw)
2302 GtkWidget *sub_menu;
2307 GList *list = nullptr;
2311 if (!lw->ui_manager) return;
2313 list = layout_window_menu_list(list);
2315 menu = gtk_ui_manager_get_widget(lw->ui_manager, options->hamburger_menu ? "/MainMenu/OpenMenu/WindowsMenu/NewWindow" : "/MainMenu/WindowsMenu/NewWindow");
2316 sub_menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu));
2318 children = gtk_container_get_children(GTK_CONTAINER(sub_menu));
2319 for (iter = children; iter != nullptr; iter = g_list_next(iter), i++)
2321 if (i >= 4) // separator, default, from current, separator
2323 gq_gtk_widget_destroy(GTK_WIDGET(iter->data));
2326 g_list_free(children);
2328 menu_item_add_divider(sub_menu);
2333 wn = static_cast<WindowNames *>(list->data);
2334 item = menu_item_add_simple(sub_menu, wn->name, G_CALLBACK(layout_menu_new_window_cb), GINT_TO_POINTER(n));
2337 gtk_widget_set_sensitive(item, FALSE);
2344 static void window_rename_cancel_cb(GenericDialog *, gpointer data)
2346 auto rw = static_cast<RenameWindow *>(data);
2348 generic_dialog_close(rw->gd);
2352 static void window_rename_ok(GenericDialog *, gpointer data)
2354 auto rw = static_cast<RenameWindow *>(data);
2356 gboolean window_layout_name_exists = FALSE;
2357 GList *list = nullptr;
2361 new_id = g_strdup(gq_gtk_entry_get_text(GTK_ENTRY(rw->window_name_entry)));
2363 list = layout_window_menu_list(list);
2366 auto ln = static_cast<WindowNames *>(list->data);
2367 if (g_strcmp0(ln->name, new_id) == 0)
2370 buf = g_strdup_printf(_("Window layout name \"%s\" already exists."), new_id);
2371 warning_dialog(_("Rename window"), buf, GQ_ICON_DIALOG_WARNING, rw->gd->dialog);
2373 window_layout_name_exists = TRUE;
2379 if (!window_layout_name_exists)
2381 xml_name = g_strdup_printf("%s.xml", rw->lw->options.id);
2382 path = g_build_filename(get_window_layouts_dir(), xml_name, NULL);
2391 g_free(rw->lw->options.id);
2392 rw->lw->options.id = g_strdup(new_id);
2393 layout_menu_new_window_update(rw->lw);
2394 layout_refresh(rw->lw);
2395 image_update_title(rw->lw->image);
2398 save_layout(rw->lw);
2401 generic_dialog_close(rw->gd);
2405 static void window_rename_ok_cb(GenericDialog *gd, gpointer data)
2407 auto rw = static_cast<RenameWindow *>(data);
2409 window_rename_ok(gd, rw);
2412 static void window_rename_entry_activate_cb(GenericDialog *gd, gpointer data)
2414 auto rw = static_cast<RenameWindow *>(data);
2416 window_rename_ok(gd, rw);
2419 static void window_delete_cancel_cb(GenericDialog *, gpointer data)
2421 auto dw = static_cast<DeleteWindow *>(data);
2426 static void window_delete_ok_cb(GenericDialog *, gpointer data)
2428 auto dw = static_cast<DeleteWindow *>(data);
2432 xml_name = g_strdup_printf("%s.xml", dw->lw->options.id);
2433 path = g_build_filename(get_window_layouts_dir(), xml_name, NULL);
2435 layout_close(dw->lw);
2446 static void layout_menu_window_default_cb(GtkWidget *, gpointer)
2448 layout_new_from_default();
2451 static void layout_menu_windows_menu_cb(GtkWidget *, gpointer data)
2453 auto lw = static_cast<LayoutWindow *>(data);
2455 GtkWidget *sub_menu;
2461 menu = gtk_ui_manager_get_widget(lw->ui_manager, options->hamburger_menu ? "/MainMenu/OpenMenu/WindowsMenu/" : "/MainMenu/WindowsMenu/");
2463 sub_menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu));
2465 /* disable Delete for temporary windows */
2466 if (g_str_has_prefix(lw->options.id, "lw"))
2469 children = gtk_container_get_children(GTK_CONTAINER(sub_menu));
2470 for (iter = children; iter != nullptr; iter = g_list_next(iter), i++)
2472 menu_label = g_strdup(gtk_menu_item_get_label(GTK_MENU_ITEM(iter->data)));
2473 if (g_strcmp0(menu_label, _("Delete window")) == 0)
2475 gtk_widget_set_sensitive(GTK_WIDGET(iter->data), FALSE);
2479 g_list_free(children);
2483 static void layout_menu_view_menu_cb(GtkWidget *, gpointer data)
2485 auto lw = static_cast<LayoutWindow *>(data);
2487 GtkWidget *sub_menu;
2494 menu = gtk_ui_manager_get_widget(lw->ui_manager, options->hamburger_menu ? "/MainMenu/OpenMenu/ViewMenu/" : "/MainMenu/ViewMenu/");
2495 sub_menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu));
2497 fd = layout_image_get_fd(lw);
2500 children = gtk_container_get_children(GTK_CONTAINER(sub_menu));
2501 for (iter = children; iter != nullptr; iter = g_list_next(iter), i++)
2503 menu_label = g_strdup(gtk_menu_item_get_label(GTK_MENU_ITEM(iter->data)));
2504 if (g_strcmp0(menu_label, _("Open archive")) == 0)
2506 if (fd && fd->format_class == FORMAT_CLASS_ARCHIVE)
2508 gtk_widget_set_sensitive(GTK_WIDGET(iter->data), TRUE);
2512 gtk_widget_set_sensitive(GTK_WIDGET(iter->data), FALSE);
2517 g_list_free(children);
2520 static void change_window_id(const gchar *infile, const gchar *outfile)
2524 GFileInputStream *in_file_stream;
2525 GFileOutputStream *out_file_stream;
2526 GDataInputStream *in_data_stream;
2527 GDataOutputStream *out_data_stream;
2531 id_name = layout_get_unique_id();
2533 in_file = g_file_new_for_path(infile);
2534 in_file_stream = g_file_read(in_file, nullptr, nullptr);
2535 in_data_stream = g_data_input_stream_new(G_INPUT_STREAM(in_file_stream));
2537 out_file = g_file_new_for_path(outfile);
2538 out_file_stream = g_file_append_to(out_file, G_FILE_CREATE_PRIVATE, nullptr, nullptr);
2539 out_data_stream = g_data_output_stream_new(G_OUTPUT_STREAM(out_file_stream));
2541 while ((line = g_data_input_stream_read_line(in_data_stream, nullptr, nullptr, nullptr)))
2543 if (g_str_has_suffix(line, "<layout"))
2545 g_data_output_stream_put_string(out_data_stream, line, nullptr, nullptr);
2546 g_data_output_stream_put_string(out_data_stream, "\n", nullptr, nullptr);
2549 line = g_data_input_stream_read_line(in_data_stream, nullptr, nullptr, nullptr);
2550 g_data_output_stream_put_string(out_data_stream, "id = \"", nullptr, nullptr);
2551 g_data_output_stream_put_string(out_data_stream, id_name, nullptr, nullptr);
2552 g_data_output_stream_put_string(out_data_stream, "\"\n", nullptr, nullptr);
2556 g_data_output_stream_put_string(out_data_stream, line, nullptr, nullptr);
2557 g_data_output_stream_put_string(out_data_stream, "\n", nullptr, nullptr);
2563 g_object_unref(out_data_stream);
2564 g_object_unref(in_data_stream);
2565 g_object_unref(out_file_stream);
2566 g_object_unref(in_file_stream);
2567 g_object_unref(out_file);
2568 g_object_unref(in_file);
2571 static void layout_menu_window_from_current_cb(GtkWidget *, gpointer data)
2573 auto lw = static_cast<LayoutWindow *>(data);
2577 char * tmp_file_out;
2578 GError *error = nullptr;
2580 fd_in = g_file_open_tmp("geeqie_layout_name_XXXXXX.xml", &tmp_file_in, &error);
2583 log_printf("Error: Window layout - cannot create file:%s\n",error->message);
2584 g_error_free(error);
2588 fd_out = g_file_open_tmp("geeqie_layout_name_XXXXXX.xml", &tmp_file_out, &error);
2591 log_printf("Error: Window layout - cannot create file:%s\n",error->message);
2592 g_error_free(error);
2597 save_config_to_file(tmp_file_in, options, lw);
2598 change_window_id(tmp_file_in, tmp_file_out);
2599 load_config_from_file(tmp_file_out, FALSE);
2601 unlink_file(tmp_file_in);
2602 unlink_file(tmp_file_out);
2603 g_free(tmp_file_in);
2604 g_free(tmp_file_out);
2607 static void layout_menu_window_cb(GtkWidget *, gpointer data)
2609 auto lw = static_cast<LayoutWindow *>(data);
2611 layout_menu_new_window_update(lw);
2614 static void layout_menu_window_rename_cb(GtkWidget *, gpointer data)
2616 auto lw = static_cast<LayoutWindow *>(data);
2620 rw = g_new0(RenameWindow, 1);
2623 rw->gd = generic_dialog_new(_("Rename window"), "rename_window", nullptr, FALSE, window_rename_cancel_cb, rw);
2624 rw->button_ok = generic_dialog_add_button(rw->gd, GQ_ICON_OK, _("OK"), window_rename_ok_cb, TRUE);
2626 generic_dialog_add_message(rw->gd, nullptr, _("rename window"), nullptr, FALSE);
2628 hbox = pref_box_new(rw->gd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, 0);
2629 pref_spacer(hbox, PREF_PAD_INDENT);
2631 hbox = pref_box_new(rw->gd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
2633 rw->window_name_entry = gtk_entry_new();
2634 gtk_widget_set_can_focus(rw->window_name_entry, TRUE);
2635 gtk_editable_set_editable(GTK_EDITABLE(rw->window_name_entry), TRUE);
2636 gq_gtk_entry_set_text(GTK_ENTRY(rw->window_name_entry), lw->options.id);
2637 gq_gtk_box_pack_start(GTK_BOX(hbox), rw->window_name_entry, TRUE, TRUE, 0);
2638 gtk_widget_grab_focus(GTK_WIDGET(rw->window_name_entry));
2639 gtk_widget_show(rw->window_name_entry);
2640 g_signal_connect(rw->window_name_entry, "activate", G_CALLBACK(window_rename_entry_activate_cb), rw);
2642 gtk_widget_show(rw->gd->dialog);
2645 static void layout_menu_window_delete_cb(GtkWidget *, gpointer data)
2647 auto lw = static_cast<LayoutWindow *>(data);
2651 dw = g_new0(DeleteWindow, 1);
2654 dw->gd = generic_dialog_new(_("Delete window"), "delete_window", nullptr, TRUE, window_delete_cancel_cb, dw);
2655 dw->button_ok = generic_dialog_add_button(dw->gd, GQ_ICON_OK, _("OK"), window_delete_ok_cb, TRUE);
2657 generic_dialog_add_message(dw->gd, nullptr, _("Delete window layout"), nullptr, FALSE);
2659 hbox = pref_box_new(dw->gd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, 0);
2660 pref_spacer(hbox, PREF_PAD_INDENT);
2661 dw->group = pref_box_new(hbox, TRUE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
2663 hbox = pref_box_new(dw->group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
2664 pref_label_new(hbox, (lw->options.id));
2666 gtk_widget_show(dw->gd->dialog);
2670 *-----------------------------------------------------------------------------
2672 *-----------------------------------------------------------------------------
2675 #define CB G_CALLBACK
2677 * tooltip is used as the description field in the Help manual shortcuts documentation
2679 * struct GtkActionEntry:
2680 * name, stock_id, label, accelerator, tooltip, callback
2682 static GtkActionEntry menu_entries[] = {
2683 { "About", GQ_ICON_ABOUT, N_("_About"), nullptr, N_("About"), CB(layout_menu_about_cb) },
2684 { "AlterNone", PIXBUF_INLINE_ICON_ORIGINAL, N_("_Original state"), "<shift>O", N_("Image rotate Original state"), CB(layout_menu_alter_none_cb) },
2685 { "Back", GQ_ICON_GO_PREV, N_("_Back"), nullptr, N_("Back in folder history"), CB(layout_menu_back_cb) },
2686 { "ClearMarks", nullptr, N_("Clear Marks..."), nullptr, N_("Clear Marks"), CB(layout_menu_clear_marks_cb) },
2687 { "CloseWindow", GQ_ICON_CLOSE, N_("C_lose window"), "<control>W", N_("Close window"), CB(layout_menu_close_cb) },
2688 { "ColorMenu", nullptr, N_("_Color Management"), nullptr, nullptr, nullptr },
2689 { "ConnectZoom100Alt1", GQ_ICON_ZOOM_100, N_("Zoom _1:1"), "<shift>KP_Divide", N_("Connected Zoom 1:1"), CB(layout_menu_connect_zoom_1_1_cb) },
2690 { "ConnectZoom100", GQ_ICON_ZOOM_100, N_("Zoom _1:1"), "<shift>Z", N_("Connected Zoom 1:1"), CB(layout_menu_connect_zoom_1_1_cb) },
2691 { "ConnectZoom200", nullptr, N_("Zoom _2:1"), nullptr, N_("Connected Zoom 2:1"), CB(layout_menu_connect_zoom_2_1_cb) },
2692 { "ConnectZoom25", nullptr, N_("Zoom 1:4"), nullptr, N_("Connected Zoom 1:4"), CB(layout_menu_connect_zoom_1_4_cb) },
2693 { "ConnectZoom300", nullptr, N_("Zoom _3:1"), nullptr, N_("Connected Zoom 3:1"), CB(layout_menu_connect_zoom_3_1_cb) },
2694 { "ConnectZoom33", nullptr, N_("Zoom 1:3"), nullptr, N_("Connected Zoom 1:3"), CB(layout_menu_connect_zoom_1_3_cb) },
2695 { "ConnectZoom400", nullptr, N_("Zoom _4:1"), nullptr, N_("Connected Zoom 4:1"), CB(layout_menu_connect_zoom_4_1_cb) },
2696 { "ConnectZoom50", nullptr, N_("Zoom 1:2"), nullptr, N_("Connected Zoom 1:2"), CB(layout_menu_connect_zoom_1_2_cb) },
2697 { "ConnectZoomFillHor", nullptr, N_("Fit _Horizontally"), "<shift>H", N_("Connected Fit Horizontally"), CB(layout_menu_connect_zoom_fit_hor_cb) },
2698 { "ConnectZoomFillVert", nullptr, N_("Fit _Vertically"), "<shift>W", N_("Connected Fit Vertically"), CB(layout_menu_connect_zoom_fit_vert_cb) },
2699 { "ConnectZoomFitAlt1", GQ_ICON_ZOOM_FIT, N_("_Zoom to fit"), "<shift>KP_Multiply", N_("Connected Zoom to fit"), CB(layout_menu_connect_zoom_fit_cb) },
2700 { "ConnectZoomFit", GQ_ICON_ZOOM_FIT, N_("_Zoom to fit"), "<shift>X", N_("Connected Zoom to fit"), CB(layout_menu_connect_zoom_fit_cb) },
2701 { "ConnectZoomInAlt1", GQ_ICON_ZOOM_IN, N_("Zoom _in"), "<shift>KP_Add", N_("Connected Zoom in"), CB(layout_menu_connect_zoom_in_cb) },
2702 { "ConnectZoomIn", GQ_ICON_ZOOM_IN, N_("Zoom _in"), "plus", N_("Connected Zoom in"), CB(layout_menu_connect_zoom_in_cb) },
2703 { "ConnectZoomMenu", nullptr, N_("_Connected Zoom"), nullptr, nullptr, nullptr },
2704 { "ConnectZoomOutAlt1", GQ_ICON_ZOOM_OUT, N_("Zoom _out"), "<shift>KP_Subtract", N_("Connected Zoom out"), CB(layout_menu_connect_zoom_out_cb) },
2705 { "ConnectZoomOut", GQ_ICON_ZOOM_OUT, N_("Zoom _out"), "underscore", N_("Connected Zoom out"), CB(layout_menu_connect_zoom_out_cb) },
2706 { "Copy", GQ_ICON_COPY, N_("_Copy..."), "<control>C", N_("Copy..."), CB(layout_menu_copy_cb) },
2707 { "CopyPath", nullptr, N_("_Copy to clipboard"), nullptr, N_("Copy to clipboard"), CB(layout_menu_copy_path_cb) },
2708 { "CopyPathUnquoted", nullptr, N_("_Copy to clipboard (unquoted)"), nullptr, N_("Copy to clipboard (unquoted)"), CB(layout_menu_copy_path_unquoted_cb) },
2709 { "CutPath", nullptr, N_("_Cut to clipboard"), "<control>X", N_("Cut to clipboard"), CB(layout_menu_cut_path_cb) },
2710 { "DeleteAlt1", GQ_ICON_USER_TRASH, N_("Move to Trash..."), "Delete", N_("Move to Trash..."), CB(layout_menu_move_to_trash_key_cb) },
2711 { "DeleteAlt2", GQ_ICON_USER_TRASH, N_("Move to Trash..."), "KP_Delete", N_("Move to Trash..."), CB(layout_menu_move_to_trash_key_cb) },
2712 { "Delete", GQ_ICON_USER_TRASH, N_("Move to Trash..."), "<control>D", N_("Move to Trash..."), CB(layout_menu_move_to_trash_cb) },
2713 { "DeleteWindow", GQ_ICON_DELETE, N_("Delete window"), nullptr, N_("Delete window"), CB(layout_menu_window_delete_cb) },
2714 { "DisableGrouping", nullptr, N_("Disable file groupi_ng"), nullptr, N_("Disable file grouping"), CB(layout_menu_disable_grouping_cb) },
2715 { "EditMenu", nullptr, N_("_Edit"), nullptr, nullptr, nullptr },
2716 { "EnableGrouping", nullptr, N_("Enable file _grouping"), nullptr, N_("Enable file grouping"), CB(layout_menu_enable_grouping_cb) },
2717 { "EscapeAlt1", GQ_ICON_LEAVE_FULLSCREEN, N_("_Leave full screen"), "Q", N_("Leave full screen"), CB(layout_menu_escape_cb) },
2718 { "Escape", GQ_ICON_LEAVE_FULLSCREEN, N_("_Leave full screen"), "Escape", N_("Leave full screen"), CB(layout_menu_escape_cb) },
2719 { "ExifWin", PIXBUF_INLINE_ICON_EXIF, N_("_Exif window"), "<control>E", N_("Exif window"), CB(layout_menu_bar_exif_cb) },
2720 { "FileDirMenu", nullptr, N_("_Files and Folders"), nullptr, nullptr, nullptr },
2721 { "FileMenu", nullptr, N_("_File"), nullptr, nullptr, nullptr },
2722 { "FindDupes", GQ_ICON_FIND, N_("_Find duplicates..."), "D", N_("Find duplicates..."), CB(layout_menu_dupes_cb) },
2723 { "FirstImage", GQ_ICON_GO_TOP, N_("_First Image"), "Home", N_("First Image"), CB(layout_menu_image_first_cb) },
2724 { "FirstPage", GQ_ICON_PREV_PAGE, N_("_First Page"), nullptr, N_( "First Page of multi-page image"), CB(layout_menu_page_first_cb) },
2725 { "Flip", GQ_ICON_FLIP_VERTICAL, N_("_Flip"), "<shift>F", N_("Image Flip"), CB(layout_menu_alter_flip_cb) },
2726 { "Forward", GQ_ICON_GO_NEXT, N_("_Forward"), nullptr, N_("Forward in folder history"), CB(layout_menu_forward_cb) },
2727 { "FullScreenAlt1", GQ_ICON_FULLSCREEN, N_("F_ull screen"), "V", N_("Full screen"), CB(layout_menu_fullscreen_cb) },
2728 { "FullScreenAlt2", GQ_ICON_FULLSCREEN, N_("F_ull screen"), "F11", N_("Full screen"), CB(layout_menu_fullscreen_cb) },
2729 { "FullScreen", GQ_ICON_FULLSCREEN, N_("F_ull screen"), "F", N_("Full screen"), CB(layout_menu_fullscreen_cb) },
2730 { "GoMenu", nullptr, N_("_Go"), nullptr, nullptr, nullptr },
2731 { "HelpChangeLog", nullptr, N_("_ChangeLog"), nullptr, N_("ChangeLog notes"), CB(layout_menu_changelog_cb) },
2732 { "HelpContents", GQ_ICON_HELP, N_("_Help manual"), "F1", N_("Help manual"), CB(layout_menu_help_cb) },
2733 { "HelpKbd", nullptr, N_("_Keyboard map"), nullptr, N_("Keyboard map"), CB(layout_menu_kbd_map_cb) },
2734 { "HelpMenu", nullptr, N_("_Help"), nullptr, nullptr, nullptr },
2735 { "HelpNotes", nullptr, N_("_Readme"), nullptr, N_("Readme"), CB(layout_menu_notes_cb) },
2736 { "HelpSearch", nullptr, N_("On-line help search"), nullptr, N_("On-line help search"), CB(layout_menu_help_search_cb) },
2737 { "HelpShortcuts", nullptr, N_("_Keyboard shortcuts"), nullptr, N_("Keyboard shortcuts"), CB(layout_menu_help_keys_cb) },
2738 { "HideTools", PIXBUF_INLINE_ICON_HIDETOOLS, N_("_Hide file list"), "<control>H", N_("Hide file list"), CB(layout_menu_hide_cb) },
2739 { "HistogramChanCycle", nullptr, N_("Cycle through histogram ch_annels"), "K", N_("Cycle through histogram channels"), CB(layout_menu_histogram_toggle_channel_cb) },
2740 { "HistogramModeCycle", nullptr, N_("Cycle through histogram mo_des"), "J", N_("Cycle through histogram modes"), CB(layout_menu_histogram_toggle_mode_cb) },
2741 { "Home", GQ_ICON_HOME, N_("_Home"), nullptr, N_("Home"), CB(layout_menu_home_cb) },
2742 { "ImageBack", GQ_ICON_GO_FIRST, N_("Image Back"), nullptr, N_("Back in image history"), CB(layout_menu_image_back_cb) },
2743 { "ImageForward", GQ_ICON_GO_LAST, N_("Image Forward"), nullptr, N_("Forward in image history"), CB(layout_menu_image_forward_cb) },
2744 { "ImageOverlayCycle", nullptr, N_("_Cycle through overlay modes"), "I", N_("Cycle through Overlay modes"), CB(layout_menu_overlay_toggle_cb) },
2745 { "KeywordAutocomplete", nullptr, N_("Keyword autocomplete"), "<alt>K", N_("Keyword Autocomplete"), CB(layout_menu_keyword_autocomplete_cb) },
2746 { "LastImage", GQ_ICON_GO_BOTTOM, N_("_Last Image"), "End", N_("Last Image"), CB(layout_menu_image_last_cb) },
2747 { "LastPage", GQ_ICON_NEXT_PAGE, N_("_Last Page"), nullptr, N_("Last Page of multi-page image"), CB(layout_menu_page_last_cb) },
2748 { "LayoutConfig", GQ_ICON_PREFERENCES, N_("_Configure this window..."), nullptr, N_("Configure this window..."), CB(layout_menu_layout_config_cb) },
2749 { "LogWindow", nullptr, N_("_Log Window"), nullptr, N_("Log Window"), CB(layout_menu_log_window_cb) },
2750 { "Maintenance", PIXBUF_INLINE_ICON_MAINTENANCE, N_("_Cache maintenance..."), nullptr, N_("Cache maintenance..."), CB(layout_menu_remove_thumb_cb) },
2751 { "Mirror", GQ_ICON_FLIP_HORIZONTAL, N_("_Mirror"), "<shift>M", N_("Image Mirror"), CB(layout_menu_alter_mirror_cb) },
2752 { "Move", PIXBUF_INLINE_ICON_MOVE, N_("_Move..."), "<control>M", N_("Move..."), CB(layout_menu_move_cb) },
2753 { "NewCollection", GQ_ICON_COLLECTION, N_("_New collection"), "C", N_("New collection"), CB(layout_menu_new_cb) },
2754 { "NewFolder", GQ_ICON_DIRECTORY, N_("N_ew folder..."), "<control>F", N_("New folder..."), CB(layout_menu_dir_cb) },
2755 { "NewWindowDefault", nullptr, N_("default"), "<control>N", N_("New window (default)"), CB(layout_menu_window_default_cb) },
2756 { "NewWindowFromCurrent", nullptr, N_("from current"), nullptr, N_("from current"), CB(layout_menu_window_from_current_cb) },
2757 { "NewWindow", nullptr, N_("New window"), nullptr, N_("New window"), CB(layout_menu_window_cb) },
2758 { "NextImageAlt1", GQ_ICON_GO_DOWN, N_("_Next Image"), "Page_Down", N_("Next Image"), CB(layout_menu_image_next_cb) },
2759 { "NextImageAlt2", GQ_ICON_GO_DOWN, N_("_Next Image"), "KP_Page_Down", N_("Next Image"), CB(layout_menu_image_next_cb) },
2760 { "NextImage", GQ_ICON_GO_DOWN, N_("_Next Image"), "space", N_("Next Image"), CB(layout_menu_image_next_cb) },
2761 { "NextPage", GQ_ICON_FORWARD_PAGE, N_("_Next Page"), nullptr, N_("Next Page of multi-page image"), CB(layout_menu_page_next_cb) },
2762 { "OpenArchive", GQ_ICON_OPEN, N_("Open archive"), nullptr, N_("Open archive"), CB(layout_menu_open_archive_cb) },
2763 { "OpenCollection", GQ_ICON_OPEN, N_("_Open collection..."), "O", N_("Open collection..."), nullptr },
2764 { "OpenMenu", nullptr, N_("☰"), nullptr, nullptr, nullptr },
2765 { "OpenRecent", nullptr, N_("Open recen_t"), nullptr, N_("Open recent collection"), nullptr },
2766 { "OpenWith", GQ_ICON_OPEN_WITH, N_("Open With..."), nullptr, N_("Open With..."), CB(layout_menu_open_with_cb) },
2767 { "OrientationMenu", nullptr, N_("_Orientation"), nullptr, nullptr, nullptr },
2768 { "OverlayMenu", nullptr, N_("Image _Overlay"), nullptr, nullptr, nullptr },
2769 { "PanView", PIXBUF_INLINE_ICON_PANORAMA, N_("Pa_n view"), "<control>J", N_("Pan view"), CB(layout_menu_pan_cb) },
2770 { "PermanentDelete", GQ_ICON_DELETE, N_("Delete..."), "<shift>Delete", N_("Delete..."), CB(layout_menu_delete_cb) },
2771 { "Plugins", GQ_ICON_PREFERENCES, N_("Configure _Plugins..."), nullptr, N_("Configure Plugins..."), CB(layout_menu_editors_cb) },
2772 { "PluginsMenu", nullptr, N_("_Plugins"), nullptr, nullptr, nullptr },
2773 { "Preferences", GQ_ICON_PREFERENCES, N_("P_references..."), "<control>O", N_("Preferences..."), CB(layout_menu_config_cb) },
2774 { "PreferencesMenu", nullptr, N_("P_references"), nullptr, nullptr, nullptr },
2775 { "PrevImageAlt1", GQ_ICON_GO_UP, N_("_Previous Image"), "Page_Up", N_("Previous Image"), CB(layout_menu_image_prev_cb) },
2776 { "PrevImageAlt2", GQ_ICON_GO_UP, N_("_Previous Image"), "KP_Page_Up", N_("Previous Image"), CB(layout_menu_image_prev_cb) },
2777 { "PrevImage", GQ_ICON_GO_UP, N_("_Previous Image"), "BackSpace", N_("Previous Image"), CB(layout_menu_image_prev_cb) },
2778 { "PrevPage", GQ_ICON_BACK_PAGE, N_("_Previous Page"), nullptr, N_("Previous Page of multi-page image"), CB(layout_menu_page_previous_cb) },
2779 { "Print", GQ_ICON_PRINT, N_("_Print..."), "<shift>P", N_("Print..."), CB(layout_menu_print_cb) },
2780 { "Quit", GQ_ICON_QUIT, N_("_Quit"), "<control>Q", N_("Quit"), CB(layout_menu_exit_cb) },
2781 { "Rating0", nullptr, N_("_Rating 0"), "<alt>KP_0", N_("Rating 0"), CB(layout_menu_rating_0_cb) },
2782 { "Rating1", nullptr, N_("_Rating 1"), "<alt>KP_1", N_("Rating 1"), CB(layout_menu_rating_1_cb) },
2783 { "Rating2", nullptr, N_("_Rating 2"), "<alt>KP_2", N_("Rating 2"), CB(layout_menu_rating_2_cb) },
2784 { "Rating3", nullptr, N_("_Rating 3"), "<alt>KP_3", N_("Rating 3"), CB(layout_menu_rating_3_cb) },
2785 { "Rating4", nullptr, N_("_Rating 4"), "<alt>KP_4", N_("Rating 4"), CB(layout_menu_rating_4_cb) },
2786 { "Rating5", nullptr, N_("_Rating 5"), "<alt>KP_5", N_("Rating 5"), CB(layout_menu_rating_5_cb) },
2787 { "RatingM1", nullptr, N_("_Rating -1"), "<alt>KP_Subtract", N_("Rating -1"), CB(layout_menu_rating_m1_cb) },
2788 { "RatingMenu", nullptr, N_("_Rating"), nullptr, nullptr, nullptr },
2789 { "Refresh", GQ_ICON_REFRESH, N_("_Refresh"), "R", N_("Refresh"), CB(layout_menu_refresh_cb) },
2790 { "Rename", PIXBUF_INLINE_ICON_RENAME, N_("_Rename..."), "<control>R", N_("Rename..."), CB(layout_menu_rename_cb) },
2791 { "RenameWindow", GQ_ICON_EDIT, N_("Rename window"), nullptr, N_("Rename window"), CB(layout_menu_window_rename_cb) },
2792 { "Rotate180", PIXBUF_INLINE_ICON_180, N_("Rotate 1_80°"), "<shift>R", N_("Image Rotate 180°"), CB(layout_menu_alter_180_cb) },
2793 { "RotateCCW", GQ_ICON_ROTATE_LEFT, N_("Rotate _counterclockwise 90°"), "bracketleft", N_("Rotate counterclockwise 90°"), CB(layout_menu_alter_90cc_cb) },
2794 { "RotateCW", GQ_ICON_ROTATE_RIGHT, N_("_Rotate clockwise 90°"), "bracketright", N_("Image Rotate clockwise 90°"), CB(layout_menu_alter_90_cb) },
2795 { "SaveMetadata", GQ_ICON_SAVE, N_("_Save metadata"), "<control>S", N_("Save metadata"), CB(layout_menu_metadata_write_cb) },
2796 { "SearchAndRunCommand", GQ_ICON_FIND, N_("Search and Run command"), "slash", N_("Search commands by keyword and run them"), CB(layout_menu_search_and_run_cb) },
2797 { "Search", GQ_ICON_FIND, N_("_Search..."), "F3", N_("Search..."), CB(layout_menu_search_cb) },
2798 { "SelectAll", PIXBUF_INLINE_ICON_SELECT_ALL, N_("Select _all"), "<control>A", N_("Select all"), CB(layout_menu_select_all_cb) },
2799 { "SelectInvert", PIXBUF_INLINE_ICON_SELECT_INVERT, N_("_Invert Selection"), "<control><shift>I", N_("Invert Selection"), CB(layout_menu_invert_selection_cb) },
2800 { "SelectMenu", nullptr, N_("_Select"), nullptr, nullptr, nullptr },
2801 { "SelectNone", PIXBUF_INLINE_ICON_SELECT_NONE, N_("Select _none"), "<control><shift>A", N_("Select none"), CB(layout_menu_unselect_all_cb) },
2802 { "SlideShowFaster", GQ_ICON_GENERIC, N_("Faster"), "<control>equal", N_("Slideshow Faster"), CB(layout_menu_slideshow_faster_cb) },
2803 { "SlideShowPause", GQ_ICON_PAUSE, N_("_Pause slideshow"), "P", N_("Pause slideshow"), CB(layout_menu_slideshow_pause_cb) },
2804 { "SlideShowSlower", GQ_ICON_GENERIC, N_("Slower"), "<control>minus", N_("Slideshow Slower"), CB(layout_menu_slideshow_slower_cb) },
2805 { "SplitDownPane", nullptr, N_("_Down Pane"), "<alt>Down", N_("Down Split Pane"), CB(layout_menu_split_pane_updown_cb) },
2806 { "SplitMenu", nullptr, N_("Spli_t"), nullptr, nullptr, nullptr },
2807 { "SplitNextPane", nullptr, N_("_Next Pane"), "<alt>Right", N_("Next Split Pane"), CB(layout_menu_split_pane_next_cb) },
2808 { "SplitPreviousPane", nullptr, N_("_Previous Pane"), "<alt>Left", N_("Previous Split Pane"), CB(layout_menu_split_pane_prev_cb) },
2809 { "SplitUpPane", nullptr, N_("_Up Pane"), "<alt>Up", N_("Up Split Pane"), CB(layout_menu_split_pane_updown_cb) },
2810 { "StereoCycle", nullptr, N_("_Cycle through stereo modes"), nullptr, N_("Cycle through stereo modes"), CB(layout_menu_stereo_mode_next_cb) },
2811 { "StereoMenu", nullptr, N_("Stere_o"), nullptr, nullptr, nullptr },
2812 { "Up", GQ_ICON_GO_UP, N_("_Up"), nullptr, N_("Up one folder"), CB(layout_menu_up_cb) },
2813 { "ViewInNewWindow", nullptr, N_("_View in new window"), "<control>V", N_("View in new window"), CB(layout_menu_view_in_new_window_cb) },
2814 { "ViewMenu", nullptr, N_("_View"), nullptr, nullptr, CB(layout_menu_view_menu_cb) },
2815 { "Wallpaper", nullptr, N_("Set as _wallpaper"), nullptr, N_("Set as wallpaper"), CB(layout_menu_wallpaper_cb) },
2816 { "WindowsMenu", nullptr, N_("_Windows"), nullptr, nullptr, CB(layout_menu_windows_menu_cb) },
2817 { "WriteRotationKeepDate", nullptr, N_("_Write orientation to file (preserve timestamp)"), nullptr, N_("Write orientation to file (preserve timestamp)"), CB(layout_menu_write_rotate_keep_date_cb) },
2818 { "WriteRotation", nullptr, N_("_Write orientation to file"), nullptr, N_("Write orientation to file"), CB(layout_menu_write_rotate_cb) },
2819 { "Zoom100Alt1", GQ_ICON_ZOOM_100, N_("Zoom _1:1"), "KP_Divide", N_("Zoom 1:1"), CB(layout_menu_zoom_1_1_cb) },
2820 { "Zoom100", GQ_ICON_ZOOM_100, N_("Zoom _1:1"), "Z", N_("Zoom 1:1"), CB(layout_menu_zoom_1_1_cb) },
2821 { "Zoom200", GQ_ICON_GENERIC, N_("Zoom _2:1"), nullptr, N_("Zoom 2:1"), CB(layout_menu_zoom_2_1_cb) },
2822 { "Zoom25", GQ_ICON_GENERIC, N_("Zoom 1:4"), nullptr, N_("Zoom 1:4"), CB(layout_menu_zoom_1_4_cb) },
2823 { "Zoom300", GQ_ICON_GENERIC, N_("Zoom _3:1"), nullptr, N_("Zoom 3:1"), CB(layout_menu_zoom_3_1_cb) },
2824 { "Zoom33", GQ_ICON_GENERIC, N_("Zoom 1:3"), nullptr, N_("Zoom 1:3"), CB(layout_menu_zoom_1_3_cb) },
2825 { "Zoom400", GQ_ICON_GENERIC, N_("Zoom _4:1"), nullptr, N_("Zoom 4:1"), CB(layout_menu_zoom_4_1_cb) },
2826 { "Zoom50", GQ_ICON_GENERIC, N_("Zoom 1:2"), nullptr, N_("Zoom 1:2"), CB(layout_menu_zoom_1_2_cb) },
2827 { "ZoomFillHor", PIXBUF_INLINE_ICON_ZOOMFILLHOR, N_("Fit _Horizontally"), "H", N_("Fit Horizontally"), CB(layout_menu_zoom_fit_hor_cb) },
2828 { "ZoomFillVert", PIXBUF_INLINE_ICON_ZOOMFILLVERT, N_("Fit _Vertically"), "W", N_("Fit Vertically"), CB(layout_menu_zoom_fit_vert_cb) },
2829 { "ZoomFitAlt1", GQ_ICON_ZOOM_FIT, N_("_Zoom to fit"), "KP_Multiply", N_("Zoom to fit"), CB(layout_menu_zoom_fit_cb) },
2830 { "ZoomFit", GQ_ICON_ZOOM_FIT, N_("_Zoom to fit"), "X", N_("Zoom to fit"), CB(layout_menu_zoom_fit_cb) },
2831 { "ZoomInAlt1", GQ_ICON_ZOOM_IN, N_("Zoom _in"), "KP_Add", N_("Zoom in"), CB(layout_menu_zoom_in_cb) },
2832 { "ZoomIn", GQ_ICON_ZOOM_IN, N_("Zoom _in"), "equal", N_("Zoom in"), CB(layout_menu_zoom_in_cb) },
2833 { "ZoomMenu", nullptr, N_("_Zoom"), nullptr, nullptr, nullptr },
2834 { "ZoomOutAlt1", GQ_ICON_ZOOM_OUT, N_("Zoom _out"), "KP_Subtract", N_("Zoom out"), CB(layout_menu_zoom_out_cb) },
2835 { "ZoomToRectangle", nullptr, N_("Zoom to rectangle"), nullptr, N_("Zoom to rectangle"), CB(layout_menu_zoom_to_rectangle_cb) },
2836 { "ZoomOut", GQ_ICON_ZOOM_OUT, N_("Zoom _out"), "minus", N_("Zoom out"), CB(layout_menu_zoom_out_cb) }
2839 static GtkToggleActionEntry menu_toggle_entries[] = {
2840 { "Animate", nullptr, N_("_Animation"), "A", N_("Toggle animation"), CB(layout_menu_animate_cb), FALSE },
2841 { "DrawRectangle", PIXBUF_INLINE_ICON_DRAW_RECTANGLE, N_("Draw Rectangle"), nullptr, N_("Draw Rectangle"), CB(layout_menu_select_rectangle_cb), FALSE },
2842 { "ExifRotate", GQ_ICON_ROTATE_LEFT, N_("_Exif rotate"), "<alt>X", N_("Toggle Exif rotate"), CB(layout_menu_exif_rotate_cb), FALSE },
2843 { "FloatTools", PIXBUF_INLINE_ICON_FLOAT, N_("_Float file list"), "L", N_("Float file list"), CB(layout_menu_float_cb), FALSE },
2844 { "Grayscale", PIXBUF_INLINE_ICON_GRAYSCALE, N_("Toggle _grayscale"), "<shift>G", N_("Toggle grayscale"), CB(layout_menu_alter_desaturate_cb), FALSE },
2845 { "HideBars", nullptr, N_("Hide Bars and Files"), "grave", N_("Hide Bars and Files"), CB(layout_menu_hide_bars_cb), FALSE },
2846 { "HideSelectableToolbars", nullptr, N_("Hide Selectable Bars"), "<control>grave", N_("Hide Selectable Bars"), CB(layout_menu_selectable_toolbars_cb), FALSE },
2847 { "IgnoreAlpha", GQ_ICON_STRIKETHROUGH, N_("Hide _alpha"), "<shift>A", N_("Hide alpha channel"), CB(layout_menu_alter_ignore_alpha_cb), FALSE },
2848 { "ImageHistogram", nullptr, N_("_Show Histogram"), nullptr, N_("Show Histogram"), CB(layout_menu_histogram_cb), FALSE },
2849 { "ImageOverlay", nullptr, N_("Image _Overlay"), nullptr, N_("Image Overlay"), CB(layout_menu_overlay_cb), FALSE },
2850 { "OverUnderExposed", PIXBUF_INLINE_ICON_EXPOSURE, N_("Over/Under Exposed"), "<shift>E", N_("Highlight over/under exposed"), CB(layout_menu_select_overunderexposed_cb), FALSE },
2851 { "RectangularSelection", PIXBUF_INLINE_ICON_SELECT_RECTANGLE, N_("Rectangular Selection"), "<alt>R", N_("Rectangular Selection"), CB(layout_menu_rectangular_selection_cb), FALSE },
2852 { "SBar", PIXBUF_INLINE_ICON_PROPERTIES, N_("_Info sidebar"), "<control>K", N_("Info sidebar"), CB(layout_menu_bar_cb), FALSE },
2853 { "SBarSort", PIXBUF_INLINE_ICON_SORT, N_("Sort _manager"), "<shift>S", N_("Sort manager"), CB(layout_menu_bar_sort_cb), FALSE },
2854 { "ShowFileFilter", GQ_ICON_FILE_FILTER, N_("Show File Filter"), nullptr, N_("Show File Filter"), CB(layout_menu_file_filter_cb), FALSE },
2855 { "ShowInfoPixel", GQ_ICON_SELECT_COLOR, N_("Pi_xel Info"), nullptr, N_("Show Pixel Info"), CB(layout_menu_info_pixel_cb), FALSE },
2856 { "ShowMarks", PIXBUF_INLINE_ICON_MARKS, N_("Show _Marks"), "M", N_("Show Marks"), CB(layout_menu_marks_cb), FALSE },
2857 { "SlideShow", GQ_ICON_PLAY, N_("Toggle _slideshow"), "S", N_("Toggle slideshow"), CB(layout_menu_slideshow_cb), FALSE },
2858 { "SplitPaneSync", PIXBUF_INLINE_SPLIT_PANE_SYNC, N_("Split Pane Sync"), nullptr, N_("Split Pane Sync"), CB(layout_menu_split_pane_sync_cb), FALSE },
2859 { "Thumbnails", PIXBUF_INLINE_ICON_THUMB, N_("Show _Thumbnails"), "T", N_("Show Thumbnails"), CB(layout_menu_thumb_cb), FALSE },
2860 { "UseColorProfiles", GQ_ICON_COLOR_MANAGEMENT, N_("Use _color profiles"), nullptr, N_("Use color profiles"), CB(layout_color_menu_enable_cb), FALSE },
2861 { "UseImageProfile", nullptr, N_("Use profile from _image"), nullptr, N_("Use profile from image"), CB(layout_color_menu_use_image_cb), FALSE }
2864 static GtkRadioActionEntry menu_radio_entries[] = {
2865 { "ViewIcons", nullptr, N_("Images as I_cons"), "<control>I", N_("View Images as Icons"), FILEVIEW_ICON },
2866 { "ViewList", nullptr, N_("Images as _List"), "<control>L", N_("View Images as List"), FILEVIEW_LIST }
2869 static GtkToggleActionEntry menu_view_dir_toggle_entries[] = {
2870 { "FolderTree", nullptr, N_("T_oggle Folder View"), "<control>T", N_("Toggle Folders View"), CB(layout_menu_view_dir_as_cb),FALSE },
2873 static GtkRadioActionEntry menu_split_radio_entries[] = {
2874 { "SplitHorizontal", nullptr, N_("_Horizontal"), "E", N_("Split panes horizontal."), SPLIT_HOR },
2875 { "SplitQuad", nullptr, N_("_Quad"), nullptr, N_("Split panes quad"), SPLIT_QUAD },
2876 { "SplitSingle", nullptr, N_("_Single"), "Y", N_("Single pane"), SPLIT_NONE },
2877 { "SplitTriple", nullptr, N_("_Triple"), nullptr, N_("Split panes triple"), SPLIT_TRIPLE },
2878 { "SplitVertical", nullptr, N_("_Vertical"), "U", N_("Split panes vertical"), SPLIT_VERT }
2881 static GtkRadioActionEntry menu_color_radio_entries[] = {
2882 { "ColorProfile0", nullptr, N_("Input _0: sRGB"), nullptr, N_("Input 0: sRGB"), COLOR_PROFILE_SRGB },
2883 { "ColorProfile1", nullptr, N_("Input _1: AdobeRGB compatible"), nullptr, N_("Input 1: AdobeRGB compatible"), COLOR_PROFILE_ADOBERGB },
2884 { "ColorProfile2", nullptr, N_("Input _2"), nullptr, N_("Input 2"), COLOR_PROFILE_FILE },
2885 { "ColorProfile3", nullptr, N_("Input _3"), nullptr, N_("Input 3"), COLOR_PROFILE_FILE + 1 },
2886 { "ColorProfile4", nullptr, N_("Input _4"), nullptr, N_("Input 4"), COLOR_PROFILE_FILE + 2 },
2887 { "ColorProfile5", nullptr, N_("Input _5"), nullptr, N_("Input 5"), COLOR_PROFILE_FILE + 3 }
2890 static GtkRadioActionEntry menu_histogram_channel[] = {
2891 { "HistogramChanB", nullptr, N_("Histogram on _Blue"), nullptr, N_("Histogram on Blue"), HCHAN_B },
2892 { "HistogramChanG", nullptr, N_("Histogram on _Green"), nullptr, N_("Histogram on Green"), HCHAN_G },
2893 { "HistogramChanRGB", nullptr, N_("_Histogram on RGB"), nullptr, N_("Histogram on RGB"), HCHAN_RGB },
2894 { "HistogramChanR", nullptr, N_("Histogram on _Red"), nullptr, N_("Histogram on Red"), HCHAN_R },
2895 { "HistogramChanV", nullptr, N_("Histogram on _Value"), nullptr, N_("Histogram on Value"), HCHAN_MAX }
2898 static GtkRadioActionEntry menu_histogram_mode[] = {
2899 { "HistogramModeLin", nullptr, N_("Li_near Histogram"), nullptr, N_("Linear Histogram"), 0 },
2900 { "HistogramModeLog", nullptr, N_("_Log Histogram"), nullptr, N_("Log Histogram"), 1 },
2903 static GtkRadioActionEntry menu_stereo_mode_entries[] = {
2904 { "StereoAuto", nullptr, N_("_Auto"), nullptr, N_("Stereo Auto"), STEREO_PIXBUF_DEFAULT },
2905 { "StereoCross", nullptr, N_("_Cross"), nullptr, N_("Stereo Cross"), STEREO_PIXBUF_CROSS },
2906 { "StereoOff", nullptr, N_("_Off"), nullptr, N_("Stereo Off"), STEREO_PIXBUF_NONE },
2907 { "StereoSBS", nullptr, N_("_Side by Side"), nullptr, N_("Stereo Side by Side"), STEREO_PIXBUF_SBS }
2911 static gchar *menu_translate(const gchar *path, gpointer)
2913 return static_cast<gchar *>(_(path));
2916 static void layout_actions_setup_mark(LayoutWindow *lw, gint mark, const gchar *name_tmpl,
2917 const gchar *label_tmpl, const gchar *accel_tmpl, const gchar *tooltip_tmpl, GCallback cb)
2923 GtkActionEntry entry = { name, nullptr, label, accel, tooltip, cb };
2926 g_snprintf(name, sizeof(name), name_tmpl, mark);
2927 g_snprintf(label, sizeof(label), label_tmpl, mark);
2930 g_snprintf(accel, sizeof(accel), accel_tmpl, mark % 10);
2932 entry.accelerator = nullptr;
2935 g_snprintf(tooltip, sizeof(tooltip), tooltip_tmpl, mark);
2937 entry.tooltip = nullptr;
2939 gtk_action_group_add_actions(lw->action_group, &entry, 1, lw);
2940 action = gtk_action_group_get_action(lw->action_group, name);
2941 g_object_set_data(G_OBJECT(action), "mark_num", GINT_TO_POINTER(mark > 0 ? mark : 10));
2944 static void layout_actions_setup_marks(LayoutWindow *lw)
2948 GString *desc = g_string_new(
2950 " <menubar name='MainMenu'>");
2952 if (options->hamburger_menu)
2954 g_string_append(desc, " <menu action='OpenMenu'>");
2956 g_string_append(desc, " <menu action='SelectMenu'>");
2958 for (mark = 1; mark <= FILEDATA_MARKS_SIZE; mark++)
2960 gint i = (mark < 10 ? mark : 0);
2962 layout_actions_setup_mark(lw, i, "Mark%d", _("Mark _%d"), nullptr, nullptr, nullptr);
2963 layout_actions_setup_mark(lw, i, "SetMark%d", _("_Set mark %d"), nullptr, _("Set mark %d"), G_CALLBACK(layout_menu_set_mark_sel_cb));
2964 layout_actions_setup_mark(lw, i, "ResetMark%d", _("_Reset mark %d"), nullptr, _("Reset mark %d"), G_CALLBACK(layout_menu_res_mark_sel_cb));
2965 layout_actions_setup_mark(lw, i, "ToggleMark%d", _("_Toggle mark %d"), "%d", _("Toggle mark %d"), G_CALLBACK(layout_menu_toggle_mark_sel_cb));
2966 layout_actions_setup_mark(lw, i, "ToggleMark%dAlt1", _("_Toggle mark %d"), "KP_%d", _("Toggle mark %d"), G_CALLBACK(layout_menu_toggle_mark_sel_cb));
2967 layout_actions_setup_mark(lw, i, "SelectMark%d", _("Se_lect mark %d"), "<control>%d", _("Select mark %d"), G_CALLBACK(layout_menu_sel_mark_cb));
2968 layout_actions_setup_mark(lw, i, "SelectMark%dAlt1", _("_Select mark %d"), "<control>KP_%d", _("Select mark %d"), G_CALLBACK(layout_menu_sel_mark_cb));
2969 layout_actions_setup_mark(lw, i, "AddMark%d", _("_Add mark %d"), nullptr, _("Add mark %d"), G_CALLBACK(layout_menu_sel_mark_or_cb));
2970 layout_actions_setup_mark(lw, i, "IntMark%d", _("_Intersection with mark %d"), nullptr, _("Intersection with mark %d"), G_CALLBACK(layout_menu_sel_mark_and_cb));
2971 layout_actions_setup_mark(lw, i, "UnselMark%d", _("_Unselect mark %d"), nullptr, _("Unselect mark %d"), G_CALLBACK(layout_menu_sel_mark_minus_cb));
2972 layout_actions_setup_mark(lw, i, "FilterMark%d", _("_Filter mark %d"), nullptr, _("Filter mark %d"), G_CALLBACK(layout_menu_mark_filter_toggle_cb));
2974 g_string_append_printf(desc,
2975 " <menu action='Mark%d'>"
2976 " <menuitem action='ToggleMark%d'/>"
2977 " <menuitem action='SetMark%d'/>"
2978 " <menuitem action='ResetMark%d'/>"
2980 " <menuitem action='SelectMark%d'/>"
2981 " <menuitem action='AddMark%d'/>"
2982 " <menuitem action='IntMark%d'/>"
2983 " <menuitem action='UnselMark%d'/>"
2985 " <menuitem action='FilterMark%d'/>"
2987 i, i, i, i, i, i, i, i, i);
2990 g_string_append(desc,
2992 if (options->hamburger_menu)
2994 g_string_append(desc, " </menu>");
2996 g_string_append(desc, " </menubar>");
2998 for (mark = 1; mark <= FILEDATA_MARKS_SIZE; mark++)
3000 gint i = (mark < 10 ? mark : 0);
3002 g_string_append_printf(desc,
3003 "<accelerator action='ToggleMark%dAlt1'/>"
3004 "<accelerator action='SelectMark%dAlt1'/>",
3007 g_string_append(desc, "</ui>" );
3010 if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, desc->str, -1, &error))
3012 g_message("building menus failed: %s", error->message);
3013 g_error_free(error);
3016 g_string_free(desc, TRUE);
3019 static GList *layout_actions_editor_menu_path(EditorDescription *editor)
3021 gchar **split = g_strsplit(editor->menu_path, "/", 0);
3023 GList *ret = nullptr;
3025 if (split[0] == nullptr)
3033 ret = g_list_prepend(ret, g_strdup(split[i]));
3039 ret = g_list_prepend(ret, g_strdup(editor->key));
3041 return g_list_reverse(ret);
3044 static void layout_actions_editor_add(GString *desc, GList *path, GList *old_path)
3049 while (path && old_path && strcmp(static_cast<gchar *>(path->data), static_cast<gchar *>(old_path->data)) == 0)
3052 old_path = old_path->next;
3054 to_open = g_list_length(path) - 1;
3055 to_close = g_list_length(old_path) - 1;
3059 old_path = g_list_last(old_path);
3060 old_path = old_path->prev;
3063 for (i = 0; i < to_close; i++)
3065 auto name = static_cast<gchar *>(old_path->data);
3066 if (g_str_has_suffix(name, "Section"))
3068 g_string_append(desc, " </placeholder>");
3070 else if (g_str_has_suffix(name, "Menu"))
3072 g_string_append(desc, " </menu>");
3076 g_warning("invalid menu path item %s", name);
3078 old_path = old_path->prev;
3081 for (i = 0; i < to_open; i++)
3083 auto name = static_cast<gchar *>(path->data);
3084 if (g_str_has_suffix(name, "Section"))
3086 g_string_append_printf(desc, " <placeholder name='%s'>", name);
3088 else if (g_str_has_suffix(name, "Menu"))
3090 g_string_append_printf(desc, " <menu action='%s'>", name);
3094 g_warning("invalid menu path item %s", name);
3100 g_string_append_printf(desc, " <menuitem action='%s'/>", static_cast<gchar *>(path->data));
3103 static void layout_actions_setup_editors(LayoutWindow *lw)
3106 GList *editors_list;
3111 if (lw->ui_editors_id)
3113 gtk_ui_manager_remove_ui(lw->ui_manager, lw->ui_editors_id);
3116 if (lw->action_group_editors)
3118 gtk_ui_manager_remove_action_group(lw->ui_manager, lw->action_group_editors);
3119 g_object_unref(lw->action_group_editors);
3121 lw->action_group_editors = gtk_action_group_new("MenuActionsExternal");
3122 gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group_editors, 1);
3124 /* lw->action_group_editors contains translated entries, no translate func is required */
3125 desc = g_string_new(
3127 " <menubar name='MainMenu'>");
3129 if (options->hamburger_menu)
3131 g_string_append(desc, " <menu action='OpenMenu'>");
3134 editors_list = editor_list_get();
3137 work = editors_list;
3141 auto editor = static_cast<EditorDescription *>(work->data);
3142 GtkActionEntry entry = { editor->key,
3146 editor->comment ? editor->comment : editor->name,
3147 G_CALLBACK(layout_menu_edit_cb) };
3151 entry.stock_id = editor->key;
3153 gtk_action_group_add_actions(lw->action_group_editors, &entry, 1, lw);
3155 path = layout_actions_editor_menu_path(editor);
3156 layout_actions_editor_add(desc, path, old_path);
3158 g_list_free_full(old_path, g_free);
3163 layout_actions_editor_add(desc, nullptr, old_path);
3164 g_list_free_full(old_path, g_free);
3166 if (options->hamburger_menu)
3168 g_string_append(desc, "</menu>");
3171 g_string_append(desc," </menubar>"
3176 lw->ui_editors_id = gtk_ui_manager_add_ui_from_string(lw->ui_manager, desc->str, -1, &error);
3177 if (!lw->ui_editors_id)
3179 g_message("building menus failed: %s", error->message);
3180 g_error_free(error);
3183 g_string_free(desc, TRUE);
3184 g_list_free(editors_list);
3187 void create_toolbars(LayoutWindow *lw)
3191 for (i = 0; i < TOOLBAR_COUNT; i++)
3193 layout_actions_toolbar(lw, static_cast<ToolbarType>(i));
3194 layout_toolbar_clear(lw, static_cast<ToolbarType>(i));
3195 layout_toolbar_add_default(lw, static_cast<ToolbarType>(i));
3199 void layout_actions_setup(LayoutWindow *lw)
3203 DEBUG_1("%s layout_actions_setup: start", get_exec_time());
3204 if (lw->ui_manager) return;
3206 lw->action_group = gtk_action_group_new("MenuActions");
3207 gtk_action_group_set_translate_func(lw->action_group, menu_translate, nullptr, nullptr);
3209 gtk_action_group_add_actions(lw->action_group,
3210 menu_entries, G_N_ELEMENTS(menu_entries), lw);
3211 gtk_action_group_add_toggle_actions(lw->action_group,
3212 menu_toggle_entries, G_N_ELEMENTS(menu_toggle_entries), lw);
3213 gtk_action_group_add_radio_actions(lw->action_group,
3214 menu_radio_entries, G_N_ELEMENTS(menu_radio_entries),
3215 0, G_CALLBACK(layout_menu_list_cb), lw);
3216 gtk_action_group_add_radio_actions(lw->action_group,
3217 menu_split_radio_entries, G_N_ELEMENTS(menu_split_radio_entries),
3218 0, G_CALLBACK(layout_menu_split_cb), lw);
3219 gtk_action_group_add_toggle_actions(lw->action_group,
3220 menu_view_dir_toggle_entries, G_N_ELEMENTS(menu_view_dir_toggle_entries),
3222 gtk_action_group_add_radio_actions(lw->action_group,
3223 menu_color_radio_entries, COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS,
3224 0, G_CALLBACK(layout_color_menu_input_cb), lw);
3225 gtk_action_group_add_radio_actions(lw->action_group,
3226 menu_histogram_channel, G_N_ELEMENTS(menu_histogram_channel),
3227 0, G_CALLBACK(layout_menu_histogram_channel_cb), lw);
3228 gtk_action_group_add_radio_actions(lw->action_group,
3229 menu_histogram_mode, G_N_ELEMENTS(menu_histogram_mode),
3230 0, G_CALLBACK(layout_menu_histogram_mode_cb), lw);
3231 gtk_action_group_add_radio_actions(lw->action_group,
3232 menu_stereo_mode_entries, G_N_ELEMENTS(menu_stereo_mode_entries),
3233 0, G_CALLBACK(layout_menu_stereo_mode_cb), lw);
3236 lw->ui_manager = gtk_ui_manager_new();
3237 gtk_ui_manager_set_add_tearoffs(lw->ui_manager, TRUE);
3238 gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group, 0);
3240 DEBUG_1("%s layout_actions_setup: add menu", get_exec_time());
3243 if (!gtk_ui_manager_add_ui_from_resource(lw->ui_manager, options->hamburger_menu ? GQ_RESOURCE_PATH_UI "/menu-hamburger.ui" : GQ_RESOURCE_PATH_UI "/menu-classic.ui" , &error))
3245 g_message("building menus failed: %s", error->message);
3246 g_error_free(error);
3250 DEBUG_1("%s layout_actions_setup: marks", get_exec_time());
3251 layout_actions_setup_marks(lw);
3253 DEBUG_1("%s layout_actions_setup: editors", get_exec_time());
3254 layout_actions_setup_editors(lw);
3256 DEBUG_1("%s layout_actions_setup: status_update_write", get_exec_time());
3257 layout_util_status_update_write(lw);
3259 DEBUG_1("%s layout_actions_setup: actions_add_window", get_exec_time());
3260 layout_actions_add_window(lw, lw->window);
3261 DEBUG_1("%s layout_actions_setup: end", get_exec_time());
3264 static gint layout_editors_reload_idle_id = -1;
3265 static GList *layout_editors_desktop_files = nullptr;
3267 static gboolean layout_editors_reload_idle_cb(gpointer)
3269 if (!layout_editors_desktop_files)
3271 DEBUG_1("%s layout_editors_reload_idle_cb: get_desktop_files", get_exec_time());
3272 layout_editors_desktop_files = editor_get_desktop_files();
3273 return G_SOURCE_CONTINUE;
3276 editor_read_desktop_file(static_cast<const gchar *>(layout_editors_desktop_files->data));
3277 g_free(layout_editors_desktop_files->data);
3278 layout_editors_desktop_files = g_list_delete_link(layout_editors_desktop_files, layout_editors_desktop_files);
3281 if (!layout_editors_desktop_files)
3284 DEBUG_1("%s layout_editors_reload_idle_cb: setup_editors", get_exec_time());
3285 editor_table_finish();
3287 work = layout_window_list;
3290 auto lw = static_cast<LayoutWindow *>(work->data);
3292 layout_actions_setup_editors(lw);
3293 if (lw->bar_sort_enabled)
3295 layout_bar_sort_toggle(lw);
3299 DEBUG_1("%s layout_editors_reload_idle_cb: setup_editors done", get_exec_time());
3301 layout_editors_reload_idle_id = -1;
3302 return G_SOURCE_REMOVE;
3304 return G_SOURCE_CONTINUE;
3307 void layout_editors_reload_start()
3309 DEBUG_1("%s layout_editors_reload_start", get_exec_time());
3311 if (layout_editors_reload_idle_id != -1)
3313 g_source_remove(layout_editors_reload_idle_id);
3314 g_list_free_full(layout_editors_desktop_files, g_free);
3317 editor_table_clear();
3318 layout_editors_reload_idle_id = g_idle_add(layout_editors_reload_idle_cb, nullptr);
3321 void layout_editors_reload_finish()
3323 if (layout_editors_reload_idle_id != -1)
3325 DEBUG_1("%s layout_editors_reload_finish", get_exec_time());
3326 g_source_remove(layout_editors_reload_idle_id);
3327 while (layout_editors_reload_idle_id != -1)
3329 layout_editors_reload_idle_cb(nullptr);
3334 void layout_actions_add_window(LayoutWindow *lw, GtkWidget *window)
3336 GtkAccelGroup *group;
3338 if (!lw->ui_manager) return;
3340 group = gtk_ui_manager_get_accel_group(lw->ui_manager);
3341 gtk_window_add_accel_group(GTK_WINDOW(window), group);
3344 GtkWidget *layout_actions_menu_bar(LayoutWindow *lw)
3346 if (lw->menu_bar) return lw->menu_bar;
3347 lw->menu_bar = gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu");
3348 g_object_ref(lw->menu_bar);
3349 return lw->menu_bar;
3352 GtkWidget *layout_actions_toolbar(LayoutWindow *lw, ToolbarType type)
3354 if (lw->toolbar[type]) return lw->toolbar[type];
3356 lw->toolbar[type] = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
3358 gtk_widget_show(lw->toolbar[type]);
3359 g_object_ref(lw->toolbar[type]);
3360 return lw->toolbar[type];
3363 GtkWidget *layout_actions_menu_tool_bar(LayoutWindow *lw)
3365 GtkWidget *menu_bar;
3368 if (lw->menu_tool_bar) return lw->menu_tool_bar;
3370 toolbar = layout_actions_toolbar(lw, TOOLBAR_MAIN);
3371 DEBUG_NAME(toolbar);
3372 lw->menu_tool_bar = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
3374 if (!options->hamburger_menu)
3376 menu_bar = layout_actions_menu_bar(lw);
3377 DEBUG_NAME(menu_bar);
3378 gq_gtk_box_pack_start(GTK_BOX(lw->menu_tool_bar), menu_bar, FALSE, FALSE, 0);
3381 gq_gtk_box_pack_start(GTK_BOX(lw->menu_tool_bar), toolbar, FALSE, FALSE, 0);
3383 g_object_ref(lw->menu_tool_bar);
3384 return lw->menu_tool_bar;
3387 void toolbar_clear_cb(GtkWidget *widget, gpointer)
3391 if (GTK_IS_BUTTON(widget))
3393 action = static_cast<GtkAction *>(g_object_get_data(G_OBJECT(widget), "action"));
3394 if (g_object_get_data(G_OBJECT(widget), "id") )
3396 g_signal_handler_disconnect(action, GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(widget), "id")));
3399 gtk_widget_destroy(widget);
3402 void layout_toolbar_clear(LayoutWindow *lw, ToolbarType type)
3404 if (lw->toolbar_merge_id[type])
3406 gtk_ui_manager_remove_ui(lw->ui_manager, lw->toolbar_merge_id[type]);
3407 gtk_ui_manager_ensure_update(lw->ui_manager);
3409 g_list_free_full(lw->toolbar_actions[type], g_free);
3410 lw->toolbar_actions[type] = nullptr;
3412 lw->toolbar_merge_id[type] = gtk_ui_manager_new_merge_id(lw->ui_manager);
3414 if (lw->toolbar[type])
3416 gtk_container_foreach(GTK_CONTAINER(lw->toolbar[type]), (GtkCallback)G_CALLBACK(toolbar_clear_cb), nullptr);
3420 void action_radio_changed_cb(GtkAction *action, GtkAction *current, gpointer data)
3422 auto button = static_cast<GtkToggleButton *>(data);
3424 if (action == current )
3426 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
3430 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE);
3434 void action_toggle_activate_cb(GtkAction* self, gpointer data)
3436 auto button = static_cast<GtkToggleButton *>(data);
3438 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(self)) != gtk_toggle_button_get_active(button))
3440 gtk_toggle_button_set_active(button, gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(self)));
3444 gboolean toolbar_button_press_event_cb(GtkWidget *, GdkEvent *, gpointer data)
3446 gtk_action_activate(GTK_ACTION(data));
3451 void layout_toolbar_add(LayoutWindow *lw, ToolbarType type, const gchar *action_name)
3453 const gchar *path = nullptr;
3454 const gchar *tooltip_text = nullptr;
3456 GtkWidget *action_icon = nullptr;
3460 if (!action_name || !lw->ui_manager) return;
3462 if (!lw->toolbar[type])
3472 case TOOLBAR_STATUS:
3473 path = "/StatusBar";
3479 if (g_str_has_suffix(action_name, ".desktop"))
3481 /* this may be called before the external editors are read
3482 create a dummy action for now */
3483 if (!lw->action_group_editors)
3485 lw->action_group_editors = gtk_action_group_new("MenuActionsExternal");
3486 gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group_editors, 1);
3488 if (!gtk_action_group_get_action(lw->action_group_editors, action_name))
3490 GtkActionEntry entry = { action_name,
3491 GQ_ICON_MISSING_IMAGE,
3497 DEBUG_1("Creating temporary action %s", action_name);
3498 gtk_action_group_add_actions(lw->action_group_editors, &entry, 1, lw);
3502 if (g_strcmp0(action_name, "Separator") == 0)
3504 button = gtk_separator_new(GTK_ORIENTATION_VERTICAL);
3508 action = gtk_action_group_get_action(lw->action_group, action_name);
3510 action_icon = gtk_action_create_icon(action, GTK_ICON_SIZE_SMALL_TOOLBAR);
3511 tooltip_text = gtk_action_get_tooltip(action);
3513 gtk_ui_manager_add_ui(lw->ui_manager, lw->toolbar_merge_id[type], path, action_name, action_name, GTK_UI_MANAGER_TOOLITEM, FALSE);
3515 if (GTK_IS_RADIO_ACTION(action) || GTK_IS_TOGGLE_ACTION(action))
3517 button = gtk_toggle_button_new();
3521 button = gtk_button_new();
3524 if (GTK_IS_TOGGLE_ACTION(action) || GTK_IS_RADIO_ACTION(action))
3526 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)));
3531 gtk_button_set_image(GTK_BUTTON(button), action_icon);
3535 gtk_button_set_label(GTK_BUTTON(button), action_name);
3538 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
3539 gtk_widget_set_tooltip_text(button, tooltip_text);
3541 if (GTK_IS_RADIO_ACTION(action))
3543 id = g_signal_connect(G_OBJECT(action), "changed", G_CALLBACK(action_radio_changed_cb), button);
3544 g_object_set_data(G_OBJECT(button), "id", GUINT_TO_POINTER(id));
3546 else if (GTK_IS_TOGGLE_ACTION(action))
3548 id = g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(action_toggle_activate_cb), button);
3549 g_object_set_data(G_OBJECT(button), "id", GUINT_TO_POINTER(id));
3552 g_signal_connect(G_OBJECT(button), "button_press_event", G_CALLBACK(toolbar_button_press_event_cb), action);
3553 g_object_set_data(G_OBJECT(button), "action", action);
3556 gq_gtk_container_add(GTK_WIDGET(lw->toolbar[type]), GTK_WIDGET(button));
3557 gtk_widget_show(GTK_WIDGET(button));
3559 lw->toolbar_actions[type] = g_list_append(lw->toolbar_actions[type], g_strdup(action_name));
3562 void layout_toolbar_add_default(LayoutWindow *lw, ToolbarType type)
3564 LayoutWindow *lw_first;
3570 if (layout_window_list)
3572 lw_first = static_cast<LayoutWindow *>(layout_window_list->data);
3573 if (lw_first->toolbar_actions[TOOLBAR_MAIN])
3575 work_action = lw_first->toolbar_actions[type];
3578 auto action = static_cast<gchar *>(work_action->data);
3579 work_action = work_action->next;
3580 layout_toolbar_add(lw, type, action);
3585 layout_toolbar_add(lw, type, "Thumbnails");
3586 layout_toolbar_add(lw, type, "Back");
3587 layout_toolbar_add(lw, type, "Forward");
3588 layout_toolbar_add(lw, type, "Up");
3589 layout_toolbar_add(lw, type, "Home");
3590 layout_toolbar_add(lw, type, "Refresh");
3591 layout_toolbar_add(lw, type, "ZoomIn");
3592 layout_toolbar_add(lw, type, "ZoomOut");
3593 layout_toolbar_add(lw, type, "ZoomFit");
3594 layout_toolbar_add(lw, type, "Zoom100");
3595 layout_toolbar_add(lw, type, "Preferences");
3596 layout_toolbar_add(lw, type, "FloatTools");
3601 layout_toolbar_add(lw, type, "Thumbnails");
3602 layout_toolbar_add(lw, type, "Back");
3603 layout_toolbar_add(lw, type, "Forward");
3604 layout_toolbar_add(lw, type, "Up");
3605 layout_toolbar_add(lw, type, "Home");
3606 layout_toolbar_add(lw, type, "Refresh");
3607 layout_toolbar_add(lw, type, "ZoomIn");
3608 layout_toolbar_add(lw, type, "ZoomOut");
3609 layout_toolbar_add(lw, type, "ZoomFit");
3610 layout_toolbar_add(lw, type, "Zoom100");
3611 layout_toolbar_add(lw, type, "Preferences");
3612 layout_toolbar_add(lw, type, "FloatTools");
3615 case TOOLBAR_STATUS:
3616 if (layout_window_list)
3618 lw_first = static_cast<LayoutWindow *>(layout_window_list->data);
3619 if (lw_first->toolbar_actions[TOOLBAR_MAIN])
3621 work_action = lw_first->toolbar_actions[type];
3624 auto action = static_cast<gchar *>(work_action->data);
3625 work_action = work_action->next;
3626 layout_toolbar_add(lw, type, action);
3631 layout_toolbar_add(lw, type, "ExifRotate");
3632 layout_toolbar_add(lw, type, "ShowInfoPixel");
3633 layout_toolbar_add(lw, type, "UseColorProfiles");
3634 layout_toolbar_add(lw, type, "SaveMetadata");
3639 layout_toolbar_add(lw, type, "ExifRotate");
3640 layout_toolbar_add(lw, type, "ShowInfoPixel");
3641 layout_toolbar_add(lw, type, "UseColorProfiles");
3642 layout_toolbar_add(lw, type, "SaveMetadata");
3652 void layout_toolbar_write_config(LayoutWindow *lw, ToolbarType type, GString *outstr, gint indent)
3654 const gchar *name = nullptr;
3655 GList *work = lw->toolbar_actions[type];
3662 case TOOLBAR_STATUS:
3669 WRITE_NL(); WRITE_STRING("<%s>", name);
3671 WRITE_NL(); WRITE_STRING("<clear/>");
3674 auto action = static_cast<gchar *>(work->data);
3676 WRITE_NL(); WRITE_STRING("<toolitem ");
3677 write_char_option(outstr, indent + 1, "action", action);
3681 WRITE_NL(); WRITE_STRING("</%s>", name);
3684 void layout_toolbar_add_from_config(LayoutWindow *lw, ToolbarType type, const char **attribute_names, const gchar **attribute_values)
3686 gchar *action = nullptr;
3688 while (*attribute_names)
3690 const gchar *option = *attribute_names++;
3691 const gchar *value = *attribute_values++;
3693 if (READ_CHAR_FULL("action", action)) continue;
3695 log_printf("unknown attribute %s = %s\n", option, value);
3698 layout_toolbar_add(lw, type, action);
3703 *-----------------------------------------------------------------------------
3705 *-----------------------------------------------------------------------------
3708 void layout_util_status_update_write(LayoutWindow *lw)
3711 gint n = metadata_queue_length();
3712 action = gtk_action_group_get_action(lw->action_group, "SaveMetadata");
3713 gtk_action_set_sensitive(action, n > 0);
3716 gchar *buf = g_strdup_printf(_("Number of files with unsaved metadata: %d"), n);
3717 g_object_set(G_OBJECT(action), "tooltip", buf, NULL);
3722 g_object_set(G_OBJECT(action), "tooltip", _("No unsaved metadata"), NULL);
3726 void layout_util_status_update_write_all()
3730 work = layout_window_list;
3733 auto lw = static_cast<LayoutWindow *>(work->data);
3736 layout_util_status_update_write(lw);
3740 static gchar *layout_color_name_parse(const gchar *name)
3742 if (!name || !*name) return g_strdup(_("Empty"));
3743 return g_strdelimit(g_strdup(name), "_", '-');
3746 void layout_util_sync_color(LayoutWindow *lw)
3751 gboolean use_image = FALSE;
3753 gchar action_name[15];
3755 gchar *image_profile;
3756 gchar *screen_profile;
3759 if (!lw->action_group) return;
3760 if (!layout_image_color_profile_get(lw, &input, &use_image)) return;
3762 use_color = layout_image_color_profile_get_use(lw);
3764 action = gtk_action_group_get_action(lw->action_group, "UseColorProfiles");
3766 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), use_color);
3767 if (layout_image_color_profile_get_status(lw, &image_profile, &screen_profile))
3770 buf = g_strdup_printf(_("Image profile: %s\nScreen profile: %s"), image_profile, screen_profile);
3771 g_object_set(G_OBJECT(action), "tooltip", buf, NULL);
3772 g_free(image_profile);
3773 g_free(screen_profile);
3778 g_object_set(G_OBJECT(action), "tooltip", _("Click to enable color management"), NULL);
3781 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), FALSE);
3782 gtk_action_set_sensitive(action, FALSE);
3783 g_object_set(G_OBJECT(action), "tooltip", _("Color profiles not supported"), NULL);
3786 action = gtk_action_group_get_action(lw->action_group, "UseImageProfile");
3787 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), use_image);
3788 gtk_action_set_sensitive(action, use_color);
3790 for (i = 0; i < COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS; i++)
3792 sprintf(action_name, "ColorProfile%d", i);
3793 action = gtk_action_group_get_action(lw->action_group, action_name);
3795 if (i >= COLOR_PROFILE_FILE)
3797 const gchar *name = options->color_profile.input_name[i - COLOR_PROFILE_FILE];
3798 const gchar *file = options->color_profile.input_file[i - COLOR_PROFILE_FILE];
3802 if (!name || !name[0]) name = filename_from_path(file);
3804 end = layout_color_name_parse(name);
3805 buf = g_strdup_printf(_("Input _%d: %s"), i, end);
3808 g_object_set(G_OBJECT(action), "label", buf, NULL);
3811 gtk_action_set_visible(action, file && file[0]);
3814 gtk_action_set_sensitive(action, !use_image);
3815 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), (i == input));
3818 action = gtk_action_group_get_action(lw->action_group, "Grayscale");
3819 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_image_get_desaturate(lw));
3822 void layout_util_sync_file_filter(LayoutWindow *lw)
3826 if (!lw->action_group) return;
3828 action = gtk_action_group_get_action(lw->action_group, "ShowFileFilter");
3829 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_file_filter);
3832 void layout_util_sync_marks(LayoutWindow *lw)
3836 if (!lw->action_group) return;
3838 action = gtk_action_group_get_action(lw->action_group, "ShowMarks");
3839 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_marks);
3842 static void layout_util_sync_views(LayoutWindow *lw)
3845 OsdShowFlags osd_flags = image_osd_get(lw->image);
3847 if (!lw->action_group) return;
3849 action = gtk_action_group_get_action(lw->action_group, "FolderTree");
3850 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.dir_view_type);
3852 action = gtk_action_group_get_action(lw->action_group, "SplitSingle");
3853 gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->split_mode);
3855 action = gtk_action_group_get_action(lw->action_group, "SplitNextPane");
3856 gtk_action_set_sensitive(action, !(lw->split_mode == SPLIT_NONE));
3857 action = gtk_action_group_get_action(lw->action_group, "SplitPreviousPane");
3858 gtk_action_set_sensitive(action, !(lw->split_mode == SPLIT_NONE));
3859 action = gtk_action_group_get_action(lw->action_group, "SplitUpPane");
3860 gtk_action_set_sensitive(action, !(lw->split_mode == SPLIT_NONE));
3861 action = gtk_action_group_get_action(lw->action_group, "SplitDownPane");
3862 gtk_action_set_sensitive(action, !(lw->split_mode == SPLIT_NONE));
3864 action = gtk_action_group_get_action(lw->action_group, "SplitPaneSync");
3865 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.split_pane_sync);
3867 action = gtk_action_group_get_action(lw->action_group, "ViewIcons");
3868 gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->options.file_view_type);
3870 action = gtk_action_group_get_action(lw->action_group, "FloatTools");
3871 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.tools_float);
3873 action = gtk_action_group_get_action(lw->action_group, "SBar");
3874 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_enabled(lw));
3876 action = gtk_action_group_get_action(lw->action_group, "SBarSort");
3877 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_sort_enabled(lw));
3879 action = gtk_action_group_get_action(lw->action_group, "HideSelectableToolbars");
3880 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.selectable_toolbars_hidden);
3882 action = gtk_action_group_get_action(lw->action_group, "ShowInfoPixel");
3883 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_info_pixel);
3885 action = gtk_action_group_get_action(lw->action_group, "SlideShow");
3886 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_image_slideshow_active(lw));
3888 action = gtk_action_group_get_action(lw->action_group, "IgnoreAlpha");
3889 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.ignore_alpha);
3891 action = gtk_action_group_get_action(lw->action_group, "Animate");
3892 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.animate);
3894 action = gtk_action_group_get_action(lw->action_group, "ImageOverlay");
3895 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), osd_flags != OSD_SHOW_NOTHING);
3897 action = gtk_action_group_get_action(lw->action_group, "ImageHistogram");
3898 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), osd_flags & OSD_SHOW_HISTOGRAM);
3900 action = gtk_action_group_get_action(lw->action_group, "ExifRotate");
3901 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), options->image.exif_rotate_enable);
3903 action = gtk_action_group_get_action(lw->action_group, "OverUnderExposed");
3904 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), options->overunderexposed);
3906 action = gtk_action_group_get_action(lw->action_group, "DrawRectangle");
3907 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), options->draw_rectangle);
3909 action = gtk_action_group_get_action(lw->action_group, "RectangularSelection");
3910 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), options->collections.rectangular_selection);
3912 action = gtk_action_group_get_action(lw->action_group, "ShowFileFilter");
3913 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_file_filter);
3915 action = gtk_action_group_get_action(lw->action_group, "HideBars");
3916 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), (lw->options.bars_state.hidden));
3918 if (osd_flags & OSD_SHOW_HISTOGRAM)
3920 action = gtk_action_group_get_action(lw->action_group, "HistogramChanR");
3921 gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), image_osd_histogram_get_channel(lw->image));
3923 action = gtk_action_group_get_action(lw->action_group, "HistogramModeLin");
3924 gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), image_osd_histogram_get_mode(lw->image));
3927 action = gtk_action_group_get_action(lw->action_group, "ConnectZoomMenu");
3928 gtk_action_set_sensitive(action, lw->split_mode != SPLIT_NONE);
3930 // @todo `which` is deprecated, use command -v
3931 gboolean is_write_rotation = !runcmd("which exiftran >/dev/null 2>&1")
3932 && !runcmd("which mogrify >/dev/null 2>&1")
3933 && !options->metadata.write_orientation;
3934 action = gtk_action_group_get_action(lw->action_group, "WriteRotation");
3935 gtk_action_set_sensitive(action, is_write_rotation);
3936 action = gtk_action_group_get_action(lw->action_group, "WriteRotationKeepDate");
3937 gtk_action_set_sensitive(action, is_write_rotation);
3939 action = gtk_action_group_get_action(lw->action_group, "StereoAuto");
3940 gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), layout_image_stereo_pixbuf_get(lw));
3942 layout_util_sync_marks(lw);
3943 layout_util_sync_color(lw);
3944 layout_image_set_ignore_alpha(lw, lw->options.ignore_alpha);
3947 void layout_util_sync_thumb(LayoutWindow *lw)
3951 if (!lw->action_group) return;
3953 action = gtk_action_group_get_action(lw->action_group, "Thumbnails");
3954 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_thumbnails);
3955 g_object_set(action, "sensitive", (lw->options.file_view_type == FILEVIEW_LIST), NULL);
3958 void layout_util_sync(LayoutWindow *lw)
3960 layout_util_sync_views(lw);
3961 layout_util_sync_thumb(lw);
3962 layout_menu_collection_recent_update(lw);
3963 layout_menu_collection_open_update(lw);
3967 * @brief Checks if event key is mapped to Help
3971 * Used to check if the user has re-mapped the Help key
3972 * in Preferences/Keyboard
3974 * Note: help_key.accel_mods and event->state
3975 * differ in the higher bits
3977 gboolean is_help_key(GdkEventKey *event)
3979 GtkAccelKey help_key;
3980 gboolean ret = FALSE;
3981 guint mask = GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK;
3983 if (gtk_accel_map_lookup_entry("<Actions>/MenuActions/HelpContents", &help_key))
3985 if (help_key.accel_key == event->keyval &&
3986 (help_key.accel_mods & mask) == (event->state & mask))
3996 *-----------------------------------------------------------------------------
3998 *-----------------------------------------------------------------------------
4001 static gboolean layout_bar_enabled(LayoutWindow *lw)
4003 return lw->bar && gtk_widget_get_visible(lw->bar);
4006 static void layout_bar_destroyed(GtkWidget *, gpointer data)
4008 auto lw = static_cast<LayoutWindow *>(data);
4012 do not call layout_util_sync_views(lw) here
4013 this is called either when whole layout is destroyed - no need for update
4014 or when the bar is replaced - sync is called by upper function at the end of whole operation
4019 static void layout_bar_set_default(LayoutWindow *lw)
4023 if (!lw->utility_box) return;
4028 layout_bar_set(lw, bar);
4030 bar_populate_default(bar);
4033 static void layout_bar_close(LayoutWindow *lw)
4043 void layout_bar_set(LayoutWindow *lw, GtkWidget *bar)
4045 if (!lw->utility_box) return;
4047 layout_bar_close(lw); /* if any */
4052 g_signal_connect(G_OBJECT(lw->bar), "destroy",
4053 G_CALLBACK(layout_bar_destroyed), lw);
4055 gtk_paned_pack2(GTK_PANED(lw->utility_paned), lw->bar, FALSE, TRUE);
4057 bar_set_fd(lw->bar, layout_image_get_fd(lw));
4061 void layout_bar_toggle(LayoutWindow *lw)
4063 if (layout_bar_enabled(lw))
4065 gtk_widget_hide(lw->bar);
4071 layout_bar_set_default(lw);
4073 gtk_widget_show(lw->bar);
4074 bar_set_fd(lw->bar, layout_image_get_fd(lw));
4076 layout_util_sync_views(lw);
4079 static void layout_bar_new_image(LayoutWindow *lw)
4081 if (!layout_bar_enabled(lw)) return;
4083 bar_set_fd(lw->bar, layout_image_get_fd(lw));
4086 static void layout_bar_new_selection(LayoutWindow *lw, gint count)
4088 if (!layout_bar_enabled(lw)) return;
4090 bar_notify_selection(lw->bar, count);
4093 static gboolean layout_bar_sort_enabled(LayoutWindow *lw)
4095 return lw->bar_sort && gtk_widget_get_visible(lw->bar_sort);
4099 static void layout_bar_sort_destroyed(GtkWidget *, gpointer data)
4101 auto lw = static_cast<LayoutWindow *>(data);
4103 lw->bar_sort = nullptr;
4106 do not call layout_util_sync_views(lw) here
4107 this is called either when whole layout is destroyed - no need for update
4108 or when the bar is replaced - sync is called by upper function at the end of whole operation
4113 static void layout_bar_sort_set_default(LayoutWindow *lw)
4117 if (!lw->utility_box) return;
4119 bar = bar_sort_new_default(lw);
4121 layout_bar_sort_set(lw, bar);
4124 static void layout_bar_sort_close(LayoutWindow *lw)
4128 bar_sort_close(lw->bar_sort);
4129 lw->bar_sort = nullptr;
4133 void layout_bar_sort_set(LayoutWindow *lw, GtkWidget *bar)
4135 if (!lw->utility_box) return;
4137 layout_bar_sort_close(lw); /* if any */
4142 g_signal_connect(G_OBJECT(lw->bar_sort), "destroy",
4143 G_CALLBACK(layout_bar_sort_destroyed), lw);
4145 gq_gtk_box_pack_end(GTK_BOX(lw->utility_box), lw->bar_sort, FALSE, FALSE, 0);
4148 void layout_bar_sort_toggle(LayoutWindow *lw)
4150 if (layout_bar_sort_enabled(lw))
4152 gtk_widget_hide(lw->bar_sort);
4158 layout_bar_sort_set_default(lw);
4160 gtk_widget_show(lw->bar_sort);
4162 layout_util_sync_views(lw);
4165 static void layout_bars_hide_toggle(LayoutWindow *lw)
4167 if (lw->options.bars_state.hidden)
4169 lw->options.bars_state.hidden = FALSE;
4170 if (lw->options.bars_state.sort)
4174 gtk_widget_show(lw->bar_sort);
4178 layout_bar_sort_set_default(lw);
4181 if (lw->options.bars_state.info)
4183 gtk_widget_show(lw->bar);
4185 layout_tools_float_set(lw, lw->options.tools_float,
4186 lw->options.bars_state.tools_hidden);
4190 lw->options.bars_state.hidden = TRUE;
4191 lw->options.bars_state.sort = layout_bar_sort_enabled(lw);
4192 lw->options.bars_state.info = layout_bar_enabled(lw);
4193 lw->options.bars_state.tools_float = lw->options.tools_float;
4194 lw->options.bars_state.tools_hidden = lw->options.tools_hidden;
4198 gtk_widget_hide(lw->bar);
4202 gtk_widget_hide(lw->bar_sort);
4203 layout_tools_float_set(lw, lw->options.tools_float, TRUE);
4206 layout_util_sync_views(lw);
4209 void layout_bars_new_image(LayoutWindow *lw)
4211 layout_bar_new_image(lw);
4213 if (lw->exif_window) advanced_exif_set_fd(lw->exif_window, layout_image_get_fd(lw));
4215 /* this should be called here to handle the metadata edited in bars */
4216 if (options->metadata.confirm_on_image_change)
4217 metadata_write_queue_confirm(FALSE, nullptr, nullptr);
4220 void layout_bars_new_selection(LayoutWindow *lw, gint count)
4222 layout_bar_new_selection(lw, count);
4225 GtkWidget *layout_bars_prepare(LayoutWindow *lw, GtkWidget *image)
4227 if (lw->utility_box) return lw->utility_box;
4228 lw->utility_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP);
4229 lw->utility_paned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
4230 DEBUG_NAME(lw->utility_paned);
4231 gq_gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->utility_paned, TRUE, TRUE, 0);
4233 gtk_paned_pack1(GTK_PANED(lw->utility_paned), image, TRUE, FALSE);
4234 gtk_widget_show(lw->utility_paned);
4236 gtk_widget_show(image);
4238 g_object_ref(lw->utility_box);
4239 return lw->utility_box;
4242 void layout_bars_close(LayoutWindow *lw)
4244 layout_bar_sort_close(lw);
4245 layout_bar_close(lw);
4248 static gboolean layout_exif_window_destroy(GtkWidget *, gpointer data)
4250 auto lw = static_cast<LayoutWindow *>(data);
4251 lw->exif_window = nullptr;
4256 void layout_exif_window_new(LayoutWindow *lw)
4258 if (lw->exif_window) return;
4260 lw->exif_window = advanced_exif_new(lw);
4261 if (!lw->exif_window) return;
4262 g_signal_connect(G_OBJECT(lw->exif_window), "destroy",
4263 G_CALLBACK(layout_exif_window_destroy), lw);
4264 advanced_exif_set_fd(lw->exif_window, layout_image_get_fd(lw));
4267 static void layout_search_and_run_window_new(LayoutWindow *lw)
4271 gtk_window_present(GTK_WINDOW(lw->sar_window));
4275 lw->sar_window = search_and_run_new(lw);
4278 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */