Philipp Hörist pushed to branch master at gajim / gajim
Commits: d93f8645 by lovetox at 2022-08-18T20:14:58+02:00 refactor: ChatList: Simplify moving chat to new workspace
- - - - -
4 changed files:
- gajim/gtk/chat_list_stack.py - gajim/gtk/main.py - gajim/gtk/menus.py - gajim/gtk/workspace_side_bar.py
Changes:
===================================== gajim/gtk/chat_list_stack.py ===================================== @@ -95,8 +95,6 @@ def _add_actions(self) -> None: actions = [ ('toggle-chat-pinned', 'a{sv}', self._toggle_chat_pinned), ('move-chat-to-workspace', 'a{sv}', self._move_chat_to_workspace), - ('move-chat-to-new-workspace', 'a{sv}', - self._move_chat_to_new_workspace), ('mark-as-read', 'a{sv}', self._mark_as_read), ]
@@ -226,23 +224,20 @@ def _move_chat_to_workspace(self, params: structs.ChatListEntryParam ) -> None:
+ workspace_id = params.workspace_id + if not workspace_id: + workspace_id = app.window.add_workspace(switch=False) + current_chatlist = cast(ChatList, self.get_visible_child()) type_ = current_chatlist.get_chat_type(params.account, params.jid) if type_ is None: return current_chatlist.remove_chat(params.account, params.jid)
- new_chatlist = self.get_chatlist(params.workspace_id) + new_chatlist = self.get_chatlist(workspace_id) new_chatlist.add_chat(params.account, params.jid, type_) self.store_open_chats(current_chatlist.workspace_id) - self.store_open_chats(params.workspace_id) - - @structs.actionmethod - def _move_chat_to_new_workspace(self, - _action: Gio.SimpleAction, - params: structs.AccountJidParam - ) -> None: - app.window.move_chat_to_new_workspace(params.account, params.jid) + self.store_open_chats(workspace_id)
@structs.actionmethod def _mark_as_read(self,
===================================== gajim/gtk/main.py ===================================== @@ -15,7 +15,6 @@ from __future__ import annotations
from typing import Any -from typing import cast from typing import Optional from typing import TYPE_CHECKING
@@ -591,14 +590,22 @@ def _add_workspace(self, if workspace_id is not None: self.add_workspace(workspace_id)
- def add_workspace(self, workspace_id: str) -> None: + def add_workspace(self, + workspace_id: Optional[str] = None, + switch: bool = True) -> str: + + if workspace_id is None: + workspace_id = app.settings.add_workspace(_('My Workspace')) + self._workspace_side_bar.add_workspace(workspace_id) self._chat_page.add_chat_list(workspace_id)
- if self._startup_finished: + if self._startup_finished and switch: self.activate_workspace(workspace_id) self._workspace_side_bar.store_workspace_order()
+ return workspace_id + def _edit_workspace(self, _action: Gio.SimpleAction, param: GLib.Variant) -> None: @@ -651,24 +658,6 @@ def get_chat_list(self, workspace_id: str) -> ChatList: chat_list_stack = self._chat_page.get_chat_list_stack() return chat_list_stack.get_chatlist(workspace_id)
- def move_chat_to_new_workspace(self, - account: str, - jid: JID - ) -> None: - chat_list_stack = self._chat_page.get_chat_list_stack() - current_chatlist = cast(ChatList, chat_list_stack.get_visible_child()) - type_ = current_chatlist.get_chat_type(account, jid) - if type_ is None: - return - current_chatlist.remove_chat(account, jid) - - workspace_id = app.settings.add_workspace(_('My Workspace')) - app.window.add_workspace(workspace_id) - new_chatlist = self.get_chat_list(workspace_id) - new_chatlist.add_chat(account, jid, type_) - chat_list_stack.store_open_chats(current_chatlist.workspace_id) - chat_list_stack.store_open_chats(workspace_id) - def _add_group_chat(self, _action: Gio.SimpleAction, param: GLib.Variant) -> None:
===================================== gajim/gtk/menus.py ===================================== @@ -422,9 +422,12 @@ def get_chat_list_row_menu(workspace_id: str, for name, params in get_workspace_params(workspace_id, account, jid): submenu.add_item(name, 'win.move-chat-to-workspace', params)
- params = AccountJidParam(account=account, jid=jid) + params = ChatListEntryParam(workspace_id='', + account=account, + jid=jid) + submenu.add_item( - _('New Workspace'), 'win.move-chat-to-new-workspace', params) + _('New Workspace'), 'win.move-chat-to-workspace', params)
if can_add_to_roster(contact): params = AccountJidParam(account=account, jid=jid)
===================================== gajim/gtk/workspace_side_bar.py ===================================== @@ -154,12 +154,12 @@ def _process_chat_list_drop(self, y_coord: int) -> None:
workspace_row = cast(Workspace, self.get_row_at_y(y_coord)) + + workspace_id = workspace_row.workspace_id if workspace_row.workspace_id == 'add': - app.window.move_chat_to_new_workspace( - account, jid) - return + workspace_id = ''
- params = ChatListEntryParam(workspace_id=workspace_row.workspace_id, + params = ChatListEntryParam(workspace_id=workspace_id, account=account, jid=jid) app.window.activate_action('move-chat-to-workspace',
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/d93f8645940174764fbffb19b603d82b8...