Project: optimized the project shutdown procedure to keep it open, if there are unsaved, non-discarded changes.

Mon, 02 Apr 2018 14:06:55 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 02 Apr 2018 14:06:55 +0200
changeset 6209
05b9989c1977
parent 6208
76445467adf8
child 6210
f5b392aac28e

Project: optimized the project shutdown procedure to keep it open, if there are unsaved, non-discarded changes.

APIs/Python3/eric6.api file | annotate | diff | comparison | revisions
Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric6.ViewManager.ViewManager.html file | annotate | diff | comparison | revisions
Project/Project.py file | annotate | diff | comparison | revisions
ViewManager/ViewManager.py file | annotate | diff | comparison | revisions
--- a/APIs/Python3/eric6.api	Mon Apr 02 13:26:53 2018 +0200
+++ b/APIs/Python3/eric6.api	Mon Apr 02 14:06:55 2018 +0200
@@ -10452,14 +10452,15 @@
 eric6.ViewManager.ViewManager.ViewManager.checkActions?7
 eric6.ViewManager.ViewManager.ViewManager.checkAllDirty?4()
 eric6.ViewManager.ViewManager.ViewManager.checkDirty?4(editor, autosave=False)
+eric6.ViewManager.ViewManager.ViewManager.checkFileDirty?4(fn)
 eric6.ViewManager.ViewManager.ViewManager.clearRecent?4()
 eric6.ViewManager.ViewManager.ViewManager.cloneEditor?4(caller, filetype, fn)
 eric6.ViewManager.ViewManager.ViewManager.closeAllWindows?4()
 eric6.ViewManager.ViewManager.ViewManager.closeCurrentWindow?4()
-eric6.ViewManager.ViewManager.ViewManager.closeEditor?4(editor)
+eric6.ViewManager.ViewManager.ViewManager.closeEditor?4(editor, ignoreDirty=False)
 eric6.ViewManager.ViewManager.ViewManager.closeEditorWindow?4(editor)
 eric6.ViewManager.ViewManager.ViewManager.closeViewManager?4()
-eric6.ViewManager.ViewManager.ViewManager.closeWindow?4(fn)
+eric6.ViewManager.ViewManager.ViewManager.closeWindow?4(fn, ignoreDirty=False)
 eric6.ViewManager.ViewManager.ViewManager.cursorChanged?7
 eric6.ViewManager.ViewManager.ViewManager.editorChanged?7
 eric6.ViewManager.ViewManager.ViewManager.editorChangedEd?7
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Mon Apr 02 13:26:53 2018 +0200
+++ b/Documentation/Help/source.qhp	Mon Apr 02 14:06:55 2018 +0200
@@ -17247,6 +17247,7 @@
       <keyword name="ViewManager.cascade" id="ViewManager.cascade" ref="eric6.ViewManager.ViewManager.html#ViewManager.cascade" />
       <keyword name="ViewManager.checkAllDirty" id="ViewManager.checkAllDirty" ref="eric6.ViewManager.ViewManager.html#ViewManager.checkAllDirty" />
       <keyword name="ViewManager.checkDirty" id="ViewManager.checkDirty" ref="eric6.ViewManager.ViewManager.html#ViewManager.checkDirty" />
+      <keyword name="ViewManager.checkFileDirty" id="ViewManager.checkFileDirty" ref="eric6.ViewManager.ViewManager.html#ViewManager.checkFileDirty" />
       <keyword name="ViewManager.clearRecent" id="ViewManager.clearRecent" ref="eric6.ViewManager.ViewManager.html#ViewManager.clearRecent" />
       <keyword name="ViewManager.cloneEditor" id="ViewManager.cloneEditor" ref="eric6.ViewManager.ViewManager.html#ViewManager.cloneEditor" />
       <keyword name="ViewManager.closeAllWindows" id="ViewManager.closeAllWindows" ref="eric6.ViewManager.ViewManager.html#ViewManager.closeAllWindows" />
--- a/Documentation/Source/eric6.ViewManager.ViewManager.html	Mon Apr 02 13:26:53 2018 +0200
+++ b/Documentation/Source/eric6.ViewManager.ViewManager.html	Mon Apr 02 14:06:55 2018 +0200
@@ -709,7 +709,10 @@
 <td>Public method to check the dirty status of all editors.</td>
 </tr><tr>
 <td><a href="#ViewManager.checkDirty">checkDirty</a></td>
-<td>Public method to check dirty status and open a message window.</td>
+<td>Public method to check the dirty status and open a message window.</td>
+</tr><tr>
+<td><a href="#ViewManager.checkFileDirty">checkFileDirty</a></td>
+<td>Public method to check the dirty status of an editor given its file name and open a message window.</td>
 </tr><tr>
 <td><a href="#ViewManager.clearRecent">clearRecent</a></td>
 <td>Public method to clear the recent files menu.</td>
@@ -2227,26 +2230,57 @@
 </p><dl>
 <dt>Returns:</dt>
 <dd>
-flag indicating successful reset of all dirty flags (boolean)
+flag indicating successful reset of all dirty flags
+</dd>
+</dl><dl>
+<dt>Return Type:</dt>
+<dd>
+bool
 </dd>
 </dl><a NAME="ViewManager.checkDirty" ID="ViewManager.checkDirty"></a>
 <h4>ViewManager.checkDirty</h4>
 <b>checkDirty</b>(<i>editor, autosave=False</i>)
 <p>
-        Public method to check dirty status and open a message window.
+        Public method to check the dirty status and open a message window.
 </p><dl>
-<dt><i>editor</i></dt>
+<dt><i>editor</i> (Editor)</dt>
 <dd>
 editor window to check
-</dd><dt><i>autosave</i></dt>
+</dd><dt><i>autosave</i> (bool)</dt>
 <dd>
 flag indicating that the file should be saved
-            automatically (boolean)
+            automatically
 </dd>
 </dl><dl>
 <dt>Returns:</dt>
 <dd>
-flag indicating successful reset of the dirty flag (boolean)
+flag indicating successful reset of the dirty flag
+</dd>
+</dl><dl>
+<dt>Return Type:</dt>
+<dd>
+bool
+</dd>
+</dl><a NAME="ViewManager.checkFileDirty" ID="ViewManager.checkFileDirty"></a>
+<h4>ViewManager.checkFileDirty</h4>
+<b>checkFileDirty</b>(<i>fn</i>)
+<p>
+        Public method to check the dirty status of an editor given its file
+        name and open a message window.
+</p><dl>
+<dt><i>fn</i> (str)</dt>
+<dd>
+file name of editor to be checked
+</dd>
+</dl><dl>
+<dt>Returns:</dt>
+<dd>
+flag indicating successful reset of the dirty flag
+</dd>
+</dl><dl>
+<dt>Return Type:</dt>
+<dd>
+bool
 </dd>
 </dl><a NAME="ViewManager.clearRecent" ID="ViewManager.clearRecent"></a>
 <h4>ViewManager.clearRecent</h4>
@@ -2292,18 +2326,26 @@
 </dd>
 </dl><a NAME="ViewManager.closeEditor" ID="ViewManager.closeEditor"></a>
 <h4>ViewManager.closeEditor</h4>
-<b>closeEditor</b>(<i>editor</i>)
+<b>closeEditor</b>(<i>editor, ignoreDirty=False</i>)
 <p>
         Public method to close an editor window.
 </p><dl>
-<dt><i>editor</i></dt>
+<dt><i>editor</i> (Editor)</dt>
 <dd>
 editor window to be closed
+</dd><dt><i>ignoreDirty</i> (bool)</dt>
+<dd>
+flag indicating to ignore the 'dirty' status
 </dd>
 </dl><dl>
 <dt>Returns:</dt>
 <dd>
-flag indicating success (boolean)
+flag indicating success
+</dd>
+</dl><dl>
+<dt>Return Type:</dt>
+<dd>
+bool
 </dd>
 </dl><a NAME="ViewManager.closeEditorWindow" ID="ViewManager.closeEditorWindow"></a>
 <h4>ViewManager.closeEditorWindow</h4>
@@ -2329,18 +2371,26 @@
 </dd>
 </dl><a NAME="ViewManager.closeWindow" ID="ViewManager.closeWindow"></a>
 <h4>ViewManager.closeWindow</h4>
-<b>closeWindow</b>(<i>fn</i>)
+<b>closeWindow</b>(<i>fn, ignoreDirty=False</i>)
 <p>
         Public method to close an arbitrary source editor.
 </p><dl>
-<dt><i>fn</i></dt>
+<dt><i>fn</i> (str)</dt>
 <dd>
-filename of editor to be closed
+file name of the editor to be closed
+</dd><dt><i>ignoreDirty</i> (bool)</dt>
+<dd>
+flag indicating to ignore the 'dirty' status
 </dd>
 </dl><dl>
 <dt>Returns:</dt>
 <dd>
-flag indicating success (boolean)
+flag indicating success
+</dd>
+</dl><dl>
+<dt>Return Type:</dt>
+<dd>
+bool
 </dd>
 </dl><a NAME="ViewManager.editorsCheckFocusInEnabled" ID="ViewManager.editorsCheckFocusInEnabled"></a>
 <h4>ViewManager.editorsCheckFocusInEnabled</h4>
--- a/Project/Project.py	Mon Apr 02 13:26:53 2018 +0200
+++ b/Project/Project.py	Mon Apr 02 14:06:55 2018 +0200
@@ -3008,13 +3008,21 @@
            not noSave:
             self.__writeDebugProperties(True)
         
-        # now save all open modified files of the project
         vm = e5App().getObject("ViewManager")
+        
+        # check dirty status of all project files first
+        for fn in vm.getOpenFilenames():
+            if self.isProjectFile(fn):
+                reset = vm.checkFileDirty(fn)
+                if not reset:
+                    # abort shutting down
+                    return False
+        
+        # close all project related editors
         success = True
         for fn in vm.getOpenFilenames():
             if self.isProjectFile(fn):
-                success &= vm.closeWindow(fn)
-        
+                success &= vm.closeWindow(fn, ignoreDirty=True)
         if not success:
             return False
         
@@ -3035,7 +3043,7 @@
             self.vcs = None
             e5App().getObject("PluginManager").deactivateVcsPlugins()
         
-        # now close all project related windows
+        # now close all project related tool windows
         self.__closeAllWindows()
         
         self.__initData()
--- 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