From 4c12e49b899dfa2067d84b2466502e45c34787de Mon Sep 17 00:00:00 2001
From: Ethan Trewhitt <ethan@trewhitt.org>
Date: Tue, 17 Feb 2015 16:11:45 -0500
Subject: grc: Reworked save confirmation dialog to allow cancel option

---
 grc/gui/MainWindow.py | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

(limited to 'grc/gui/MainWindow.py')

diff --git a/grc/gui/MainWindow.py b/grc/gui/MainWindow.py
index d1cf866ce7..f26f30ea78 100644
--- a/grc/gui/MainWindow.py
+++ b/grc/gui/MainWindow.py
@@ -236,10 +236,15 @@ class MainWindow(gtk.Window):
         if self.page_to_be_closed.get_proc() or not self.page_to_be_closed.get_saved():
             self._set_page(self.page_to_be_closed)
         #unsaved? ask the user
-        if not self.page_to_be_closed.get_saved() and self._save_changes():
-            Actions.FLOW_GRAPH_SAVE() #try to save
-            if not self.page_to_be_closed.get_saved(): #still unsaved?
-                self.page_to_be_closed = None #set the page to be closed back to None
+        if not self.page_to_be_closed.get_saved():
+            response = self._save_changes() # return value is either OK, CLOSE, or CANCEL
+            if response == gtk.RESPONSE_OK:
+                Actions.FLOW_GRAPH_SAVE() #try to save
+                if not self.page_to_be_closed.get_saved(): #still unsaved?
+                    self.page_to_be_closed = None #set the page to be closed back to None
+                    return
+            elif response == gtk.RESPONSE_CANCEL:
+                self.page_to_be_closed = None
                 return
         #stop the flow graph if executing
         if self.page_to_be_closed.get_proc(): Actions.FLOW_GRAPH_KILL()
@@ -337,12 +342,17 @@ class MainWindow(gtk.Window):
         Save changes to flow graph?
 
         Returns:
-            true if yes
+            the response_id (see buttons variable below)
         """
+        buttons = (
+            'Close without saving', gtk.RESPONSE_CLOSE,
+            gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
+            gtk.STOCK_SAVE, gtk.RESPONSE_OK
+        )
         return MessageDialogHelper(
-            gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, 'Unsaved Changes!',
-            'Would you like to save changes before closing?'
-        ) == gtk.RESPONSE_YES
+            gtk.MESSAGE_QUESTION, gtk.BUTTONS_NONE, 'Unsaved Changes!',
+            'Would you like to save changes before closing?', buttons
+        )
 
     def _get_files(self):
         """
-- 
cgit v1.2.3