From 91ad83bc91b75fe53eeb4f214eb88c650d90baf4 Mon Sep 17 00:00:00 2001 From: Efimov Vasily Date: Mon, 4 Jul 2022 23:07:08 +0300 Subject: [PATCH] cola: add Open Worktree command to Status Widget Signed-off-by: Efimov Vasily --- cola/cmds.py | 12 ++++++++++++ cola/widgets/common.py | 13 +++++++++++++ cola/widgets/status.py | 5 +++++ 3 files changed, 30 insertions(+) diff --git a/cola/cmds.py b/cola/cmds.py index 7a76d5d9..5d2d0d8f 100644 --- a/cola/cmds.py +++ b/cola/cmds.py @@ -1716,6 +1716,18 @@ class OpenParentDir(OpenDir): return dirnames +class OpenWorktree(OpenDir): + """Open worktree directory using the OS default.""" + + @staticmethod + def name(): + return N_('Open Worktree') + + def __init__(self, context, __): + dirnames = [context.git.worktree()] + super(OpenWorktree, self).__init__(context, dirnames) + + class OpenNewRepo(ContextCommand): """Launches git-cola on a repo.""" diff --git a/cola/widgets/common.py b/cola/widgets/common.py index 036ad44c..ba0903e7 100644 --- a/cola/widgets/common.py +++ b/cola/widgets/common.py @@ -52,6 +52,19 @@ def parent_dir_action(context, parent, fn): return action +def worktree_dir_action(context, parent, *keys): + """Open the repository worktree -> QAction""" + action = cmd_action( + parent, + cmds.OpenWorktree, + context, + lambda: None, # nop + *keys + ) + action.setIcon(icons.folder()) + return action + + def refresh_action(context, parent): """Refresh the repository state -> QAction""" return qtutils.add_action( diff --git a/cola/widgets/status.py b/cola/widgets/status.py index 2b547534..887c18b3 100644 --- a/cola/widgets/status.py +++ b/cola/widgets/status.py @@ -193,6 +193,8 @@ class StatusTreeWidget(QtWidgets.QTreeWidget): context, self, self.selected_group ) + self.worktree_dir_action = common.worktree_dir_action(context, self) + self.terminal_action = common.terminal_action( context, self, self.selected_group ) @@ -684,6 +686,9 @@ class StatusTreeWidget(QtWidgets.QTreeWidget): if self.terminal_action is not None: menu.addAction(self.terminal_action) + if not utils.is_win32(): + menu.addAction(self.worktree_dir_action) + self._add_copy_actions(menu) return menu -- 2.11.4.GIT