Daniel Brötzmann pushed to branch master at gajim / gajim
Commits: 49a5c9b1 by wurstsalat at 2022-08-17T19:03:57+02:00 feat: Workspaces: Add shortcuts for switching
Workspaces can be activated by their position using Primary+{position}
- - - - -
4 changed files:
- gajim/data/gui/shortcuts_window.ui - gajim/data/other/shortcuts.json - gajim/gtk/main.py - gajim/gtk/workspace_side_bar.py
Changes:
===================================== gajim/data/gui/shortcuts_window.ui ===================================== @@ -151,35 +151,35 @@ <object class="GtkShortcutsShortcut"> <property name="visible">1</property> <property name="accelerator"><primary>Page_Up</property> - <property name="title" translatable="yes">Switch to the previous tab</property> + <property name="title" translatable="yes">Switch to the previous chat</property> </object> </child> <child> <object class="GtkShortcutsShortcut"> <property name="visible">1</property> <property name="accelerator"><primary>Page_Down</property> - <property name="title" translatable="yes">Switch to the next tab</property> + <property name="title" translatable="yes">Switch to the next chat</property> </object> </child> <child> <object class="GtkShortcutsShortcut"> <property name="visible">1</property> <property name="accelerator"><Alt>1...9</property> - <property name="title" translatable="yes">Switch to the first - ninth tab</property> + <property name="title" translatable="yes">Switch to the first - ninth chat</property> </object> </child> <child> <object class="GtkShortcutsShortcut"> <property name="visible">1</property> <property name="accelerator"><primary><shift>Tab</property> - <property name="title" translatable="yes">Switch to the previous unread tab</property> + <property name="title" translatable="yes">Switch to the previous unread chat</property> </object> </child> <child> <object class="GtkShortcutsShortcut"> <property name="visible">1</property> <property name="accelerator"><primary>Tab</property> - <property name="title" translatable="yes">Switch to the next unread tab</property> + <property name="title" translatable="yes">Switch to the next unread chat</property> </object> </child> <child> @@ -189,6 +189,13 @@ <property name="title" translatable="yes">Close chat</property> </object> </child> + <child> + <object class="GtkShortcutsShortcut"> + <property name="visible">1</property> + <property name="accelerator"><primary>1...9</property> + <property name="title" translatable="yes">Switch to the first - ninth workspace</property> + </object> + </child> </object> </child> <child>
===================================== gajim/data/other/shortcuts.json ===================================== @@ -29,5 +29,14 @@ "win.switch-tab-7": ["<Alt>7", "<Alt>KP_7"], "win.switch-tab-8": ["<Alt>8", "<Alt>KP_8"], "win.switch-tab-9": ["<Alt>9", "<Alt>KP_9"], + "win.switch-workspace-1": ["<Primary>1", "<Primary>KP_1"], + "win.switch-workspace-2": ["<Primary>2", "<Primary>KP_2"], + "win.switch-workspace-3": ["<Primary>3", "<Primary>KP_3"], + "win.switch-workspace-4": ["<Primary>4", "<Primary>KP_4"], + "win.switch-workspace-5": ["<Primary>5", "<Primary>KP_5"], + "win.switch-workspace-6": ["<Primary>6", "<Primary>KP_6"], + "win.switch-workspace-7": ["<Primary>7", "<Primary>KP_7"], + "win.switch-workspace-8": ["<Primary>8", "<Primary>KP_8"], + "win.switch-workspace-9": ["<Primary>9", "<Primary>KP_9"], "win.toggle-chat-list": ["<Primary>R"] }
===================================== gajim/gtk/main.py ===================================== @@ -373,6 +373,15 @@ def _add_actions2(self) -> None: 'switch-tab-7', 'switch-tab-8', 'switch-tab-9', + 'switch-workspace-1', + 'switch-workspace-2', + 'switch-workspace-3', + 'switch-workspace-4', + 'switch-workspace-5', + 'switch-workspace-6', + 'switch-workspace-7', + 'switch-workspace-8', + 'switch-workspace-9', 'toggle-chat-list', ]
@@ -442,6 +451,10 @@ def _on_action(self, number = int(action_name[-1]) - 1 self.select_chat_number(number)
+ elif action_name.startswith('switch-workspace-'): + number = int(action_name[-1]) - 1 + self._workspace_side_bar.activate_workspace_number(number) + elif action_name == 'toggle-chat-list': self._toggle_chat_list()
===================================== gajim/gtk/workspace_side_bar.py ===================================== @@ -218,9 +218,8 @@ def add_workspace(self, workspace_id: str) -> None: self.insert(row, len(self.get_children()) - 1)
def store_workspace_order(self) -> None: - workspaces: list[CommonWorkspace] = cast( - list[CommonWorkspace], self.get_children()) - order: list[str] = [row.workspace_id for row in workspaces] + workspaces = cast(list[CommonWorkspace], self.get_children()) + order = [row.workspace_id for row in workspaces] order.remove('add') app.settings.set_app_setting('workspace_order', order)
@@ -239,6 +238,11 @@ def activate_workspace(self, workspace_id: str) -> None: row = self._workspaces[workspace_id] self.select_row(row)
+ def activate_workspace_number(self, number: int) -> None: + row = cast(CommonWorkspace, self.get_row_at_index(number)) + if row is not None and row.workspace_id != 'add': + app.window.activate_workspace(row.workspace_id) + def get_active_workspace(self) -> Optional[str]: row = cast(CommonWorkspace, self.get_selected_row()) if row is None: @@ -246,8 +250,7 @@ def get_active_workspace(self) -> Optional[str]: return row.workspace_id
def get_first_workspace(self) -> str: - workspaces: list[CommonWorkspace] = cast( - list[CommonWorkspace], self.get_children()) + workspaces = cast(list[CommonWorkspace], self.get_children()) for row in workspaces: return row.workspace_id return '' @@ -255,8 +258,7 @@ def get_first_workspace(self) -> str: def get_workspace_by_id(self, workspace_id: str ) -> Optional[CommonWorkspace]: - workspaces: list[CommonWorkspace] = cast( - list[CommonWorkspace], self.get_children()) + workspaces = cast(list[CommonWorkspace], self.get_children()) for row in workspaces: if row.workspace_id == workspace_id: return row
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/49a5c9b13603e5b2c2e25f0a4eebf627b...