Philipp Hörist pushed to branch mainwindow at gajim / gajim

Commits:

3 changed files:

Changes:

  • gajim/gtk/chat_list_stack.py
    ... ... @@ -16,6 +16,8 @@ def __init__(self, ui, chat_stack):
    16 16
             self._chat_stack = chat_stack
    
    17 17
             self._chat_lists = {}
    
    18 18
     
    
    19
    +        self.add_named(Gtk.Box(), 'default')
    
    20
    +
    
    19 21
             self.show_all()
    
    20 22
             self._ui.search_entry.connect(
    
    21 23
                 'search-changed', self._on_search_changed)
    
    ... ... @@ -35,7 +37,7 @@ def add_chat_list(self, workspace_id):
    35 37
         def remove_chat_list(self, workspace_id):
    
    36 38
             chat_list = self._chat_lists[workspace_id]
    
    37 39
             self.remove(chat_list)
    
    38
    -        for account, jid in chat_list.get_open_chats():
    
    40
    +        for account, jid, _ in chat_list.get_open_chats():
    
    39 41
                 self.remove_chat(workspace_id, account, jid)
    
    40 42
     
    
    41 43
             self._chat_lists.pop(workspace_id)
    
    ... ... @@ -48,9 +50,16 @@ def _on_row_selected(self, _chat_list, row):
    48 50
             self._chat_stack.show_chat(row.account, row.jid)
    
    49 51
     
    
    50 52
         def show_chat_list(self, workspace_id):
    
    51
    -        self.set_visible_child_name(workspace_id)
    
    53
    +        current_workspace_id = self.get_visible_child_name()
    
    54
    +        if current_workspace_id == workspace_id:
    
    55
    +            return
    
    56
    +
    
    57
    +        if current_workspace_id != 'default':
    
    58
    +            self._chat_lists[current_workspace_id].unselect_all()
    
    59
    +
    
    52 60
             self._ui.workspace_label.set_text(
    
    53 61
                 app.settings.get_workspace_setting(workspace_id, 'name'))
    
    62
    +        self.set_visible_child_name(workspace_id)
    
    54 63
     
    
    55 64
         def add_chat(self, workspace_id, account, jid, type_):
    
    56 65
             chat_list = self._chat_lists.get(workspace_id)
    
    ... ... @@ -66,7 +75,6 @@ def select_chat(self, workspace_id, account, jid):
    66 75
         def store_open_chats(self, workspace_id):
    
    67 76
             chat_list = self._chat_lists[workspace_id]
    
    68 77
             open_chats = chat_list.get_open_chats()
    
    69
    -        print('store', open_chats)
    
    70 78
             app.settings.set_workspace_setting(
    
    71 79
                 workspace_id, 'open_chats', open_chats)
    
    72 80
     
    

  • gajim/gtk/main.py
    ... ... @@ -105,10 +105,22 @@ def add_workspace(self, _action, param):
    105 105
     
    
    106 106
         def remove_workspace(self, _action, param):
    
    107 107
             workspace_id = param.get_string()
    
    108
    -        self._workspace_side_bar.remove_workspace(workspace_id)
    
    108
    +
    
    109
    +        was_active = self.get_active_workspace() == workspace_id
    
    110
    +
    
    111
    +        success = self._workspace_side_bar.remove_workspace(workspace_id)
    
    112
    +        if not success:
    
    113
    +            return
    
    114
    +
    
    115
    +        if was_active:
    
    116
    +            new_active_id = self._workspace_side_bar.get_first_workspace()
    
    117
    +            self._workspace_side_bar.activate_workspace(new_active_id)
    
    118
    +            self._chat_list_stack.show_chat_list(new_active_id)
    
    119
    +
    
    109 120
             self._chat_list_stack.remove_chat_list(workspace_id)
    
    110 121
             app.settings.remove_workspace(workspace_id)
    
    111 122
     
    
    123
    +
    
    112 124
         def activate_workspace(self, _action, param):
    
    113 125
             workspace_id = param.get_string()
    
    114 126
             self._workspace_side_bar.activate_workspace(workspace_id)
    
    ... ... @@ -145,6 +157,11 @@ def _load_chats(self):
    145 157
                         continue
    
    146 158
                     self.add_chat_for_workspace(workspace_id, account, jid, type_)
    
    147 159
     
    
    160
    +        for workspace_id in app.settings.get_workspaces():
    
    161
    +            self._workspace_side_bar.activate_workspace(workspace_id)
    
    162
    +            self._chat_list_stack.show_chat_list(workspace_id)
    
    163
    +            break
    
    164
    +
    
    148 165
             self._startup_finished = True
    
    149 166
     
    
    150 167
         def _on_start_chat_clicked(self, _button):
    

  • gajim/gtk/workspace_side_bar.py
    ... ... @@ -51,8 +51,11 @@ def add_workspace(self, workspace_id):
    51 51
             self.add(row)
    
    52 52
     
    
    53 53
         def remove_workspace(self, workspace_id):
    
    54
    +        if len(self._workspaces) == 1:
    
    55
    +            return False
    
    54 56
             row = self._workspaces.pop(workspace_id)
    
    55 57
             self.remove(row)
    
    58
    +        return True
    
    56 59
     
    
    57 60
         def activate_workspace(self, workspace_id):
    
    58 61
             row = self.get_selected_row()
    
    ... ... @@ -68,6 +71,10 @@ def get_active_workspace(self):
    68 71
                 return None
    
    69 72
             return row.workspace_id
    
    70 73
     
    
    74
    +    def get_first_workspace(self):
    
    75
    +        for row in self.get_children():
    
    76
    +            return row.workspace_id
    
    77
    +
    
    71 78
         def update_avatar(self, workspace_id):
    
    72 79
             row = self._workspaces[workspace_id]
    
    73 80
             row.update_avatar()