summaryrefslogtreecommitdiff
path: root/grc/gui
diff options
context:
space:
mode:
authorEthan Trewhitt <ethan@trewhitt.org>2015-02-17 16:11:45 -0500
committerSebastian Koslowski <koslowski@kit.edu>2015-04-02 09:09:59 +0200
commit4c12e49b899dfa2067d84b2466502e45c34787de (patch)
treec30f036827c5d577ea622f4e580e7394b1b2371e /grc/gui
parent7fe6115297c9d5d1d9220dc23bab96aa88b2b72d (diff)
grc: Reworked save confirmation dialog to allow cancel option
Diffstat (limited to 'grc/gui')
-rw-r--r--grc/gui/Dialogs.py6
-rw-r--r--grc/gui/MainWindow.py26
2 files changed, 22 insertions, 10 deletions
diff --git a/grc/gui/Dialogs.py b/grc/gui/Dialogs.py
index eb0a6c11b0..cf0ca02969 100644
--- a/grc/gui/Dialogs.py
+++ b/grc/gui/Dialogs.py
@@ -116,7 +116,7 @@ class TextDisplay(gtk.TextView):
menu.show_all()
return False
-def MessageDialogHelper(type, buttons, title=None, markup=None):
+def MessageDialogHelper(type, buttons, title=None, markup=None, extra_buttons=None):
"""
Create a modal message dialog and run it.
@@ -126,8 +126,9 @@ def MessageDialogHelper(type, buttons, title=None, markup=None):
gtk.BUTTONS_NONE, gtk.BUTTONS_OK, gtk.BUTTONS_CLOSE, gtk.BUTTONS_CANCEL, gtk.BUTTONS_YES_NO, gtk.BUTTONS_OK_CANCEL
Args:
- tittle: the title of the window (string)
+ title: the title of the window (string)
markup: the message text with pango markup
+ extra_buttons: a tuple containing pairs of values; each value is the button's text and the button's return value
Returns:
the gtk response from run()
@@ -135,6 +136,7 @@ def MessageDialogHelper(type, buttons, title=None, markup=None):
message_dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, type, buttons)
if title: message_dialog.set_title(title)
if markup: message_dialog.set_markup(markup)
+ if extra_buttons: message_dialog.add_buttons(*extra_buttons)
response = message_dialog.run()
message_dialog.destroy()
return response
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):
"""