|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the data for a 'git worktree add' operation. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import pyqtSlot |
|
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
|
12 |
|
13 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes |
|
14 |
|
15 from .Ui_GitWorktreeAddDialog import Ui_GitWorktreeAddDialog |
|
16 |
|
17 |
|
18 class GitWorktreeAddDialog(QDialog, Ui_GitWorktreeAddDialog): |
|
19 """ |
|
20 Class implementing a dialog to enter the data for a 'git worktree add' operation. |
|
21 """ |
|
22 |
|
23 def __init__(self, parentDirectory, tagsList, branchesList, parent=None): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param parentDirectory path of the worktrees parent directory |
|
28 @type str |
|
29 @param tagsList list of tags |
|
30 @type list of str |
|
31 @param branchesList list of branches |
|
32 @type list of str |
|
33 @param parent reference to the parent widget (defaults to None) |
|
34 @type QWidget (optional) |
|
35 """ |
|
36 super().__init__(parent) |
|
37 self.setupUi(self) |
|
38 |
|
39 self.__parentDirectory = parentDirectory |
|
40 |
|
41 self.worktreePathPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) |
|
42 self.worktreePathPicker.setDefaultDirectory(parentDirectory) |
|
43 self.worktreePathPicker.setText(parentDirectory) |
|
44 |
|
45 self.tagCombo.addItems(sorted(tagsList)) |
|
46 self.branchCombo.addItems(["master"] + sorted(branchesList)) |
|
47 |
|
48 self.__updateOK() |
|
49 |
|
50 def __updateOK(self): |
|
51 """ |
|
52 Private method to set the enabled state of the OK button. |
|
53 """ |
|
54 enable = True |
|
55 if self.revButton.isChecked(): |
|
56 enable = self.revEdit.text() != "" |
|
57 elif self.tagButton.isChecked(): |
|
58 enable = self.tagCombo.currentText() != "" |
|
59 elif self.branchButton.isChecked(): |
|
60 enable = self.branchCombo.currentText() != "" |
|
61 |
|
62 worktreePath = self.worktreePathPicker.text() |
|
63 enable &= bool(worktreePath) and worktreePath not in ( |
|
64 self.__parentDirectory, |
|
65 self.__parentDirectory + "/", |
|
66 self.__parentDirectory + "\\", |
|
67 ) |
|
68 |
|
69 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(enable) |
|
70 |
|
71 @pyqtSlot(str) |
|
72 def on_worktreePathPicker_textChanged(self, worktree): |
|
73 """ |
|
74 Private slot handling a change of the worktree path. |
|
75 |
|
76 @param worktree entered worktree path |
|
77 @type str |
|
78 """ |
|
79 self.__updateOK() |
|
80 |
|
81 @pyqtSlot(bool) |
|
82 def on_revButton_toggled(self, checked): |
|
83 """ |
|
84 Private slot to handle changes of the rev select button. |
|
85 |
|
86 @param checked state of the button |
|
87 @type bool |
|
88 """ |
|
89 self.__updateOK() |
|
90 |
|
91 @pyqtSlot(str) |
|
92 def on_revEdit_textChanged(self, txt): |
|
93 """ |
|
94 Private slot to handle changes of the rev edit. |
|
95 |
|
96 @param txt text of the edit |
|
97 @type str |
|
98 """ |
|
99 self.__updateOK() |
|
100 |
|
101 @pyqtSlot(bool) |
|
102 def on_tagButton_toggled(self, checked): |
|
103 """ |
|
104 Private slot to handle changes of the Tag select button. |
|
105 |
|
106 @param checked state of the button |
|
107 @type bool |
|
108 """ |
|
109 self.__updateOK() |
|
110 |
|
111 @pyqtSlot(str) |
|
112 def on_tagCombo_editTextChanged(self, txt): |
|
113 """ |
|
114 Private slot to handle changes of the Tag combo. |
|
115 |
|
116 @param txt text of the combo |
|
117 @type str |
|
118 """ |
|
119 self.__updateOK() |
|
120 |
|
121 @pyqtSlot(bool) |
|
122 def on_branchButton_toggled(self, checked): |
|
123 """ |
|
124 Private slot to handle changes of the Branch select button. |
|
125 |
|
126 @param checked state of the button |
|
127 @type bool |
|
128 """ |
|
129 self.__updateOK() |
|
130 |
|
131 @pyqtSlot(str) |
|
132 def on_branchCombo_editTextChanged(self, txt): |
|
133 """ |
|
134 Private slot to handle changes of the Branch combo. |
|
135 |
|
136 @param txt text of the combo |
|
137 @type str |
|
138 """ |
|
139 self.__updateOK() |
|
140 |
|
141 def getParameters(self): |
|
142 """ |
|
143 Public method to get the entered parameters for the 'git worktree add' |
|
144 operation. |
|
145 |
|
146 @return dictionary containing the entered data. This dictionary has these keys. |
|
147 <ul> |
|
148 <li>path: path for the new worktree</li> |
|
149 <li>branch: name for the worktree branch</li> |
|
150 <li>force_branch: enforce creating the branch</li> |
|
151 <li>lock: flag indicating to lock the worktree</li> |
|
152 <li>lock_reason: optional reason string for the lock</li> |
|
153 <li>detach: flag indicating to detach the HEAD in the new worktree</li> |
|
154 <li>commit: commit to check out in the new worktree (branch, tag, commit ID |
|
155 or empty for HEAD) </li> |
|
156 <li>force: flag indicating to enforce the worktree creation</li> |
|
157 </ul> |
|
158 @rtype dict |
|
159 """ |
|
160 if self.revButton.isChecked(): |
|
161 commit = self.revEdit.text() |
|
162 elif self.tagButton.isChecked(): |
|
163 commit = self.tagCombo.currentText() |
|
164 elif self.branchButton.isChecked(): |
|
165 commit = self.branchCombo.currentText() |
|
166 else: |
|
167 commit = "" |
|
168 |
|
169 return { |
|
170 "path": self.worktreePathPicker.text(), |
|
171 "branch": self.branchNameEdit.text(), |
|
172 "force_branch": self.forceBranchCheckBox.isChecked(), |
|
173 "lock": self.lockCheckBox.isChecked(), |
|
174 "lock_reason": self.lockReasonEdit.text(), |
|
175 "detach": self.detachCheckBox.isChecked(), |
|
176 "commit": commit, |
|
177 "force": self.forceCheckBox.isChecked(), |
|
178 } |