eric7/VCS/StatusWidget.py

branch
eric7
changeset 8624
5192a2592324
parent 8622
149d51870ce8
child 8626
fa4ec5a82698
diff -r fced5aa98d41 -r 5192a2592324 eric7/VCS/StatusWidget.py
--- a/eric7/VCS/StatusWidget.py	Wed Sep 22 19:52:28 2021 +0200
+++ b/eric7/VCS/StatusWidget.py	Thu Sep 23 18:20:31 2021 +0200
@@ -13,11 +13,14 @@
 from PyQt6.QtCore import pyqtSlot, Qt
 from PyQt6.QtWidgets import (
     QWidget, QVBoxLayout, QHBoxLayout, QLabel, QSizePolicy, QListView,
-    QListWidget, QListWidgetItem, QToolButton, QAbstractItemView, QMenu
+    QListWidget, QListWidgetItem, QToolButton, QAbstractItemView, QMenu,
+    QGroupBox, QDialog
 )
 
 from EricWidgets.EricApplication import ericApp
 from EricWidgets import EricMessageBox
+from EricWidgets.EricSpellCheckedTextEdit import EricSpellCheckedTextEdit
+from EricWidgets.EricListSelectionDialog import EricListSelectionDialog
 
 import Preferences
 import UI.PixmapCache
@@ -53,7 +56,7 @@
         self.__topLayout = QHBoxLayout()
         self.__topLayout.setObjectName("topLayout")
         
-        # Create the top row
+        # Create the top area
         self.__infoLabel = QLabel(self)
         self.__infoLabel.setSizePolicy(
             QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred)
@@ -69,7 +72,7 @@
         self.__commitButton = QToolButton(self)
         self.__commitButton.setIcon(UI.PixmapCache.getIcon("vcsCommit"))
         self.__commitButton.setToolTip(
-            self.tr("Press to commit the marked entries"))
+            self.tr("Press to commit the marked entries with options"))
         self.__commitButton.clicked.connect(self.__commit)
         self.__topLayout.addWidget(self.__commitButton)
         
@@ -97,7 +100,9 @@
         self.__topLayout.addWidget(self.__actionsButton)
         
         self.__layout.addLayout(self.__topLayout)
+        ###################################################################
         
+        # Create the middle part
         self.__statusList = QListWidget(self)
         self.__statusList.setAlternatingRowColors(True)
         self.__statusList.setSortingEnabled(True)
@@ -106,9 +111,58 @@
         self.__statusList.setSelectionMode(
             QAbstractItemView.SelectionMode.ExtendedSelection)
         self.__statusList.itemSelectionChanged.connect(
-            self.__updateButtonStates)
+            self.__updateEnabledStates)
         self.__statusList.itemDoubleClicked.connect(self.__itemDoubleClicked)
         self.__layout.addWidget(self.__statusList)
+        ###################################################################
+        
+        # create the Quick Commit area
+        self.__quickCommitGroup = QGroupBox(self.tr("Quick Commit"), self)
+        self.__quickCommitLayout = QVBoxLayout()
+        self.__quickCommitEdit = EricSpellCheckedTextEdit(self)
+        self.__quickCommitEdit.setSizePolicy(
+            QSizePolicy.Policy.Expanding,
+            QSizePolicy.Policy.Preferred)
+        self.__quickCommitEdit.setMaximumHeight(100)
+        self.__quickCommitEdit.textChanged.connect(
+            self.__quickCommitEditTextChanged)
+        self.__quickCommitLayout.addWidget(self.__quickCommitEdit)
+        
+        self.__quickCommitLayout2 = QHBoxLayout()
+        self.__quickCommitLayout2.addStretch()
+        
+        self.__quickCommitHistoryButton = QToolButton(self)
+        self.__quickCommitHistoryButton.setIcon(
+            UI.PixmapCache.getIcon("history"))
+        self.__quickCommitHistoryButton.setToolTip(
+            self.tr("Select commit message from previous commits"))
+        self.__quickCommitHistoryButton.clicked.connect(
+            self.__selectQuickCommitMessage)
+        self.__quickCommitLayout2.addWidget(self.__quickCommitHistoryButton)
+        
+        self.__quickCommitHistoryClearButton = QToolButton(self)
+        self.__quickCommitHistoryClearButton.setIcon(
+            UI.PixmapCache.getIcon("historyClear"))
+        self.__quickCommitHistoryClearButton.setToolTip(
+            self.tr("Clear the list of saved commit messages"))
+        self.__quickCommitHistoryClearButton.clicked.connect(
+            self.__clearCommitMessages)
+        self.__quickCommitLayout2.addWidget(
+            self.__quickCommitHistoryClearButton)
+        
+        self.__quickCommitButton = QToolButton(self)
+        self.__quickCommitButton.setIcon(
+            UI.PixmapCache.getIcon("vcsCommit"))
+        self.__quickCommitButton.setToolTip(
+            self.tr("Press to commit the marked entries"))
+        self.__quickCommitButton.clicked.connect(
+            self.__quickCommit)
+        self.__quickCommitLayout2.addWidget(self.__quickCommitButton)
+        
+        self.__quickCommitLayout.addLayout(self.__quickCommitLayout2)
+        self.__quickCommitGroup.setLayout(self.__quickCommitLayout)
+        self.__layout.addWidget(self.__quickCommitGroup)
+        ###################################################################
         
         self.setLayout(self.__layout)
         
@@ -161,7 +215,7 @@
             UI.PixmapCache.getIcon("vcsCommit"),
             self.tr("Commit"), self.__commit)
         self.__commitAct.setToolTip(self.tr(
-            "Commit the selected changes"))
+            "Commit the marked entries with options"))
         self.__commitSelectAct = self.__actionsMenu.addAction(
             self.tr("Select all for commit"), self.__commitSelectAll)
         self.__commitDeselectAct = self.__actionsMenu.addAction(
@@ -275,10 +329,13 @@
         self.__commitToggleButton.setEnabled(False)
         self.__commitButton.setEnabled(False)
         self.__addButton.setEnabled(False)
+        
+        self.__quickCommitEdit.clear()
+        self.__quickCommitGroup.setEnabled(False)
     
-    def __updateButtonStates(self):
+    def __updateEnabledStates(self):
         """
-        Private method to set the button states depending on the list state.
+        Private method to set the enabled states depending on the list state.
         """
         modified = len(self.__getModifiedItems())
         unversioned = len(self.__getSelectedUnversionedItems())
@@ -287,6 +344,8 @@
         self.__commitToggleButton.setEnabled(modified)
         self.__commitButton.setEnabled(commitable)
         self.__addButton.setEnabled(unversioned)
+        
+        self.__quickCommitGroup.setEnabled(True)
     
     @pyqtSlot(dict)
     def __processStatusData(self, data):
@@ -331,7 +390,7 @@
         
         self.__statusList.sortItems(Qt.SortOrder.AscendingOrder)
         
-        self.__updateButtonStates()
+        self.__updateEnabledStates()
     
     @pyqtSlot()
     def __toggleCheckMark(self):
@@ -766,3 +825,77 @@
         vcs = self.__project.getVcs()
         vcs and vcs.vcsResolved(names)
         self.__reload()
+    
+    #######################################################################
+    ## Quick Commit handling methods
+    #######################################################################
+    
+    @pyqtSlot()
+    def __selectQuickCommitMessage(self):
+        """
+        Private slot to select a commit message from the list of
+        saved messages.
+        """
+        vcs = self.__project.getVcs()
+        if vcs:
+            commitMessages = vcs.vcsCommitMessages()
+            dlg = EricListSelectionDialog(
+                commitMessages,
+                selectionMode=QAbstractItemView.SelectionMode.SingleSelection,
+                title=self.tr("Quick Commit"),
+                message=self.tr("Select your commit message:"),
+                parent=self
+            )
+            if dlg.exec() == QDialog.DialogCode.Accepted:
+                selection = dlg.getSelection()
+                if selection:
+                    self.__quickCommitEdit.setPlainText(selection[0])
+    
+    @pyqtSlot()
+    def __clearCommitMessages(self):
+        """
+        Private slot to clear the list of saved commit messages.
+        """
+        vcs = self.__project.getVcs()
+        vcs and vcs.vcsClearCommitMessages()
+    
+    @pyqtSlot()
+    def __quickCommit(self):
+        """
+        Private slot to commit all marked entries with the entered
+        commit message.
+        """
+        projectPath = self.__project.getProjectPath()
+        names = []
+        
+        for row in range(self.__statusList.count()):
+            itm = self.__statusList.item(row)
+            if itm.checkState() == Qt.CheckState.Checked:
+                names.append(os.path.join(projectPath, itm.text()))
+        
+        if not names:
+            EricMessageBox.information(
+                self,
+                self.tr("Commit"),
+                self.tr("""There are no entries selected to be"""
+                        """ committed."""))
+            return
+        
+        if Preferences.getVCS("AutoSaveFiles"):
+            vm = ericApp().getObject("ViewManager")
+            for name in names:
+                vm.saveEditor(name)
+        
+        commitMessage = self.__quickCommitEdit.toPlainText()
+        vcs = self.__project.getVcs()
+        if vcs:
+            vcs.vcsCommit(names, commitMessage, noDialog=True)
+            vcs.vcsAddCommitMessage(commitMessage)
+    
+    @pyqtSlot()
+    def __quickCommitEditTextChanged(self):
+        """
+        Private slot to react upon changes of the quick commit text.
+        """
+        self.__quickCommitButton.setEnabled(bool(
+            self.__quickCommitEdit.toPlainText()))

eric ide

mercurial