11 import os |
11 import os |
12 |
12 |
13 from PyQt6.QtCore import pyqtSlot, Qt |
13 from PyQt6.QtCore import pyqtSlot, Qt |
14 from PyQt6.QtWidgets import ( |
14 from PyQt6.QtWidgets import ( |
15 QWidget, QVBoxLayout, QHBoxLayout, QLabel, QSizePolicy, QListView, |
15 QWidget, QVBoxLayout, QHBoxLayout, QLabel, QSizePolicy, QListView, |
16 QListWidget, QListWidgetItem, QToolButton, QAbstractItemView, QMenu |
16 QListWidget, QListWidgetItem, QToolButton, QAbstractItemView, QMenu, |
|
17 QGroupBox, QDialog |
17 ) |
18 ) |
18 |
19 |
19 from EricWidgets.EricApplication import ericApp |
20 from EricWidgets.EricApplication import ericApp |
20 from EricWidgets import EricMessageBox |
21 from EricWidgets import EricMessageBox |
|
22 from EricWidgets.EricSpellCheckedTextEdit import EricSpellCheckedTextEdit |
|
23 from EricWidgets.EricListSelectionDialog import EricListSelectionDialog |
21 |
24 |
22 import Preferences |
25 import Preferences |
23 import UI.PixmapCache |
26 import UI.PixmapCache |
24 import Utilities |
27 import Utilities |
25 |
28 |
51 self.__layout.setObjectName("MainLayout") |
54 self.__layout.setObjectName("MainLayout") |
52 self.__layout.setContentsMargins(0, 3, 0, 0) |
55 self.__layout.setContentsMargins(0, 3, 0, 0) |
53 self.__topLayout = QHBoxLayout() |
56 self.__topLayout = QHBoxLayout() |
54 self.__topLayout.setObjectName("topLayout") |
57 self.__topLayout.setObjectName("topLayout") |
55 |
58 |
56 # Create the top row |
59 # Create the top area |
57 self.__infoLabel = QLabel(self) |
60 self.__infoLabel = QLabel(self) |
58 self.__infoLabel.setSizePolicy( |
61 self.__infoLabel.setSizePolicy( |
59 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred) |
62 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred) |
60 self.__topLayout.addWidget(self.__infoLabel) |
63 self.__topLayout.addWidget(self.__infoLabel) |
61 |
64 |
67 self.__topLayout.addWidget(self.__commitToggleButton) |
70 self.__topLayout.addWidget(self.__commitToggleButton) |
68 |
71 |
69 self.__commitButton = QToolButton(self) |
72 self.__commitButton = QToolButton(self) |
70 self.__commitButton.setIcon(UI.PixmapCache.getIcon("vcsCommit")) |
73 self.__commitButton.setIcon(UI.PixmapCache.getIcon("vcsCommit")) |
71 self.__commitButton.setToolTip( |
74 self.__commitButton.setToolTip( |
72 self.tr("Press to commit the marked entries")) |
75 self.tr("Press to commit the marked entries with options")) |
73 self.__commitButton.clicked.connect(self.__commit) |
76 self.__commitButton.clicked.connect(self.__commit) |
74 self.__topLayout.addWidget(self.__commitButton) |
77 self.__topLayout.addWidget(self.__commitButton) |
75 |
78 |
76 self.__addButton = QToolButton(self) |
79 self.__addButton = QToolButton(self) |
77 self.__addButton.setIcon(UI.PixmapCache.getIcon("vcsAdd")) |
80 self.__addButton.setIcon(UI.PixmapCache.getIcon("vcsAdd")) |
95 self.__actionsButton.setPopupMode( |
98 self.__actionsButton.setPopupMode( |
96 QToolButton.ToolButtonPopupMode.InstantPopup) |
99 QToolButton.ToolButtonPopupMode.InstantPopup) |
97 self.__topLayout.addWidget(self.__actionsButton) |
100 self.__topLayout.addWidget(self.__actionsButton) |
98 |
101 |
99 self.__layout.addLayout(self.__topLayout) |
102 self.__layout.addLayout(self.__topLayout) |
100 |
103 ################################################################### |
|
104 |
|
105 # Create the middle part |
101 self.__statusList = QListWidget(self) |
106 self.__statusList = QListWidget(self) |
102 self.__statusList.setAlternatingRowColors(True) |
107 self.__statusList.setAlternatingRowColors(True) |
103 self.__statusList.setSortingEnabled(True) |
108 self.__statusList.setSortingEnabled(True) |
104 self.__statusList.setViewMode(QListView.ViewMode.ListMode) |
109 self.__statusList.setViewMode(QListView.ViewMode.ListMode) |
105 self.__statusList.setTextElideMode(Qt.TextElideMode.ElideLeft) |
110 self.__statusList.setTextElideMode(Qt.TextElideMode.ElideLeft) |
106 self.__statusList.setSelectionMode( |
111 self.__statusList.setSelectionMode( |
107 QAbstractItemView.SelectionMode.ExtendedSelection) |
112 QAbstractItemView.SelectionMode.ExtendedSelection) |
108 self.__statusList.itemSelectionChanged.connect( |
113 self.__statusList.itemSelectionChanged.connect( |
109 self.__updateButtonStates) |
114 self.__updateEnabledStates) |
110 self.__statusList.itemDoubleClicked.connect(self.__itemDoubleClicked) |
115 self.__statusList.itemDoubleClicked.connect(self.__itemDoubleClicked) |
111 self.__layout.addWidget(self.__statusList) |
116 self.__layout.addWidget(self.__statusList) |
|
117 ################################################################### |
|
118 |
|
119 # create the Quick Commit area |
|
120 self.__quickCommitGroup = QGroupBox(self.tr("Quick Commit"), self) |
|
121 self.__quickCommitLayout = QVBoxLayout() |
|
122 self.__quickCommitEdit = EricSpellCheckedTextEdit(self) |
|
123 self.__quickCommitEdit.setSizePolicy( |
|
124 QSizePolicy.Policy.Expanding, |
|
125 QSizePolicy.Policy.Preferred) |
|
126 self.__quickCommitEdit.setMaximumHeight(100) |
|
127 self.__quickCommitEdit.textChanged.connect( |
|
128 self.__quickCommitEditTextChanged) |
|
129 self.__quickCommitLayout.addWidget(self.__quickCommitEdit) |
|
130 |
|
131 self.__quickCommitLayout2 = QHBoxLayout() |
|
132 self.__quickCommitLayout2.addStretch() |
|
133 |
|
134 self.__quickCommitHistoryButton = QToolButton(self) |
|
135 self.__quickCommitHistoryButton.setIcon( |
|
136 UI.PixmapCache.getIcon("history")) |
|
137 self.__quickCommitHistoryButton.setToolTip( |
|
138 self.tr("Select commit message from previous commits")) |
|
139 self.__quickCommitHistoryButton.clicked.connect( |
|
140 self.__selectQuickCommitMessage) |
|
141 self.__quickCommitLayout2.addWidget(self.__quickCommitHistoryButton) |
|
142 |
|
143 self.__quickCommitHistoryClearButton = QToolButton(self) |
|
144 self.__quickCommitHistoryClearButton.setIcon( |
|
145 UI.PixmapCache.getIcon("historyClear")) |
|
146 self.__quickCommitHistoryClearButton.setToolTip( |
|
147 self.tr("Clear the list of saved commit messages")) |
|
148 self.__quickCommitHistoryClearButton.clicked.connect( |
|
149 self.__clearCommitMessages) |
|
150 self.__quickCommitLayout2.addWidget( |
|
151 self.__quickCommitHistoryClearButton) |
|
152 |
|
153 self.__quickCommitButton = QToolButton(self) |
|
154 self.__quickCommitButton.setIcon( |
|
155 UI.PixmapCache.getIcon("vcsCommit")) |
|
156 self.__quickCommitButton.setToolTip( |
|
157 self.tr("Press to commit the marked entries")) |
|
158 self.__quickCommitButton.clicked.connect( |
|
159 self.__quickCommit) |
|
160 self.__quickCommitLayout2.addWidget(self.__quickCommitButton) |
|
161 |
|
162 self.__quickCommitLayout.addLayout(self.__quickCommitLayout2) |
|
163 self.__quickCommitGroup.setLayout(self.__quickCommitLayout) |
|
164 self.__layout.addWidget(self.__quickCommitGroup) |
|
165 ################################################################### |
112 |
166 |
113 self.setLayout(self.__layout) |
167 self.setLayout(self.__layout) |
114 |
168 |
115 self.__statusIcons = { |
169 self.__statusIcons = { |
116 "A": "vcs-added", # added |
170 "A": "vcs-added", # added |
159 |
213 |
160 self.__commitAct = self.__actionsMenu.addAction( |
214 self.__commitAct = self.__actionsMenu.addAction( |
161 UI.PixmapCache.getIcon("vcsCommit"), |
215 UI.PixmapCache.getIcon("vcsCommit"), |
162 self.tr("Commit"), self.__commit) |
216 self.tr("Commit"), self.__commit) |
163 self.__commitAct.setToolTip(self.tr( |
217 self.__commitAct.setToolTip(self.tr( |
164 "Commit the selected changes")) |
218 "Commit the marked entries with options")) |
165 self.__commitSelectAct = self.__actionsMenu.addAction( |
219 self.__commitSelectAct = self.__actionsMenu.addAction( |
166 self.tr("Select all for commit"), self.__commitSelectAll) |
220 self.tr("Select all for commit"), self.__commitSelectAll) |
167 self.__commitDeselectAct = self.__actionsMenu.addAction( |
221 self.__commitDeselectAct = self.__actionsMenu.addAction( |
168 self.tr("Unselect all from commit"), self.__commitDeselectAll) |
222 self.tr("Unselect all from commit"), self.__commitDeselectAll) |
169 |
223 |
273 self.__statusList.clear() |
327 self.__statusList.clear() |
274 |
328 |
275 self.__commitToggleButton.setEnabled(False) |
329 self.__commitToggleButton.setEnabled(False) |
276 self.__commitButton.setEnabled(False) |
330 self.__commitButton.setEnabled(False) |
277 self.__addButton.setEnabled(False) |
331 self.__addButton.setEnabled(False) |
278 |
332 |
279 def __updateButtonStates(self): |
333 self.__quickCommitEdit.clear() |
280 """ |
334 self.__quickCommitGroup.setEnabled(False) |
281 Private method to set the button states depending on the list state. |
335 |
|
336 def __updateEnabledStates(self): |
|
337 """ |
|
338 Private method to set the enabled states depending on the list state. |
282 """ |
339 """ |
283 modified = len(self.__getModifiedItems()) |
340 modified = len(self.__getModifiedItems()) |
284 unversioned = len(self.__getSelectedUnversionedItems()) |
341 unversioned = len(self.__getSelectedUnversionedItems()) |
285 commitable = len(self.__getCommitableItems()) |
342 commitable = len(self.__getCommitableItems()) |
286 |
343 |
287 self.__commitToggleButton.setEnabled(modified) |
344 self.__commitToggleButton.setEnabled(modified) |
288 self.__commitButton.setEnabled(commitable) |
345 self.__commitButton.setEnabled(commitable) |
289 self.__addButton.setEnabled(unversioned) |
346 self.__addButton.setEnabled(unversioned) |
|
347 |
|
348 self.__quickCommitGroup.setEnabled(True) |
290 |
349 |
291 @pyqtSlot(dict) |
350 @pyqtSlot(dict) |
292 def __processStatusData(self, data): |
351 def __processStatusData(self, data): |
293 """ |
352 """ |
294 Private slot to process the status data emitted by the project. |
353 Private slot to process the status data emitted by the project. |
764 return |
823 return |
765 |
824 |
766 vcs = self.__project.getVcs() |
825 vcs = self.__project.getVcs() |
767 vcs and vcs.vcsResolved(names) |
826 vcs and vcs.vcsResolved(names) |
768 self.__reload() |
827 self.__reload() |
|
828 |
|
829 ####################################################################### |
|
830 ## Quick Commit handling methods |
|
831 ####################################################################### |
|
832 |
|
833 @pyqtSlot() |
|
834 def __selectQuickCommitMessage(self): |
|
835 """ |
|
836 Private slot to select a commit message from the list of |
|
837 saved messages. |
|
838 """ |
|
839 vcs = self.__project.getVcs() |
|
840 if vcs: |
|
841 commitMessages = vcs.vcsCommitMessages() |
|
842 dlg = EricListSelectionDialog( |
|
843 commitMessages, |
|
844 selectionMode=QAbstractItemView.SelectionMode.SingleSelection, |
|
845 title=self.tr("Quick Commit"), |
|
846 message=self.tr("Select your commit message:"), |
|
847 parent=self |
|
848 ) |
|
849 if dlg.exec() == QDialog.DialogCode.Accepted: |
|
850 selection = dlg.getSelection() |
|
851 if selection: |
|
852 self.__quickCommitEdit.setPlainText(selection[0]) |
|
853 |
|
854 @pyqtSlot() |
|
855 def __clearCommitMessages(self): |
|
856 """ |
|
857 Private slot to clear the list of saved commit messages. |
|
858 """ |
|
859 vcs = self.__project.getVcs() |
|
860 vcs and vcs.vcsClearCommitMessages() |
|
861 |
|
862 @pyqtSlot() |
|
863 def __quickCommit(self): |
|
864 """ |
|
865 Private slot to commit all marked entries with the entered |
|
866 commit message. |
|
867 """ |
|
868 projectPath = self.__project.getProjectPath() |
|
869 names = [] |
|
870 |
|
871 for row in range(self.__statusList.count()): |
|
872 itm = self.__statusList.item(row) |
|
873 if itm.checkState() == Qt.CheckState.Checked: |
|
874 names.append(os.path.join(projectPath, itm.text())) |
|
875 |
|
876 if not names: |
|
877 EricMessageBox.information( |
|
878 self, |
|
879 self.tr("Commit"), |
|
880 self.tr("""There are no entries selected to be""" |
|
881 """ committed.""")) |
|
882 return |
|
883 |
|
884 if Preferences.getVCS("AutoSaveFiles"): |
|
885 vm = ericApp().getObject("ViewManager") |
|
886 for name in names: |
|
887 vm.saveEditor(name) |
|
888 |
|
889 commitMessage = self.__quickCommitEdit.toPlainText() |
|
890 vcs = self.__project.getVcs() |
|
891 if vcs: |
|
892 vcs.vcsCommit(names, commitMessage, noDialog=True) |
|
893 vcs.vcsAddCommitMessage(commitMessage) |
|
894 |
|
895 @pyqtSlot() |
|
896 def __quickCommitEditTextChanged(self): |
|
897 """ |
|
898 Private slot to react upon changes of the quick commit text. |
|
899 """ |
|
900 self.__quickCommitButton.setEnabled(bool( |
|
901 self.__quickCommitEdit.toPlainText())) |