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

repofilter: extract branch filter as RepoFilterBar

- move branch toolbar from workbench to RepoFilterBar
- put RepoFilterBar on top of each RepoWidget
- connect RepoFilterBar and RepoWidget via branchChanged signal

Changeset f4eb98b42017

Parent 68879b630197

by Yuya Nishihara

Changes to 3 files · Browse files at f4eb98b42017 Showing diff from parent 68879b630197 Diff from another changeset...

Change 1 of 1 Show Entire File tortoisehg/​hgqt/​repofilter.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
@@ -0,0 +1,93 @@
+# repofilter.py - TortoiseHg toolbar for filtering changesets +# +# Copyright (C) 2007-2010 Logilab. All rights reserved. +# Copyright (C) 2010 Yuya Nishihara <yuya@tcha.org> +# +# This software may be used and distributed according to the terms +# of the GNU General Public License, incorporated herein by reference. + +from PyQt4.QtCore import * +from PyQt4.QtGui import * + +class RepoFilterBar(QToolBar): + """Toolbar for RepoWidget to filter changesets""" + + branchChanged = pyqtSignal(unicode, bool) + """Emitted (branch, allparents) when branch selection changed""" + + def __init__(self, repo, parent=None): + super(RepoFilterBar, self).__init__(parent) + self.layout().setContentsMargins(0, 0, 0, 0) + self._repo = repo + + self.addWidget(QLineEdit(text='### placeholder for revsets ###', + enabled=False)) + + self._initbranchfilter() + self.refresh() + + def _initbranchfilter(self): + 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._emitBranchChanged) + cbranch_action.toggled.connect(self.refresh) + allpar_action.toggled.connect(self._emitBranchChanged) + + self.branchLabelAction = self.addWidget(self.branchLabel) + self.branchComboAction = self.addWidget(self.branchCombo) + + def _updatebranchfilter(self): + """Update the list of branches""" + curbranch = self.branch() + + allbranches = sorted(self._repo.branchtags().items()) + + openbr = [] + for branch, brnode in allbranches: + openbr.extend(self._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) + + self.setBranch(curbranch) + + @pyqtSlot(unicode) + def setBranch(self, branch): + """Change the current branch by name [unicode]""" + self.branchCombo.setCurrentIndex(self.branchCombo.findText(branch)) + + def branch(self): + """Return the current branch name [unicode]""" + return unicode(self.branchCombo.currentText()) + + @pyqtSlot() + def _emitBranchChanged(self): + self.branchChanged.emit(self.branch(), + self.allpar_action.isChecked()) + + @pyqtSlot() + def refresh(self): + self._updatebranchfilter()
 
23
24
25
 
26
27
28
 
71
72
73
 
 
 
 
 
74
75
76
 
449
450
451
 
452
453
454
 
479
480
481
 
482
483
484
 
498
499
500
 
 
 
 
 
 
501
502
503
504
505
506
507
508
509
510
511
512
513
514
 
23
24
25
26
27
28
29
 
72
73
74
75
76
77
78
79
80
81
82
 
455
456
457
458
459
460
461
 
486
487
488
489
490
491
492
 
506
507
508
509
510
511
512
513
514
515
516
517
518
 
 
 
 
 
 
 
519
520
521
@@ -23,6 +23,7 @@
 from tortoisehg.hgqt import cmdui, update, tag, backout, merge, visdiff  from tortoisehg.hgqt import archive, thgimport, thgstrip, run, thgrepo, purge   +from tortoisehg.hgqt.repofilter import RepoFilterBar  from tortoisehg.hgqt.repoview import HgRepoView  from tortoisehg.hgqt.revdetails import RevDetailsWidget  from tortoisehg.hgqt.commit import CommitWidget @@ -71,6 +72,11 @@
  self.repotabs_splitter = QSplitter(orientation=Qt.Vertical)   self.setLayout(QVBoxLayout())   self.layout().setContentsMargins(0, 0, 0, 0) + + self.filterbar = RepoFilterBar(self.repo) + self.filterbar.branchChanged.connect(self.setBranch) + self.layout().addWidget(self.filterbar) +   self.layout().addWidget(self.repotabs_splitter)     self.repoview = view = HgRepoView(self.workbench, self.repo) @@ -449,6 +455,7 @@
  self.repo.thginvalidate()   self.rebuildGraph()   self.commitDemand.forward('reload') + self.filterbar.refresh()     def rebuildGraph(self):   self.showMessage('') @@ -479,6 +486,7 @@
  self.repo.thginvalidate()   self.repomodel.invalidate()   self.revDetailsWidget.reload() + self.filterbar.refresh()     def repositoryDestroyed(self):   'Repository has detected itself to be deleted' @@ -498,17 +506,16 @@
  self.titleChanged.emit(self.title())   # TODO: emit only if actually changed   + @pyqtSlot(unicode, bool) + def setBranch(self, branch, allparents=True): + 'Change the branch filter' + self.repomodel.setBranch(branch=branch, allparents=allparents) + self.titleChanged.emit(self.title()) +   ##   ## Workbench methods   ##   - def setBranch(self, branch, allparents=True): - 'Triggered by workbench on branch selection' - self.repomodel.setBranch(branch=branch, allparents=allparents) - - def filterbranch(self): - return self.repomodel.branch() -   def switchedTo(self):   'Update back / forward actions'   self.repoview.updateActions()
 
143
144
145
146
147
148
149
150
151
152
153
 
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
 
536
537
538
539
540
541
542
 
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
 
706
707
708
709
710
711
712
 
720
721
722
723
724
725
726
 
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
 
143
144
145
 
 
 
 
 
146
147
148
 
348
349
350
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
351
352
353
 
507
508
509
 
510
511
512
 
537
538
539
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
540
541
542
 
637
638
639
 
640
641
642
 
650
651
652
 
653
654
655
 
659
660
661
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
662
663
664
@@ -143,11 +143,6 @@
  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')) @@ -353,30 +348,6 @@
  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) @@ -536,7 +507,6 @@
  self.updateMenu()     def repoTabChanged(self, index=0): - self.setupBranchCombo()   w = self.repoTabsWidget.currentWidget()   if w:   w.switchedTo() @@ -567,45 +537,6 @@
  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)   @@ -706,7 +637,6 @@
  w = self.repoTabsWidget.currentWidget()   if w:   w.reload() - self.setupBranchCombo()     def reloadTaskTab(self, root):   rw = self.repoTabsWidget.currentWidget() @@ -720,7 +650,6 @@
  def reloadRepository(self, root):   for rw in self._findrepowidget(root):   rw.reload() - self.setupBranchCombo()     def _findrepowidget(self, root):   """Iterates RepoWidget for the specified root""" @@ -730,22 +659,6 @@
  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