Skip to content

Commit

Permalink
Merge pull request git-cola#713 from javierrodriguezcuevas/feature/br…
Browse files Browse the repository at this point in the history
…anches_filter

* javierrodriguezcuevas/feature/branches_filter:
  branch: applying bold text to filtered branches
  branch: add filter widget

Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information
davvid committed Jul 29, 2017
2 parents 4829ed2 + d21b7e8 commit eccc2c3
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 3 deletions.
72 changes: 70 additions & 2 deletions cola/widgets/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import division, absolute_import, unicode_literals
import re

from qtpy import QtGui
from qtpy import QtWidgets
from qtpy.QtCore import Qt
from qtpy.QtCore import Signal
Expand All @@ -14,8 +15,10 @@
from ..widgets import defs
from ..widgets import standard
from .. import gitcmds
from .. import hotkeys
from .. import icons
from .. import qtutils
from .text import LineEdit


SEPARATOR_CHAR = '/'
Expand Down Expand Up @@ -44,17 +47,40 @@ def task(self):


class BranchesWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
def __init__(self, titlebar, parent=None):
QtWidgets.QWidget.__init__(self, parent)

tooltip = N_('Toggle the branches filter')
icon = icons.ellipsis()
self.filter_button = qtutils.create_action_button(tooltip=tooltip,
icon=icon)

self.tree = BranchesTreeWidget(parent=self)
self.filter_widget = BranchesFilterWidget(self.tree)
self.filter_widget.hide()

self.setFocusProxy(self.tree)
self.setToolTip(N_('Branches'))

self.main_layout = qtutils.vbox(defs.no_margin, defs.spacing, self.tree)
self.main_layout = qtutils.vbox(defs.no_margin, defs.spacing,
self.filter_widget, self.tree)
self.setLayout(self.main_layout)

self.toggle_action = qtutils.add_action(self, tooltip,
self.toggle_filter,
hotkeys.FILTER)

titlebar.add_corner_widget(self.filter_button)
qtutils.connect_button(self.filter_button, self.toggle_filter)

def toggle_filter(self):
shown = not self.filter_widget.isVisible()
self.filter_widget.setVisible(shown)
if shown:
self.filter_widget.setFocus(True)
else:
self.tree.setFocus(True)


class BranchesTreeWidget(standard.TreeWidget):
updated = Signal()
Expand Down Expand Up @@ -523,3 +549,45 @@ def show_result(command, status, out, err):
if err:
msg += err
qtutils.critical(title, msg, details)


class BranchesFilterWidget(QtWidgets.QWidget):
def __init__(self, tree, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.tree = tree

hint = N_('Filter branches...')
self.text = LineEdit()
self.text.setClearButtonEnabled(True)
self.text.setToolTip(hint)
self.setFocusProxy(self.text)
self._filter = None

self.main_layout = qtutils.hbox(defs.no_margin, defs.spacing, self.text)
self.setLayout(self.main_layout)

text = self.text
text.textChanged.connect(self.apply_filter)
self.tree.updated.connect(self.apply_filter, type=Qt.QueuedConnection)

def apply_filter(self):
text = self.text.value()
if text == self._filter:
return

self._apply_bold(self._filter, False)
self._filter = text

if text == '':
return

self._apply_bold(text, True)

def _apply_bold(self, text, value):
children = self.tree.findItems(text, Qt.MatchContains | Qt.MatchRecursive)

for child in children:
if child.childCount() == 0:
font = child.font(0)
font.setBold(value)
child.setFont(0, font)
4 changes: 3 additions & 1 deletion cola/widgets/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ def __init__(self, model, parent=None, settings=None):

# "Branch" widgets
self.branchdockwidget = create_dock(N_('Branches'), self)
self.branchwidget = branch.BranchesWidget(parent=self.branchdockwidget)
titlebar = self.branchdockwidget.titleBarWidget()
self.branchwidget = branch.BranchesWidget(titlebar,
parent=self.branchdockwidget)
self.branchdockwidget.setWidget(self.branchwidget)

# "Commit Message Editor" widget
Expand Down

0 comments on commit eccc2c3

Please sign in to comment.