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