-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
PR: Added shortcut and menu option to re-run last cell #3974
Changes from 7 commits
ba688de
caa9696
62e5ad0
33dd17a
5759aa4
585865a
b813bdd
42c5ac0
b71d468
58fc05e
3655f34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,9 +105,12 @@ def setup_page(self): | |
|
||
interface_group = QGroupBox(_("Interface")) | ||
newcb = self.create_checkbox | ||
fpsorting_box = newcb(_("Sort files according to full path"), | ||
'fullpath_sorting') | ||
showtabbar_box = newcb(_("Show tab bar"), 'show_tab_bar') | ||
|
||
interface_layout = QVBoxLayout() | ||
interface_layout.addWidget(fpsorting_box) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also remove this. |
||
interface_layout.addWidget(showtabbar_box) | ||
interface_group.setLayout(interface_layout) | ||
|
||
|
@@ -539,6 +542,9 @@ def restore_scrollbar_position(self): | |
def get_plugin_title(self): | ||
"""Return widget title""" | ||
title = _('Editor') | ||
filename = self.get_current_filename() | ||
if filename: | ||
title += ' - '+to_text_string(filename) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these new lines are not needed either. |
||
return title | ||
|
||
def get_plugin_icon(self): | ||
|
@@ -834,6 +840,17 @@ def get_plugin_actions(self): | |
triggered=self.run_cell_and_advance, | ||
context=Qt.WidgetShortcut) | ||
|
||
re_run_last_cell_action = create_action(self, | ||
_("Re-run last cell"), | ||
icon=ima.icon('run_cell'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please leave this action without an icon. |
||
tip=_("Re run last cell "), | ||
triggered=self.re_run_last_cell, | ||
context=Qt.WidgetShortcut) | ||
self.register_shortcut(re_run_last_cell_action, | ||
context="Editor", | ||
name='re-run last cell', | ||
add_sc_to_tip=True) | ||
|
||
# --- Source code Toolbar --- | ||
self.todo_list_action = create_action(self, | ||
_("Show todo list"), icon=ima.icon('todo_list'), | ||
|
@@ -1041,13 +1058,14 @@ def get_plugin_actions(self): | |
|
||
# ---- Run menu/toolbar construction ---- | ||
run_menu_actions = [run_action, run_cell_action, | ||
run_cell_advance_action, MENU_SEPARATOR, | ||
run_cell_advance_action, | ||
re_run_last_cell_action, MENU_SEPARATOR, | ||
run_selected_action, re_run_action, | ||
configure_action, MENU_SEPARATOR] | ||
self.main.run_menu_actions += run_menu_actions | ||
run_toolbar_actions = [run_action, run_cell_action, | ||
run_cell_advance_action, run_selected_action, | ||
re_run_action] | ||
run_cell_advance_action, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the confusion, please restore |
||
re_run_action, configure_action] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove |
||
self.main.run_toolbar_actions += run_toolbar_actions | ||
|
||
# ---- Debug menu/toolbar construction ---- | ||
|
@@ -1115,6 +1133,7 @@ def get_plugin_actions(self): | |
debug_action, run_selected_action, | ||
run_cell_action, | ||
run_cell_advance_action, | ||
re_run_last_cell_action, | ||
blockcomment_action, | ||
unblockcomment_action, | ||
self.winpdb_action] | ||
|
@@ -2413,6 +2432,12 @@ def run_cell_and_advance(self): | |
editorstack = self.get_current_editorstack() | ||
editorstack.run_cell_and_advance() | ||
|
||
@Slot() | ||
def re_run_last_cell(self): | ||
"""Run last executed cell.""" | ||
editorstack = self.get_current_editorstack() | ||
editorstack.re_run_last_cell() | ||
|
||
#------ Zoom in/out/reset | ||
def zoom(self, factor): | ||
"""Zoom in/out/reset""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -272,6 +272,8 @@ def __init__(self, parent=None): | |
self.matched_p_color = QColor(Qt.green) | ||
self.unmatched_p_color = QColor(Qt.red) | ||
|
||
self.last_cursor_cell = None | ||
|
||
def setup_completion(self): | ||
size = CONF.get('main', 'completion/size') | ||
font = get_font() | ||
|
@@ -621,18 +623,31 @@ def get_selection_as_executable_code(self): | |
|
||
return ls.join(lines) | ||
|
||
def get_cell_as_executable_code(self): | ||
"""Return cell contents as executable code""" | ||
def __exec_cell(self): | ||
init_cur = QTextCursor(self.textCursor()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename this variable to |
||
start_pos, end_pos = self.__save_selection() | ||
cursor, whole_file_selected = self.select_current_cell() | ||
if not whole_file_selected: | ||
self.setTextCursor(cursor) | ||
text = self.get_selection_as_executable_code() | ||
self.last_cursor_cell = init_cur | ||
self.__restore_selection(start_pos, end_pos) | ||
if text is not None: | ||
text = text.rstrip() | ||
return text | ||
|
||
def get_cell_as_executable_code(self): | ||
"""Return cell contents as executable code""" | ||
return self.__exec_cell() | ||
|
||
def get_last_cell_as_executable_code(self): | ||
text = None | ||
if self.last_cursor_cell: | ||
self.setTextCursor(self.last_cursor_cell) | ||
self.highlight_current_cell() | ||
text = self.__exec_cell() | ||
return text | ||
|
||
def is_cell_separator(self, cursor=None, block=None): | ||
"""Return True if cursor (or text block) is on a block separator""" | ||
assert cursor is not None or block is not None | ||
|
@@ -691,7 +706,7 @@ def select_current_cell(self): | |
prev_pos = cur_pos | ||
cell_at_file_end = cursor.atEnd() | ||
return cursor, cell_at_file_start and cell_at_file_end | ||
|
||
def select_current_cell_in_visible_portion(self): | ||
"""Select cell under cursor in the visible portion of the file | ||
cell = group of lines separated by CELL_SEPARATORS | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this option. It's not need anymore in the 3.x branch.