Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.0, 2.0.1, and 2.0.2

stable qreorder: Show patch description on patch list

Changeset 08a1010521ce

Parent 35e27b5924eb

by Angel Ezquerra

Changes to one file · Browse files at 08a1010521ce Showing diff from parent 35e27b5924eb Diff from another changeset...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
 
 
 
174
175
176
177
178
179
180
181
182
183
184
185
 
186
187
188
 
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
 
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
 
 
185
186
187
188
189
190
191
192
193
194
195
196
197
198
 
199
200
201
 
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
 # qreorder.py - reorder unapplied MQ patches  #  # Copyright 2010 Steve Borho <steve@borho.org>  #  # This software may be used and distributed according to the terms of the  # GNU General Public License version 2, incorporated herein by reference.    import os    from hgext import mq    from tortoisehg.hgqt import qtlib, thgrepo, qrename  from tortoisehg.util import hglib, paths  from tortoisehg.hgqt.i18n import _    from PyQt4.QtCore import *  from PyQt4.QtGui import *    # TODO:  # This approach will nuke any user configured guards  # Explicit refresh    class QReorderDialog(QDialog):   def __init__(self, repo, parent=None):   QDialog.__init__(self, parent)     self.setWindowTitle(_('Reorder Unapplied Patches'))   self.setWindowFlags(Qt.Window)   self.setWindowIcon(qtlib.geticon('hg-qreorder'))     self.repo = repo   self.cached = None   repo.repositoryChanged.connect(self.refresh)     layout = QVBoxLayout()   layout.setMargin(4)   self.setLayout(layout)     hb = QHBoxLayout()   hb.setMargin(2)   lbl = QLabel(_('Repository:'))   hb.addWidget(lbl)   le = QLineEdit()   hb.addWidget(le)   le.setReadOnly(True)   le.setFont(qtlib.getfont('fontlist').font())   le.setText(repo.displayname)   le.setFocusPolicy(Qt.NoFocus)   layout.addLayout(hb)   hl = qtlib.LabeledSeparator('')   layout.addWidget(hl)     class PatchListWidget(QListWidget):   menuRequested = pyqtSignal(QPoint, object)   def __init__(self, parent):   QListWidget.__init__(self, parent)   self.setCurrentRow(0)   def contextMenuEvent(self, event):   self.menuRequested.emit(event.globalPos(),   hglib.fromunicode(self.item(self.currentRow()).text()))   def focusInEvent(self, e):   i = self.item(self.currentRow())   if i:   self.parent().parent().showSummary(i)   QListWidget.focusInEvent(self, e)     ugb = QGroupBox(_('Unapplied Patches - drag to reorder'))   ugb.setLayout(QVBoxLayout())   ugb.layout().setContentsMargins(*(0,)*4)   self.ulw = PatchListWidget(self)   self.ulw.setDragDropMode(QListView.InternalMove)   ugb.layout().addWidget(self.ulw)   self.ulw.currentItemChanged.connect(lambda:   self.showSummary(self.ulw.item(self.ulw.currentRow())))   self.ulw.menuRequested.connect(self.patchlistMenuRequest)   layout.addWidget(ugb)     agb = QGroupBox(_('Applied Patches'))   agb.setLayout(QVBoxLayout())   agb.layout().setContentsMargins(*(0,)*4)   self.alw = PatchListWidget(self)   agb.layout().addWidget(self.alw)   self.alw.currentItemChanged.connect(lambda:   self.showSummary(self.alw.item(self.alw.currentRow())))   self.alw.menuRequested.connect(self.patchlistMenuRequest)   layout.addWidget(agb)     slbl = QLabel(_('Summary:'))   layout.addWidget(slbl)   self.summ = QTextEdit()   self.summ.setFont(qtlib.getfont('fontcomment').font())   self.summ.setMinimumWidth(500) # min 80 chars   self.summ.setMaximumHeight(100)   self.summ.setReadOnly(True)   self.summ.setFocusPolicy(Qt.NoFocus)   layout.addWidget(self.summ)     self._readsettings()     self.refresh()     # dialog buttons   BB = QDialogButtonBox   bb = QDialogButtonBox(BB.Ok|BB.Cancel)   self.apply_button = bb.button(BB.Apply)   bb.accepted.connect(self.accept)   bb.rejected.connect(self.reject)   bb.button(BB.Ok).setDefault(True)   layout.addWidget(bb)     self.alw.setCurrentRow(0)   self.ulw.setCurrentRow(0)   self.ulw.setFocus()     def patchlistMenuRequest(self, point, selection):   self.menuselection = selection   menu = QMenu(self)   act = QAction(_('Rename patch'), self)   act.triggered.connect(self.qrenamePatch)   menu.addAction(act)   menu.exec_(point)     def qrenamePatch(self):   patchname = self.menuselection   dlg = qrename.QRenameDialog(self.repo, patchname, self)   dlg.finished.connect(dlg.deleteLater)   dlg.output.connect(self.parent().output)   dlg.makeLogVisible.connect(self.parent().makeLogVisible)   dlg.exec_()     def refresh(self):   patchnames = self.repo.mq.series[:]   applied = [p.name for p in self.repo.mq.applied]   if (patchnames, applied) == self.cached:   return     alw, ulw = self.alw, self.ulw   if self.cached:   if applied != self.cached[1]:   cw = alw   else:   cw = ulw   else:   cw = ulw   ar = alw.currentRow()   ur = ulw.currentRow()   ulw.clear()   alw.clear()   for p in reversed(patchnames): - item = QListWidgetItem(hglib.tounicode(p)) + # Each row in the patch list has the + # format [patchname] patchdescription + # The patch description is the first line of the patch message + # If the message has more than one line, we add "..." to the first + # line to create the patch description + patchmessage = mq.patchheader(self.repo.mq.join(p)).message + patchdesc = patchmessage[0] + if len(patchmessage) > 1: + patchdesc = patchdesc + '...' + item = QListWidgetItem('[%s]\t%s' % (hglib.tounicode(p), hglib.tounicode(patchdesc))) + # Save the patchname with the item so that we can easily + # retrieve it later + item.patchname = p +   if p in applied:   item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)   item.setForeground(QColor(111,111,111)) # gray, like disabled   alw.addItem(item)   else:   item.setFlags(Qt.ItemIsSelectable |   Qt.ItemIsEnabled |   Qt.ItemIsDragEnabled)   ulw.addItem(item)   self.cached = patchnames, applied   if cw == ulw:   alw.setCurrentRow(ar)   ulw.setCurrentRow(ur)   self.ulw.setFocus()   else:   ulw.setCurrentRow(ur)   alw.setCurrentRow(ar)   self.alw.setFocus()     def showSummary(self, item):   try: - patchname = hglib.fromunicode(item.text()) - txt = '\n'.join(mq.patchheader(self.repo.mq.join(patchname)).message) + # Note that item.patchname uses the local encoding and hence does + # not need to be converted from unicode + txt = '\n'.join(mq.patchheader(self.repo.mq.join(item.patchname)).message)   self.summ.setText(hglib.tounicode(txt))   except:   pass     def accept(self):   self._writesettings()   try:   self.repo.incrementBusyCount()   lines = []   for i in xrange(self.alw.count()-1, -1, -1):   item = self.alw.item(i) - lines.append(hglib.fromunicode(item.text())) + lines.append(item.patchname)   for i in xrange(self.ulw.count()-1, -1, -1):   item = self.ulw.item(i) - lines.append(hglib.fromunicode(item.text())) + lines.append(item.patchname)   if lines:   fp = self.repo.mq.opener('series', 'wb')   fp.write('\n'.join(lines))   fp.close()   finally:   self.repo.decrementBusyCount()   QDialog.accept(self)     def reject(self):   QDialog.reject(self)     def closeEvent(self, event):   self._writesettings()   super(QReorderDialog, self).closeEvent(event)     def _readsettings(self):   s = QSettings()   self.restoreGeometry(s.value('qreorder/geom').toByteArray())     def _writesettings(self):   s = QSettings()   s.setValue('qreorder/geom', self.saveGeometry())    def run(ui, *pats, **opts):   repo = thgrepo.repository(None, paths.find_root())   if hasattr(repo, 'mq'):   return QReorderDialog(repo)   else:   qtlib.ErrorMsgBox(_('TortoiseHg Error'),   _('Please enable the MQ extension first.'))