Skip to content

Commit

Permalink
views.main: Make Ctrl+C "copy to clipboard" in the diff viewer
Browse files Browse the repository at this point in the history
Closes #63

Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information
davvid committed Aug 25, 2010
1 parent b14ff6c commit fb294f3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
21 changes: 17 additions & 4 deletions cola/views/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from cola.controllers.options import update_options
from cola.controllers.stash import stash


class MainView(MainWindow):
"""The main cola interface."""

Expand Down Expand Up @@ -98,7 +99,7 @@ def __init__(self, parent=None):
self._connect_button(self.stash_button, stash)

# Menu actions
actions = (
actions = [
(self.menu_quit, self.close),
(self.menu_branch_compare, compare.branch_compare),
(self.menu_branch_diff, guicmds.branch_diff),
Expand Down Expand Up @@ -161,7 +162,19 @@ def __init__(self, parent=None):
(self.menu_redo, self.commitmsg.redo),
(self.menu_classic, classic.cola_classic),
(self.menu_dag, dag.git_dag),
)
]

# Diff Actions
if hasattr(Qt, 'WidgetWithChildrenShortcut'):
# We can only enable this shortcut on newer versions of Qt
# that support WidgetWithChildrenShortcut otherwise we get
# an ambiguous shortcut error.
self.diff_copy = QtGui.QAction(self.display_text)
self.diff_copy.setShortcut(QtGui.QKeySequence.Copy)
self.diff_copy.setShortcutContext(Qt.WidgetWithChildrenShortcut)
self.display_text.addAction(self.diff_copy)
actions.append((self.diff_copy, self.copy_display,))

for menu, callback in actions:
self.connect(menu, SIGNAL('triggered()'), callback)

Expand Down Expand Up @@ -330,8 +343,8 @@ def _load_gui_state(self):
def diff_key_press_event(self, event):
"""Handle shortcut keys in the diff view."""
if event.key() != QtCore.Qt.Key_H and event.key() != QtCore.Qt.Key_S:
event.ignore()
return
return QtGui.QTextEdit.keyPressEvent(self.display_text, event)

staged, modified, unmerged, untracked = cola.single_selection()
if event.key() == QtCore.Qt.Key_H:
if self.mode == self.model.mode_worktree and modified:
Expand Down
14 changes: 8 additions & 6 deletions cola/views/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __init__(self, parent=None):
self.menu_stage_untracked = self.create_action('Stage All Untracked')
self.menu_export_patches = self.create_action('Export Patches...')
self.menu_cut = self.create_action('Cut')
self.menu_copy = self.create_action('Copy')
self.menu_copy = self.create_action('Copy', local=True)
self.menu_paste = self.create_action('Paste')
self.menu_select_all = self.create_action('Select All')
self.menu_options = self.create_action('Options')
Expand Down Expand Up @@ -341,10 +341,10 @@ def __init__(self, parent=None):
self.menu_stage_modified.setShortcut(tr('Alt+A'))
self.menu_stage_untracked.setShortcut(tr('Alt+U'))
self.menu_export_patches.setShortcut(tr('Ctrl+E'))
self.menu_cut.setShortcut(tr('Ctrl+X'))
self.menu_copy.setShortcut(tr('Ctrl+C'))
self.menu_paste.setShortcut(tr('Ctrl+V'))
self.menu_select_all.setShortcut(tr('Ctrl+A'))
self.menu_cut.setShortcut(QtGui.QKeySequence.Cut)
self.menu_copy.setShortcut(QtGui.QKeySequence.Copy)
self.menu_paste.setShortcut(QtGui.QKeySequence.Paste)
self.menu_select_all.setShortcut(QtGui.QKeySequence.SelectAll)
self.menu_options.setShortcut(tr('Ctrl+O'))
self.menu_delete.setShortcut(tr('Del'))
self.menu_undo.setShortcut(tr('Ctrl+Z'))
Expand Down Expand Up @@ -380,10 +380,12 @@ def create_menu(self, title, parent):
qmenu.setTitle(tr(title))
return qmenu

def create_action(self, title):
def create_action(self, title, local=False):
"""Create an action and set its title."""
action = QtGui.QAction(self)
action.setText(tr(title))
if local and hasattr(Qt, 'WidgetWithChildrenShortcut'):
action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
return action

def closeEvent(self, event):
Expand Down

0 comments on commit fb294f3

Please sign in to comment.