On exit additional check for multiple windows open
authorColin Clark <colin.clark@cclark.uk>
Fri, 15 Sep 2023 17:07:39 +0000 (18:07 +0100)
committerColin Clark <colin.clark@cclark.uk>
Fri, 15 Sep 2023 17:07:39 +0000 (18:07 +0100)
If there is more than one window open when quit is executed, there is a
warning dialog.

src/layout.cc
src/layout.h
src/main.cc

index 2adcb86..8ce8a19 100644 (file)
@@ -1106,6 +1106,10 @@ void layout_mark_filter_toggle(LayoutWindow *lw, gint mark)
        if (lw->vf) vf_mark_filter_toggle(lw->vf, mark);
 }
 
+guint layout_window_count()
+{
+       return g_list_length(layout_window_list);
+}
 
 /*
  *-----------------------------------------------------------------------------
index 00d0c8b..4fe1236 100644 (file)
@@ -243,5 +243,7 @@ void layout_split_change(LayoutWindow *lw, ImageSplitMode mode);
 
 void save_layout(LayoutWindow *lw);
 gchar *layout_get_unique_id();
+guint layout_window_count();
+
 #endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
index 10edaba..f1d4aa2 100644 (file)
@@ -1086,6 +1086,7 @@ static gint exit_confirm_dlg()
        GtkWidget *parent;
        LayoutWindow *lw;
        gchar *msg;
+       GString *message;
 
        if (exit_dialog)
                {
@@ -1093,7 +1094,7 @@ static gint exit_confirm_dlg()
                return TRUE;
                }
 
-       if (!collection_window_modified_exists()) return FALSE;
+       if (!collection_window_modified_exists() && (layout_window_count() == 1)) return FALSE;
 
        parent = nullptr;
        lw = nullptr;
@@ -1108,13 +1109,29 @@ static gint exit_confirm_dlg()
                                exit_confirm_cancel_cb, nullptr);
        g_free(msg);
        msg = g_strdup_printf(_("Quit %s"), GQ_APPNAME);
-       generic_dialog_add_message(exit_dialog, GQ_ICON_DIALOG_QUESTION,
-                                  msg, _("Collections have been modified. Quit anyway?"), TRUE);
+
+       message = g_string_new(NULL);
+
+       if (collection_window_modified_exists())
+               {
+               message = g_string_append(message, _("Collections have been modified.\n"));
+               }
+
+       if (layout_window_count() > 1)
+               {
+               g_string_append_printf(message, _("%d windows are open.\n\n"), layout_window_count());
+               }
+
+       message = g_string_append(message, _("Quit anyway?"));
+
+       generic_dialog_add_message(exit_dialog, GQ_ICON_DIALOG_QUESTION, msg, message->str, TRUE);
        g_free(msg);
        generic_dialog_add_button(exit_dialog, GQ_ICON_QUIT, _("Quit"), exit_confirm_exit_cb, TRUE);
 
        gtk_widget_show(exit_dialog->dialog);
 
+       g_string_free(message, TRUE);
+
        return TRUE;
 }