Daniel Brötzmann pushed to branch master at gajim / gajim
Commits: 54248d4d by wurstsalat at 2021-12-07T20:30:02+01:00 WorkspaceSidebar: Add Edit… menu item
- - - - -
4 changed files:
- gajim/gtk/chat_page.py - gajim/gtk/main.py - gajim/gtk/workspace_dialog.py - gajim/gtk/workspace_side_bar.py
Changes:
===================================== gajim/gtk/chat_page.py ===================================== @@ -130,7 +130,7 @@ def _on_filter_revealer_toggled(self, toggle_button):
@staticmethod def _on_edit_workspace_clicked(_button): - app.window.lookup_action('edit-workspace').activate() + app.window.activate_action('edit-workspace', GLib.Variant('s', ''))
def _on_chat_selected(self, _chat_list_stack: ChatListStack, workspace_id: str, account: str,
===================================== gajim/gtk/main.py ===================================== @@ -176,7 +176,7 @@ def _on_signed_in(event): def _add_actions(self): actions = [ ('add-workspace', 's', self._add_workspace), - ('edit-workspace', None, self._edit_workspace), + ('edit-workspace', 's', self._edit_workspace), ('remove-workspace', None, self._remove_workspace), ('activate-workspace', 's', self._activate_workspace), ('add-chat', 'a{sv}', self._add_chat), @@ -357,11 +357,11 @@ def add_workspace(self, workspace_id: str) -> None:
def _edit_workspace(self, _action: Gio.SimpleAction, - _param: Optional[GLib.Variant]) -> None: - - workspace_id = self.get_active_workspace() - if workspace_id is not None: - open_window('WorkspaceDialog', workspace_id=workspace_id) + param: GLib.Variant) -> None: + workspace_id = param.get_string() or None + if workspace_id is None: + workspace_id = self.get_active_workspace() + open_window('WorkspaceDialog', workspace_id=workspace_id)
def _remove_workspace(self, _action: Gio.SimpleAction,
===================================== gajim/gtk/workspace_dialog.py ===================================== @@ -32,7 +32,7 @@
class WorkspaceDialog(Gtk.ApplicationWindow): - def __init__(self, workspace_id: str = None) -> None: + def __init__(self, workspace_id: Optional[str] = None) -> None: Gtk.ApplicationWindow.__init__(self) self.set_name('WorkspaceDialog') self.set_application(app.app)
===================================== gajim/gtk/workspace_side_bar.py ===================================== @@ -12,7 +12,12 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see http://www.gnu.org/licenses/.
+from typing import Any +from typing import List + from gi.repository import Gdk +from gi.repository import Gio +from gi.repository import GLib from gi.repository import Gtk
from gajim.common import app @@ -214,6 +219,8 @@ def __init__(self, workspace_id): CommonWorkspace.__init__(self, workspace_id) self.get_style_context().add_class('workspace-sidebar-item')
+ self._workspace_id = workspace_id + self._unread_label = Gtk.Label() self._unread_label.get_style_context().add_class( 'unread-counter') @@ -248,11 +255,42 @@ def __init__(self, workspace_id): Gdk.DragAction.MOVE) eventbox.connect('drag-begin', self._on_drag_begin) eventbox.connect('drag-data-get', self._on_drag_data_get) + eventbox.connect('button-press-event', self._popup_menu) eventbox.add(overlay) - self.add(eventbox) self.show_all()
+ def _popup_menu(self, _widget, event): + if event.button != 3: # right click + return + + menu = self._get_workspace_menu() + + rectangle = Gdk.Rectangle() + rectangle.x = event.x + rectangle.y = event.y + rectangle.width = rectangle.height = 1 + + popover = Gtk.Popover.new_from_model(self, menu) + popover.set_relative_to(self) + popover.set_position(Gtk.PositionType.RIGHT) + popover.set_pointing_to(rectangle) + popover.popup() + + def _get_workspace_menu(self) -> Gio.Menu: + menu_items: List[Any] = [ + ('edit-workspace', _('Edit…')), + ] + menu = Gio.Menu() + for item in menu_items: + action, label = item + action = f'win.{action}' + menuitem = Gio.MenuItem.new(label, action) + variant = GLib.Variant('s', self._workspace_id) + menuitem.set_action_and_target_value(action, variant) + menu.append_item(menuitem) + return menu + def update_avatar(self): self._image.update()
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/54248d4d97e1937835e050cbe5f1ebc84...