Plugins/VcsPlugins/vcsGit/GitBranchDialog.py

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

eric ide

mercurial