11 def cmd_action(parent
, cmd
, context
, func
, *keys
):
12 """Wrap a standard Command object in a QAction
14 This function assumes that :func:`func()` takes no arguments,
15 that `cmd` has a :func:`name()` method, and that the `cmd`
16 constructor takes a single argument, as returned by `func`.
19 return qtutils
.add_action(
20 parent
, cmd
.name(), lambda: cmds
.do(cmd
, context
, func()), *keys
24 def default_app_action(context
, parent
, func
):
25 """Open paths with the OS-default app -> QAction"""
27 parent
, cmds
.OpenDefaultApp
, context
, func
, hotkeys
.PRIMARY_ACTION
29 action
.setIcon(icons
.default_app())
33 def edit_action(context
, parent
, *keys
):
34 """Launch an editor -> QAction"""
35 action
= qtutils
.add_action_with_tooltip(
37 cmds
.LaunchEditor
.name(),
38 N_('Edit selected paths'),
39 cmds
.run(cmds
.LaunchEditor
, context
),
43 action
.setIcon(icons
.edit())
47 def parent_dir_action(context
, parent
, func
):
48 """Open the parent directory of paths -> QAction"""
49 hotkey
= hotkeys
.SECONDARY_ACTION
50 action
= cmd_action(parent
, cmds
.OpenParentDir
, context
, func
, hotkey
)
51 action
.setIcon(icons
.folder())
55 def worktree_dir_action(context
, parent
, *keys
):
56 """Open the repository worktree -> QAction"""
57 # lambda: None is a no-op.
58 action
= cmd_action(parent
, cmds
.OpenWorktree
, context
, lambda: None, *keys
)
59 action
.setIcon(icons
.folder())
63 def refresh_action(context
, parent
):
64 """Refresh the repository state -> QAction"""
65 return qtutils
.add_action(
66 parent
, cmds
.Refresh
.name(), cmds
.run(cmds
.Refresh
, context
), hotkeys
.REFRESH
70 def terminal_action(context
, parent
, func
=None, hotkey
=None):
71 """Launch a terminal -> QAction"""
73 if cmds
.LaunchTerminal
.is_available(context
):
75 func
= functools
.partial(lambda: None)
80 lambda: utils
.select_directory(func()),
82 action
.setIcon(icons
.terminal())
83 if hotkey
is not None:
84 action
.setShortcut(hotkey
)