15 |
15 |
16 class GitBranchDialog(QDialog, Ui_GitBranchDialog): |
16 class GitBranchDialog(QDialog, Ui_GitBranchDialog): |
17 """ |
17 """ |
18 Class implementing a dialog to enter the data for a branching operation. |
18 Class implementing a dialog to enter the data for a branching operation. |
19 """ |
19 """ |
|
20 |
20 CreateBranch = 1 |
21 CreateBranch = 1 |
21 DeleteBranch = 2 |
22 DeleteBranch = 2 |
22 RenameBranch = 3 |
23 RenameBranch = 3 |
23 CreateSwitchBranch = 4 |
24 CreateSwitchBranch = 4 |
24 CreateTrackingBranch = 5 |
25 CreateTrackingBranch = 5 |
25 SetTrackingBranch = 6 |
26 SetTrackingBranch = 6 |
26 UnsetTrackingBranch = 7 |
27 UnsetTrackingBranch = 7 |
27 |
28 |
28 def __init__(self, branchlist, revision=None, branchName=None, |
29 def __init__( |
29 branchOp=None, parent=None): |
30 self, branchlist, revision=None, branchName=None, branchOp=None, parent=None |
|
31 ): |
30 """ |
32 """ |
31 Constructor |
33 Constructor |
32 |
34 |
33 @param branchlist list of previously entered branches (list of strings) |
35 @param branchlist list of previously entered branches (list of strings) |
34 @param revision revision to set tag for (string) |
36 @param revision revision to set tag for (string) |
35 @param branchName name of the branch (string) |
37 @param branchName name of the branch (string) |
36 @param branchOp desired branch operation (integer) |
38 @param branchOp desired branch operation (integer) |
37 @param parent parent widget (QWidget) |
39 @param parent parent widget (QWidget) |
38 """ |
40 """ |
39 super().__init__(parent) |
41 super().__init__(parent) |
40 self.setupUi(self) |
42 self.setupUi(self) |
41 |
43 |
42 self.okButton = self.buttonBox.button( |
44 self.okButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok) |
43 QDialogButtonBox.StandardButton.Ok) |
|
44 self.okButton.setEnabled(False) |
45 self.okButton.setEnabled(False) |
45 |
46 |
46 self.__remoteBranches = [b for b in branchlist |
47 self.__remoteBranches = [b for b in branchlist if b.startswith("remotes/")] |
47 if b.startswith("remotes/")] |
48 self.__lokalBranches = [b for b in branchlist if not b.startswith("remotes/")] |
48 self.__lokalBranches = [b for b in branchlist |
49 |
49 if not b.startswith("remotes/")] |
|
50 |
|
51 self.branchCombo.clear() |
50 self.branchCombo.clear() |
52 self.branchCombo.addItem("") |
51 self.branchCombo.addItem("") |
53 self.branchCombo.addItems(sorted(self.__lokalBranches)) |
52 self.branchCombo.addItems(sorted(self.__lokalBranches)) |
54 |
53 |
55 self.remoteBranchCombo.clear() |
54 self.remoteBranchCombo.clear() |
56 self.remoteBranchCombo.addItems(sorted(self.__remoteBranches)) |
55 self.remoteBranchCombo.addItems(sorted(self.__remoteBranches)) |
57 |
56 |
58 if revision: |
57 if revision: |
59 self.revisionEdit.setText(revision) |
58 self.revisionEdit.setText(revision) |
60 |
59 |
61 if branchName: |
60 if branchName: |
62 index = self.branchCombo.findText(branchName) |
61 index = self.branchCombo.findText(branchName) |
63 if index > -1: |
62 if index > -1: |
64 self.branchCombo.setCurrentIndex(index) |
63 self.branchCombo.setCurrentIndex(index) |
65 # suggest the most relevant branch action |
64 # suggest the most relevant branch action |
66 self.deleteBranchButton.setChecked(True) |
65 self.deleteBranchButton.setChecked(True) |
67 else: |
66 else: |
68 self.branchCombo.setEditText(branchName) |
67 self.branchCombo.setEditText(branchName) |
69 self.createBranchButton.setChecked(True) |
68 self.createBranchButton.setChecked(True) |
70 |
69 |
71 if branchOp: |
70 if branchOp: |
72 if branchOp == GitBranchDialog.CreateBranch: |
71 if branchOp == GitBranchDialog.CreateBranch: |
73 self.createBranchButton.setChecked(True) |
72 self.createBranchButton.setChecked(True) |
74 elif branchOp == GitBranchDialog.DeleteBranch: |
73 elif branchOp == GitBranchDialog.DeleteBranch: |
75 self.deleteBranchButton.setChecked(True) |
74 self.deleteBranchButton.setChecked(True) |
84 elif branchOp == GitBranchDialog.UnsetTrackingBranch: |
83 elif branchOp == GitBranchDialog.UnsetTrackingBranch: |
85 self.unsetTrackingButton.setChecked(True) |
84 self.unsetTrackingButton.setChecked(True) |
86 else: |
85 else: |
87 # Oops, fall back to a save default |
86 # Oops, fall back to a save default |
88 self.createBranchButton.setChecked(True) |
87 self.createBranchButton.setChecked(True) |
89 |
88 |
90 msh = self.minimumSizeHint() |
89 msh = self.minimumSizeHint() |
91 self.resize(max(self.width(), msh.width()), msh.height()) |
90 self.resize(max(self.width(), msh.width()), msh.height()) |
92 |
91 |
93 def __updateOK(self): |
92 def __updateOK(self): |
94 """ |
93 """ |
95 Private method used to enable/disable the OK-button. |
94 Private method used to enable/disable the OK-button. |
96 """ |
95 """ |
97 if ( |
96 if self.setTrackingButton.isChecked() or self.unsetTrackingButton.isChecked(): |
98 self.setTrackingButton.isChecked() or |
|
99 self.unsetTrackingButton.isChecked() |
|
100 ): |
|
101 enable = True |
97 enable = True |
102 else: |
98 else: |
103 enable = self.branchCombo.currentText() != "" |
99 enable = self.branchCombo.currentText() != "" |
104 if self.moveBranchButton.isChecked(): |
100 if self.moveBranchButton.isChecked(): |
105 enable &= self.newBranchNameEdit.text() != "" |
101 enable &= self.newBranchNameEdit.text() != "" |
106 |
102 |
107 self.okButton.setEnabled(enable) |
103 self.okButton.setEnabled(enable) |
108 |
104 |
109 @pyqtSlot(bool) |
105 @pyqtSlot(bool) |
110 def on_createTrackingButton_toggled(self, checked): |
106 def on_createTrackingButton_toggled(self, checked): |
111 """ |
107 """ |
112 Private slot to handle the selection of creating a tracking branch. |
108 Private slot to handle the selection of creating a tracking branch. |
113 |
109 |
114 @param checked state of the selection (boolean) |
110 @param checked state of the selection (boolean) |
115 """ |
111 """ |
116 self.branchCombo.setEditable(not checked) |
112 self.branchCombo.setEditable(not checked) |
117 self.branchCombo.clear() |
113 self.branchCombo.clear() |
118 if checked: |
114 if checked: |
119 self.branchCombo.addItems(sorted(self.__remoteBranches)) |
115 self.branchCombo.addItems(sorted(self.__remoteBranches)) |
120 else: |
116 else: |
121 self.branchCombo.addItem("") |
117 self.branchCombo.addItem("") |
122 self.branchCombo.addItems(sorted(self.__lokalBranches)) |
118 self.branchCombo.addItems(sorted(self.__lokalBranches)) |
123 self.__updateOK() |
119 self.__updateOK() |
124 |
120 |
125 @pyqtSlot(bool) |
121 @pyqtSlot(bool) |
126 def on_setTrackingButton_toggled(self, checked): |
122 def on_setTrackingButton_toggled(self, checked): |
127 """ |
123 """ |
128 Private slot to handle the selection of setting a tracking branch. |
124 Private slot to handle the selection of setting a tracking branch. |
129 |
125 |
130 @param checked state of the selection (boolean) |
126 @param checked state of the selection (boolean) |
131 """ |
127 """ |
132 self.__updateOK() |
128 self.__updateOK() |
133 |
129 |
134 @pyqtSlot(bool) |
130 @pyqtSlot(bool) |
135 def on_unsetTrackingButton_toggled(self, checked): |
131 def on_unsetTrackingButton_toggled(self, checked): |
136 """ |
132 """ |
137 Private slot to handle the selection of unsetting a tracking branch. |
133 Private slot to handle the selection of unsetting a tracking branch. |
138 |
134 |
139 @param checked state of the selection (boolean) |
135 @param checked state of the selection (boolean) |
140 """ |
136 """ |
141 self.__updateOK() |
137 self.__updateOK() |
142 |
138 |
143 @pyqtSlot(str) |
139 @pyqtSlot(str) |
144 def on_branchCombo_editTextChanged(self, text): |
140 def on_branchCombo_editTextChanged(self, text): |
145 """ |
141 """ |
146 Private slot to handle a change of the branch. |
142 Private slot to handle a change of the branch. |
147 |
143 |
148 @param text branch name entered in the combo (string) |
144 @param text branch name entered in the combo (string) |
149 """ |
145 """ |
150 self.__updateOK() |
146 self.__updateOK() |
151 |
147 |
152 @pyqtSlot(str) |
148 @pyqtSlot(str) |
153 def on_newBranchNameEdit_textChanged(self, text): |
149 def on_newBranchNameEdit_textChanged(self, text): |
154 """ |
150 """ |
155 Private slot to handle a change of the new branch. |
151 Private slot to handle a change of the new branch. |
156 |
152 |
157 @param text new branch name entered (string) |
153 @param text new branch name entered (string) |
158 """ |
154 """ |
159 self.__updateOK() |
155 self.__updateOK() |
160 |
156 |
161 def getParameters(self): |
157 def getParameters(self): |
162 """ |
158 """ |
163 Public method to retrieve the branch data. |
159 Public method to retrieve the branch data. |
164 |
160 |
165 @return tuple of an int, four strings and a boolean |
161 @return tuple of an int, four strings and a boolean |
166 (branch operation, branch name, revision, new branch name, |
162 (branch operation, branch name, revision, new branch name, |
167 remote branch name, enforce operation) |
163 remote branch name, enforce operation) |
168 """ |
164 """ |
169 branch = self.branchCombo.currentText().replace(" ", "_") |
165 branch = self.branchCombo.currentText().replace(" ", "_") |
170 |
166 |
171 if self.createBranchButton.isChecked(): |
167 if self.createBranchButton.isChecked(): |
172 branchOp = GitBranchDialog.CreateBranch |
168 branchOp = GitBranchDialog.CreateBranch |
173 elif self.deleteBranchButton.isChecked(): |
169 elif self.deleteBranchButton.isChecked(): |
174 branchOp = GitBranchDialog.DeleteBranch |
170 branchOp = GitBranchDialog.DeleteBranch |
175 elif self.moveBranchButton.isChecked(): |
171 elif self.moveBranchButton.isChecked(): |