Changeset f4eb98b42017…
Parent 68879b630197…
by
Changes to 3 files · Browse files at f4eb98b42017 Showing diff from parent 68879b630197 Diff from another changeset...
|
@@ -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,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,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
|
Loading...