Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlovetox <philipp@hoerist.com>2022-08-18 21:10:34 +0300
committerlovetox <philipp@hoerist.com>2022-08-18 21:14:58 +0300
commitd93f8645940174764fbffb19b603d82b85e1d7ce (patch)
tree314e06e43ff14715f9b580ad8a86a92dd6e43ceb
parent3543572a85dacce94d09d63f7b215ed12ad0b1c4 (diff)
refactor: ChatList: Simplify moving chat to new workspace
-rw-r--r--gajim/gtk/chat_list_stack.py17
-rw-r--r--gajim/gtk/main.py31
-rw-r--r--gajim/gtk/menus.py7
-rw-r--r--gajim/gtk/workspace_side_bar.py8
4 files changed, 25 insertions, 38 deletions
diff --git a/gajim/gtk/chat_list_stack.py b/gajim/gtk/chat_list_stack.py
index b1964a065..117a9f197 100644
--- a/gajim/gtk/chat_list_stack.py
+++ b/gajim/gtk/chat_list_stack.py
@@ -95,8 +95,6 @@ class ChatListStack(Gtk.Stack, EventHelper):
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 @@ class ChatListStack(Gtk.Stack, EventHelper):
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,
diff --git a/gajim/gtk/main.py b/gajim/gtk/main.py
index 61e22af93..b2b428c42 100644
--- a/gajim/gtk/main.py
+++ b/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 @@ class MainWindow(Gtk.ApplicationWindow, EventHelper):
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 @@ class MainWindow(Gtk.ApplicationWindow, EventHelper):
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:
diff --git a/gajim/gtk/menus.py b/gajim/gtk/menus.py
index 16bfca20f..105655871 100644
--- a/gajim/gtk/menus.py
+++ b/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)
diff --git a/gajim/gtk/workspace_side_bar.py b/gajim/gtk/workspace_side_bar.py
index 73601bf99..eca26eac1 100644
--- a/gajim/gtk/workspace_side_bar.py
+++ b/gajim/gtk/workspace_side_bar.py
@@ -154,12 +154,12 @@ class WorkspaceSideBar(Gtk.ListBox):
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',