diff --git a/mu/app.py b/mu/app.py index badf0e703..9337bc5f7 100644 --- a/mu/app.py +++ b/mu/app.py @@ -472,6 +472,8 @@ def load_theme(theme): editor_window.connect_find_again(find_again_handlers, "F3") editor_window.connect_toggle_comments(editor.toggle_comments, "Ctrl+K") editor_window.connect_close_tab(editor.close_tab, "Ctrl+W") + editor_window.connect_move_forward_tab(editor.move_forward_tab, "Ctrl+.") + editor_window.connect_move_backward_tab(editor.move_backward_tab, "Ctrl+,") editor.connect_to_status_bar(editor_window.status_bar) # Restore the previous session along with files passed by the os diff --git a/mu/interface/main.py b/mu/interface/main.py index 87bd4bc41..e852478e7 100644 --- a/mu/interface/main.py +++ b/mu/interface/main.py @@ -499,6 +499,22 @@ def focus_tab(self, tab): self.tabs.setCurrentIndex(index) tab.setFocus() + def move_tab(self, tab, is_forward): + """ + Move focused tab to forward / backward. + """ + tab_cnt = len(self.tabs) + if tab_cnt: + index = self.tabs.indexOf(tab) + if is_forward: + index += 1 + if index == tab_cnt: index = 0 + else: + index -= 1 + if index < 0: index = tab_cnt - 1 + self.tabs.setCurrentIndex(index) + tab.setFocus() + @property def tab_count(self): """ @@ -1366,11 +1382,27 @@ def connect_close_tab(self, handler, shortcut): def close_tab(self): """ - Delete complete line on the cursor in the currently active tab. + Close the currently active tab. """ if self.current_tab: self.tabs.removeTab(self.widgets.index(self.current_tab)) + def connect_move_forward_tab(self, handler, shortcut): + """ + Create a keyboard shortcut and associate it with a handler for moving + a current active tab forward. + """ + self.move_forward_tab_shortcut = QShortcut(QKeySequence(shortcut), self) + self.move_forward_tab_shortcut.activated.connect(handler) + + def connect_move_backward_tab(self, handler, shortcut): + """ + Create a keyboard shortcut and associate it with a handler for moving + a current active tab backward. + """ + self.move_backward_tab_shortcut = QShortcut(QKeySequence(shortcut), self) + self.move_backward_tab_shortcut.activated.connect(handler) + def show_device_selector(self): """ Reveals the device selector in the status bar diff --git a/mu/logic.py b/mu/logic.py index 7be4d37c5..84906973f 100644 --- a/mu/logic.py +++ b/mu/logic.py @@ -2011,6 +2011,18 @@ def close_tab(self): """ self._view.close_tab() + def move_forward_tab(self): + """ + Handle a shortcut for moving the current tab forward. + """ + self._view.move_tab(self._view.current_tab, True) + + def move_backward_tab(self): + """ + Handle a shortcut for moving the current tab backward. + """ + self._view.move_tab(self._view.current_tab, False) + def tidy_code(self): """ Prettify code with Black.