Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesFoldDialog.py

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

eric ide

mercurial