[gnome-music/wip/jfelder/gtk4-v3: 235/259] songlistitem: Add support for song menu




commit ba850066946ebea948f72c8572d46f779fe22d19
Author: Jean Felder <jfelder src gnome org>
Date:   Sat Feb 12 14:35:13 2022 +0100

    songlistitem: Add support for song menu

 data/ui/SongListItem.ui              |  9 +++++++++
 gnomemusic/views/songsview.py        |  9 ++++++++-
 gnomemusic/widgets/songwidgetmenu.py | 11 ++++++++---
 3 files changed, 25 insertions(+), 4 deletions(-)
---
diff --git a/data/ui/SongListItem.ui b/data/ui/SongListItem.ui
index 8599fcb53..3d906d61a 100644
--- a/data/ui/SongListItem.ui
+++ b/data/ui/SongListItem.ui
@@ -59,5 +59,14 @@
         </child>
       </object>
     </child>
+    <child>
+      <object class="GtkMenuButton" id="_menu_button">
+        <property name="focusable">True</property>
+        <property name="icon-name">view-more-symbolic</property>
+        <style>
+          <class name="flat"/>
+        </style>
+      </object>
+    </child>
   </object>
 </interface>
diff --git a/gnomemusic/views/songsview.py b/gnomemusic/views/songsview.py
index 17c17b518..72eae3ca2 100644
--- a/gnomemusic/views/songsview.py
+++ b/gnomemusic/views/songsview.py
@@ -25,6 +25,7 @@
 from gettext import gettext as _
 from gi.repository import GObject, Gtk
 
+from gnomemusic.widgets.songwidgetmenu import SongWidgetMenu
 import gnomemusic.utils as utils
 
 
@@ -55,6 +56,7 @@ class SongsView(Gtk.Box):
 
         self.props.name = "songs"
 
+        self._application = application
         self._coremodel = application.props.coremodel
         self._coreselection = application.props.coreselection
         self._player = application.props.player
@@ -136,10 +138,12 @@ class SongsView(Gtk.Box):
         check = list_row.get_first_child()
         info_box = check.get_next_sibling()
         duration_label = info_box.get_next_sibling()
-        star_image = duration_label.get_next_sibling().get_first_child()
+        star_box = duration_label.get_next_sibling()
+        star_image = star_box.get_first_child()
         title_label = info_box.get_first_child()
         album_label = title_label.get_next_sibling()
         artist_label = album_label.get_next_sibling()
+        menu_button = star_box.get_next_sibling()
 
         def _on_star_toggle(
                 controller: Gtk.GestureClick, n_press: int, x: float,
@@ -166,6 +170,9 @@ class SongsView(Gtk.Box):
         star_hover.connect("leave", _on_star_leave)
         star_image.add_controller(star_hover)
 
+        menu_button.props.popover = SongWidgetMenu(
+            self._application, list_row, coresong)
+
         coresong.bind_property(
             "title", title_label, "label",
             GObject.BindingFlags.SYNC_CREATE)
diff --git a/gnomemusic/widgets/songwidgetmenu.py b/gnomemusic/widgets/songwidgetmenu.py
index 0384b09a4..2eddd7a72 100644
--- a/gnomemusic/widgets/songwidgetmenu.py
+++ b/gnomemusic/widgets/songwidgetmenu.py
@@ -31,11 +31,11 @@ from gi.repository import Gio, Gtk
 from gnomemusic.grilowrappers.grltrackerplaylists import Playlist
 from gnomemusic.widgets.notificationspopup import PlaylistNotification
 from gnomemusic.widgets.playlistdialog import PlaylistDialog
+from gnomemusic.widgets.songwidget import SongWidget
 if typing.TYPE_CHECKING:
     from gnomemusic.application import Application
     from gnomemusic.corealbum import CoreAlbum
     from gnomemusic.coresong import CoreSong
-    from gnomemusic.widgets.songwidget import SongWidget
 
 
 @Gtk.Template(resource_path="/org/gnome/Music/ui/SongWidgetMenu.ui")
@@ -44,7 +44,8 @@ class SongWidgetMenu(Gtk.PopoverMenu):
     __gtype_name__ = "SongWidgetMenu"
 
     def __init__(
-            self, application: Application, song_widget: SongWidget,
+            self, application: Application,
+            song_widget: Union[SongWidget, Gtk.ListItem],
             coreobject: Union[CoreAlbum, CoreSong, Playlist]) -> None:
         """Menu to interact with the song of a SongWidget.
 
@@ -62,7 +63,11 @@ class SongWidgetMenu(Gtk.PopoverMenu):
 
         self._coreobject = coreobject
         self._song_widget = song_widget
-        self._coresong = song_widget.props.coresong
+
+        if isinstance(song_widget, SongWidget):
+            self._coresong = song_widget.props.coresong
+        else:
+            self._coresong = coreobject
 
         self._playlist_dialog: Optional[PlaylistDialog] = None
 


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