Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
-
54248d4d
by wurstsalat at 2021-12-07T20:30:02+01:00
4 changed files:
- gajim/gtk/chat_page.py
- gajim/gtk/main.py
- gajim/gtk/workspace_dialog.py
- gajim/gtk/workspace_side_bar.py
Changes:
| ... | ... | @@ -130,7 +130,7 @@ def _on_filter_revealer_toggled(self, toggle_button): |
| 130 | 130 |
|
| 131 | 131 |
@staticmethod
|
| 132 | 132 |
def _on_edit_workspace_clicked(_button):
|
| 133 |
- app.window.lookup_action('edit-workspace').activate()
|
|
| 133 |
+ app.window.activate_action('edit-workspace', GLib.Variant('s', ''))
|
|
| 134 | 134 |
|
| 135 | 135 |
def _on_chat_selected(self, _chat_list_stack: ChatListStack,
|
| 136 | 136 |
workspace_id: str, account: str,
|
| ... | ... | @@ -176,7 +176,7 @@ def _on_signed_in(event): |
| 176 | 176 |
def _add_actions(self):
|
| 177 | 177 |
actions = [
|
| 178 | 178 |
('add-workspace', 's', self._add_workspace),
|
| 179 |
- ('edit-workspace', None, self._edit_workspace),
|
|
| 179 |
+ ('edit-workspace', 's', self._edit_workspace),
|
|
| 180 | 180 |
('remove-workspace', None, self._remove_workspace),
|
| 181 | 181 |
('activate-workspace', 's', self._activate_workspace),
|
| 182 | 182 |
('add-chat', 'a{sv}', self._add_chat),
|
| ... | ... | @@ -357,11 +357,11 @@ def add_workspace(self, workspace_id: str) -> None: |
| 357 | 357 |
|
| 358 | 358 |
def _edit_workspace(self,
|
| 359 | 359 |
_action: Gio.SimpleAction,
|
| 360 |
- _param: Optional[GLib.Variant]) -> None:
|
|
| 361 |
- |
|
| 362 |
- workspace_id = self.get_active_workspace()
|
|
| 363 |
- if workspace_id is not None:
|
|
| 364 |
- open_window('WorkspaceDialog', workspace_id=workspace_id)
|
|
| 360 |
+ param: GLib.Variant) -> None:
|
|
| 361 |
+ workspace_id = param.get_string() or None
|
|
| 362 |
+ if workspace_id is None:
|
|
| 363 |
+ workspace_id = self.get_active_workspace()
|
|
| 364 |
+ open_window('WorkspaceDialog', workspace_id=workspace_id)
|
|
| 365 | 365 |
|
| 366 | 366 |
def _remove_workspace(self,
|
| 367 | 367 |
_action: Gio.SimpleAction,
|
| ... | ... | @@ -32,7 +32,7 @@ |
| 32 | 32 |
|
| 33 | 33 |
|
| 34 | 34 |
class WorkspaceDialog(Gtk.ApplicationWindow):
|
| 35 |
- def __init__(self, workspace_id: str = None) -> None:
|
|
| 35 |
+ def __init__(self, workspace_id: Optional[str] = None) -> None:
|
|
| 36 | 36 |
Gtk.ApplicationWindow.__init__(self)
|
| 37 | 37 |
self.set_name('WorkspaceDialog')
|
| 38 | 38 |
self.set_application(app.app)
|
| ... | ... | @@ -12,7 +12,12 @@ |
| 12 | 12 |
# You should have received a copy of the GNU General Public License
|
| 13 | 13 |
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
| 14 | 14 |
|
| 15 |
+from typing import Any
|
|
| 16 |
+from typing import List
|
|
| 17 |
+ |
|
| 15 | 18 |
from gi.repository import Gdk
|
| 19 |
+from gi.repository import Gio
|
|
| 20 |
+from gi.repository import GLib
|
|
| 16 | 21 |
from gi.repository import Gtk
|
| 17 | 22 |
|
| 18 | 23 |
from gajim.common import app
|
| ... | ... | @@ -214,6 +219,8 @@ def __init__(self, workspace_id): |
| 214 | 219 |
CommonWorkspace.__init__(self, workspace_id)
|
| 215 | 220 |
self.get_style_context().add_class('workspace-sidebar-item')
|
| 216 | 221 |
|
| 222 |
+ self._workspace_id = workspace_id
|
|
| 223 |
+ |
|
| 217 | 224 |
self._unread_label = Gtk.Label()
|
| 218 | 225 |
self._unread_label.get_style_context().add_class(
|
| 219 | 226 |
'unread-counter')
|
| ... | ... | @@ -248,11 +255,42 @@ def __init__(self, workspace_id): |
| 248 | 255 |
Gdk.DragAction.MOVE)
|
| 249 | 256 |
eventbox.connect('drag-begin', self._on_drag_begin)
|
| 250 | 257 |
eventbox.connect('drag-data-get', self._on_drag_data_get)
|
| 258 |
+ eventbox.connect('button-press-event', self._popup_menu)
|
|
| 251 | 259 |
eventbox.add(overlay)
|
| 252 |
- |
|
| 253 | 260 |
self.add(eventbox)
|
| 254 | 261 |
self.show_all()
|
| 255 | 262 |
|
| 263 |
+ def _popup_menu(self, _widget, event):
|
|
| 264 |
+ if event.button != 3: # right click
|
|
| 265 |
+ return
|
|
| 266 |
+ |
|
| 267 |
+ menu = self._get_workspace_menu()
|
|
| 268 |
+ |
|
| 269 |
+ rectangle = Gdk.Rectangle()
|
|
| 270 |
+ rectangle.x = event.x
|
|
| 271 |
+ rectangle.y = event.y
|
|
| 272 |
+ rectangle.width = rectangle.height = 1
|
|
| 273 |
+ |
|
| 274 |
+ popover = Gtk.Popover.new_from_model(self, menu)
|
|
| 275 |
+ popover.set_relative_to(self)
|
|
| 276 |
+ popover.set_position(Gtk.PositionType.RIGHT)
|
|
| 277 |
+ popover.set_pointing_to(rectangle)
|
|
| 278 |
+ popover.popup()
|
|
| 279 |
+ |
|
| 280 |
+ def _get_workspace_menu(self) -> Gio.Menu:
|
|
| 281 |
+ menu_items: List[Any] = [
|
|
| 282 |
+ ('edit-workspace', _('Edit…')),
|
|
| 283 |
+ ]
|
|
| 284 |
+ menu = Gio.Menu()
|
|
| 285 |
+ for item in menu_items:
|
|
| 286 |
+ action, label = item
|
|
| 287 |
+ action = f'win.{action}'
|
|
| 288 |
+ menuitem = Gio.MenuItem.new(label, action)
|
|
| 289 |
+ variant = GLib.Variant('s', self._workspace_id)
|
|
| 290 |
+ menuitem.set_action_and_target_value(action, variant)
|
|
| 291 |
+ menu.append_item(menuitem)
|
|
| 292 |
+ return menu
|
|
| 293 |
+ |
|
| 256 | 294 |
def update_avatar(self):
|
| 257 | 295 |
self._image.update()
|
| 258 | 296 |
|