From 90cbdf518071c91fec747bbfbb3989f5233aa9a2 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sat, 31 Mar 2012 17:57:45 -0700 Subject: [PATCH] commitmsg: Add 'Sign Off' and 'Commit' to the context menus We recently made it so that 'tab' jumps from the summary to the extended description. A consequence of this is that we can no longer tab over to the commit button. Add a new entry point to this action in the summary and extended description's context menus to compensate for it. This also advertises the 'Ctrl+Return' keyboard shortcut in the context menu, which makes it more discoverable. Signed-off-by: David Aguilar --- cola/widgets/commitmsg.py | 50 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/cola/widgets/commitmsg.py b/cola/widgets/commitmsg.py index 77681b4b..3d69fcbf 100644 --- a/cola/widgets/commitmsg.py +++ b/cola/widgets/commitmsg.py @@ -34,8 +34,25 @@ class CommitMessageEditor(QtGui.QWidget): self.model = model self.notifying = False + # Actions + self.signoff_action = add_action(self, 'Sign Off', + emit(self, signals.signoff), + 'Ctrl+I') + self.signoff_action.setToolTip('Sign off on this commit') + + self.commit_action = add_action(self, 'Commit@@verb', + self.commit, + 'Ctrl+Return') + self.commit_action.setToolTip(tr('Commit staged changes')) + + # Widgets self.summary = CommitSummaryLineEdit() + self.summary.extra_actions.append(self.signoff_action) + self.summary.extra_actions.append(self.commit_action) + self.description = CommitMessageTextEdit() + self.description.extra_actions.append(self.signoff_action) + self.description.extra_actions.append(self.commit_action) commit_button_tooltip = 'Commit staged changes\nShortcut: Ctrl+Enter' self.commit_button = create_toolbutton(text='Commit@@verb', @@ -48,16 +65,11 @@ class CommitMessageEditor(QtGui.QWidget): self.actions_button.setMenu(self.actions_menu) self.actions_button.setPopupMode(QtGui.QToolButton.InstantPopup) - # Amend checkbox - self.signoff_action = self.actions_menu.addAction(tr('Sign Off')) - self.signoff_action.setToolTip('Sign off on this commit') - self.signoff_action.setShortcut('Ctrl+I') - - self.commit_action = self.actions_menu.addAction(tr('Commit@@verb')) - self.commit_action.setToolTip(tr('Commit staged changes')) - self.commit_action.setShortcut('Ctrl+Return') - + self.actions_menu.addAction(self.signoff_action) + self.actions_menu.addAction(self.commit_action) self.actions_menu.addSeparator() + + # Amend checkbox self.amend_action = self.actions_menu.addAction(tr('Amend Last Commit')) self.amend_action.setCheckable(True) @@ -84,8 +96,6 @@ class CommitMessageEditor(QtGui.QWidget): SIGNAL(signals.load_previous_message)) connect_button(self.commit_button, self.commit) - connect_action(self.commit_action, self.commit) - connect_action(self.signoff_action, emit(self, signals.signoff)) cola.notifier().connect(signals.amend, self.amend_action.setChecked) @@ -346,6 +356,7 @@ class CommitSummaryLineEdit(HintedLineEdit): def __init__(self, parent=None): hint = u'Commit summary' HintedLineEdit.__init__(self, hint, parent) + self.extra_actions = [] def keyPressEvent(self, event): if event.key() == Qt.Key_Down: @@ -361,11 +372,20 @@ class CommitSummaryLineEdit(HintedLineEdit): return HintedLineEdit.keyPressEvent(self, event) + def contextMenuEvent(self, event): + menu = self.createStandardContextMenu() + if self.extra_actions: + menu.addSeparator() + for action in self.extra_actions: + menu.addAction(action) + menu.exec_(self.mapToGlobal(event.pos())) + class CommitMessageTextEdit(HintedTextEdit): def __init__(self, parent=None): hint = u'Extended description...' HintedTextEdit.__init__(self, hint, parent) + self.extra_actions = [] self.setMinimumSize(QtCore.QSize(1, 1)) self.action_emit_shift_tab = add_action(self, @@ -384,6 +404,14 @@ class CommitMessageTextEdit(HintedTextEdit): return False + def contextMenuEvent(self, event): + menu = self.createStandardContextMenu() + if self.extra_actions: + menu.addSeparator() + for action in self.extra_actions: + menu.addAction(action) + menu.exec_(self.mapToGlobal(event.pos())) + def keyPressEvent(self, event): if event.key() == Qt.Key_Up: cursor = self.textCursor() -- 2.11.4.GIT