eric6/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesFoldDialog.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2011 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to enter data to fold patches.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot, Qt
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem
14
15 from .Ui_HgQueuesFoldDialog import Ui_HgQueuesFoldDialog
16
17 import UI.PixmapCache
18
19
20 class HgQueuesFoldDialog(QDialog, Ui_HgQueuesFoldDialog):
21 """
22 Class implementing a dialog to enter data to fold patches.
23 """
24 def __init__(self, patchesList, parent=None):
25 """
26 Constructor
27
28 @param patchesList list of patches to select from (list of strings)
29 @param parent reference to the parent widget (QWidget)
30 """
31 super(HgQueuesFoldDialog, self).__init__(parent)
32 self.setupUi(self)
33
34 self.addButton.setIcon(UI.PixmapCache.getIcon("plus.png"))
35 self.removeButton.setIcon(UI.PixmapCache.getIcon("minus.png"))
36 self.upButton.setIcon(UI.PixmapCache.getIcon("1uparrow.png"))
37 self.downButton.setIcon(UI.PixmapCache.getIcon("1downarrow.png"))
38
39 for patch in patchesList:
40 name, summary = patch.split("@@")
41 QTreeWidgetItem(self.sourcePatches, [name, summary])
42
43 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
44
45 def __updateOkButton(self):
46 """
47 Private slot to update the status of the OK button.
48 """
49 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
50 self.selectedPatches.topLevelItemCount() != 0)
51
52 @pyqtSlot()
53 def on_addButton_clicked(self):
54 """
55 Private slot to add a patch to the list of selected patches.
56 """
57 row = self.sourcePatches.indexOfTopLevelItem(
58 self.sourcePatches.currentItem())
59 itm = self.sourcePatches.takeTopLevelItem(row)
60
61 curItm = self.selectedPatches.currentItem()
62 if curItm is not None:
63 row = self.selectedPatches.indexOfTopLevelItem(curItm) + 1
64 self.selectedPatches.insertTopLevelItem(row, itm)
65 else:
66 self.selectedPatches.addTopLevelItem(itm)
67
68 self.__updateOkButton()
69
70 @pyqtSlot()
71 def on_removeButton_clicked(self):
72 """
73 Private slot to remove a patch from the list of selected patches.
74 """
75 row = self.selectedPatches.indexOfTopLevelItem(
76 self.selectedPatches.currentItem())
77 itm = self.selectedPatches.takeTopLevelItem(row)
78 self.sourcePatches.addTopLevelItem(itm)
79 self.sourcePatches.sortItems(0, Qt.AscendingOrder)
80
81 self.__updateOkButton()
82
83 @pyqtSlot()
84 def on_upButton_clicked(self):
85 """
86 Private slot to move a patch up in the list.
87 """
88 row = self.selectedPatches.indexOfTopLevelItem(
89 self.selectedPatches.currentItem())
90 if row > 0:
91 targetRow = row - 1
92 itm = self.selectedPatches.takeTopLevelItem(row)
93 self.selectedPatches.insertTopLevelItem(targetRow, itm)
94 self.selectedPatches.setCurrentItem(itm)
95
96 @pyqtSlot()
97 def on_downButton_clicked(self):
98 """
99 Private slot to move a patch down in the list.
100 """
101 row = self.selectedPatches.indexOfTopLevelItem(
102 self.selectedPatches.currentItem())
103 if row < self.selectedPatches.topLevelItemCount() - 1:
104 targetRow = row + 1
105 itm = self.selectedPatches.takeTopLevelItem(row)
106 self.selectedPatches.insertTopLevelItem(targetRow, itm)
107 self.selectedPatches.setCurrentItem(itm)
108
109 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
110 def on_sourcePatches_currentItemChanged(self, current, previous):
111 """
112 Private slot to react on changes of the current item of source patches.
113
114 @param current reference to the new current item (QTreeWidgetItem)
115 @param previous reference to the previous current item
116 (QTreeWidgetItem)
117 """
118 self.addButton.setEnabled(current is not None)
119
120 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
121 def on_selectedPatches_currentItemChanged(self, current, previous):
122 """
123 Private slot to react on changes of the current item of selected
124 patches.
125
126 @param current reference to the new current item (QTreeWidgetItem)
127 @param previous reference to the previous current item
128 (QTreeWidgetItem)
129 """
130 self.removeButton.setEnabled(current is not None)
131
132 row = self.selectedPatches.indexOfTopLevelItem(current)
133 self.upButton.setEnabled(row > 0)
134 self.downButton.setEnabled(
135 row < self.selectedPatches.topLevelItemCount() - 1)
136
137 def getData(self):
138 """
139 Public method to retrieve the entered data.
140
141 @return tuple of commit message and list of selected patches
142 (string, list of strings)
143 """
144 patchesList = []
145 for row in range(self.selectedPatches.topLevelItemCount()):
146 patchesList.append(self.selectedPatches.topLevelItem(row).text(0))
147
148 return self.messageEdit.toPlainText(), patchesList

eric ide

mercurial