Philipp Hörist pushed to branch mainwindow at gajim / gajim
Commits: 00407e29 by lovetox at 2021-01-23T22:42:34+01:00 Allow to add chats to different workspaces
- - - - -
3 changed files:
- gajim/gtk/chat_list_stack.py - gajim/gtk/main.py - gajim/gtk/workspace_side_bar.py
Changes:
===================================== gajim/gtk/chat_list_stack.py ===================================== @@ -39,6 +39,15 @@ def add_chat_list(self, workspace_id): self.add_named(chat_list, workspace_id) return chat_list
+ def remove_chat_list(self, workspace_id): + chat_list = self._chat_lists[workspace_id] + self.remove(chat_list) + for account, jid in chat_list.get_open_chats(): + self.remove_chat(workspace_id, account, jid) + + self._chat_lists.pop(workspace_id) + chat_list.destroy() + def _on_row_selected(self, _chat_list, row): if row is None: self._chat_stack.clear()
===================================== gajim/gtk/main.py ===================================== @@ -52,6 +52,7 @@ def _add_actions(self): actions = [ ('add-workspace', 's', self.add_workspace), ('remove-workspace', 's', self.remove_workspace), + ('activate-workspace', 's', self.activate_workspace), ('remove-chat', 'as', self.remove_chat), ]
@@ -78,21 +79,27 @@ def get_active_jid(self, *args): pass
def get_active_workspace(self): - # TODO - return app.settings.get_workspaces()[0] + return self._workspace_side_bar.get_active_workspace()
def add_workspace(self, _action, param): name = param.get_string() workspace_id = app.settings.add_workspace(name) self._workspace_side_bar.add_workspace(workspace_id) + self._chat_list_stack.add_chat_list(workspace_id)
def remove_workspace(self, _action, param): workspace_id = param.get_string() self._workspace_side_bar.remove_workspace(workspace_id) + self._chat_list_stack.remove_chat_list(workspace_id) app.settings.remove_workspace(workspace_id)
+ def activate_workspace(self, _action, param): + workspace_id = param.get_string() + self._workspace_side_bar.activate_workspace(workspace_id) + self._chat_list_stack.show_chat_list(workspace_id) + def add_chat(self, account, jid): - workspace_id = self.get_active_workspace() + workspace_id = self._workspace_side_bar.get_active_workspace() self.add_chat_for_workspace(workspace_id, account, jid)
def add_chat_for_workspace(self, workspace_id, account, jid): @@ -113,6 +120,7 @@ def get_control(self, account, jid): def _load_chats(self): for workspace_id in app.settings.get_workspaces(): self._workspace_side_bar.add_workspace(workspace_id) + self._chat_list_stack.add_chat_list(workspace_id) open_chats = app.settings.get_workspace_setting(workspace_id, 'open_chats') for account, jid in open_chats:
===================================== gajim/gtk/workspace_side_bar.py ===================================== @@ -19,6 +19,8 @@ def __init__(self): self.connect('button-press-event', self._on_button_press) self.connect('row-activated', self._on_row_activated)
+ self._workspaces = {} + @staticmethod def _sort_func(child1, child2): if child1.sort_index < child2.sort_index: @@ -44,13 +46,27 @@ def _on_row_activated(self, _listbox, row): 'activate-workspace', GLib.Variant('s', row.workspace_id))
def add_workspace(self, workspace_id): - self.add(Workspace(workspace_id)) + row = Workspace(workspace_id) + self._workspaces[workspace_id] = row + self.add(row)
def remove_workspace(self, workspace_id): - for row in self.get_children(): - if row.workspace_id == workspace_id: - self.remove(row) - break + row = self._workspaces.pop(workspace_id) + self.remove(row) + + def activate_workspace(self, workspace_id): + row = self.get_selected_row() + if row is not None and row.workspace_id == workspace_id: + return + + row = self._workspaces[workspace_id] + self.select_row(row) + + def get_active_workspace(self): + row = self.get_selected_row() + if row is None: + return None + return row.workspace_id
class CommonWorkspace(Gtk.ListBoxRow):
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/00407e2901e789c3e3db32297a9c8eb0d...