ViewManager/ViewManager.py

changeset 6209
05b9989c1977
parent 6118
da9e08920e7c
child 6210
f5b392aac28e
--- a/ViewManager/ViewManager.py	Mon Apr 02 13:26:53 2018 +0200
+++ b/ViewManager/ViewManager.py	Mon Apr 02 14:06:55 2018 +0200
@@ -4419,12 +4419,15 @@
 
     def checkDirty(self, editor, autosave=False):
         """
-        Public method to check dirty status and open a message window.
+        Public method to check the dirty status and open a message window.
         
         @param editor editor window to check
+        @type Editor
         @param autosave flag indicating that the file should be saved
-            automatically (boolean)
-        @return flag indicating successful reset of the dirty flag (boolean)
+            automatically
+        @type bool
+        @return flag indicating successful reset of the dirty flag
+        @rtype bool
         """
         if editor.isModified():
             fn = editor.getFileName()
@@ -4457,7 +4460,8 @@
         """
         Public method to check the dirty status of all editors.
         
-        @return flag indicating successful reset of all dirty flags (boolean)
+        @return flag indicating successful reset of all dirty flags
+        @rtype bool
         """
         for editor in self.editors:
             if not self.checkDirty(editor):
@@ -4465,15 +4469,38 @@
         
         return True
         
-    def closeEditor(self, editor):
+    def checkFileDirty(self, fn):
+        """
+        Public method to check the dirty status of an editor given its file
+        name and open a message window.
+        
+        @param fn file name of editor to be checked
+        @type str
+        @return flag indicating successful reset of the dirty flag
+        @rtype bool
+        """
+        for editor in self.editors:
+            if Utilities.samepath(fn, editor.getFileName()):
+                break
+        else:
+            return True
+        
+        res = self.checkDirty(editor)
+        return res
+        
+    def closeEditor(self, editor, ignoreDirty=False):
         """
         Public method to close an editor window.
         
         @param editor editor window to be closed
-        @return flag indicating success (boolean)
+        @type Editor
+        @param ignoreDirty flag indicating to ignore the 'dirty' status
+        @type bool
+        @return flag indicating success
+        @rtype bool
         """
         # save file if necessary
-        if not self.checkDirty(editor):
+        if not ignoreDirty and not self.checkDirty(editor):
             return False
         
         # get the filename of the editor for later use
@@ -4522,12 +4549,16 @@
         for editor in savedEditors:
             self.closeEditor(editor)
         
-    def closeWindow(self, fn):
+    def closeWindow(self, fn, ignoreDirty=False):
         """
         Public method to close an arbitrary source editor.
         
-        @param fn filename of editor to be closed
-        @return flag indicating success (boolean)
+        @param fn file name of the editor to be closed
+        @type str
+        @param ignoreDirty flag indicating to ignore the 'dirty' status
+        @type bool
+        @return flag indicating success
+        @rtype bool
         """
         for editor in self.editors:
             if Utilities.samepath(fn, editor.getFileName()):
@@ -4535,7 +4566,7 @@
         else:
             return True
         
-        res = self.closeEditor(editor)
+        res = self.closeEditor(editor, ignoreDirty=ignoreDirty)
         if res and editor == self.currentEditor:
             self.currentEditor = None
         

eric ide

mercurial