Daniel Brötzmann pushed to branch mainwindow at gajim / gajim


Commits:
78bf8ae2 by wurstsalat at 2021-10-31T17:36:42+01:00
Workspace: Add removal confirmation

- - - - -
f2931af5 by wurstsalat at 2021-10-31T17:46:01+01:00
ChatList: Show move to workspace only if we have more than one

- - - - -


5 changed files:

- gajim/gtk/chat_list.py
- gajim/gtk/chat_list_stack.py
- gajim/gtk/main.py
- gajim/gtk/workspace_dialog.py
- gajim/gui_menu_builder.py


Changes:

=====================================
gajim/gtk/chat_list.py
=====================================
@@ -277,17 +277,19 @@ def toggle_chat_pinned(self, account, jid):
         row.toggle_pinned()
         self.invalidate_sort()
 
-    def remove_chat(self, account, jid):
+    def remove_chat(self, account, jid, emit_unread=True):
         row = self._chats.pop((account, jid))
         self.remove(row)
         row.destroy()
-        self.emit_unread_changed()
+        if emit_unread:
+            self.emit_unread_changed()
 
     def remove_chats_for_account(self, account):
         for row_account, jid in list(self._chats.keys()):
             if row_account != account:
                 continue
             self.remove_chat(account, jid)
+        self.emit_unread_changed()
 
     def get_selected_chat(self):
         row = self.get_selected_row()


=====================================
gajim/gtk/chat_list_stack.py
=====================================
@@ -209,7 +209,7 @@ def _move_chat_to_workspace(self, _action, param):
     def remove_chat(self, workspace_id, account, jid):
         chat_list = self._chat_lists[workspace_id]
         type_ = chat_list.get_chat_type(account, jid)
-        chat_list.remove_chat(account, jid)
+        chat_list.remove_chat(account, jid, emit_unread=False)
         self.store_open_chats(workspace_id)
         self.emit('chat-removed', account, jid, type_)
 


=====================================
gajim/gtk/main.py
=====================================
@@ -380,6 +380,10 @@ def update_workspace(self, workspace_id):
         self._chat_page.update_workspace(workspace_id)
         self._workspace_side_bar.update_avatar(workspace_id)
 
+    def get_chat_list(self, workspace_id):
+        chat_list_stack = self._chat_page.get_chat_list_stack()
+        return chat_list_stack.get_chatlist(workspace_id)
+
     def _add_group_chat(self, _action, param):
         self.add_group_chat(**param.unpack())
 


=====================================
gajim/gtk/workspace_dialog.py
=====================================
@@ -21,6 +21,8 @@
 
 from .avatar import make_workspace_avatar
 from .avatar_selector import AvatarSelector
+from .dialogs import ConfirmationDialog
+from .dialogs import DialogButton
 from .util import get_builder
 from .util import rgba_to_float
 from .util import make_rgba
@@ -83,8 +85,24 @@ def _on_key_press_event(self, _widget, event):
             self.destroy()
 
     def _on_remove_workspace(self, _button):
-        app.window.remove_workspace(self._workspace_id)
-        self.destroy()
+        def _on_remove():
+            app.window.remove_workspace(self._workspace_id)
+            self.destroy()
+
+        chat_list = app.window.get_chat_list(self._workspace_id)
+        open_chats = chat_list.get_open_chats()
+        if len(open_chats) > 0:
+            ConfirmationDialog(
+                _('Remove Workspace'),
+                _('Remove Workspace'),
+                _('This workspace contains chats. Remove anyway?'),
+                [DialogButton.make('Cancel',
+                                   text=_('_No')),
+                 DialogButton.make('Remove',
+                                   callback=_on_remove)]).show()
+            return
+        # No chats in chat list, it is save to remove workspace
+        _on_remove()
 
     def _on_cancel(self, _button):
         self.destroy()


=====================================
gajim/gui_menu_builder.py
=====================================
@@ -388,9 +388,12 @@ def get_chat_list_row_menu(workspace_id, account, jid, 
pinned):
 
     menu_items = [
         ('toggle-chat-pinned', toggle_label),
-        (_('Move Chat'), []),
     ]
 
+    workspaces = app.settings.get_workspaces()
+    if len(workspaces) > 1:
+        menu_items.append((_('Move Chat'), []))
+
     is_self_contact = contact.jid.bare == client.get_own_jid().bare
     pm_with_jid = contact.is_pm_contact and contact.real_jid is not None
     if (not contact.is_groupchat and not contact.is_in_roster and
@@ -409,8 +412,10 @@ def get_chat_list_row_menu(workspace_id, account, jid, 
pinned):
             menu.append_item(menuitem)
         else:
             # This is a submenu
-            submenu = build_workspaces_submenu(workspace_id, account, str(jid))
-            menu.append_submenu(item[0], submenu)
+            if len(workspaces) > 1:
+                submenu = build_workspaces_submenu(
+                    workspace_id, account, str(jid))
+                menu.append_submenu(item[0], submenu)
 
     return menu
 



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/compare/b38b74fa10b61ae9e6448e06d011c7281349fd5c...f2931af52c443c9e4f9a2c60023c5b5f7d8a9db9

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/compare/b38b74fa10b61ae9e6448e06d011c7281349fd5c...f2931af52c443c9e4f9a2c60023c5b5f7d8a9db9
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

Reply via email to