[nemiver] Adding a popup when quitting nemiver. (Closes: #553217)



commit 5748ddcf00a0c20b758b0402a0e62eea4344dd4e
Author: Seemanta Dutta <seemanta gmail com>
Date:   Sun May 23 09:39:39 2010 +0200

    Adding a popup when quitting nemiver. (Closes: #553217)
    
    	* src/persp/dbgperspective/nmv-dbg-perspective.h
    	(DBGPerspective::agree_to_shutdown): Declare
    	new fn.
    	* src/persp/dbgperspective/nmv-dbg-perspective.cc
    	(DBGPerspective::agree_to_shutdown): Define new fn.
    	* src/persp/nmv-i-perspective.h (IPerspective::agree_to_shutdown):
    	New function declaration.
    	* src/workbench/nmv-workbench.cc
    	(Workbench::query_for_shutdown): New function.
    	(Workbench::on_delete_event): Call it.
    	(Workbench::on_quit_menu_item_action): Likewise.

 src/persp/dbgperspective/nmv-dbg-perspective.cc |   21 +++++++++++++++
 src/persp/dbgperspective/nmv-dbg-perspective.h  |    2 +
 src/persp/nmv-i-perspective.h                   |   11 ++++++++
 src/workbench/nmv-workbench.cc                  |   32 ++++++++++++++++++++---
 4 files changed, 62 insertions(+), 4 deletions(-)
---
diff --git a/src/persp/dbgperspective/nmv-dbg-perspective.cc b/src/persp/dbgperspective/nmv-dbg-perspective.cc
index 5841f19..a0b36a7 100644
--- a/src/persp/dbgperspective/nmv-dbg-perspective.cc
+++ b/src/persp/dbgperspective/nmv-dbg-perspective.cc
@@ -705,6 +705,8 @@ public:
     bool do_unmonitor_file (const UString &a_path);
 
     void activate_status_view(Gtk::Widget& page);
+ 
+    bool agree_to_shutdown ();
 
     sigc::signal<void, bool>& show_command_view_signal ();
     sigc::signal<void, bool>& show_target_output_view_signal ();
@@ -7239,6 +7241,25 @@ DBGPerspective::show_log_view_signal ()
     return m_priv->show_log_view_signal;
 }
 
+bool
+DBGPerspective::agree_to_shutdown ()
+{
+    LOG_FUNCTION_SCOPE_NORMAL_DD;
+    if (debugger ()->is_attached_to_target ()) {
+	UString message;
+        message.printf (_("There is a program being currently debugged. "
+                          "Do you really want to exit from the debugger?"));
+        if (nemiver::ui_utils::ask_yes_no_question (message) ==
+            Gtk::RESPONSE_YES) {
+            return true;
+        } else {
+            return false;
+        }
+    } else {
+        return true;
+    }
+}
+
 class DBGPerspectiveModule : DynamicModule {
 
 public:
diff --git a/src/persp/dbgperspective/nmv-dbg-perspective.h b/src/persp/dbgperspective/nmv-dbg-perspective.h
index 4d1db34..4d51f1a 100644
--- a/src/persp/dbgperspective/nmv-dbg-perspective.h
+++ b/src/persp/dbgperspective/nmv-dbg-perspective.h
@@ -167,6 +167,8 @@ public:
     virtual sigc::signal<void, bool>& activated_signal () = 0;
 
     virtual sigc::signal<void, bool>& debugger_ready_signal () = 0;
+
+    virtual bool agree_to_shutdown () = 0;
 };//end class IDBGPerspective
 
 NEMIVER_END_NAMESPACE (nemiver)
diff --git a/src/persp/nmv-i-perspective.h b/src/persp/nmv-i-perspective.h
index fad359d..b8ca7f0 100644
--- a/src/persp/nmv-i-perspective.h
+++ b/src/persp/nmv-i-perspective.h
@@ -121,6 +121,17 @@ public:
     virtual Gtk::Widget* load_menu (const UString &a_filename,
                                     const UString &a_widget_name) = 0;
 
+    /// \brief Should return true to allow shutdown.
+    /// This Method will be called for each perspective before 
+    /// workbench initiates a shutdown (). This is a chance given to
+    /// the perspective to veto the shutdown (). Each perspective has
+    /// to implement this function wherein it can decide for itself
+    /// whether it wants to veto the shutdown or not. Returning 'true'
+    /// from here means that the perspective is ok with the shutdown
+    /// returning 'false' vetoes the shutdown and nemiver does not go
+    /// down.
+    virtual bool agree_to_shutdown () = 0;
+
     /// \name signals
 
     /// @{
diff --git a/src/workbench/nmv-workbench.cc b/src/workbench/nmv-workbench.cc
index 31f68bd..a0a7c5b 100644
--- a/src/workbench/nmv-workbench.cc
+++ b/src/workbench/nmv-workbench.cc
@@ -132,6 +132,7 @@ private:
         WorkbenchStaticInit::do_init ();
     }
     bool on_delete_event (GdkEventAny* event);
+    bool query_for_shutdown ();
 
 public:
     Workbench (DynamicModule *a_dynmod);
@@ -189,6 +190,22 @@ struct Workbench::Priv {
 //****************
 //private methods
 //****************
+bool
+Workbench::query_for_shutdown ()
+{
+    bool retval = true;
+    list<IPerspectiveSafePtr>::const_iterator iter;
+    for (iter = m_priv->perspectives.begin ();
+         iter != m_priv->perspectives.end ();
+         ++iter) {
+         if ((*iter)->agree_to_shutdown () == false) {
+             retval = false;
+             break;
+         }
+    }
+    return retval;
+}
+
 
 //*********************
 //signal slots methods
@@ -197,6 +214,7 @@ bool
 Workbench::on_delete_event (GdkEventAny* a_event)
 {
     LOG_FUNCTION_SCOPE_NORMAL_DD;
+    bool retval = true;
 
     NEMIVER_TRY
     // use event so that compilation doesn't fail with -Werror :(
@@ -204,11 +222,15 @@ Workbench::on_delete_event (GdkEventAny* a_event)
 
     // clicking the window manager's X and shutting down the with Quit menu item
     // should do the same thing
-    on_quit_menu_item_action ();
+    if (query_for_shutdown () == true) {
+        shut_down ();
+        retval = false;
+    }
+
     NEMIVER_CATCH
 
-    //keep propagating
-    return false;
+    //Will propagate if retval = false, else not
+    return retval;
 }
 
 void
@@ -218,7 +240,9 @@ Workbench::on_quit_menu_item_action ()
 
     NEMIVER_TRY
 
-    shut_down ();
+    if (query_for_shutdown () == true) {
+        shut_down ();
+    }
 
     NEMIVER_CATCH
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]