Refactored the Mercurial commit dialog.

Wed, 16 Nov 2016 20:03:45 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 16 Nov 2016 20:03:45 +0100
changeset 5329
ebec303b4e50
parent 5328
9c11e9285a46
child 5330
381665763704

Refactored the Mercurial commit dialog.

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.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.html file | annotate | diff | comparison | revisions
Plugins/PluginVcsMercurial.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/HgCommitDialog.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/hg.py file | annotate | diff | comparison | revisions
--- a/APIs/Python3/eric6.api	Wed Nov 16 19:12:01 2016 +0100
+++ b/APIs/Python3/eric6.api	Wed Nov 16 20:03:45 2016 +0100
@@ -4762,9 +4762,7 @@
 eric6.Plugins.VcsPlugins.vcsMercurial.HgCommandDialog.HgCommandDialog.on_commandCombo_editTextChanged?4(text)
 eric6.Plugins.VcsPlugins.vcsMercurial.HgCommandDialog.HgCommandDialog?1(argvList, ppath, parent=None)
 eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.HgCommitDialog.accepted?7
-eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.HgCommitDialog.amend?4()
-eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.HgCommitDialog.commitSubrepositories?4()
-eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.HgCommitDialog.logMessage?4()
+eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.HgCommitDialog.getCommitData?4()
 eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.HgCommitDialog.on_buttonBox_accepted?4()
 eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.HgCommitDialog.on_buttonBox_clicked?4(button)
 eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.HgCommitDialog.on_buttonBox_rejected?4()
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Wed Nov 16 19:12:01 2016 +0100
+++ b/Documentation/Help/source.qhp	Wed Nov 16 20:03:45 2016 +0100
@@ -7300,9 +7300,7 @@
       <keyword name="HgCommitDialog" id="HgCommitDialog" ref="eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.html#HgCommitDialog" />
       <keyword name="HgCommitDialog (Constructor)" id="HgCommitDialog (Constructor)" ref="eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.html#HgCommitDialog.__init__" />
       <keyword name="HgCommitDialog (Module)" id="HgCommitDialog (Module)" ref="eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.html" />
-      <keyword name="HgCommitDialog.amend" id="HgCommitDialog.amend" ref="eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.html#HgCommitDialog.amend" />
-      <keyword name="HgCommitDialog.commitSubrepositories" id="HgCommitDialog.commitSubrepositories" ref="eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.html#HgCommitDialog.commitSubrepositories" />
-      <keyword name="HgCommitDialog.logMessage" id="HgCommitDialog.logMessage" ref="eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.html#HgCommitDialog.logMessage" />
+      <keyword name="HgCommitDialog.getCommitData" id="HgCommitDialog.getCommitData" ref="eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.html#HgCommitDialog.getCommitData" />
       <keyword name="HgCommitDialog.on_buttonBox_accepted" id="HgCommitDialog.on_buttonBox_accepted" ref="eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.html#HgCommitDialog.on_buttonBox_accepted" />
       <keyword name="HgCommitDialog.on_buttonBox_clicked" id="HgCommitDialog.on_buttonBox_clicked" ref="eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.html#HgCommitDialog.on_buttonBox_clicked" />
       <keyword name="HgCommitDialog.on_buttonBox_rejected" id="HgCommitDialog.on_buttonBox_rejected" ref="eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.html#HgCommitDialog.on_buttonBox_rejected" />
--- a/Documentation/Source/eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.html	Wed Nov 16 19:12:01 2016 +0100
+++ b/Documentation/Source/eric6.Plugins.VcsPlugins.vcsMercurial.HgCommitDialog.html	Wed Nov 16 20:03:45 2016 +0100
@@ -69,14 +69,8 @@
 <td><a href="#HgCommitDialog.__init__">HgCommitDialog</a></td>
 <td>Constructor</td>
 </tr><tr>
-<td><a href="#HgCommitDialog.amend">amend</a></td>
-<td>Public method to retrieve the state of the amend flag.</td>
-</tr><tr>
-<td><a href="#HgCommitDialog.commitSubrepositories">commitSubrepositories</a></td>
-<td>Public method to retrieve the state of the commit sub-repositories flag.</td>
-</tr><tr>
-<td><a href="#HgCommitDialog.logMessage">logMessage</a></td>
-<td>Public method to retrieve the log message.</td>
+<td><a href="#HgCommitDialog.getCommitData">getCommitData</a></td>
+<td>Public method to retrieve the entered data for the commit.</td>
 </tr><tr>
 <td><a href="#HgCommitDialog.on_buttonBox_accepted">on_buttonBox_accepted</a></td>
 <td>Private slot called by the buttonBox accepted signal.</td>
@@ -117,36 +111,22 @@
 <dd>
 parent widget (QWidget)
 </dd>
-</dl><a NAME="HgCommitDialog.amend" ID="HgCommitDialog.amend"></a>
-<h4>HgCommitDialog.amend</h4>
-<b>amend</b>(<i></i>)
+</dl><a NAME="HgCommitDialog.getCommitData" ID="HgCommitDialog.getCommitData"></a>
+<h4>HgCommitDialog.getCommitData</h4>
+<b>getCommitData</b>(<i></i>)
 <p>
-        Public method to retrieve the state of the amend flag.
+        Public method to retrieve the entered data for the commit.
 </p><dl>
 <dt>Returns:</dt>
 <dd>
-state of the amend flag (boolean)
+tuple containing the log message, a flag indicating to amend
+            the last commit and a flag indicating to commit subrepositories
+            as well
 </dd>
-</dl><a NAME="HgCommitDialog.commitSubrepositories" ID="HgCommitDialog.commitSubrepositories"></a>
-<h4>HgCommitDialog.commitSubrepositories</h4>
-<b>commitSubrepositories</b>(<i></i>)
-<p>
-        Public method to retrieve the state of the commit sub-repositories
-        flag.
-</p><dl>
-<dt>Returns:</dt>
+</dl><dl>
+<dt>Return Type:</dt>
 <dd>
-state of the sub-repositories flag (boolean)
-</dd>
-</dl><a NAME="HgCommitDialog.logMessage" ID="HgCommitDialog.logMessage"></a>
-<h4>HgCommitDialog.logMessage</h4>
-<b>logMessage</b>(<i></i>)
-<p>
-        Public method to retrieve the log message.
-</p><dl>
-<dt>Returns:</dt>
-<dd>
-the log message (string)
+tuple of str, bool, bool
 </dd>
 </dl><a NAME="HgCommitDialog.on_buttonBox_accepted" ID="HgCommitDialog.on_buttonBox_accepted"></a>
 <h4>HgCommitDialog.on_buttonBox_accepted</h4>
--- a/Plugins/PluginVcsMercurial.py	Wed Nov 16 19:12:01 2016 +0100
+++ b/Plugins/PluginVcsMercurial.py	Wed Nov 16 20:03:45 2016 +0100
@@ -163,6 +163,7 @@
             "UseLogBrowser": True,
             "LogLimit": 20,
             "CommitMessages": 20,
+            "Commits": [],
             "PullUpdate": False,
             "PreferUnbundle": False,
             "ServerPort": 8000,
--- a/Plugins/VcsPlugins/vcsMercurial/HgCommitDialog.py	Wed Nov 16 19:12:01 2016 +0100
+++ b/Plugins/VcsPlugins/vcsMercurial/HgCommitDialog.py	Wed Nov 16 20:03:45 2016 +0100
@@ -14,8 +14,6 @@
 
 from .Ui_HgCommitDialog import Ui_HgCommitDialog
 
-import Preferences
-
 
 # TODO: add capability to set the author
 # TODO: add capability to set date and time, 
@@ -41,6 +39,8 @@
         super(HgCommitDialog, self).__init__(parent, Qt.WindowFlags(Qt.Window))
         self.setupUi(self)
         
+        self.__vcs = vcs
+        
         self.logEdit.setPlainText(msg)
         
         if mq:
@@ -55,46 +55,14 @@
         
         @param evt the event (QShowEvent)
         """
-        self.recentCommitMessages = Preferences.toList(
-            Preferences.Prefs.settings.value('Mercurial/Commits'))
+        commitMessages = self.__vcs.getPlugin().getPreferences('Commits')
         self.recentComboBox.clear()
         self.recentComboBox.addItem("")
-        self.recentComboBox.addItems(self.recentCommitMessages)
-    
-    def logMessage(self):
-        """
-        Public method to retrieve the log message.
-        
-        @return the log message (string)
-        """
-        msg = self.logEdit.toPlainText()
-        if msg:
-            if msg in self.recentCommitMessages:
-                self.recentCommitMessages.remove(msg)
-            self.recentCommitMessages.insert(0, msg)
-            no = int(Preferences.Prefs.settings.value(
-                'Mercurial/CommitMessages', 20))
-            del self.recentCommitMessages[no:]
-            Preferences.Prefs.settings.setValue(
-                'Mercurial/Commits', self.recentCommitMessages)
-        return msg
-    
-    def amend(self):
-        """
-        Public method to retrieve the state of the amend flag.
-        
-        @return state of the amend flag (boolean)
-        """
-        return self.amendCheckBox.isChecked()
-    
-    def commitSubrepositories(self):
-        """
-        Public method to retrieve the state of the commit sub-repositories
-        flag.
-        
-        @return state of the sub-repositories flag (boolean)
-        """
-        return self.subrepoCheckBox.isChecked()
+        for message in commitMessages:
+            abbrMsg = message[:60]
+            if len(message) > 60:
+                abbrMsg += "..."
+            self.recentComboBox.addItem(abbrMsg, message)
     
     def on_buttonBox_clicked(self, button):
         """
@@ -127,4 +95,30 @@
         @param txt text of the selected entry (string)
         """
         if txt:
-            self.logEdit.setPlainText(txt)
+            self.logEdit.setPlainText(self.recentComboBox.currentData())
+    
+    def getCommitData(self):
+        """
+        Public method to retrieve the entered data for the commit.
+        
+        @return tuple containing the log message, a flag indicating to amend
+            the last commit and a flag indicating to commit subrepositories
+            as well
+        @rtype tuple of str, bool, bool
+        """
+        msg = self.logEdit.toPlainText()
+        if msg:
+            commitMessages = self.__vcs.getPlugin().getPreferences('Commits')
+            if msg in commitMessages:
+                commitMessages.remove(msg)
+            commitMessages.insert(0, msg)
+            no = self.__vcs.getPlugin().getPreferences("CommitMessages")
+            del commitMessages[no:]
+            self.__vcs.getPlugin().setPreferences(
+                'Commits', commitMessages)
+        
+        return (
+            msg,
+            self.amendCheckBox.isChecked(),
+            self.subrepoCheckBox.isChecked()
+        )
--- a/Plugins/VcsPlugins/vcsMercurial/hg.py	Wed Nov 16 19:12:01 2016 +0100
+++ b/Plugins/VcsPlugins/vcsMercurial/hg.py	Wed Nov 16 20:03:45 2016 +0100
@@ -493,9 +493,8 @@
                 return
         
         if self.__commitDialog is not None:
-            msg = self.__commitDialog.logMessage()
-            amend = self.__commitDialog.amend()
-            commitSubrepositories = self.__commitDialog.commitSubrepositories()
+            msg, amend, commitSubrepositories = \
+                self.__commitDialog.getCommitData()
             self.__commitDialog.deleteLater()
             self.__commitDialog = None
             if amend and not msg:

eric ide

mercurial