Read about our upcoming Code of Conduct on this issue

This instance was upgraded to Heptapod 0.28.0 today

repofilter.py 5.91 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
# 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 *

Yuya Nishihara's avatar
Yuya Nishihara committed
12
from tortoisehg.hgqt.i18n import _
13
from tortoisehg.hgqt import revset, qtlib
Yuya Nishihara's avatar
Yuya Nishihara committed
14

15
16
17
class RepoFilterBar(QToolBar):
    """Toolbar for RepoWidget to filter changesets"""

18
19
    revisionSet = pyqtSignal(object)
    clearSet = pyqtSignal()
20
    filterToggled = pyqtSignal(bool)
21
22
23
24

    showMessage = pyqtSignal(QString)
    progress = pyqtSignal(QString, object, QString, QString, object)

25
26
27
    branchChanged = pyqtSignal(unicode, bool)
    """Emitted (branch, allparents) when branch selection changed"""

28
    def __init__(self, repo, parent):
29
30
        super(RepoFilterBar, self).__init__(parent)
        self.layout().setContentsMargins(0, 0, 0, 0)
31
32
33
        self.setIconSize(QSize(16,16))
        self.setFloatable(False)
        self.setMovable(False)
34
35
        self._repo = repo

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
        self.entrydlg = revset.RevisionSetQuery(repo, self)
        self.entrydlg.progress.connect(self.progress)
        self.entrydlg.showMessage.connect(self.showMessage)
        self.entrydlg.queryIssued.connect(self.dialogQuery)
        self.entrydlg.hide()

        self.clear = QPushButton(_('clear'))
        self.addWidget(self.clear)

        self.editor = QPushButton(_('editor'))
        self.editor.clicked.connect(self.openEditor)
        self.addWidget(self.editor)

        s = QSettings()
        self.entrydlg.restoreGeometry(s.value('revset/geom').toByteArray())
        self.revsethist = list(s.value('revset-queries').toStringList())
        self.revsetle = le = QLineEdit()
53
        le.setCompleter(QCompleter(self.revsethist, self))
54
        le.returnPressed.connect(self.returnPressed)
55
56
        if hasattr(self.revsetle, 'setPlaceholderText'): # Qt >= 4.7 
            self.revsetle.setPlaceholderText('### revision set query ###')
57
58
59
60
61
        self.addWidget(le)

        self.clear.clicked.connect(le.clear)
        self.clear.clicked.connect(self.clearSet)

62
        self.filtercb = f = QCheckBox(_('filter'))
63
        f.setChecked(s.value('revset-filter', True).toBool())
64
65
66
        f.toggled.connect(self.filterToggled)
        self.addWidget(f)

67
68
69
70
71
        self.store = store = QPushButton(_('store'))
        store.clicked.connect(self.saveQuery)
        le.textChanged.connect(lambda t: store.setEnabled(False))
        store.setEnabled(False)
        self.addWidget(store)
72
73
74
75

        self._initbranchfilter()
        self.refresh()

76
77
78
    def showEvent(self, event):
        self.revsetle.setFocus()

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    def openEditor(self):
        query = self.revsetle.text().simplified()
        self.entrydlg.entry.setText(query)
        self.entrydlg.entry.setCursorPosition(0, len(query))
        self.entrydlg.entry.setFocus()
        self.entrydlg.setShown(True)

    def dialogQuery(self, query, revset):
        self.revsetle.setText(query)
        self.store.setEnabled(True)
        self.revisionSet.emit(revset)

    def returnPressed(self):
        'Return pressed on revset line entry, forward to dialog'
        query = self.revsetle.text().simplified()
        if query:
            self.entrydlg.entry.setText(query)
            self.entrydlg.runQuery()

    def saveQuery(self):
        query = self.revsetle.text()
        if query in self.revsethist:
            self.revsethist.remove(query)
        self.revsethist.insert(0, query)
103
        self.revsetle.setCompleter(QCompleter(self.revsethist, self))
104
105
106
107
108
109
        self.store.setEnabled(False)
        self.showMessage.emit(_('Revision set query saved'))

    def storeConfigs(self, s):
        s.setValue('revset/geom', self.entrydlg.saveGeometry())
        s.setValue('revset-queries', self.revsethist)
110
        s.setValue('revset-filter', self.filtercb.isChecked())
111

112
    def _initbranchfilter(self):
113
        self._branchLabel = QToolButton(
114
115
            text=_('Branch'), popupMode=QToolButton.InstantPopup,
            statusTip=_('Display graph the named branch only'))
116
117
        self._branchMenu = QMenu(self._branchLabel)
        self._cbranchAction = self._branchMenu.addAction(
118
            _('Display closed branches'), self.refresh)
119
120
        self._cbranchAction.setCheckable(True)
        self._allparAction = self._branchMenu.addAction(
121
            _('Include all ancestors'), self._emitBranchChanged)
122
123
        self._allparAction.setCheckable(True)
        self._branchLabel.setMenu(self._branchMenu)
124

125
126
        self._branchCombo = QComboBox()
        self._branchCombo.currentIndexChanged.connect(self._emitBranchChanged)
127
        self._branchReloading = False
128

129
130
        self.addWidget(self._branchLabel)
        self.addWidget(self._branchCombo)
131
132
133
134
135

    def _updatebranchfilter(self):
        """Update the list of branches"""
        curbranch = self.branch()

136
137
138
139
140
        if self._cbranchAction.isChecked():
            branches = sorted(self._repo.branchtags().keys())
        else:
            branches = self._repo.namedbranches

141
        self._branchReloading = True
142
143
144
145
        self._branchCombo.clear()
        self._branchCombo.addItems([''] + branches)
        self._branchLabel.setEnabled(len(branches) > 1)
        self._branchCombo.setEnabled(len(branches) > 1)
146
        self._branchReloading = False
147
148
149
150
151
152

        self.setBranch(curbranch)

    @pyqtSlot(unicode)
    def setBranch(self, branch):
        """Change the current branch by name [unicode]"""
153
        self._branchCombo.setCurrentIndex(self._branchCombo.findText(branch))
154
155
156

    def branch(self):
        """Return the current branch name [unicode]"""
157
        return unicode(self._branchCombo.currentText())
158
159
160

    @pyqtSlot()
    def _emitBranchChanged(self):
161
162
163
        if not self._branchReloading:
            self.branchChanged.emit(self.branch(),
                                    self._allparAction.isChecked())
164
165
166
167

    @pyqtSlot()
    def refresh(self):
        self._updatebranchfilter()