Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

qtlib, etc: remove ui arguments from getfont() and get*_lexer

Fonts and colors are not, cannot be, repository specific

Changeset 80029362c3d4

Parent 7bc379cf4015

by Steve Borho

Changes to 16 files · Browse files at 80029362c3d4 Showing diff from parent 7bc379cf4015 Diff from another changeset...

 
44
45
46
47
 
48
49
50
 
201
202
203
204
205
 
206
207
208
 
44
45
46
 
47
48
49
50
 
201
202
203
 
 
204
205
206
207
@@ -44,7 +44,7 @@
  self.setMarginLineNumbers(1, True)   self.setMarginType(2, QsciScintilla.TextMarginRightJustified)   self.setMouseTracking(True) - self.setFont(qtlib.getfont(ui.ui(), 'fontlog').font()) + self.setFont(qtlib.getfont('fontlog').font())   self.setContextMenuPolicy(Qt.CustomContextMenu)   self.customContextMenuRequested.connect(self.menuRequest)   self._revs = [] # by line @@ -201,8 +201,7 @@
    def _updatelexer(self, fctx):   """Update the lexer according to the given file""" - lex = lexers.get_lexer(fctx.path(), hglib.tounicode(fctx.data()), - ui=self.repo.ui) + lex = lexers.get_lexer(fctx.path(), hglib.tounicode(fctx.data()))   if lex:   self.setLexer(lex)  
 
254
255
256
257
258
 
259
260
261
 
254
255
256
 
 
257
258
259
260
@@ -254,8 +254,7 @@
  self._initmarkers()     def _initfont(self): - from mercurial import ui # XXX workaround to pass fake ui obj - tf = qtlib.getfont(ui.ui(), 'fontlog') + tf = qtlib.getfont('fontlog')   tf.changed.connect(lambda f: self.setFont(f))   self.setFont(tf.font())  
 
95
96
97
98
 
99
100
101
 
95
96
97
 
98
99
100
101
@@ -95,7 +95,7 @@
    msgte = QPlainTextEdit()   msgte.setLineWrapMode(QPlainTextEdit.NoWrap) - msgfont = qtlib.getfont(self.repo.ui, 'fontcomment') + msgfont = qtlib.getfont('fontcomment')   msgte.setFont(msgfont.font())   msgfont.changed.connect(lambda fnt: msgte.setFont(fnt))   msgte.textChanged.connect(self.msgChanged)
 
36
37
38
39
 
40
41
42
 
36
37
38
 
39
40
41
42
@@ -36,7 +36,7 @@
    def load_config(self, ui):   # TODO: connect to font changed signal - self._font = qtlib.getfont(ui, 'fontlog').font() + self._font = qtlib.getfont('fontlog').font()   self.rowheight = 8   self.users, self.aliases = [], []  
 
75
76
77
78
 
79
80
81
 
75
76
77
 
78
79
80
81
@@ -75,7 +75,7 @@
  data = f.read(head)   else:   data = '' # too big - lexer = get_lexer(self.filename, data, self.repo.ui) + lexer = get_lexer(self.filename, data)   if lexer:   lexer.setDefaultFont(self._font)   lexer.setFont(self._font)
 
334
335
336
337
 
338
339
340
341
342
 
343
344
345
 
334
335
336
 
337
338
339
340
341
 
342
343
344
345
@@ -334,12 +334,12 @@
  return     if self._mode == 'diff' and fd.diff: - lexer = get_diff_lexer(repo.ui) + lexer = get_diff_lexer()   self._cur_lexer = lexer # SJB - holding refcount?   self.sci.setLexer(lexer)   self.sci.setText(fd.diff)   else: - lexer = get_lexer(filename, fd.contents, repo.ui) + lexer = get_lexer(filename, fd.contents)   self._cur_lexer = lexer # SJB - holding refcount?   self.sci.setLexer(lexer)   nlines = fd.contents.count('\n')
 
255
256
257
258
259
 
 
260
261
262
 
255
256
257
 
 
258
259
260
261
262
@@ -255,8 +255,8 @@
  w.setUtf8(True)   w.setReadOnly(True)   w.setMarginWidth(1, 0) # hide area for line numbers - lex = lexers.get_diff_lexer(self._ui) - fh = qtlib.getfont(self._ui, 'fontdiff') + lex = lexers.get_diff_lexer() + fh = qtlib.getfont('fontdiff')   fh.changed.connect(lambda f: lex.setFont(f))   # TODO: why cannot we connect directly, without lambda?   lex.setFont(fh.font())
 
17
18
19
20
 
21
22
23
24
 
25
26
27
 
 
28
29
30
 
128
129
130
131
 
132
133
134
 
138
139
140
141
 
142
143
144
 
151
152
153
154
155
 
 
156
157
 
158
159
160
 
161
 
17
18
19
 
20
21
22
23
 
24
25
 
 
26
27
28
29
30
 
128
129
130
 
131
132
133
134
 
138
139
140
 
141
142
143
144
 
151
152
153
 
 
154
155
156
 
157
158
159
 
160
161
@@ -17,14 +17,14 @@
  def match(self, filename, filedata):   return False   - def lexer(self, ui): + def lexer(self):   """   Return a configured instance of the lexer   """ - return self.cfg_lexer(self._lexer(), ui) + return self.cfg_lexer(self._lexer())   - def cfg_lexer(self, lexer, ui): - font = qtlib.getfont(ui, 'fontlog').font() + def cfg_lexer(self, lexer): + font = qtlib.getfont('fontlog').font()   lexer.setFont(font, -1)   return lexer   @@ -128,7 +128,7 @@
  extensions = ()   _lexer = Qsci.QsciLexerDiff   regex = re.compile(r'^@@ [-]\d+,\d+ [+]\d+,\d+ @@$') - def cfg_lexer(self, lexer, ui): + def cfg_lexer(self, lexer):   #lexer.setDefaultPaper(QtGui.QColor(cfg.getDiffBGColor()))   #lexer.setColor(QtGui.QColor(cfg.getDiffFGColor()), -1)   for label, i in (('diff.inserted', 6), @@ -138,7 +138,7 @@
  for e in effect.split(';'):   if e.startswith('color:'):   lexer.setColor(QColor(e[7:]), i) - font = qtlib.getfont(ui, 'fontdiff').font() + font = qtlib.getfont('fontdiff').font()   lexer.setFont(font, -1)   return lexer   @@ -151,11 +151,11 @@
  #print clsname   lexers.append(cls())   -def get_diff_lexer(ui=None): - return DiffLexerSelector().lexer(ui) +def get_diff_lexer(): + return DiffLexerSelector().lexer()   -def get_lexer(filename, filedata, ui=None): +def get_lexer(filename, filedata):   for lselector in lexers:   if lselector.match(filename, filedata): - return lselector.lexer(ui) + return lselector.lexer()   return None
 
81
82
83
84
 
85
86
87
 
105
106
107
108
 
109
110
111
 
81
82
83
 
84
85
86
87
 
105
106
107
 
108
109
110
111
@@ -81,7 +81,7 @@
  self.setMarginLineNumbers(1, True)   self.setMarginWidth(1, '000')   self.setReadOnly(True) - self.setFont(qtlib.getfont(self._ui, 'fontlog').font()) + self.setFont(qtlib.getfont('fontlog').font())   self.setUtf8(True)   self.SendScintilla(QsciScintilla.SCI_SETSELEOLFILLED, True)   @@ -105,7 +105,7 @@
  data = _("binary file")   else:   data = tounicode(data) - lexer = get_lexer(path, data, ui=self._ui) + lexer = get_lexer(path, data)   if lexer:   self.setLexer(lexer)   nlines = data.count('\n')
 
202
203
204
205
206
207
 
 
 
208
209
 
 
 
210
211
212
 
202
203
204
 
 
 
205
206
207
208
209
210
211
212
213
214
215
@@ -202,11 +202,14 @@
  'fontlog': 'monospace,10'  }  _fontcache = {} -def getfont(ui, name): - assert name in _fontdefaults - if name not in _fontcache: + +def initfontcache(ui): + for name in _fontdefaults:   fname = ui.config('tortoisehg', name, _fontdefaults[name])   _fontcache[name] = ThgFont(fname) + +def getfont(name): + assert name in _fontdefaults   return _fontcache[name]    def CommonMsgBox(icon, title, main, text='', buttons=QMessageBox.Close,
 
193
194
195
196
 
197
198
199
 
193
194
195
 
196
197
198
199
@@ -193,7 +193,7 @@
  return gw     def load_config(self): - self._font = getfont(self.repo.ui, 'fontlog') + self._font = getfont('fontlog').font()   self.rowheight = 8   self.users, self.aliases = [], []   self.hidefinddelay = False
 
160
161
162
163
 
164
165
166
 
160
161
162
 
163
164
165
166
@@ -160,7 +160,7 @@
  revisiondetails_layout.addWidget(self.filelist_splitter)     def load_config(self): - self._font = getfont(self.repo.ui, 'fontlog').font() + self._font = getfont('fontlog').font()   self.rowheight = 8   self.users, self.aliases = [], []  
 
46
47
48
49
 
50
51
52
 
46
47
48
 
49
50
51
52
@@ -46,7 +46,7 @@
  self._message = w = QTextBrowser()   w.setLineWrapMode(QTextEdit.NoWrap)   #w.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) - f = qtlib.getfont(ui, 'fontcomment') + f = qtlib.getfont('fontcomment')   f.changed.connect(lambda newfont: w.setFont(newfont))   w.setFont(f.font())   w.setOpenLinks(False)
 
407
408
409
 
410
411
412
 
407
408
409
410
411
412
413
@@ -407,6 +407,7 @@
  self._mainapp.setApplicationVersion(thgversion.version())   qtlib.setup_font_substitutions()   qtlib.configstyles(ui) + qtlib.initfontcache(ui)   self._mainapp.setStyleSheet(qtlib.appstylesheet)   self._mainapp.setWindowIcon(qtlib.geticon('thg_logo'))   dlg = dlgfunc(ui, *args, **opts)
 
156
157
158
159
 
160
161
162
 
156
157
158
 
159
160
161
162
@@ -156,7 +156,7 @@
  QPushButton.focusInEvent(self, e)     def on_clicked(self, checked): - thgf = qtlib.getfont(ui.ui(), self.fname) + thgf = qtlib.getfont(self.fname)   dlg = QFontDialog(self)   dlg.setCurrentFont(self.currentFont() or thgf.font())   if dlg.exec_() == QDialog.Accepted:
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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
 # -*- coding: iso-8859-1 -*-  #!/usr/bin/env python  # workbench.py - main TortoiseHg Window  #  # Copyright (C) 2007-2010 Logilab. All rights reserved.  #  # This software may be used and distributed according to the terms  # of the GNU General Public License, incorporated herein by reference.  """  Main Qt4 application for TortoiseHg  """    import os  import subprocess    from mercurial.error import RepoError    from tortoisehg.util import paths, hglib    #from tortoisehg.hgqt.decorators import timeit    from tortoisehg.hgqt import repomodel, thgrepo, cmdui  from tortoisehg.hgqt.i18n import _  from tortoisehg.hgqt.qtlib import geticon, getfont, InfoMsgBox  from tortoisehg.hgqt.repowidget import RepoWidget  from tortoisehg.hgqt.reporegistry import RepoRegistryView  from tortoisehg.hgqt.logcolumns import ColumnSelectDialog  from tortoisehg.hgqt.docklog import LogDockWidget  from tortoisehg.hgqt.settings import SettingsDialog    from PyQt4.QtCore import *  from PyQt4.QtGui import *    class Workbench(QMainWindow):   """hg repository viewer/browser application"""   finished = pyqtSignal(int)     def __init__(self, ui, repo=None):   self.ui = ui     self._reload_rev = None   self._reload_file = None     self._loading = True   self._scanForRepoChanges = True   self._searchWidgets = []     QMainWindow.__init__(self)     self.load_config(ui)   self.setupUi()     self.setWindowTitle('TortoiseHg Workbench')     self.reporegistry = rr = RepoRegistryView(ui, self)   rr.setObjectName('RepoRegistryView')   self.addDockWidget(Qt.LeftDockWidgetArea, rr)     self.log = LogDockWidget(self)   self.log.setObjectName('Log')   self.log.progressReceived.connect(self.statusbar.progress)   self.addDockWidget(Qt.BottomDockWidgetArea, self.log)     rr.openRepoSignal.connect(self.openRepo)     self.createActions()   self.createToolbars()     self.repoTabChanged()     def gotVisible(state):   self.actionShowRepoRegistry.setChecked(self.reporegistry.isVisible())   def logVisible(state):   self.actionShowLog.setChecked(self.log.isVisible())     self.reporegistry.visibilityChanged.connect(gotVisible)   self.log.visibilityChanged.connect(logVisible)     self.restoreSettings()   self.setAcceptDrops(True)     if repo:   self.addRepoTab(repo)   else:   self.reporegistry.setVisible(True)     def load_config(self, ui):   # TODO: connect to font changed signal - font = getfont(ui, 'fontlog').font() - self._font = font + self._font = getfont('fontlog').font()   self.rowheight = 8   self.users, self.aliases = [], []     def accept(self):   self.close()     def reject(self):   self.close()     def setupUi(self):   desktopgeom = qApp.desktop().availableGeometry()   self.resize(desktopgeom.size() * 0.8)     icon = QIcon()   icon.addPixmap(QPixmap(":/icons/log.svg"), QIcon.Normal, QIcon.Off)   self.setWindowIcon(icon)     self.centralwidget = QWidget(self)     self.verticalLayout = vl = QVBoxLayout(self.centralwidget)   vl.setSpacing(0)   vl.setMargin(0)     self.repoTabsWidget = tw = QTabWidget()   tw.setDocumentMode(True)   tw.setTabsClosable(True)   tw.setMovable(True)   sp = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)   sp.setHorizontalStretch(1)   sp.setVerticalStretch(1)   sp.setHeightForWidth(tw.sizePolicy().hasHeightForWidth())   tw.setSizePolicy(sp)   tw.tabCloseRequested.connect(self.repoTabCloseRequested)   tw.currentChanged.connect(self.repoTabChanged)   vl.addWidget(tw)     self.setCentralWidget(self.centralwidget)   self.statusbar = cmdui.ThgStatusBar(self)   self.setStatusBar(self.statusbar)     self.filterToolbar = tb = QToolBar(_("Filter Toolbar"), self)   tb.setEnabled(True)   tb.setObjectName("filterToolbar")   self.addToolBar(Qt.ToolBarArea(Qt.TopToolBarArea), tb)     self.actionHelp = a = QAction(_("Help"), self)   a.setShortcut(QKeySequence.HelpContents)   a.setIcon(geticon('help'))     self.actionNew_repository = a = QAction(_("&New Repository..."), self)   a.setShortcut(QKeySequence.New)     self.actionOpen_repository = a = QAction(_("&Open Repository..."), self)   a.setShortcut(QKeySequence.Open)     self.actionClose_repository = a = QAction(_("&Close Repository"), self)   a.setShortcut(QKeySequence.Close)     self.actionSettings = a = QAction(_('&Settings...'), self)   a.setShortcut(QKeySequence.Preferences)   a.setIcon(geticon('settings_user'))     self.actionRefresh = a = QAction(_("&Refresh"), self)   a.setIcon(geticon('reload'))   a.setShortcut(QKeySequence.Refresh)   a.setToolTip(_('Refresh all for current repository'))     self.actionRefreshTaskTab = a = QAction(_("Refresh &Task Tab"), self)   a.setIcon(geticon('reloadtt'))   b = QKeySequence.keyBindings(QKeySequence.Refresh)   a.setShortcut(QKeySequence.fromString(u'Shift+' + b[0].toString()))   a.setToolTip(_('Refresh only the current task tab'))     self.actionFind = a = QAction(_('Find'), self)   a.setIcon(geticon('find'))     self.actionQuit = a = QAction(_("E&xit"), self)   a.setIcon(geticon('quit'))   a.setShortcut(QKeySequence.Quit)   a.setIconText(_("Exit"))   a.setToolTip(_("Exit"))     self.actionAbout = QAction(_("About"), self)   self.actionDisplayAllBranches = QAction("displayAllBranches", self)     self.actionBack = a = QAction(_("Back"), self)   a.setEnabled(False)   icon = QIcon()   icon.addPixmap(QPixmap(":/icons/back.svg"), QIcon.Normal, QIcon.Off)   a.setIcon(icon)     self.actionForward = a = QAction(_("Forward"), self)   a.setEnabled(False)   icon = QIcon()   icon.addPixmap(QPixmap(":/icons/forward.svg"), QIcon.Normal, QIcon.Off)   a.setIcon(icon)     self.actionLoadAll = a = QAction(_("Load all"), self)   a.setEnabled(True)   icon = QIcon()   icon.addPixmap(QPixmap(":/icons/loadall.png"), QIcon.Normal, QIcon.Off)   a.setIcon(icon)     self.actionShowPaths = a = QAction(_("Show Paths"), self)   a.setCheckable(True)     self.actionSelectColumns = QAction(_("Choose Log Columns..."), self)     self.actionGroupTaskView = ag = QActionGroup(self)   ag.setEnabled(False)   self.actionSelectTaskLog = a = QAction(_("Revision &Details"), ag)   a.setIcon(geticon('log'))   self.actionSelectTaskCommit = a = QAction(_("&Commit..."), ag)   a.setIcon(geticon('commit'))   self.actionSelectTaskManifest = a = QAction(_("&Manifest..."), ag)   a.setIcon(geticon('annotate'))   self.actionSelectTaskGrep = a = QAction(_("&Search..."), ag)   a.setIcon(geticon('repobrowse'))   self.actionSelectTaskSync = a = QAction(_("S&ynchronize..."), ag)   a.setIcon(geticon('sync'))   for a in ag.actions():   a.setCheckable(True)     self.actionShowRepoRegistry = a = QAction(_("Show Repository Registry"), self)   a.setCheckable(True)   icon = QIcon()   icon.addPixmap(QPixmap(":/icons/repotree.svg"), QIcon.Normal, QIcon.Off)   a.setIcon(icon)     self.actionShowLog = a = QAction(_("Show Output &Log"), self)   a.setCheckable(True)   icon = QIcon()   icon.addPixmap(QPixmap(":/icons/showlog.png"), QIcon.Normal, QIcon.Off)   a.setIcon(icon)   a.setShortcut(QKeySequence("Ctrl+L"))     self.actionServe = QAction(_("Web Server"), self)   self.actionImport = QAction(_("Import"), self)   self.actionVerify = QAction(_("Verify"), self)   self.actionRecover = QAction(_("Recover"), self)   self.actionRollback = QAction(_("Rollback/Undo"), self)   self.actionPurge = QAction(_("Purge"), self)   self.actionExplore = a = QAction(_("Explore"), self)   a.setShortcut(QKeySequence("Shift+Ctrl+S"))   self.actionTerminal = a = QAction(_("Terminal"), self)   a.setShortcut(QKeySequence("Shift+Ctrl+T"))     # TODO: Use long names when these have icons   self.actionIncoming = a = QAction(_('In'), self)   a.setToolTip(_('Check for incoming changes from default pull target'))   self.actionPull = a = QAction(_('Pull'), self)   a.setToolTip(_('Pull incoming changes from default pull target'))   self.actionOutgoing = a = QAction(_('Out'), self)   a.setToolTip(_('Detect outgoing changes to default push target'))   self.actionPush = a = QAction(_('Push'), self)   a.setToolTip(_('Push outgoing changes to default push target'))     self.menubar = QMenuBar(self)   self.setMenuBar(self.menubar)     self.menuFile = m = QMenu(_("&File"), self.menubar)   m.addAction(self.actionNew_repository)   m.addAction(self.actionOpen_repository)   m.addAction(self.actionClose_repository)   m.addSeparator()   m.addAction(self.actionSettings)   m.addSeparator()   m.addAction(self.actionQuit)     self.menuView = m = QMenu(_("&View"), self.menubar)   m.addAction(self.actionShowRepoRegistry)   m.addAction(self.actionShowPaths)   m.addAction(self.actionShowLog)   m.addSeparator()   m.addAction(self.actionSelectColumns)   m.addSeparator()   m.addActions(self.actionGroupTaskView.actions())   m.addSeparator()   m.addAction(self.actionRefresh)   m.addAction(self.actionRefreshTaskTab)     self.menuRepository = m = QMenu(_("&Repository"), self.menubar)   m.addAction(self.actionServe)   m.addSeparator()   m.addAction(self.actionImport)   m.addSeparator()   m.addAction(self.actionVerify)   m.addAction(self.actionRecover)   m.addSeparator()   m.addAction(self.actionRollback)   m.addAction(self.actionPurge)   m.addSeparator()   m.addAction(self.actionExplore)   m.addAction(self.actionTerminal)     self.menuHelp = m = QMenu(_("&Help"), self.menubar)   m.addAction(self.actionHelp)   m.addAction(self.actionAbout)     self.menubar.addAction(self.menuFile.menuAction())   self.menubar.addAction(self.menuView.menuAction())   self.menubar.addAction(self.menuRepository.menuAction())   self.menubar.addAction(self.menuHelp.menuAction())     self.updateMenu()     def createToolbars(self):   self.edittbar = tb = QToolBar(_("Edit Toolbar"), self)   tb.setEnabled(True)   tb.setObjectName("edittbar")   tb.addAction(self.actionRefresh)   tb.addAction(self.actionRefreshTaskTab)   tb.addSeparator()   tb.addAction(self.actionBack)   tb.addAction(self.actionForward)   tb.addAction(self.actionLoadAll)   tb.addSeparator()   tb.addAction(self.actionFind)   self.addToolBar(Qt.ToolBarArea(Qt.TopToolBarArea), tb)     self.docktbar = tb = QToolBar(_("Dock Toolbar"), self)   tb.setEnabled(True)   tb.setObjectName("docktbar")   tb.addAction(self.actionShowRepoRegistry)   tb.addAction(self.actionShowLog)   self.addToolBar(Qt.ToolBarArea(Qt.TopToolBarArea), tb)     self.synctbar = tb = QToolBar(_('Sync Toolbar'), self)   tb.setEnabled(True)   tb.setObjectName('synctbar')   tb.addAction(self.actionIncoming)   tb.addAction(self.actionPull)   tb.addAction(self.actionOutgoing)   tb.addAction(self.actionPush)   self.addToolBar(Qt.ToolBarArea(Qt.TopToolBarArea), tb)     # tree filters toolbar   self.branchLabel = QToolButton()   self.branchLabel.setText("Branch")   self.branchLabel.setStatusTip("Display graph the named branch only")   self.branchLabel.setPopupMode(QToolButton.InstantPopup)   self.branch_menu = QMenu()   cbranch_action = self.branch_menu.addAction("Display closed branches")   cbranch_action.setCheckable(True)   self.cbranch_action = cbranch_action   allpar_action = self.branch_menu.addAction("Include all ancestors")   allpar_action.setCheckable(True)   self.allpar_action = allpar_action   self.branchLabel.setMenu(self.branch_menu)   self.branchCombo = QComboBox()   self.branchCombo.activated.connect(self.setBranch)   cbranch_action.toggled.connect(self.setupBranchCombo)   allpar_action.toggled.connect(self.setBranch)     self.filterToolbar.layout().setSpacing(3)     self.branchLabelAction = self.filterToolbar.addWidget(self.branchLabel)   self.branchComboAction = self.filterToolbar.addWidget(self.branchCombo)   self.filterToolbar.addSeparator()     def createActions(self):   # main window actions (from .ui file)   self.actionFind.triggered.connect(self.find)   self.actionRefresh.triggered.connect(self.reload)   self.actionRefreshTaskTab.triggered.connect(self.reloadTaskTab)   self.actionAbout.triggered.connect(self.on_about)   self.actionQuit.triggered.connect(self.close)   self.actionBack.triggered.connect(self.back)   self.actionForward.triggered.connect(self.forward)   self.actionImport.triggered.connect(self.thgimport)   self.actionLoadAll.triggered.connect(self.loadall)   self.actionSelectColumns.triggered.connect(self.setHistoryColumns)   self.actionSelectTaskLog.triggered.connect(self.showRepoTaskLog)   self.actionSelectTaskCommit.triggered.connect(self.showRepoTaskCommit)   self.actionSelectTaskManifest.triggered.connect(self.showRepoTaskManifest)   self.actionSelectTaskGrep.triggered.connect(self.showRepoTaskGrep)   self.actionSelectTaskSync.triggered.connect(self.showRepoTaskSync)   self.actionShowPaths.toggled.connect(self.actionShowPathsToggled)   self.actionShowRepoRegistry.toggled.connect(self.showRepoRegistry)   self.actionShowLog.toggled.connect(self.showLog)     self.actionNew_repository.triggered.connect(self.newRepository)   self.actionOpen_repository.triggered.connect(self.openRepository)   self.actionClose_repository.triggered.connect(self.closeRepository)   self.actionSettings.triggered.connect(self.editSettings)     self.actionServe.triggered.connect(self.serve)   self.actionVerify.triggered.connect(self.verify)   self.actionRecover.triggered.connect(self.recover)   self.actionRollback.triggered.connect(self.rollback)   self.actionPurge.triggered.connect(self.purge)   self.actionExplore.triggered.connect(self.explore)   self.actionTerminal.triggered.connect(self.terminal)     self.actionIncoming.triggered.connect(self.incoming)   self.actionPull.triggered.connect(self.pull)   self.actionOutgoing.triggered.connect(self.outgoing)   self.actionPush.triggered.connect(self.push)     self.actionHelp.triggered.connect(self.on_help)     def showRepoRegistry(self, show):   self.reporegistry.setVisible(show)     def showLog(self, show):   self.log.setVisible(show)     def showRepoTaskLog(self, show):   rw = self.repoTabsWidget.currentWidget()   if not rw: return   rw.taskTabsWidget.setCurrentIndex(rw.logTabIndex)     def showRepoTaskCommit(self, show):   rw = self.repoTabsWidget.currentWidget()   if not rw: return   rw.taskTabsWidget.setCurrentIndex(rw.commitTabIndex)     def showRepoTaskManifest(self, show):   rw = self.repoTabsWidget.currentWidget()   if not rw: return   rw.taskTabsWidget.setCurrentIndex(rw.manifestTabIndex)     def showRepoTaskSync(self, show):   rw = self.repoTabsWidget.currentWidget()   if not rw: return   rw.taskTabsWidget.setCurrentIndex(rw.syncTabIndex)     def showRepoTaskGrep(self, show):   rw = self.repoTabsWidget.currentWidget()   if not rw: return   rw.taskTabsWidget.setCurrentIndex(rw.grepTabIndex)     def openRepo(self, repopath):   if isinstance(repopath, (unicode, QString)): # as Qt slot   repopath = hglib.fromunicode(repopath)   try:   repo = thgrepo.repository(self.ui, path=repopath)   self.addRepoTab(repo)   except RepoError:   QMessageBox.warning(self, _('Failed to open repository'),   _('%s is not a valid repository') % repopath)     def find_root(self, url):   p = hglib.fromunicode(url.toLocalFile())   return paths.find_root(p)     def dragEnterEvent(self, event):   d = event.mimeData()   for u in d.urls():   root = self.find_root(u)   if root:   event.setDropAction(Qt.LinkAction)   event.accept()   break     def dropEvent(self, event):   accept = False   d = event.mimeData()   for u in d.urls():   root = self.find_root(u)   if root:   self.openRepo(root)   accept = True   if accept:   event.setDropAction(Qt.LinkAction)   event.accept()     def linkActivated(self, link):   link = hglib.fromunicode(link)   if link.startswith('subrepo:'):   self.openRepo(link[8:])     def updateMenu(self):   someRepoOpen = self.repoTabsWidget.count() > 0   self.actionGroupTaskView.setEnabled(someRepoOpen)   self.updateTaskViewMenu()     self.actionFind.setEnabled(someRepoOpen)   self.actionRefresh.setEnabled(someRepoOpen)   self.actionRefreshTaskTab.setEnabled(someRepoOpen)   self.actionLoadAll.setEnabled(someRepoOpen)     self.actionClose_repository.setEnabled(someRepoOpen)   self.actionImport.setEnabled(someRepoOpen)   self.actionServe.setEnabled(someRepoOpen)   self.actionVerify.setEnabled(someRepoOpen)   self.actionRecover.setEnabled(someRepoOpen)   self.actionRollback.setEnabled(someRepoOpen)   self.actionPurge.setEnabled(someRepoOpen)   self.actionExplore.setEnabled(someRepoOpen)   self.actionTerminal.setEnabled(someRepoOpen)     self.actionIncoming.setEnabled(someRepoOpen)   self.actionPull.setEnabled(someRepoOpen)   self.actionOutgoing.setEnabled(someRepoOpen)   self.actionPush.setEnabled(someRepoOpen)     def updateTaskViewMenu(self, taskIndex=0):   # Fetch selected task tab from current repowidget and check corresponding action in menu   if self.repoTabsWidget.count() == 0:   for a in self.actionGroupTaskView.actions():   a.setChecked(False)   else:   repoWidget = self.repoTabsWidget.currentWidget()   taskIndex = repoWidget.taskTabsWidget.currentIndex()   self.actionGroupTaskView.actions()[taskIndex].setChecked(True)     def repoTabCloseSelf(self, widget):   self.repoTabsWidget.setCurrentWidget(widget)   index = self.repoTabsWidget.currentIndex()   if widget.closeRepoWidget():   self.repoTabsWidget.removeTab(index)   self.updateMenu()     def repoTabCloseRequested(self, index):   tw = self.repoTabsWidget   w = tw.widget(index)   if w and w.closeRepoWidget():   tw.removeTab(index)   self.updateMenu()     def repoTabChanged(self, index=0):   self.setupBranchCombo()   w = self.repoTabsWidget.currentWidget()   if w:   w.switchedTo()   self.updateTaskViewMenu()   self.log.setRepository(w and w.repo or None)     def addRepoTab(self, repo):   '''opens the given repo in a new tab'''   rw = RepoWidget(repo, self)   rw.showMessageSignal.connect(self.showMessage)   rw.closeSelfSignal.connect(self.repoTabCloseSelf)   rw.progress.connect(lambda tp, p, i, u, tl:   self.statusbar.progress(tp, p, i, u, tl, repo.root))   rw.output.connect(self.log.output)   rw.makeLogVisible.connect(self.log.setShown)   rw.taskTabsWidget.currentChanged.connect(self.updateTaskViewMenu)     tw = self.repoTabsWidget   index = self.repoTabsWidget.addTab(rw, repo.shortname)   tw.setCurrentIndex(index)   self.reporegistry.addRepo(repo.root)     self.updateMenu()       def showMessage(self, msg):   self.statusbar.showMessage(msg)     def setupBranchCombo(self, *args):   w = self.repoTabsWidget.currentWidget()   if not w:   self.branchLabelAction.setEnabled(False)   self.branchComboAction.setEnabled(False)   self.branchCombo.clear()   return     repo = w.repo   allbranches = sorted(repo.branchtags().items())     openbr = []   for branch, brnode in allbranches:   openbr.extend(repo.branchheads(branch, closed=False))   clbranches = [br for br, node in allbranches if node not in openbr]   branches = [br for br, node in allbranches if node in openbr]   if self.cbranch_action.isChecked():   branches = branches + clbranches     if len(branches) == 1:   self.branchLabelAction.setEnabled(False)   self.branchComboAction.setEnabled(False)   self.branchCombo.clear()   else:   branches = [''] + branches   self.branchesmodel = QStringListModel(branches)   self.branchCombo.setModel(self.branchesmodel)   self.branchLabelAction.setEnabled(True)   self.branchComboAction.setEnabled(True)     branch = w.filterbranch()   index = -1   for i, b in enumerate(branches):   if b == branch:   index = i   break   self.branchCombo.setCurrentIndex(index)       def actionShowPathsToggled(self, show):   self.reporegistry.showPaths(show)     def setHistoryColumns(self, *args):   """Display the column selection dialog"""   w = self.repoTabsWidget.currentWidget()   dlg = ColumnSelectDialog(repomodel.ALLCOLUMNS, w and w.repoview.model().columns)   if dlg.exec_() == QDialog.Accepted:   if w:   w.repoview.model().updateColumns()   w.repoview.resizeColumns()     def serve(self):   w = self.repoTabsWidget.currentWidget()   if w:   from tortoisehg.hgqt import run   run.serve(self.ui, root=w.repo.root)     def thgimport(self):   w = self.repoTabsWidget.currentWidget()   if w:   w.thgimport()     def verify(self):   w = self.repoTabsWidget.currentWidget()   if w:   w.verify()     def recover(self):   w = self.repoTabsWidget.currentWidget()   if w:   w.recover()     def rollback(self):   w = self.repoTabsWidget.currentWidget()   if w:   w.rollback()     def purge(self):   w = self.repoTabsWidget.currentWidget()   if w:   w.purge()     def back(self):   w = self.repoTabsWidget.currentWidget()   if w:   w.back()     def forward(self):   w = self.repoTabsWidget.currentWidget()   if w:   w.forward()     def find(self):   w = self.repoTabsWidget.currentWidget()   if w:   w.find()     def loadall(self):   w = self.repoTabsWidget.currentWidget()   if w:   w.repoview.model().loadall()     def newRepository(self):   """ Run init dialog """   from tortoisehg.hgqt.hginit import InitDialog   initdlg = InitDialog(parent=self)   if initdlg.exec_():   path = initdlg.getPath()   self.openRepo(path)     def openRepository(self):   caption = _('Select repository directory to open')   FD = QFileDialog   path = FD.getExistingDirectory(parent=self, caption=caption,   options=FD.ShowDirsOnly | FD.ReadOnly)   if path:   try:   repo = thgrepo.repository(self.ui, path=hglib.fromunicode(path))   self.addRepoTab(repo)   except RepoError:   QMessageBox.warning(self, _('Failed to open repository'),   _('%s is not a valid repository') % path)     def reload(self):   w = self.repoTabsWidget.currentWidget()   if w:   w.reload()   self.setupBranchCombo()     def reloadTaskTab(self, root):   rw = self.repoTabsWidget.currentWidget()   if rw:   rw.reloadTaskTab()     def goto(self, root, rev):   for rw in self._findrepowidget(root):   rw.goto(rev)     def reloadRepository(self, root):   for rw in self._findrepowidget(root):   rw.reload()   self.setupBranchCombo()     def _findrepowidget(self, root):   """Iterates RepoWidget for the specified root"""   tw = self.repoTabsWidget   for idx in range(tw.count()):   rw = tw.widget(idx)   if rw.repo.root == root:   yield rw     #@timeit   def setBranch(self, *args, **kw):   'Handle new branch choice or allparents toggle'   branch = self.branchCombo.currentText()   branch = str(branch)   allparents = self.allpar_action.isChecked()   tw = self.repoTabsWidget   w = tw.currentWidget()   if w:   w.setBranch(branch, allparents)   if branch:   tabtext = '%s [%s]' % (w.reponame(), branch)   else:   tabtext = w.reponame()   tw.setTabText(tw.currentIndex(), tabtext)     def on_about(self, *args):   """ Display about dialog """   from tortoisehg.hgqt.about import AboutDialog   ad = AboutDialog()   ad.exec_()     def on_help(self, *args):   pass     def storeSettings(self):   s = QSettings()   wb = "Workbench/"   s.setValue(wb + 'geometry', self.saveGeometry())   s.setValue(wb + 'windowState', self.saveState())   s.setValue(wb + 'showPaths', self.actionShowPaths.isChecked())     def restoreSettings(self):   s = QSettings()   wb = "Workbench/"   self.restoreGeometry(s.value(wb + 'geometry').toByteArray())   self.restoreState(s.value(wb + 'windowState').toByteArray())   # Allow repo registry to assemble itself before toggling path state   sp = s.value(wb + 'showPaths').toBool()   QTimer.singleShot(0, lambda: self.actionShowPaths.setChecked(sp))     def closeEvent(self, event):   if not self.closeRepoTabs():   event.ignore()   else:   self.storeSettings()   self.reporegistry.close()   # mimic QDialog exit   self.finished.emit(0)     def closeRepoTabs(self):   '''returns False if close should be aborted'''   tw = self.repoTabsWidget   for idx in range(tw.count()):   rw = tw.widget(idx)   if not rw.closeRepoWidget():   return False   return True     def closeRepository(self):   """close the current repo tab"""   self.repoTabCloseRequested(self.repoTabsWidget.currentIndex())     def explore(self):   w = self.repoTabsWidget.currentWidget()   if w:   self.launchExplorer(w.repo.root)     def terminal(self):   w = self.repoTabsWidget.currentWidget()   if w:   self.launchTerminal(w.repo)     def incoming(self):   w = self.repoTabsWidget.currentWidget()   if w:   w.incoming()     def pull(self):   w = self.repoTabsWidget.currentWidget()   if w:   w.pull()     def outgoing(self):   w = self.repoTabsWidget.currentWidget()   if w:   w.outgoing()     def push(self):   w = self.repoTabsWidget.currentWidget()   if w:   w.push()     def launchExplorer(self, root):   """open Windows Explorer at the repo root"""   QDesktopServices.openUrl(QUrl.fromLocalFile(root))     def launchTerminal(self, repo):   shell = repo.shell()   if shell:   cwd = os.getcwd()   try:   os.chdir(repo.root)   QProcess.startDetached(shell)   finally:   os.chdir(cwd)   else:   InfoMsgBox(_('No shell configured'),   _('A terminal shell must be configured'))     def editSettings(self):   tw = self.repoTabsWidget   w = tw.currentWidget()   twrepo = (w and w.repo.root or '')   sd = SettingsDialog(configrepo=False, focus='tortoisehg.authorcolor',   parent=self, root=twrepo)   sd.exec_()      def run(ui, *pats, **opts):   repo = None   root = opts.get('root') or paths.find_root()   if root:   repo = thgrepo.repository(ui, path=root)   return Workbench(ui, repo)