|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2010 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the data for a merge 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_HgMergeDialog import Ui_HgMergeDialog |
|
16 |
|
17 |
|
18 class HgMergeDialog(QDialog, Ui_HgMergeDialog): |
|
19 """ |
|
20 Class implementing a dialog to enter the data for a merge operation. |
|
21 """ |
|
22 def __init__(self, tagsList, branchesList, bookmarksList=None, |
|
23 parent=None): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param tagsList list of tags (list of strings) |
|
28 @param branchesList list of branches (list of strings) |
|
29 @param bookmarksList list of bookmarks (list of strings) |
|
30 @param parent parent widget (QWidget) |
|
31 """ |
|
32 super(HgMergeDialog, self).__init__(parent) |
|
33 self.setupUi(self) |
|
34 |
|
35 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
|
36 |
|
37 self.tagCombo.addItems(sorted(tagsList)) |
|
38 self.branchCombo.addItems(["default"] + sorted(branchesList)) |
|
39 if bookmarksList is not None: |
|
40 self.bookmarkCombo.addItems(sorted(bookmarksList)) |
|
41 else: |
|
42 self.bookmarkButton.setHidden(True) |
|
43 self.bookmarkCombo.setHidden(True) |
|
44 |
|
45 msh = self.minimumSizeHint() |
|
46 self.resize(max(self.width(), msh.width()), msh.height()) |
|
47 |
|
48 def __updateOK(self): |
|
49 """ |
|
50 Private slot to update the OK button. |
|
51 """ |
|
52 enabled = True |
|
53 if self.idButton.isChecked(): |
|
54 enabled = self.idEdit.text() != "" |
|
55 elif self.tagButton.isChecked(): |
|
56 enabled = self.tagCombo.currentText() != "" |
|
57 elif self.branchButton.isChecked(): |
|
58 enabled = self.branchCombo.currentText() != "" |
|
59 elif self.bookmarkButton.isChecked(): |
|
60 enabled = self.bookmarkCombo.currentText() != "" |
|
61 |
|
62 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enabled) |
|
63 |
|
64 @pyqtSlot(bool) |
|
65 def on_idButton_toggled(self, checked): |
|
66 """ |
|
67 Private slot to handle changes of the ID select button. |
|
68 |
|
69 @param checked state of the button (boolean) |
|
70 """ |
|
71 self.__updateOK() |
|
72 |
|
73 @pyqtSlot(bool) |
|
74 def on_tagButton_toggled(self, checked): |
|
75 """ |
|
76 Private slot to handle changes of the Tag select button. |
|
77 |
|
78 @param checked state of the button (boolean) |
|
79 """ |
|
80 self.__updateOK() |
|
81 |
|
82 @pyqtSlot(bool) |
|
83 def on_branchButton_toggled(self, checked): |
|
84 """ |
|
85 Private slot to handle changes of the Branch select button. |
|
86 |
|
87 @param checked state of the button (boolean) |
|
88 """ |
|
89 self.__updateOK() |
|
90 |
|
91 @pyqtSlot(bool) |
|
92 def on_bookmarkButton_toggled(self, checked): |
|
93 """ |
|
94 Private slot to handle changes of the Bookmark select button. |
|
95 |
|
96 @param checked state of the button (boolean) |
|
97 """ |
|
98 self.__updateOK() |
|
99 |
|
100 @pyqtSlot(str) |
|
101 def on_idEdit_textChanged(self, txt): |
|
102 """ |
|
103 Private slot to handle changes of the ID edit. |
|
104 |
|
105 @param txt text of the edit (string) |
|
106 """ |
|
107 self.__updateOK() |
|
108 |
|
109 @pyqtSlot(str) |
|
110 def on_tagCombo_editTextChanged(self, txt): |
|
111 """ |
|
112 Private slot to handle changes of the Tag combo. |
|
113 |
|
114 @param txt text of the combo (string) |
|
115 """ |
|
116 self.__updateOK() |
|
117 |
|
118 @pyqtSlot(str) |
|
119 def on_branchCombo_editTextChanged(self, txt): |
|
120 """ |
|
121 Private slot to handle changes of the Branch combo. |
|
122 |
|
123 @param txt text of the combo (string) |
|
124 """ |
|
125 self.__updateOK() |
|
126 |
|
127 @pyqtSlot(str) |
|
128 def on_bookmarkCombo_editTextChanged(self, txt): |
|
129 """ |
|
130 Private slot to handle changes of the Bookmark combo. |
|
131 |
|
132 @param txt text of the combo (string) |
|
133 """ |
|
134 self.__updateOK() |
|
135 |
|
136 def getParameters(self): |
|
137 """ |
|
138 Public method to retrieve the merge data. |
|
139 |
|
140 @return tuple naming the revision and a flag indicating a |
|
141 forced merge (string, boolean) |
|
142 """ |
|
143 if self.numberButton.isChecked(): |
|
144 rev = "rev({0})".format(self.numberSpinBox.value()) |
|
145 elif self.idButton.isChecked(): |
|
146 rev = "id({0})".format(self.idEdit.text()) |
|
147 elif self.tagButton.isChecked(): |
|
148 rev = self.tagCombo.currentText() |
|
149 elif self.branchButton.isChecked(): |
|
150 rev = self.branchCombo.currentText() |
|
151 elif self.bookmarkButton.isChecked(): |
|
152 rev = self.bookmarkCombo.currentText() |
|
153 else: |
|
154 rev = "" |
|
155 |
|
156 return rev, self.forceCheckBox.isChecked() |