changeset 367:898d503db27b

- Added a confirmation dialog for closing with Windows/Tabs > 1
author jcid
date Tue, 30 Sep 2008 16:19:42 +0200
parents 01ae350c7f7d
children 2242da885677
files src/bw.c src/bw.h src/uicmd.cc
diffstat 3 files changed, 33 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/bw.c	Tue Sep 30 16:06:54 2008 +0200
+++ b/src/bw.c	Tue Sep 30 16:19:42 2008 +0200
@@ -258,6 +258,11 @@
 
 /*--------------------------------------------------------------------------*/
 
+int a_Bw_num()
+{
+   return num_bws;
+}
+
 /*
  * TODO: remove this Hack.
  */
--- a/src/bw.h	Tue Sep 30 16:06:54 2008 +0200
+++ b/src/bw.h	Tue Sep 30 16:19:42 2008 +0200
@@ -76,6 +76,7 @@
 BrowserWindow *a_Bw_new();
 void a_Bw_free(BrowserWindow *bw);
 BrowserWindow *a_Bw_get();
+int a_Bw_num();
 
 void a_Bw_add_client(BrowserWindow *bw, int Key, int Root);
 int a_Bw_remove_client(BrowserWindow *bw, int ClientKey);
--- a/src/uicmd.cc	Tue Sep 30 16:06:54 2008 +0200
+++ b/src/uicmd.cc	Tue Sep 30 16:19:42 2008 +0200
@@ -34,7 +34,7 @@
 #include "nav.h"
 
 // Handy macro
-#define BW2UI(bw) ((UI*)(bw->ui))
+#define BW2UI(bw) ((UI*)((bw)->ui))
 
 // Platform idependent part
 using namespace dw::core;
@@ -109,6 +109,24 @@
    }
 };
 
+static void win_cb (fltk::Widget *w, void *cb_data) {
+   CustTabGroup *tabs;
+   int choice = 0;
+
+   if (cb_data == NULL) {
+      w->hide ();
+   } else {
+      // It is assumed that user_data() of a window contains a pointer
+      // to the current BrowserWindow.
+      tabs = BW2UI((BrowserWindow*) cb_data)->tabs();
+      if (tabs->children () > 1)
+         choice = a_Dialog_choice3 ("Window contains more than one tab.",
+            "Close all tabs", "Cancel", NULL);
+      if (choice == 0)
+         for (int i = tabs->children() - 1; i >= 0; i--)
+            a_UIcmd_close_bw(((UI*)tabs->child(i))->vbw());
+   }
+}
 
 /*
  * Create a new UI and its associated BrowserWindow data structure.
@@ -132,6 +150,7 @@
    CustTabGroup *DilloTabs = new CustTabGroup(0, 0, ww, wh);
    DilloTabs->selection_color(156);
    win->add(DilloTabs);
+   win->callback(win_cb, (void*) NULL);
 
    // Create and set the UI
    UI *new_ui = new UI(0, 0, ww, wh, "Label", old_bw ? BW2UI(old_bw) : NULL);
@@ -254,9 +273,14 @@
 void a_UIcmd_close_all_bw()
 {
    BrowserWindow *bw;
+   int choice = 0;
 
-   while ((bw = a_Bw_get()))
-      a_UIcmd_close_bw((void*)bw);
+   if (a_Bw_num() > 1)
+      choice = a_Dialog_choice3 ("More than one open tab or Window.",
+         "Close all tabs and windows", "Cancel", NULL);
+   if (choice == 0)
+      while ((bw = a_Bw_get()))
+         a_UIcmd_close_bw((void*)bw);
 }
 
 /*