[gnome-music/wip/jfelder/albumwidget-add-contextmenu: 8/8] searchview: Add support for a song context menu




commit f45311c53f0f42820b260c61266c55ef4983e2c0
Author: Jean Felder <jfelder src gnome org>
Date:   Sat Aug 7 16:00:46 2021 +0200

    searchview: Add support for a song context menu
    
    right clicking on a SongWidget displays a SongWidgetMenu.

 data/ui/SearchView.ui          |  6 ++++++
 gnomemusic/views/searchview.py | 19 +++++++++++++++++++
 2 files changed, 25 insertions(+)
---
diff --git a/data/ui/SearchView.ui b/data/ui/SearchView.ui
index 52dca40f8..ff19fddd9 100644
--- a/data/ui/SearchView.ui
+++ b/data/ui/SearchView.ui
@@ -232,4 +232,10 @@
       </object>
     </child>
   </template>
+  <object class="GtkGestureMultiPress" id="_songs_listbox_ctrlr">
+    <property name="widget">_songs_listbox</property>
+    <property name="propagation-phase">capture</property>
+    <property name="button">3</property>
+    <signal name="pressed" handler="_songs_listbox_right_click" swapped="no"/>
+  </object>
 </interface>
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index 85a2e6dab..0c14bc454 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -77,6 +77,7 @@ class SearchView(Gtk.Stack):
     _search_results = Gtk.Template.Child()
     _songs_header = Gtk.Template.Child()
     _songs_listbox = Gtk.Template.Child()
+    _songs_listbox_ctrlr = Gtk.Template.Child()
     _view_all_albums = Gtk.Template.Child()
     _view_all_artists = Gtk.Template.Child()
 
@@ -276,6 +277,24 @@ class SearchView(Gtk.Stack):
 
         return True
 
+    @Gtk.Template.Callback()
+    def _songs_listbox_right_click(
+            self, gesture: Gtk.GestureMultiPress, n_press: int, x: int,
+            y: int) -> None:
+        song_widget = self._songs_listbox.get_row_at_y(y)
+
+        _, y0 = song_widget.translate_coordinates(self._songs_listbox, 0, 0)
+        row_height = song_widget.get_allocated_height()
+        rect = Gdk.Rectangle()
+        rect.x = x
+        rect.y = y0 + 0.5 * row_height
+
+        song_context_menu = SongWidgetMenu(
+            self._application, song_widget, song_widget.props.coresong)
+        song_context_menu.props.relative_to = self._songs_listbox
+        song_context_menu.props.pointing_to = rect
+        song_context_menu.popup()
+
     def _on_album_flowbox_size_allocate(self, widget, allocation, data=None):
         nb_children = self._album_filter.get_n_items()
         if nb_children == 0:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]