Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keyboard shortcuts to context menu in editor #3294

Merged
merged 3 commits into from
Jul 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 58 additions & 52 deletions spyderlib/widgets/sourcecode/codeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def cursor_move_event():
unblockcomment, line_start, line_end, prev_line, next_line,
prev_char, next_char, prev_word, next_word, kill_line_end,
kill_line_start, yank, kill_ring_rotate, kill_prev_word,
kill_next_word, start_doc, end_doc, undo, redo, copy,
kill_next_word, start_doc, end_doc, undo, redo, cut, copy,
paste, delete, select_all]

def get_shortcut_data(self):
Expand Down Expand Up @@ -2454,61 +2454,67 @@ def autoinsert_quotes(self, key):
#===============================================================================
def setup_context_menu(self):
"""Setup context menu"""
self.undo_action = create_action(self, _("Undo"),
icon=ima.icon('undo'), triggered=self.undo)
self.redo_action = create_action(self, _("Redo"),
icon=ima.icon('redo'), triggered=self.redo)
self.cut_action = create_action(self, _("Cut"),
icon=ima.icon('editcut'), triggered=self.cut)
self.copy_action = create_action(self, _("Copy"),
icon=ima.icon('editcopy'), triggered=self.copy)
self.paste_action = create_action(self, _("Paste"),
icon=ima.icon('editpaste'), triggered=self.paste)
selectall_action = create_action(self, _("Select All"),
icon=ima.icon('selectall'),
triggered=self.selectAll)
toggle_comment_action = create_action(self,
_("Comment")+"/"+_("Uncomment"),
icon=ima.icon('comment'),
triggered=self.toggle_comment)
self.clear_all_output_action = create_action(self,
_("Clear all ouput"), icon=ima.icon('ipython_console'),
triggered=self.clear_all_output)
self.ipynb_convert_action = create_action(self,
_("Convert to Python script"),
triggered=self.convert_notebook,
icon=ima.icon('python'))
self.gotodef_action = create_action(self, _("Go to definition"),
triggered=self.go_to_definition_from_cursor)
self.undo_action = create_action(
self, _("Undo"), icon=ima.icon('undo'),
shortcut=get_shortcut('editor', 'undo'), triggered=self.undo)
self.redo_action = create_action(
self, _("Redo"), icon=ima.icon('redo'),
shortcut=get_shortcut('editor', 'redo'), triggered=self.redo)
self.cut_action = create_action(
self, _("Cut"), icon=ima.icon('editcut'),
shortcut=get_shortcut('editor', 'cut'), triggered=self.cut)
self.copy_action = create_action(
self, _("Copy"), icon=ima.icon('editcopy'),
shortcut=get_shortcut('editor', 'copy'), triggered=self.copy)
self.paste_action = create_action(
self, _("Paste"), icon=ima.icon('editpaste'),
shortcut=get_shortcut('editor', 'paste'), triggered=self.paste)
selectall_action = create_action(
self, _("Select All"), icon=ima.icon('selectall'),
shortcut=get_shortcut('editor', 'select all'),
triggered=self.selectAll)
toggle_comment_action = create_action(
self, _("Comment")+"/"+_("Uncomment"), icon=ima.icon('comment'),
shortcut=get_shortcut('editor', 'toggle comment'),
triggered=self.toggle_comment)
self.clear_all_output_action = create_action(
self, _("Clear all ouput"), icon=ima.icon('ipython_console'),
triggered=self.clear_all_output)
self.ipynb_convert_action = create_action(
self, _("Convert to Python script"), icon=ima.icon('python'),
triggered=self.convert_notebook)
self.gotodef_action = create_action(
self, _("Go to definition"),
shortcut=get_shortcut('editor', 'go to definition'),
triggered=self.go_to_definition_from_cursor)

# Run actions
self.run_cell_action = create_action(self,
_("Run cell"),
icon=ima.icon('run_cell'),
shortcut=QKeySequence(RUN_CELL_SHORTCUT),
triggered=lambda: self.run_cell.emit())
self.run_cell_and_advance_action = create_action(self,
_("Run cell and advance"),
icon=ima.icon('run_cell'),
shortcut=QKeySequence(RUN_CELL_AND_ADVANCE_SHORTCUT),
triggered=lambda: self.run_cell_and_advance.emit())
self.run_selection_action = create_action(self,
_("Run &selection or current line"),
icon=ima.icon('run_selection'),
triggered=lambda: self.run_selection.emit())
self.run_cell_action = create_action(
self, _("Run cell"), icon=ima.icon('run_cell'),
shortcut=QKeySequence(RUN_CELL_SHORTCUT),
triggered=self.run_cell.emit)
self.run_cell_and_advance_action = create_action(
self, _("Run cell and advance"), icon=ima.icon('run_cell'),
shortcut=QKeySequence(RUN_CELL_AND_ADVANCE_SHORTCUT),
triggered=self.run_cell_and_advance.emit)
self.run_selection_action = create_action(
self, _("Run &selection or current line"),
icon=ima.icon('run_selection'),
shortcut=get_shortcut('editor', 'run selection'),
triggered=self.run_selection.emit)

# Zoom actions
zoom_in_action = create_action(self, _("Zoom in"),
QKeySequence(QKeySequence.ZoomIn),
icon=ima.icon('zoom_in'),
triggered=lambda: self.zoom_in.emit())
zoom_out_action = create_action(self, _("Zoom out"),
QKeySequence(QKeySequence.ZoomOut),
icon=ima.icon('zoom_out'),
triggered=lambda: self.zoom_out.emit())
zoom_reset_action = create_action(self, _("Zoom reset"),
QKeySequence("Ctrl+0"),
triggered=lambda: self.zoom_reset.emit())
zoom_in_action = create_action(
self, _("Zoom in"), icon=ima.icon('zoom_in'),
shortcut=QKeySequence(QKeySequence.ZoomIn),
triggered=self.zoom_in.emit)
zoom_out_action = create_action(
self, _("Zoom out"), icon=ima.icon('zoom_out'),
shortcut=QKeySequence(QKeySequence.ZoomOut),
triggered=self.zoom_out.emit)
zoom_reset_action = create_action(
self, _("Zoom reset"), shortcut=QKeySequence("Ctrl+0"),
triggered=self.zoom_reset.emit)

# Build menu
self.menu = QMenu(self)
Expand Down