From b50af4a6f80e8e0f54fbd570dbe42a313dbe0ec5 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sun, 7 Feb 2021 15:11:16 -0800 Subject: [PATCH] toolbar: add tooltips to the Reset actions Related-to: #890 Signed-off-by: David Aguilar --- cola/widgets/toolbar.py | 37 +++++++++++++++++++++++++------------ cola/widgets/toolbarcmds.py | 19 ++++++++++--------- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/cola/widgets/toolbar.py b/cola/widgets/toolbar.py index a214f7cf..e1eb4005 100644 --- a/cola/widgets/toolbar.py +++ b/cola/widgets/toolbar.py @@ -212,6 +212,11 @@ class ToolBar(QtWidgets.QToolBar): toolbar_action.setData(data) + tooltip = command.get('tooltip', None) + if tooltip: + toolbar_action.setToolTip('%s\n%s' % (title, tooltip)) + + def delete_toolbar(self): self.parent().removeToolBar(self) @@ -331,8 +336,9 @@ class ToolbarView(standard.Dialog): except KeyError: pass title = command['title'] - icon = command['icon'] - self.right_list.add_item(title, data, icon) + icon = command.get('icon', None) + tooltip = command.get('tooltip', None) + self.right_list.add_item(title, tooltip, data, icon) def load_left_items(self): commands = self.toolbar.commands @@ -343,7 +349,11 @@ class ToolbarView(standard.Dialog): command = commands[item] except KeyError: pass - child = create_child(parent, item, command['title'], command['icon']) + icon = command.get('icon', None) + tooltip = command.get('tooltip', None) + child = create_child( + parent, item, command['title'], tooltip, icon + ) top.appendRow(child) top.sortChildren(0, Qt.AscendingOrder) @@ -435,14 +445,16 @@ class DraggableListWidget(QtWidgets.QListWidget): self.addItem(item) - def add_item(self, title, data, icon_text=None): + def add_item(self, title, tooltip, data, icon): item = QtWidgets.QListWidgetItem() item.setText(N_(title)) item.setData(Qt.UserRole, data) + if tooltip: + item.setToolTip(tooltip) - if icon_text is not None: - icon = getattr(icons, icon_text, None) - item.setIcon(icon()) + if icon: + icon_func = getattr(icons, icon) + item.setIcon(icon_func()) self.addItem(item) @@ -476,13 +488,14 @@ class ToolbarTreeWidget(standard.TreeView): return item -def create_child(parent, child, title, icon_text=None): +def create_child(parent, child, title, tooltip, icon): data = {'parent': parent, 'child': child} item = create_item(title, data) - - if icon_text is not None: - icon = getattr(icons, icon_text, None) - item.setIcon(icon()) + if tooltip: + item.setToolTip(tooltip) + if icon: + icon_func = getattr(icons, icon, None) + item.setIcon(icon_func()) return item diff --git a/cola/widgets/toolbarcmds.py b/cola/widgets/toolbarcmds.py index 2d272696..fafa7c29 100644 --- a/cola/widgets/toolbarcmds.py +++ b/cola/widgets/toolbarcmds.py @@ -121,22 +121,26 @@ COMMANDS = { 'Actions::ResetSoft': { 'title': 'Reset Branch (Soft)', 'action': guicmds.reset_soft, - 'icon': None, + 'icon': 'style_dialog_reset', + 'tooltip': cmds.ResetSoft.tooltip(''), }, 'Actions::ResetMixed': { 'title': 'Reset Branch and Stage (Mixed)', 'action': guicmds.reset_mixed, - 'icon': None, + 'icon': 'style_dialog_reset', + 'tooltip': cmds.ResetMixed.tooltip(''), }, 'Actions::ResetKeep': { 'title': 'Restore Worktree and Reset All (Keep Unstaged Changes)', 'action': guicmds.reset_keep, - 'icon': None, + 'icon': 'style_dialog_reset', + 'tooltip': cmds.ResetKeep.tooltip(''), }, 'Actions::ResetHard': { 'title': 'Restore Worktre and Reset All (Hard)', 'action': guicmds.reset_hard, - 'icon': None, + 'icon': 'style_dialog_reset', + 'tooltip': cmds.ResetHard.tooltip(''), }, 'Actions::Grep': { 'title': 'Grep', @@ -156,7 +160,7 @@ COMMANDS = { 'Commit::AmendLast': { 'title': 'Amend Last Commit', 'action': cmds.run(cmds.AmendMode), - 'icon': None, + 'icon': 'edit', }, 'Commit::UndoLastCommit': { 'title': 'Undo Last Commit', @@ -166,12 +170,11 @@ COMMANDS = { 'Commit::StageAll': { 'title': 'Stage All Untracked', 'action': cmds.run(cmds.StageUntracked), - 'icon': None, }, 'Commit::UnstageAll': { 'title': 'Unstage All', 'action': cmds.run(cmds.UnstageAll), - 'icon': None, + 'icon': 'remove', }, 'Commit::Unstage': { 'title': 'Unstage', @@ -181,12 +184,10 @@ COMMANDS = { 'Commit::LoadCommitMessage': { 'title': 'Load Commit Message...', 'action': guicmds.load_commitmsg, - 'icon': None, }, 'Commit::GetCommitMessageTemplate': { 'title': 'Get Commit Message Template', 'action': cmds.run(cmds.LoadCommitMessageFromTemplate), - 'icon': None, }, 'Diff::Difftool': { 'title': 'Launch Diff tool', -- 2.11.4.GIT