Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

widgets.grep: Add an 'Edit' button

Make the GUI more discoverable by displaying its unique feature.

Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information...
commit 57b955b799967e9bfe28b09e1dd0dc7c1e4e04a9 1 parent 59ac741
@davvid davvid authored
Showing with 32 additions and 10 deletions.
  1. +4 −0 cola/qtutils.py
  2. +4 −0 cola/widgets/defs.py
  3. +24 −10 cola/widgets/grep.py
View
4 cola/qtutils.py
@@ -430,6 +430,10 @@ def open_icon():
return cached_icon(QtGui.QStyle.SP_DirOpenIcon)
+def open_file_icon():
+ return icon('open.svg')
+
+
def options_icon():
"""Return a standard open directory icon"""
return icon('options.svg')
View
4 cola/widgets/defs.py
@@ -2,3 +2,7 @@
spacing = 4
handle_width = 4
button_spacing = 12
+
+difftool_shortcut = 'Ctrl+D'
+editor_shortcut = 'Ctrl+E'
+stage_shortcut = 'Ctrl+S'
View
34 cola/widgets/grep.py
@@ -27,8 +27,9 @@ def run(self):
args = utils.shell_split(self.txt)
else:
args = [self.txt]
- result = core.decode(git.grep(with_stderr=True, n=True, *args))
- self.emit(SIGNAL('result'), result)
+ status, out = git.grep(with_status=True, with_stderr=True,
+ n=True, *args)
+ self.emit(SIGNAL('result'), status, core.decode(out))
class Grep(Dialog):
@@ -44,18 +45,24 @@ def __init__(self, parent):
self.input_txt = HintedLineEdit(hint, self)
self.input_txt.enable_hint(True)
+ self.search_button = QtGui.QPushButton('Search')
+
hint = 'grep result...'
self.result_txt = GrepTextView(hint, self)
self.result_txt.enable_hint(True)
- self.search_button = QtGui.QPushButton('Search')
- self.shell_checkbox = QtGui.QCheckBox('Shell arguments')
+ self.edit_button = QtGui.QPushButton(self.tr('Edit'))
+ self.edit_button.setIcon(qtutils.open_file_icon())
+ self.edit_button.setEnabled(False)
+ self.edit_button.setShortcut(defs.editor_shortcut)
+
+ self.shell_checkbox = QtGui.QCheckBox(self.tr('Shell arguments'))
self.shell_checkbox.setToolTip(
'Parse arguments using a shell.\n'
'Queries with spaces will require "double quotes".')
self.shell_checkbox.setChecked(False)
- self.close_button = QtGui.QPushButton('Close')
+ self.close_button = QtGui.QPushButton(self.tr('Close'))
self.input_layout = QtGui.QHBoxLayout()
self.input_layout.setMargin(0)
@@ -73,6 +80,7 @@ def __init__(self, parent):
self.input_layout.addWidget(self.input_txt)
self.input_layout.addWidget(self.search_button)
+ self.bottom_layout.addWidget(self.edit_button)
self.bottom_layout.addWidget(self.shell_checkbox)
self.bottom_layout.addStretch()
self.bottom_layout.addWidget(self.close_button)
@@ -92,6 +100,7 @@ def __init__(self, parent):
lambda x: self.search_button.setEnabled(bool(unicode(x))))
qtutils.connect_button(self.search_button, self.search)
+ qtutils.connect_button(self.edit_button, self.edit)
qtutils.connect_button(self.close_button, self.close)
qtutils.add_close_action(self)
@@ -103,27 +112,32 @@ def done(self, exit_code):
return Dialog.done(self, exit_code)
def search(self):
+ self.search_button.setEnabled(False)
+ self.edit_button.setEnabled(False)
+
self.grep_thread.txt = self.input_txt.as_unicode()
self.grep_thread.shell = self.shell_checkbox.isChecked()
self.grep_thread.start()
- self.search_button.setEnabled(False)
def search_for(self, txt):
self.input_txt.set_value(txt)
self.run()
- def process_result(self, result):
- self.result_txt.set_value(result)
+ def process_result(self, status, out):
+ self.result_txt.set_value(out)
self.search_button.setEnabled(True)
+ self.edit_button.setEnabled(status == 0)
+ def edit(self):
+ guicmds.goto_grep(self.result_txt.selected_line()),
class GrepTextView(HintedTextView):
def __init__(self, hint, parent):
HintedTextView.__init__(self, hint, parent)
self.goto_action = qtutils.add_action(
self, 'Launch Editor',
- lambda: guicmds.goto_grep(self.selected_line()),
- 'Ctrl+E')
+ lambda: guicmds.goto_grep(self.selected_line()))
+ self.goto_action.setShortcut(defs.editor_shortcut)
def contextMenuEvent(self, event):
menu = self.createStandardContextMenu(event.pos())
Please sign in to comment.
Something went wrong with that request. Please try again.