[pybliographer] Add Cancel button to the confirm dialog



commit f7a0709d08ff97a76e13ec6322b577c7e730ff9f
Author: Zoltan Kota <zoltank gmail com>
Date:   Fri Mar 7 23:59:22 2014 +0100

    Add Cancel button to the confirm dialog
    
    Once upon a time... the confirm method for closing modified
    documents was changed. Closing the window one could only
    close with or without saving. Now it's possible to cancel
    the operation and recheck the document.

 Pyblio/GnomeUI/Document.py      |   10 +++++++---
 Pyblio/GnomeUI/Pybliographic.py |    8 ++++----
 Pyblio/GnomeUI/Utils.py         |   14 ++++++++++++--
 3 files changed, 23 insertions(+), 9 deletions(-)
---
diff --git a/Pyblio/GnomeUI/Document.py b/Pyblio/GnomeUI/Document.py
index 0e8a6a5..3c1404b 100644
--- a/Pyblio/GnomeUI/Document.py
+++ b/Pyblio/GnomeUI/Document.py
@@ -466,9 +466,13 @@ class Document (Connector.Publisher):
                                       self.w).answer ()
       
            else:
-               if Utils.Callback (_("The database has been modified.\nSave changes?"),
-                                  self.w).answer () and self.modification_check ():
-                   self.save_document ()
+               answer = Utils.Callback (_("The database has been modified.\nSave changes?"),
+                                        self.w, cancel_add = True).answer ()
+                if answer == 2:
+                    return False
+                elif answer and self.modification_check ():
+                    self.save_document ()
+                    return True
                else:
                    return True
        return 1
diff --git a/Pyblio/GnomeUI/Pybliographic.py b/Pyblio/GnomeUI/Pybliographic.py
index 82035a3..89286d7 100644
--- a/Pyblio/GnomeUI/Pybliographic.py
+++ b/Pyblio/GnomeUI/Pybliographic.py
@@ -103,14 +103,14 @@ class Pybliographic:
     
     def close_document (self, document, maybe_exit = False):
         ''' close one specified document '''
-        
-        if not document.close_document_request ():
-            return
 
         if len (self.documents) == 1 and maybe_exit:
             self.exit_application (self.documents [0])
             return
-        
+
+        if not document.close_document_request ():
+            return
+
         document.w.destroy ()
         self.documents.remove (document)
         
diff --git a/Pyblio/GnomeUI/Utils.py b/Pyblio/GnomeUI/Utils.py
index e293c2a..e2d745e 100644
--- a/Pyblio/GnomeUI/Utils.py
+++ b/Pyblio/GnomeUI/Utils.py
@@ -37,7 +37,7 @@ class Callback:
     ''' This class provides a simple requested that asks the user a
     queation and waits for an answer. '''
     
-    def __init__ (self, question, parent = None):
+    def __init__ (self, question, parent = None, cancel_add = False):
 
         self.dialog = \
                     gtk.MessageDialog (parent,
@@ -46,10 +46,20 @@ class Callback:
                                        gtk.MESSAGE_QUESTION,
                                        gtk.BUTTONS_YES_NO,
                                        question)
+        if cancel_add:
+            self.dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
+
         return
 
     def answer (self):
-        res = self.dialog.run () == gtk.RESPONSE_YES
+        res = self.dialog.run ()
+        if res == gtk.RESPONSE_YES:
+            res = True
+        elif res == gtk.RESPONSE_NO:
+            res = False
+        else:
+            res = 2
+
         self.dialog.destroy ()
         return res
 


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