Commits

Yuya Nishihara committed 10f8da1

patches for branch filter, etc.

Comments (0)

Files changed (7)

branch-editable.diff

+# HG changeset patch
+# Date 1361632710 -32400
+# Parent 07fe5dce850aca93f75d39d9eaae06f8750b5565
+repofilter: allow to manually input branch name to filter
+
+If there are many branches, it isn't easy to select branch from the list.
+
+diff --git a/tests/widget/repofilterbar_branch_test.py b/tests/widget/repofilterbar_branch_test.py
+--- a/tests/widget/repofilterbar_branch_test.py
++++ b/tests/widget/repofilterbar_branch_test.py
+@@ -74,6 +74,17 @@ class RepoFilterBarBranchTest(unittest.T
+         self.assertEqual('foo', self.widget.branch())
+         self.branchchanged.assert_called_once_with('foo', False)
+ 
++    def test_edit_branch_not_exposing_temporary_value(self):
++        self.widget.setBranch('foo')
++        self.widget._branchCombo.setEditText('bar')
++        self.assertEqual('foo', self.widget.branch())
++
++    def test_edit_branch_restore_original_if_not_found(self):
++        self.widget.setBranch('foo')
++        self.widget._branchCombo.setEditText('unknown')
++        self.widget._branchCombo.lineEdit().returnPressed.emit()
++        self.assertEqual('foo', self.widget._branchCombo.currentText())
++
+     def test_label_for_all_branches(self):
+         self.widget.setBranch('')  # all branches
+         self.assertEqual('', self.widget.branch())
+diff --git a/tortoisehg/hgqt/repofilter.py b/tortoisehg/hgqt/repofilter.py
+--- a/tortoisehg/hgqt/repofilter.py
++++ b/tortoisehg/hgqt/repofilter.py
+@@ -243,7 +243,11 @@ class RepoFilterBar(QToolBar):
+         self._branchCombo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
+         self._branchCombo.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLength)
+         self._branchCombo.setMaxVisibleItems(30)
++        self._branchCombo.setEditable(True)
++        self._branchCombo.setInsertPolicy(QComboBox.NoInsert)
+         self._branchCombo.currentIndexChanged.connect(self._emitBranchChanged)
++        le = self._branchCombo.lineEdit()
++        le.returnPressed.connect(self._fixupEditedBranch)
+         self._branchReloading = False
+ 
+         self.addWidget(self._branchLabel)
+@@ -295,10 +299,12 @@ class RepoFilterBar(QToolBar):
+ 
+     def branch(self):
+         """Return the current branch name [unicode]"""
+-        if self._branchCombo.currentIndex() == 0:
++        index = self._branchCombo.currentIndex()
++        if index == 0:
+             return ''
+         else:
+-            return unicode(self._branchCombo.currentText())
++            # don't expose manually-edited value by currentText()
++            return unicode(self._branchCombo.itemText(index))
+ 
+     @pyqtSlot()
+     def _emitBranchChanged(self):
+@@ -307,5 +313,13 @@ class RepoFilterBar(QToolBar):
+                                     self._allparAction.isChecked())
+ 
+     @pyqtSlot()
++    def _fixupEditedBranch(self):
++        newbranch = unicode(self._branchCombo.currentText())
++        if not newbranch:
++            self._branchCombo.setCurrentIndex(0)  # show all
++        elif self._branchCombo.findText(newbranch) < 0:
++            self._branchCombo.setCurrentIndex(self._branchCombo.currentIndex())
++
++    @pyqtSlot()
+     def refresh(self):
+         self._updatebranchfilter()

branch-selectall.diff

+# HG changeset patch
+# Date 1361632719 -32400
+# Parent 316c052ec9de163bd17834b4e20aff71e6076ef3
+repofilter: select branch or revset text on focus by mouse-click
+
+The other focus reasons are handled as such by QLineEdit.
+
+This uses old-style signal connection because new-style doesn't work.
+I guess that's because the reference to watched.lineEdit() is released
+too early.
+
+diff --git a/tortoisehg/hgqt/repofilter.py b/tortoisehg/hgqt/repofilter.py
+--- a/tortoisehg/hgqt/repofilter.py
++++ b/tortoisehg/hgqt/repofilter.py
+@@ -63,6 +63,7 @@ class RepoFilterBar(QToolBar):
+         combo.setEditable(True)
+         combo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
+         combo.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLength)
++        combo.installEventFilter(self)
+         qtlib.allowCaseChangingInput(combo)
+         le = combo.lineEdit()
+         le.returnPressed.connect(self.returnPressed)
+@@ -112,6 +113,15 @@ class RepoFilterBar(QToolBar):
+         self._initbranchfilter()
+         self.refresh()
+ 
++    def eventFilter(self, watched, event):
++        if ((watched is self.revsetcombo or watched is self._branchCombo)
++            and event.type() == QEvent.FocusIn
++            and event.reason() == Qt.MouseFocusReason):
++            # delayed because next mouse-release will cancel selection
++            QTimer.singleShot(0, watched.lineEdit(), SLOT('selectAll()'))
++            return False
++        return super(RepoFilterBar, self).eventFilter(watched, event)
++
+     def onClearButtonClicked(self):
+         if self.revsetcombo.lineEdit().text():
+             self.revsetcombo.lineEdit().clear()
+@@ -245,6 +255,7 @@ class RepoFilterBar(QToolBar):
+         self._branchCombo.setMaxVisibleItems(30)
+         self._branchCombo.setEditable(True)
+         self._branchCombo.setInsertPolicy(QComboBox.NoInsert)
++        self._branchCombo.installEventFilter(self)
+         self._branchCombo.currentIndexChanged.connect(self._emitBranchChanged)
+         le = self._branchCombo.lineEdit()
+         le.returnPressed.connect(self._fixupEditedBranch)
+# HG changeset patch
+# Parent 710ce222c53ecca90a3dde267943d82eb1e9d0cc
+repofilter: separate "show all" from list of branches
+
+diff --git a/tortoisehg/hgqt/repofilter.py b/tortoisehg/hgqt/repofilter.py
+--- a/tortoisehg/hgqt/repofilter.py
++++ b/tortoisehg/hgqt/repofilter.py
+@@ -283,6 +283,8 @@ class RepoFilterBar(QToolBar):
+         self._branchReloading = True
+         self._branchCombo.clear()
+         self._branchCombo.addItem(self._allBranchesLabel)
++        if branches:
++            self._branchCombo.insertSeparator(1)
+         for branch in branches:
+             self._branchCombo.addItem(hglib.tounicode(branch))
+             self._branchCombo.setItemData(self._branchCombo.count() - 1,

dbgtools-gcmode.diff

+# HG changeset patch
+# Parent 015b94a0da71bda193dea61a5f607816ce31a7f9
+
+diff --git a/contrib/thgdebugtools/core.py b/contrib/thgdebugtools/core.py
+--- a/contrib/thgdebugtools/core.py
++++ b/contrib/thgdebugtools/core.py
+@@ -18,6 +18,10 @@ import dbgutil, infobar, widgets
+ class DebugMenuActions(dbgutil.BaseMenuActions):
+     """Set up top-level debug menu"""
+ 
++    NoGc = 0
++    AutoGc = 1
++    IntervalGc = 2
++
+     def _setupMenu(self, menu):
+         if self._workbench():
+             m = menu.addMenu('&InfoBar')
+@@ -37,10 +41,19 @@ class DebugMenuActions(dbgutil.BaseMenuA
+         a.setEnabled(False)
+         self._gcStatusAction = a
+ 
+-        a = menu.addAction('&Enable Garbage Collector')
+-        a.setCheckable(True)
+-        a.triggered.connect(self.setGcEnabled)
+-        self._gcEnabledAction = a
++        gcmodes = [
++            (self.NoGc, 'Disable GC'),
++            (self.AutoGc, 'Enable Python GC'),
++            (self.IntervalGc, 'Enable Interval GC'),
++            ]
++        ag = QActionGroup(self)
++        for i, n in gcmodes:
++            a = ag.addAction(n)
++            a.setData(i)
++            a.setCheckable(True)
++        ag.triggered.connect(self._setGcModeByAction)
++        menu.addActions(ag.actions())
++        self._gcModeActionGroup = ag
+         menu.aboutToShow.connect(self._updateGcAction)
+ 
+     @pyqtSlot()
+@@ -56,21 +69,38 @@ class DebugMenuActions(dbgutil.BaseMenuA
+     def _gcTimer(self):
+         return run.qtrun._gc.timer
+ 
+-    def isGcEnabled(self):
+-        return self._gcTimer.isActive()
++    def gcMode(self):
++        if gc.isenabled():
++            return self.AutoGc
++        elif self._gcTimer.isActive():
++            return self.IntervalGc
++        else:
++            return self.NoGc
+ 
+-    @pyqtSlot(bool)
+-    def setGcEnabled(self, enabled):
+-        if enabled:
++    @pyqtSlot(QAction)
++    def _setGcModeByAction(self, action):
++        mode, _ok = action.data().toInt()
++        self.setGcMode(mode)
++
++    def setGcMode(self, mode):
++        if mode == self.NoGc:
++            gc.disable()
++            self._gcTimer.stop()
++        elif mode == self.AutoGc:
++            gc.enable()
++            self._gcTimer.stop()
++        elif mode == self.IntervalGc:
++            gc.disable()
+             self._gcTimer.start()
+         else:
+-            self._gcTimer.stop()
++            raise ValueError('invalid gc mode: %d' % mode)
++        self._updateGcAction()
+ 
+     @pyqtSlot()
+     def _updateGcAction(self):
+         self._gcStatusAction.setText('  count = %s'
+                                      % ', '.join(map(str, gc.get_count())))
+-        self._gcEnabledAction.setChecked(self.isGcEnabled())
++        self._gcModeActionGroup.actions()[self.gcMode()].setChecked(True)
+ 
+ def _workbenchrun(orig, ui, *pats, **opts):
+     dlg = orig(ui, *pats, **opts)
+# HG changeset patch
+# Date 1361683905 -32400
+# Parent 015b94a0da71bda193dea61a5f607816ce31a7f9
+repofilter: have revset combo take more space if possible
+
+804a09d0d7b5 intended to do this, but it has no effect due to fixes for #670,
+b2669fcd6319 and 38cb0dc489f0.
+
+Unlike the name of setMinimumContentsLength(), it can avoid the combo box
+taking too much space. If specified, minimumSizeHint() follows that value and
+sizeHint() follows the specified SizeAdjustPolicy. Thus, the branch combo will
+have preferred width only if it can fit to the layout.
+
+http://qt.gitorious.org/qt/qt/blobs/4.7/src/gui/widgets/qcombobox.cpp#line293
+
+diff --git a/tortoisehg/hgqt/repofilter.py b/tortoisehg/hgqt/repofilter.py
+--- a/tortoisehg/hgqt/repofilter.py
++++ b/tortoisehg/hgqt/repofilter.py
+@@ -62,7 +62,7 @@ class RepoFilterBar(QToolBar):
+         self.revsetcombo = combo = QComboBox()
+         combo.setEditable(True)
+         combo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
+-        combo.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLength)
++        combo.setMinimumContentsLength(10)
+         qtlib.allowCaseChangingInput(combo)
+         le = combo.lineEdit()
+         le.returnPressed.connect(self.returnPressed)
+@@ -240,8 +240,7 @@ class RepoFilterBar(QToolBar):
+         self._branchLabel.setMenu(self._branchMenu)
+ 
+         self._branchCombo = QComboBox()
+-        self._branchCombo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
+-        self._branchCombo.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLength)
++        self._branchCombo.setMinimumContentsLength(10)
+         self._branchCombo.currentIndexChanged.connect(self._emitBranchChanged)
+         self._branchReloading = False
+ 

revsetnotfound.diff

+# HG changeset patch
+# Date 1361637146 -32400
+# Parent 316c052ec9de163bd17834b4e20aff71e6076ef3
+repofilter: say "no matches found" loudly in infobar (closes #344)
+
+diff --git a/tortoisehg/hgqt/repofilter.py b/tortoisehg/hgqt/repofilter.py
+--- a/tortoisehg/hgqt/repofilter.py
++++ b/tortoisehg/hgqt/repofilter.py
+@@ -25,6 +25,7 @@ class RepoFilterBar(QToolBar):
+ 
+     setRevisionSet = pyqtSignal(object)
+     clearRevisionSet = pyqtSignal()
++    revisionSetNotFound = pyqtSignal()
+     filterToggled = pyqtSignal(bool)
+ 
+     showMessage = pyqtSignal(QString)
+@@ -166,7 +167,7 @@ class RepoFilterBar(QToolBar):
+         if revset:
+             self.setRevisionSet.emit(revset)
+         else:
+-            self.clearRevisionSet.emit()
++            self.revisionSetNotFound.emit()
+         self.saveQuery()
+         self.revsetcombo.lineEdit().selectAll()
+ 
+diff --git a/tortoisehg/hgqt/repowidget.py b/tortoisehg/hgqt/repowidget.py
+--- a/tortoisehg/hgqt/repowidget.py
++++ b/tortoisehg/hgqt/repowidget.py
+@@ -169,6 +169,8 @@ class RepoWidget(QWidget):
+         self.filterbar.showMessage.connect(self.showMessage)
+         self.filterbar.setRevisionSet.connect(self.setRevisionSet)
+         self.filterbar.clearRevisionSet.connect(self._unapplyRevisionSet)
++        self.filterbar.revisionSetNotFound.connect(
++            self._unapplyRevisionSetOnNotFound)
+         self.filterbar.filterToggled.connect(self.filterToggled)
+         self.filterbar.hide()
+         self.revsetfilter = self.filterbar.filtercb.isChecked()
+@@ -573,6 +575,11 @@ class RepoWidget(QWidget):
+             self.refresh()
+         return False
+ 
++    @pyqtSlot()
++    def _unapplyRevisionSetOnNotFound(self):
++        self.setInfoBar(qtlib.StatusInfoBar, _('No matches found'))
++        self._unapplyRevisionSet()
++
+     def setRevisionSet(self, revisions):
+         revs = revisions[:]
+         revs.sort(reverse=True)
+@@ -585,6 +592,7 @@ class RepoWidget(QWidget):
+         self.repoview.resetBrowseHistory(self.revset)
+         self._reload_rev = self.revset[0]
+         self.repoview._paletteswitcher.enablefilterpalette(revs)
++        self.clearInfoBar(qtlib.InfoBar.INFO)
+ 
+     @pyqtSlot(bool)
+     def filterToggled(self, checked):
+longbra.diff
+branch-editable.diff
+revsetnotfound.diff
+branch-selectall.diff
+branch-sep.diff
+dbgtools-gcmode.diff
 filterbarev.diff
 finished-nodel-debug.diff
 no-delete-later.diff