Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph

Merge with stable

Changeset 2f06fb2116a1

Parents acf33fe36841

Parents 4172a81623d1

by Steve Borho

Changes to 9 files · Browse files at 2f06fb2116a1 Showing diff from parent acf33fe36841 4172a81623d1 Diff from another changeset...

 
191
192
193
194
 
195
196
197
198
199
200
201
202
203
 
 
204
205
206
 
191
192
193
 
194
195
 
196
197
198
199
 
 
 
200
201
202
203
204
@@ -191,16 +191,14 @@
  FD = QFileDialog   if select['type'] == 'files':   caption = _('Select Destination Folder') - path = FD.getExistingDirectory(parent=self, caption=caption, + response = FD.getExistingDirectory(parent=self, caption=caption,   directory=dest, options=FD.ShowDirsOnly | FD.ReadOnly) - response = str(path)   else:   caption = _('Open File')   ext = '*' + select['ext']   filter = '%s (%s)\nAll Files (*.*)' % (select['label'], ext) - filename = FD.getOpenFileName(parent=self, caption=caption, - directory=dest, filter=filter, options=FD.ReadOnly ); - response = str(filename) + response = FD.getOpenFileName(parent=self, caption=caption, + directory=dest, filter=filter, options=FD.ReadOnly)   if response:   self.dest_edit.setText(response)   self.update_path()
 
10
11
12
13
 
14
15
16
 
232
233
234
 
235
236
237
 
419
420
421
422
 
423
424
425
 
10
11
12
 
13
14
15
16
 
232
233
234
235
236
237
238
 
420
421
422
 
423
424
425
426
@@ -10,7 +10,7 @@
 from tortoisehg.util import hglib  from tortoisehg.hgqt.i18n import _  from tortoisehg.hgqt import qtlib, csinfo, i18n, cmdui, status, resolve -from tortoisehg.hgqt import commit, qscilib, thgrepo +from tortoisehg.hgqt import qscilib, thgrepo, messageentry    from PyQt4.QtCore import *  from PyQt4.QtGui import * @@ -232,6 +232,7 @@
  cmd = hglib.fromunicode(cmd)   repo = self.repo   if cmd == 'commit': + from tortoisehg.hgqt import commit   dlg = commit.CommitDialog(repo, [], {}, self.wizard())   dlg.finished.connect(dlg.deleteLater)   dlg.exec_() @@ -419,7 +420,7 @@
  # commit message area   msg_sep = qtlib.LabeledSeparator(_('Commit message'))   self.layout().addWidget(msg_sep) - msgEntry = commit.MessageEntry(self) + msgEntry = messageentry.MessageEntry(self)   msgEntry.installEventFilter(qscilib.KeyPressInterceptor(self))   msgEntry.refresh(repo)   msgEntry.loadSettings(QSettings(), 'backout/message')
 
9
10
11
 
 
 
 
 
 
 
12
13
14
 
15
16
17
18
19
20
21
22
 
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
 
9
10
11
12
13
14
15
16
17
18
19
20
 
21
22
 
 
 
 
23
24
25
 
27
28
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
31
32
@@ -9,14 +9,17 @@
   from mercurial import ui, util, error   +from tortoisehg.util import hglib, shlib, wconfig, bugtraq + +from tortoisehg.hgqt.i18n import _ +from tortoisehg.hgqt.messageentry import MessageEntry +from tortoisehg.hgqt import qtlib, qscilib, status, cmdui, branchop, revpanel +from tortoisehg.hgqt import hgrcutil, mq +  from PyQt4.QtCore import *  from PyQt4.QtGui import * -from PyQt4.Qsci import QsciScintilla, QsciAPIs, QsciLexerMakefile +from PyQt4.Qsci import QsciAPIs   -from tortoisehg.hgqt.i18n import _ -from tortoisehg.util import hglib, shlib, wconfig, bugtraq -from tortoisehg.hgqt import qtlib, qscilib, status, cmdui, branchop, revpanel -from tortoisehg.hgqt import hgrcutil, mq    # Technical Debt for CommitWidget  # disable commit button while no message is entered or no files are selected @@ -24,136 +27,6 @@
 # spell check / tab completion  # in-memory patching / committing chunk selected files   -class MessageEntry(qscilib.Scintilla): - - def __init__(self, parent, getCheckedFunc=None): - super(MessageEntry, self).__init__(parent) - self.setEdgeColor(QColor('LightSalmon')) - self.setEdgeMode(QsciScintilla.EdgeLine) - self.setReadOnly(False) - self.setMarginWidth(1, 0) - self.setFont(qtlib.getfont('fontcomment').font()) - self.setCaretWidth(10) - self.setCaretLineBackgroundColor(QColor("#e6fff0")) - self.setCaretLineVisible(True) - self.setAutoIndent(True) - self.setAutoCompletionThreshold(2) - self.setAutoCompletionSource(QsciScintilla.AcsAPIs) - self.setAutoCompletionFillupsEnabled(True) - self.setLexer(QsciLexerMakefile(self)) - self.lexer().setFont(qtlib.getfont('fontcomment').font()) - self.lexer().setColor(QColor(Qt.red), QsciLexerMakefile.Error) - self.setMatchedBraceBackgroundColor(Qt.yellow) - self.setIndentationsUseTabs(False) - self.setBraceMatching(QsciScintilla.SloppyBraceMatch) - #self.setIndentationGuidesBackgroundColor(QColor("#e6e6de")) - #self.setFolding(QsciScintilla.BoxedFoldStyle) - # http://www.riverbankcomputing.com/pipermail/qscintilla/2009-February/000461.html - self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) - self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) - # default message entry widgets to word wrap, user may override - self.setWrapMode(QsciScintilla.WrapWord) - - self.getChecked = getCheckedFunc - self.setContextMenuPolicy(Qt.CustomContextMenu) - self.customContextMenuRequested.connect(self.menuRequested) - - def menuRequested(self, point): - line = self.lineAt(point) - point = self.viewport().mapToGlobal(point) - - def apply(): - line = 0 - while True: - line = self.reflowBlock(line) - if line is None: - break; - def paste(): - files = self.getChecked() - self.insert(', '.join(files)) - def settings(): - from tortoisehg.hgqt.settings import SettingsDialog - dlg = SettingsDialog(True, focus='tortoisehg.summarylen') - dlg.exec_() - - menu = self.createStandardContextMenu() - menu.addSeparator() - if self.getChecked: - action = menu.addAction(_('Paste &Filenames')) - action.triggered.connect(paste) - for name, func in [(_('App&ly Format'), apply), - (_('C&onfigure Format'), settings)]: - def add(name, func): - action = menu.addAction(name) - action.triggered.connect(func) - add(name, func) - return menu.exec_(point) - - def refresh(self, repo): - self.setEdgeColumn(repo.summarylen) - self.setIndentationWidth(repo.tabwidth) - self.setTabWidth(repo.tabwidth) - self.summarylen = repo.summarylen - - def reflowBlock(self, line): - lines = self.text().split('\n', QString.KeepEmptyParts) - if line >= len(lines): - return None - if not len(lines[line]) > 1: - return line+1 - - # find boundaries (empty lines or bounds) - b = line - while b and len(lines[b-1]) > 1: - b = b - 1 - e = line - while e+1 < len(lines) and len(lines[e+1]) > 1: - e = e + 1 - group = QStringList([lines[l].simplified() for l in xrange(b, e+1)]) - sentence = group.join(' ') - parts = sentence.split(' ', QString.SkipEmptyParts) - - outlines = QStringList() - line = QStringList() - partslen = 0 - for part in parts: - if partslen + len(line) + len(part) + 1 > self.summarylen: - if line: - outlines.append(line.join(' ')) - line, partslen = QStringList(), 0 - line.append(part) - partslen += len(part) - if line: - outlines.append(line.join(' ')) - - self.beginUndoAction() - self.setSelection(b, 0, e+1, 0) - self.removeSelectedText() - self.insertAt(outlines.join('\n')+'\n', b, 0) - self.endUndoAction() - self.setCursorPosition(b, 0) - return b + len(outlines) + 1 - - def moveCursorToEnd(self): - lines = self.lines() - if lines: - lines -= 1 - pos = self.lineLength(lines) - self.setCursorPosition(lines, pos) - self.ensureLineVisible(lines) - self.horizontalScrollBar().setSliderPosition(0) - - def keyPressEvent(self, event): - if event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_E: - line, col = self.getCursorPosition() - self.reflowBlock(line) - elif event.key() == Qt.Key_Backtab: - event.accept() - newev = QKeyEvent(event.type(), Qt.Key_Tab, Qt.ShiftModifier) - super(MessageEntry, self).keyPressEvent(newev) - else: - super(MessageEntry, self).keyPressEvent(event) -  class CommitWidget(QWidget, qtlib.TaskWidget):   'A widget that encompasses a StatusWidget and commit extras'   commitButtonEnable = pyqtSignal(bool)
 
10
11
12
13
14
 
 
15
16
17
 
295
296
297
 
298
299
300
 
496
497
498
499
 
500
501
502
 
10
11
12
 
 
13
14
15
16
17
 
295
296
297
298
299
300
301
 
497
498
499
 
500
501
502
503
@@ -10,8 +10,8 @@
   from tortoisehg.util import hglib  from tortoisehg.hgqt.i18n import _ -from tortoisehg.hgqt import qtlib, csinfo, i18n, cmdui, status, commit, resolve -from tortoisehg.hgqt import qscilib, thgrepo +from tortoisehg.hgqt import qtlib, csinfo, i18n, cmdui, status, resolve +from tortoisehg.hgqt import qscilib, thgrepo, messageentry    from PyQt4.QtCore import *  from PyQt4.QtGui import * @@ -295,6 +295,7 @@
  cmd = hglib.fromunicode(cmd)   repo = self.repo   if cmd == 'commit': + from tortoisehg.hgqt import commit   dlg = commit.CommitDialog(repo, [], {}, self)   dlg.finished.connect(dlg.deleteLater)   dlg.exec_() @@ -496,7 +497,7 @@
  # commit message area   msg_sep = qtlib.LabeledSeparator(_('Commit message'))   self.layout().addWidget(msg_sep) - msgEntry = commit.MessageEntry(self) + msgEntry = messageentry.MessageEntry(self)   msgEntry.installEventFilter(qscilib.KeyPressInterceptor(self))   msgEntry.refresh(repo)   msgEntry.loadSettings(QSettings(), 'merge/message')
Change 1 of 1 Show Entire File tortoisehg/​hgqt/​messageentry.py Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
@@ -0,0 +1,145 @@
+# messageentry.py - TortoiseHg's commit message editng widget +# +# Copyright 2011 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 PyQt4.QtCore import * +from PyQt4.QtGui import * +from PyQt4.Qsci import QsciScintilla, QsciLexerMakefile + +from tortoisehg.hgqt.i18n import _ +from tortoisehg.hgqt import qtlib, qscilib + +class MessageEntry(qscilib.Scintilla): + + def __init__(self, parent, getCheckedFunc=None): + super(MessageEntry, self).__init__(parent) + self.setEdgeColor(QColor('LightSalmon')) + self.setEdgeMode(QsciScintilla.EdgeLine) + self.setReadOnly(False) + self.setMarginWidth(1, 0) + self.setFont(qtlib.getfont('fontcomment').font()) + self.setCaretWidth(10) + self.setCaretLineBackgroundColor(QColor("#e6fff0")) + self.setCaretLineVisible(True) + self.setAutoIndent(True) + self.setAutoCompletionThreshold(2) + self.setAutoCompletionSource(QsciScintilla.AcsAPIs) + self.setAutoCompletionFillupsEnabled(True) + self.setLexer(QsciLexerMakefile(self)) + self.lexer().setFont(qtlib.getfont('fontcomment').font()) + self.lexer().setColor(QColor(Qt.red), QsciLexerMakefile.Error) + self.setMatchedBraceBackgroundColor(Qt.yellow) + self.setIndentationsUseTabs(False) + self.setBraceMatching(QsciScintilla.SloppyBraceMatch) + #self.setIndentationGuidesBackgroundColor(QColor("#e6e6de")) + #self.setFolding(QsciScintilla.BoxedFoldStyle) + # http://www.riverbankcomputing.com/pipermail/qscintilla/2009-February/000461.html + self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) + self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) + # default message entry widgets to word wrap, user may override + self.setWrapMode(QsciScintilla.WrapWord) + + self.getChecked = getCheckedFunc + self.setContextMenuPolicy(Qt.CustomContextMenu) + self.customContextMenuRequested.connect(self.menuRequested) + + def menuRequested(self, point): + line = self.lineAt(point) + point = self.viewport().mapToGlobal(point) + + def apply(): + line = 0 + while True: + line = self.reflowBlock(line) + if line is None: + break; + def paste(): + files = self.getChecked() + self.insert(', '.join(files)) + def settings(): + from tortoisehg.hgqt.settings import SettingsDialog + dlg = SettingsDialog(True, focus='tortoisehg.summarylen') + dlg.exec_() + + menu = self.createStandardContextMenu() + menu.addSeparator() + if self.getChecked: + action = menu.addAction(_('Paste &Filenames')) + action.triggered.connect(paste) + for name, func in [(_('App&ly Format'), apply), + (_('C&onfigure Format'), settings)]: + def add(name, func): + action = menu.addAction(name) + action.triggered.connect(func) + add(name, func) + return menu.exec_(point) + + def refresh(self, repo): + self.setEdgeColumn(repo.summarylen) + self.setIndentationWidth(repo.tabwidth) + self.setTabWidth(repo.tabwidth) + self.summarylen = repo.summarylen + + def reflowBlock(self, line): + lines = self.text().split('\n', QString.KeepEmptyParts) + if line >= len(lines): + return None + if not len(lines[line]) > 1: + return line+1 + + # find boundaries (empty lines or bounds) + b = line + while b and len(lines[b-1]) > 1: + b = b - 1 + e = line + while e+1 < len(lines) and len(lines[e+1]) > 1: + e = e + 1 + group = QStringList([lines[l].simplified() for l in xrange(b, e+1)]) + sentence = group.join(' ') + parts = sentence.split(' ', QString.SkipEmptyParts) + + outlines = QStringList() + line = QStringList() + partslen = 0 + for part in parts: + if partslen + len(line) + len(part) + 1 > self.summarylen: + if line: + outlines.append(line.join(' ')) + line, partslen = QStringList(), 0 + line.append(part) + partslen += len(part) + if line: + outlines.append(line.join(' ')) + + self.beginUndoAction() + self.setSelection(b, 0, e+1, 0) + self.removeSelectedText() + self.insertAt(outlines.join('\n')+'\n', b, 0) + self.endUndoAction() + self.setCursorPosition(b, 0) + return b + len(outlines) + 1 + + def moveCursorToEnd(self): + lines = self.lines() + if lines: + lines -= 1 + pos = self.lineLength(lines) + self.setCursorPosition(lines, pos) + self.ensureLineVisible(lines) + self.horizontalScrollBar().setSliderPosition(0) + + def keyPressEvent(self, event): + if event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_E: + line, col = self.getCursorPosition() + self.reflowBlock(line) + elif event.key() == Qt.Key_Backtab: + event.accept() + newev = QKeyEvent(event.type(), Qt.Key_Tab, Qt.ShiftModifier) + super(MessageEntry, self).keyPressEvent(newev) + else: + super(MessageEntry, self).keyPressEvent(event)
 
18
19
20
21
22
 
 
23
24
25
 
654
655
656
657
 
658
659
660
 
856
857
858
 
859
860
861
 
18
19
20
 
 
21
22
23
24
25
 
654
655
656
 
657
658
659
660
 
856
857
858
859
860
861
862
@@ -18,8 +18,8 @@
   from tortoisehg.util import hglib, patchctx  from tortoisehg.hgqt.i18n import _ -from tortoisehg.hgqt import qtlib, cmdui, rejects, commit, qscilib, thgrepo -from tortoisehg.hgqt import qqueue, qreorder, fileview, thgimport, status +from tortoisehg.hgqt import qtlib, cmdui, rejects, qscilib, thgrepo, status +from tortoisehg.hgqt import qqueue, qreorder, fileview, thgimport, messageentry  from tortoisehg.hgqt.qtlib import geticon    # TODO @@ -654,7 +654,7 @@
  mtbarhbox.addWidget(self.newCheckBox)   mtbarhbox.addWidget(self.patchNameLE, 1)   - self.messageEditor = commit.MessageEntry(self) + self.messageEditor = messageentry.MessageEntry(self)   self.messageEditor.installEventFilter(qscilib.KeyPressInterceptor(self))   self.messageEditor.refresh(repo)   @@ -856,6 +856,7 @@
  @pyqtSlot()   def qinitOrCommit(self):   if os.path.isdir(self.repo.mq.join('.hg')): + from tortoisehg.hgqt import commit   mqrepo = thgrepo.repository(None, self.repo.mq.path)   dlg = commit.CommitDialog(mqrepo, [], {}, self)   dlg.finished.connect(dlg.deleteLater)
 
16
17
18
19
20
 
21
22
23
 
36
37
38
39
 
40
41
42
 
16
17
18
 
 
19
20
21
22
 
35
36
37
 
38
39
40
41
@@ -16,8 +16,7 @@
   from tortoisehg.util import hglib  from tortoisehg.hgqt.i18n import _ -from tortoisehg.hgqt import cmdui, qscilib, qtlib -from tortoisehg.hgqt.commit import MessageEntry +from tortoisehg.hgqt import cmdui, qscilib, qtlib, messageentry    class QFoldDialog(QDialog):   @@ -36,7 +35,7 @@
    mlbl = QLabel(_('New patch message:'))   self.layout().addWidget(mlbl) - self.msgte = MessageEntry(self) + self.msgte = messageentry.MessageEntry(self)   self.msgte.installEventFilter(qscilib.KeyPressInterceptor(self))   self.layout().addWidget(self.msgte)  
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
 
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
 
410
411
412
 
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
 
486
487
488
 
489
490
491
492
493
494
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
 # repotreeitem.py - treeitems for the reporegistry  #  # Copyright 2010 Adrian Buehlmann <adrian@cadifra.com>  #  # This software may be used and distributed according to the terms of the  # GNU General Public License version 2 or any later version.    import sys, os    from mercurial import node  from mercurial import ui, hg, util, error    from tortoisehg.util import hglib  from tortoisehg.hgqt.i18n import _  from tortoisehg.hgqt import qtlib, hgrcutil    from PyQt4.QtCore import *  from PyQt4.QtGui import *      xmlClassMap = {   'allgroup': 'AllRepoGroupItem',   'group': 'RepoGroupItem',   'repo': 'RepoItem',   'subrepo': 'SubrepoItem',   'treeitem': 'RepoTreeItem',   }    inverseXmlClassMap = {}    def xmlToClass(ele):   return xmlClassMap[ele]    def classToXml(classname):   if len(inverseXmlClassMap) == 0:   for k,v in xmlClassMap.iteritems():   inverseXmlClassMap[v] = k   return inverseXmlClassMap[classname]    def undumpObject(xr):   classname = xmlToClass(str(xr.name().toString()))   class_ = getattr(sys.modules[RepoTreeItem.__module__], classname)   obj = class_()   obj.undump(xr)   return obj      class RepoTreeItem(object):   def __init__(self, parent=None):   self._parent = parent   self.childs = []   self._row = 0     def appendChild(self, child):   child._row = len(self.childs)   child._parent = self   self.childs.append(child)     def insertChild(self, row, child):   child._row = row   child._parent = self   self.childs.insert(row, child)     def child(self, row):   return self.childs[row]     def childCount(self):   return len(self.childs)     def columnCount(self):   return 2     def data(self, column, role):   return QVariant()     def setData(self, column, value):   return False     def row(self):   return self._row     def parent(self):   return self._parent     def menulist(self):   return []     def flags(self):   return Qt.NoItemFlags     def removeRows(self, row, count):   cs = self.childs   remove = cs[row : row + count]   keep = cs[:row] + cs[row + count:]   self.childs = keep   for c in remove:   c._row = 0   c._parent = None   for i, c in enumerate(keep):   c._row = i   return True     def dump(self, xw):   for c in self.childs:   c.dumpObject(xw)     def undump(self, xr):   while not xr.atEnd():   xr.readNext()   if xr.isStartElement():   try:   item = undumpObject(xr)   self.appendChild(item)   except KeyError:   pass # ignore unknown classes in xml   elif xr.isEndElement():   break     def dumpObject(self, xw):   xw.writeStartElement(classToXml(self.__class__.__name__))   self.dump(xw)   xw.writeEndElement()     def isRepo(self):   return False     def details(self):   return ''     def getRepoItem(self, reporoot, lookForSubrepos=False):   for c in self.childs:   ri = c.getRepoItem(reporoot, lookForSubrepos=lookForSubrepos)   if ri:   return ri   return None     def okToDelete(self):   return True     def getSupportedDragDropActions(self):   return Qt.MoveAction      class RepoItem(RepoTreeItem):   shortnameChanged = pyqtSignal()   def __init__(self, root=None, parent=None):   RepoTreeItem.__init__(self, parent)   self._root = root or ''   self._shortname = u''   self._basenode = node.nullid   self._repotype = 'hg'   # The _valid property is used to display a "warning" icon for repos   # that cannot be open   # If root is set we assume that the repo is valid (an actual validity   # test would require calling hg.repository() which is expensive)   # Regardless, self._valid may be set to False if self.undump() fails   if self._root:   self._valid = True   else:   self._valid = False   self._isActiveTab = False     def isRepo(self):   return True     def rootpath(self):   return self._root     def shortname(self):   if self._shortname:   return self._shortname   else:   return hglib.tounicode(os.path.basename(self._root))     def repotype(self):   return self._repotype     def basenode(self):   """Return node id of revision 0"""   return self._basenode     def setBaseNode(self, basenode):   self._basenode = basenode     def setShortName(self, uname):   if uname != self._shortname:   self._shortname = uname     def data(self, column, role):   if role == Qt.DecorationRole:   if column == 0:   ico = qtlib.geticon('hg')   if not self._valid:   ico = qtlib.getoverlaidicon(ico, qtlib.geticon('dialog-warning'))   return QVariant(ico)   return QVariant()   elif role == Qt.FontRole:   if self._isActiveTab:   font = QFont()   font.setBold(True)   else:   return QVariant()   return QVariant(font)   if column == 0:   return QVariant(self.shortname())   elif column == 1:   return QVariant(self.shortpath())   return QVariant()     def getCommonPath(self):   return self.parent().getCommonPath()     def shortpath(self):   try:   cpath = self.getCommonPath()   except:   cpath = ''   spath = os.path.normpath(self._root)   if cpath and spath.startswith(cpath):   iShortPathStart = len(cpath) + 1   spath = spath[iShortPathStart:]   return hglib.tounicode(spath)     def menulist(self):   return ['open', 'clone', 'addsubrepo', None, 'explore',   'terminal', 'copypath', None, 'rename', 'remove', None, 'settings']     def flags(self):   return (Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled   | Qt.ItemIsEditable)     def dump(self, xw):   xw.writeAttribute('root', hglib.tounicode(self._root))   xw.writeAttribute('shortname', self.shortname())   xw.writeAttribute('basenode', node.hex(self.basenode()))     def undump(self, xr):   self._valid = True   a = xr.attributes()   self._root = hglib.fromunicode(a.value('', 'root').toString())   self._shortname = unicode(a.value('', 'shortname').toString())   self._basenode = node.bin(str(a.value('', 'basenode').toString()))   RepoTreeItem.undump(self, xr)     def details(self):   return _('Local Repository %s') % hglib.tounicode(self._root)     def getRepoItem(self, reporoot, lookForSubrepos=False):   reporoot = os.path.normcase(reporoot)   if (reporoot == os.path.normcase(self._root)):   return self   if lookForSubrepos:   return super(RepoItem, self).getRepoItem(reporoot, lookForSubrepos)   return None     def appendSubrepos(self, repo=None):   invalidRepoList = []   try:   sri = None   if repo is None:   repo = hg.repository(ui.ui(), self._root)   wctx = repo['.']   for subpath in wctx.substate:   sri = None   abssubpath = repo.wjoin(subpath)   subtype = wctx.substate[subpath][2]   sriIsValid = os.path.isdir(abssubpath)   sri = SubrepoItem(abssubpath, subtype=subtype)   sri._valid = sriIsValid   self.appendChild(sri)     if not sriIsValid:   self._valid = False   sri._valid = False   invalidRepoList.append(repo.wjoin(subpath))   return invalidRepoList   continue     if subtype == 'hg':   # Only recurse into mercurial subrepos   sctx = wctx.sub(subpath)   invalidSubrepoList = sri.appendSubrepos(sctx._repo)   if invalidSubrepoList:   self._valid = False   invalidRepoList += invalidSubrepoList     except (EnvironmentError, error.RepoError, util.Abort), e:   # Add the repo to the list of repos/subrepos   # that could not be open   self._valid = False   if sri:   sri._valid = False   invalidRepoList.append(abssubpath)   invalidRepoList.append(self._root)     return invalidRepoList     def setActive(self, sel):   # Will be set to true when this item corresponds to the currently   # selected tab widget on the workbench   self._isActiveTab = sel     def setData(self, column, value):   if column == 0:   shortname = hglib.fromunicode(value.toString())   abshgrcpath = os.path.join(self.rootpath(), '.hg', 'hgrc')   if not hgrcutil.setConfigValue(abshgrcpath, 'web.name', shortname):   qtlib.WarningMsgBox(_('Unable to update repository name'),   _('An error occurred while updating the repository hgrc '   'file (%s)' % abshgrcpath))   return False + self.setShortName(shortname)   return True   return False      class SubrepoItem(RepoItem):   _subrepoType2IcoMap = {   'hg': 'hg',   'git': 'thg-git-subrepo',   'svn': 'thg-svn-subrepo',   }     def __init__(self, repo=None, parent=None, parentrepo=None, subtype='hg'):   RepoItem.__init__(self, repo, parent)   self._parentrepo = parentrepo   self._repotype = subtype   if self._repotype != 'hg':   # Make sure that we cannot drag non hg subrepos   # To do so we disable the dumpObject method for non hg subrepos   def doNothing(dummy):   pass   self.dumpObject = doNothing     # Limit the context menu to those actions that are valid for non   # mercurial subrepos   def nonHgMenulist():   return ['remove', None, 'explore', 'terminal']   self.menulist = nonHgMenulist     def data(self, column, role):   if role == Qt.DecorationRole:   if column == 0:   subiconame = SubrepoItem._subrepoType2IcoMap.get(self._repotype, None)   if subiconame is None:   # Unknown (or generic) subrepo type   ico = qtlib.geticon('thg-subrepo')   else:   # Overlay the "subrepo icon" on top of the selected subrepo   # type icon   ico = qtlib.geticon(subiconame)   ico = qtlib.getoverlaidicon(ico, qtlib.geticon('thg-subrepo'))     if not self._valid:   ico = qtlib.getoverlaidicon(ico, qtlib.geticon('dialog-warning'))     return QVariant(ico)   return QVariant()   else:   return super(SubrepoItem, self).data(column, role)     def menulist(self):   if isinstance(self._parent, RepoGroupItem):   return super(SubrepoItem, self).menulist()   else:   return ['open', 'clone', 'addsubrepo', None, 'explore', 'terminal',   'copypath', None, 'settings']     def getSupportedDragDropActions(self):   if issubclass(type(self.parent()), RepoGroupItem):   return Qt.MoveAction   else:   return Qt.CopyAction     def flags(self):   # Only stand-alone subrepo items can be renamed   if isinstance(self._parent, RepoGroupItem):   return super(SubrepoItem, self).flags()   else:   return (Qt.ItemIsEnabled | Qt.ItemIsSelectable   | Qt.ItemIsDragEnabled)      class RepoGroupItem(RepoTreeItem):   def __init__(self, name=None, parent=None):   RepoTreeItem.__init__(self, parent)   if name:   self.name = name   else:   self.name = QString()   self._commonpath = ''     def data(self, column, role):   if role == Qt.DecorationRole:   if column == 0:   s = QApplication.style()   ico = s.standardIcon(QStyle.SP_DirIcon)   return QVariant(ico)   return QVariant()   if column == 0:   return QVariant(self.name)   elif column == 1:   return QVariant(self.getCommonPath())   return QVariant()     def setData(self, column, value):   if column == 0:   self.name = value.toString()   return True   return False +   def menulist(self):   return ['openAll', 'add', None, 'newGroup', None, 'rename', 'remove',   None, 'reloadRegistry'] +   def flags(self):   return (Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDropEnabled   | Qt.ItemIsDragEnabled | Qt.ItemIsEditable)     def childRoots(self):   return [c._root for c in self.childs]     def dump(self, xw):   xw.writeAttribute('name', self.name)   RepoTreeItem.dump(self, xw)     def undump(self, xr):   a = xr.attributes()   self.name = a.value('', 'name').toString()   RepoTreeItem.undump(self, xr)     def okToDelete(self):   return False     def updateCommonPath(self, cpath=None):   """   Update or set the group 'common path'     When called with no arguments, the group common path is calculated by   looking for the common path of all the repos on a repo group     When called with an argument, the group common path is set to the input   argument. This is commonly used to set the group common path to an empty   string, thus disabling the "show short paths" functionality.   """   if not cpath is None:   self._commonpath = cpath   elif len(self.childs) == 0:   # If a group has no repo items, the common path is empty   self._commonpath = ''   else:   # Calculate the group common path   def splitPath(path):   path = os.path.normpath(path)   return path.split(os.path.sep)[:-1]     cpath = splitPath(self.childs[0].rootpath())     for c in self.childs[1:]:   if not cpath:   # There is no common path   break   # Update the common path to the common path with the current   # child   childpath = splitPath(c.rootpath())   # The common part cannot go beyond the smaller of the current   # common path and the current child   clen = min(len(cpath), len(childpath))   cpath = cpath[:clen]   childpath = childpath[:clen]   if cpath == childpath:   # Trivial case   continue   for n in range(clen):   # From left to right, find the first path part that is not   # the same   if cpath[n] != childpath[n]:   cpath = cpath[:n]   break   self._commonpath = os.path.sep.join(cpath)   return self._commonpath     def getCommonPath(self):   return self._commonpath    class AllRepoGroupItem(RepoGroupItem):   def __init__(self, parent=None):   RepoGroupItem.__init__(self, name=_('default'), parent=parent) +   def menulist(self):   return ['openAll', 'add', None, 'newGroup', None, 'rename',   None, 'reloadRegistry'] +   def undump(self, xr):   a = xr.attributes()   name = a.value('', 'name').toString()   if name:   self.name = name   RepoTreeItem.undump(self, xr)
 
1413
1414
1415
1416
 
1417
1418
 
1419
1420
 
 
1421
1422
1423
 
1446
1447
1448
1449
 
1450
1451
1452
 
1468
1469
1470
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1471
1472
1473
 
1413
1414
1415
 
1416
1417
 
1418
1419
 
1420
1421
1422
1423
1424
 
1447
1448
1449
 
1450
1451
1452
1453
 
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
@@ -1413,11 +1413,12 @@
  def exportRevisions(self, revisions):   if not revisions:   revisions = [self.rev] - dir = QFileDialog.getExistingDirectory(self, _('Export patch'), + udir = QFileDialog.getExistingDirectory(self, _('Export patch'),   hglib.tounicode(self.repo.root)) - if not dir: + if not udir:   return - epath = os.path.join(hglib.fromunicode(dir), + strdir = hglib.fromunicode(udir) + epath = os.path.join(strdir,   hglib.fromunicode(self.repo.shortname)+'_%r.patch')     cmdline = ['export', '--repository', self.repo.root, '--verbose', @@ -1446,7 +1447,7 @@
  'in the selected location (%s).\n\n') \   % (len(existingRevisions),   " ,".join([str(rev) for rev in existingRevisions]), - dir) + udir)     warningMessage += \   _('What do you want to do?\n') + u'\n' + \ @@ -1468,6 +1469,29 @@
    self.runCommand(cmdline)   + if len(revisions) == 1: + # Show a message box with a link to the export folder and to the + # exported file + rev = revisions[0] + patchfilename = os.path.normpath(epath % rev) + patchdirname = os.path.normpath(strdir) + patchshortname = os.path.basename(patchfilename) + qtlib.InfoMsgBox(_('Patch exported'), + _('Revision #%d (%s) was exported to:<p>' + '<a href="file:///%s">%s</a>%s' + '<a href="file:///%s">%s</a>') \ + % (rev, str(self.repo[rev]), + patchdirname, patchdirname, os.path.sep, + patchfilename, patchshortname)) + else: + # Show a message box with a link to the export folder + qtlib.InfoMsgBox(_('Patches exported'), + _('%d patches were exported to:<p>' + '<a href="file:///%s">%s</a>') \ + % (len(revisions), + strdir, + strdir)) +   def visualDiffRevision(self):   opts = dict(change=self.rev)   dlg = visdiff.visualdiff(self.repo.ui, self.repo, [], opts)