cmds: add a separate LaunchEditorAtLine command
[git-cola.git] / cola / actions.py
blob0780749192cc2687745b111bdda56376bdc935b2
1 """QAction creator functions"""
2 from __future__ import absolute_import, division, unicode_literals
4 from . import cmds
5 from . import hotkeys
6 from . import icons
7 from . import qtutils
8 from .i18n import N_
11 def cmd_action(widget, cmd, context, icon, *shortcuts):
12 """Wrap a generic ContextCommand in a QAction"""
13 action = qtutils.add_action(widget, cmd.name(), cmds.run(cmd, context),
14 *shortcuts)
15 action.setIcon(icon)
16 return action
19 def launch_editor(context, widget, *shortcuts):
20 """Create a QAction to launch an editor"""
21 icon = icons.edit()
22 return cmd_action(widget, cmds.LaunchEditor, context, icon, hotkeys.EDIT,
23 *shortcuts)
26 def launch_editor_at_line(context, widget, *shortcuts):
27 """Create a QAction to launch an editor"""
28 icon = icons.edit()
29 return cmd_action(widget, cmds.LaunchEditorAtLine, context, icon,
30 hotkeys.EDIT, *shortcuts)
33 def launch_difftool(context, widget):
34 """Create a QAction to launch git-difftool(1)"""
35 icon = icons.diff()
36 cmd = cmds.LaunchDifftool
37 action = qtutils.add_action(widget, cmd.name(), cmds.run(cmd, context),
38 hotkeys.DIFF)
39 action.setIcon(icon)
40 return action
43 def stage_or_unstage(context, widget):
44 """Create a QAction to stage or unstage the selection"""
45 icon = icons.add()
46 return cmd_action(widget, cmds.StageOrUnstage, context, icon,
47 hotkeys.STAGE_SELECTION)
50 def move_down(widget):
51 """Create a QAction to select the next item"""
52 return qtutils.add_action(widget, N_('Next File'), widget.down.emit,
53 hotkeys.MOVE_DOWN_SECONDARY)
56 def move_up(widget):
57 """Create a QAction to select the previous/above item"""
58 return qtutils.add_action(widget, N_('Previous File'), widget.up.emit,
59 hotkeys.MOVE_UP_SECONDARY)