Browse Source

Change discard changes dialog to save changes dialog

Based on other applications: in case of unsaved changes, ask to 'discard',
'save' or 'cancel' the action.
Martijn Buijs 7 years ago
parent
commit
0a69964a84
1 changed files with 16 additions and 6 deletions
  1. 16 6
      labelme/app.py

+ 16 - 6
labelme/app.py

@@ -965,12 +965,22 @@ class MainWindow(QMainWindow, WindowMixin):
         return True
 
     def mayContinue(self):
-        return not (self.dirty and not self.discardChangesDialog())
-
-    def discardChangesDialog(self):
-        yes, no = QMessageBox.Yes, QMessageBox.No
-        msg = 'You have unsaved changes, proceed anyway?'
-        return yes == QMessageBox.warning(self, 'Attention', msg, yes|no)
+        if not self.dirty:
+            return True
+        mb = QMessageBox
+        msg = 'Save annotations to "{}" before closing?'.format(self.filename)
+        answer = mb.question(self,
+                             'Save annotations?',
+                             msg,
+                             mb.Save | mb.Discard | mb.Cancel,
+                             mb.Save)
+        if answer == mb.Discard:
+            return True
+        elif answer == mb.Save:
+            self.saveFile()
+            return True
+        else: # answer == mb.Cancel
+            return False
 
     def errorMessage(self, title, message):
         return QMessageBox.critical(self, title,