Philipp Hörist pushed to branch mainwindow at gajim / gajim
Commits:
d71682a0 by lovetox at 2021-04-28T10:38:06+02:00
Refactor ChatList
- - - - -
3 changed files:
- gajim/gtk/chat_list_stack.py
- gajim/gtk/chat_page.py
- gajim/gtk/main.py
Changes:
=====================================
gajim/gtk/chat_list_stack.py
=====================================
@@ -44,16 +44,17 @@ class ChatListStack(Gtk.Stack):
'chat-unselected': (GObject.SignalFlags.RUN_LAST,
None,
()),
+ 'chat-removed': (GObject.SignalFlags.RUN_LAST,
+ None,
+ (str, str, str)),
}
- def __init__(self, main_window, ui, chat_stack):
+ def __init__(self, main_window, search_entry):
Gtk.Stack.__init__(self)
self.set_hexpand(True)
self.set_vexpand(True)
self.set_vhomogeneous(False)
- self._ui = ui
- self._chat_stack = chat_stack
self._chat_lists = {}
self._last_visible_child_name = 'default'
@@ -61,9 +62,7 @@ def __init__(self, main_window, ui, chat_stack):
self.add_named(Gtk.Box(), 'default')
self.connect('notify::visible-child-name', self._on_visible_child_name)
- self._ui.search_entry.connect(
- 'search-changed', self._on_search_changed)
-
+ search_entry.connect('search-changed', self._on_search_changed)
main_window.connect('notify::is-active', self._on_window_active)
self._add_actions()
@@ -94,7 +93,6 @@ def _on_visible_child_name(self, _stack, _param):
if self._last_visible_child_name == self.get_visible_child_name():
return
- self._ui.search_entry.set_text('')
if self._last_visible_child_name != 'default':
child = self.get_child_by_name(self._last_visible_child_name)
child.set_filter_text('')
@@ -157,8 +155,6 @@ def show_chat_list(self, workspace_id):
if current_workspace_id != 'default':
self._chat_lists[current_workspace_id].unselect_all()
- self._ui.workspace_label.set_text(
- app.settings.get_workspace_setting(workspace_id, 'name'))
self.set_visible_child_name(workspace_id)
def add_chat(self, workspace_id, account, jid, type_, pinned=False):
@@ -204,12 +200,7 @@ def remove_chat(self, workspace_id, account, jid):
type_ = chat_list.get_chat_type(account, jid)
chat_list.remove_chat(account, jid)
self.store_open_chats(workspace_id)
-
- if not self.contains_chat(account, jid):
- self._chat_stack.remove_chat(account, jid)
- if type_ == 'groupchat':
- client = app.get_client(account)
- client.get_module('MUC').leave(jid)
+ self.emit('chat-removed', account, jid, type_)
def _find_chat(self, account, jid):
for chat_list in self._chat_lists.values():
=====================================
gajim/gtk/chat_page.py
=====================================
@@ -59,10 +59,13 @@ def __init__(self):
self._search_revealer.add(self._search_view)
self._ui.right_grid_overlay.add_overlay(self._search_revealer)
- self._chat_list_stack = ChatListStack(self, self._ui, self._chat_stack)
+ self._chat_list_stack = ChatListStack(app.window,
self._ui.search_entry)
self._chat_list_stack.connect('chat-selected', self._on_chat_selected)
self._chat_list_stack.connect('chat-unselected',
self._on_chat_unselected)
+ self._chat_list_stack.connect('chat-removed', self._on_chat_removed)
+ self._chat_list_stack.connect('notify::visible-child-name',
+ self._on_chat_list_changed)
self._ui.chat_list_scrolled.add(self._chat_list_stack)
self._ui.start_chat_button.connect('clicked',
@@ -120,6 +123,10 @@ def _on_button_release(paned, event):
def _on_chat_selected(self, _chat_list_stack, workspace_id, account, jid):
self._chat_stack.show_chat(account, jid)
self._search_view.set_context(account, jid)
+
+ self._ui.workspace_label.set_text(
+ app.settings.get_workspace_setting(workspace_id, 'name'))
+
self.emit('chat-selected', workspace_id, account, jid)
def _on_chat_unselected(self, _chat_list_stack):
@@ -136,6 +143,9 @@ def _on_search_history(self, _action, _param):
def _on_search_hide(self, *args):
self._search_revealer.hide()
+ def _on_chat_list_changed(self, *args):
+ self._ui.search_entry.set_text('')
+
def process_event(self, event):
self._chat_stack.process_event(event)
self._chat_list_stack.process_event(event)
@@ -219,6 +229,12 @@ def remove_chat(self, account, jid):
self._chat_list_stack.remove_chat(workspace_id, account, jid)
return
+ def _on_chat_removed(self, _chat_list, account, jid, type_):
+ self._chat_stack.remove_chat(account, jid)
+ if type_ == 'groupchat':
+ client = app.get_client(account)
+ client.get_module('MUC').leave(jid)
+
def get_control(self, account, jid):
return self._chat_stack.get_control(account, jid)
@@ -230,3 +246,7 @@ def get_active_control(self):
def get_controls(self, account=None):
return self._chat_stack.get_controls(account)
+
+ def hide_search(self):
+ if self._search_revealer.get_reveal_child():
+ self._search_revealer.hide()
=====================================
gajim/gtk/main.py
=====================================
@@ -173,8 +173,7 @@ def _on_action(self, action, _param):
return res
if action == 'escape':
- if self._search_revealer.get_reveal_child():
- self._search_revealer.hide()
+ self._chat_page.hide_search()
# if action == 'escape' and app.settings.get('escape_key_closes'):
# self.remove_tab(control, self.CLOSE_ESC)
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/d71682a0e7c4bbf5bb98f5df71a348526007feb9
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/d71682a0e7c4bbf5bb98f5df71a348526007feb9
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits