Daniel Brötzmann pushed to branch master at gajim / gajim
Commits: 757ddea1 by wurstsalat at 2022-10-03T17:19:45+02:00 imprv: Drag and drop: Highlight target areas
Adds highlighting for workspace and chat list drag and drop
Fixes #11173
- - - - -
5 changed files:
- gajim/data/style/gajim.css - gajim/gtk/chat_list.py - gajim/gtk/chat_list_row.py - gajim/gtk/main.py - gajim/gtk/workspace_side_bar.py
Changes:
===================================== gajim/data/style/gajim.css ===================================== @@ -813,6 +813,14 @@ .badge { font-weight: bold; }
+.dnd-target { + animation-name: pulse-opacity; + animation-duration: 2.0s; + animation-timing-function: ease-in-out; + animation-iteration-count: infinite; + border: 2px dashed @theme_selected_bg_color; +} + @keyframes pulse-opacity { 0% { opacity: 1.0; } 20% { opacity: 0.5; }
===================================== gajim/gtk/chat_list.py ===================================== @@ -279,6 +279,9 @@ def select_chat_number(self, number: int) -> None: assert isinstance(row, ChatListRow) self.select_chat(row.account, row.jid)
+ def get_chat_list_rows(self) -> list[ChatListRow]: + return cast(list[ChatListRow], self.get_children()) + def remove_chat(self, account: str, jid: JID,
===================================== gajim/gtk/chat_list_row.py ===================================== @@ -114,6 +114,7 @@ def __init__(self, entries, Gdk.DragAction.MOVE) self.connect('drag-begin', self._on_drag_begin) + self.connect('drag-end', self._on_drag_end) self.connect('drag-data-get', self._on_drag_data_get)
if self.type == 'groupchat': @@ -428,6 +429,15 @@ def _on_drag_begin(self, self.draw(context) Gtk.drag_set_icon_surface(drag_context, surface)
+ app.window.highlight_dnd_targets(row, True) + + def _on_drag_end(self, + row: ChatListRow, + _drag_context: Gdk.DragContext + ) -> None: + + app.window.highlight_dnd_targets(row, False) + def _on_drag_data_get(self, _widget: Gtk.Widget, _drag_context: Gdk.DragContext,
===================================== gajim/gtk/main.py ===================================== @@ -46,6 +46,7 @@ from .main_stack import MainStack from .call_window import CallWindow from .chat_list import ChatList +from .chat_list_row import ChatListRow from .chat_stack import ChatStack from .const import MAIN_WIN_ACTIONS from .dialogs import DialogButton @@ -566,6 +567,32 @@ def is_chat_active(self, account: str, jid: JID) -> bool: return False return self._chat_page.is_chat_active(account, jid)
+ def highlight_dnd_targets(self, drag_row: Any, highlight: bool) -> None: + css_class = 'dnd-target' + + if isinstance(drag_row, ChatListRow): + chat_list_stack = self._chat_page.get_chat_list_stack() + workspace = self.get_active_workspace() + if workspace is None: + return + + if drag_row.is_pinned: + chat_list = chat_list_stack.get_chatlist(workspace) + for row in chat_list.get_chat_list_rows(): + if not row.is_pinned: + continue + + if highlight: + row.get_style_context().add_class(css_class) + else: + row.get_style_context().remove_class(css_class) + + if highlight: + self._workspace_side_bar.get_style_context().add_class(css_class) + else: + self._workspace_side_bar.get_style_context().remove_class( + css_class) + def _add_workspace(self, _action: Gio.SimpleAction, param: GLib.Variant) -> None:
===================================== gajim/gtk/workspace_side_bar.py ===================================== @@ -322,6 +322,7 @@ def __init__(self, workspace_id: str) -> None: entries, Gdk.DragAction.MOVE) eventbox.connect('drag-begin', self._on_drag_begin) + eventbox.connect('drag-end', self._on_drag_end) eventbox.connect('drag-data-get', self._on_drag_data_get) eventbox.connect('button-press-event', self._popup_menu) eventbox.add(overlay) @@ -348,9 +349,10 @@ def set_unread_count(self, count: int) -> None: self._unread_label.set_visible(bool(count))
def _on_drag_begin(self, - _widget: Gtk.Widget, + row: Workspace, drag_context: Gdk.DragContext ) -> None: + scale = self.get_scale_factor() surface = app.app.avatar_storage.get_workspace_surface( self.workspace_id, AvatarSize.WORKSPACE, scale) @@ -360,6 +362,15 @@ def _on_drag_begin(self, listbox = cast(WorkspaceSideBar, self.get_parent()) listbox.set_drag_row(self)
+ app.window.highlight_dnd_targets(row, True) + + def _on_drag_end(self, + row: Workspace, + drag_context: Gdk.DragContext + ) -> None: + + app.window.highlight_dnd_targets(row, False) + def _on_drag_data_get(self, _widget: Gtk.Widget, _drag_context: Gdk.DragContext,
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/757ddea13b188b1511c2196ce84710410...