[gnome-music/wip/jfelder/songeditor-gtk4: 26/32] songwidgetmenu: Add support to launch song editor dialog




commit 5581377ce36a4dbc467a37a52a5b7056950ae672
Author: Jean Felder <jfelder src gnome org>
Date:   Fri Aug 6 21:46:50 2021 +0200

    songwidgetmenu: Add support to launch song editor dialog

 data/ui/SongWidgetMenu.ui            |  4 ++++
 gnomemusic/widgets/songwidgetmenu.py | 21 ++++++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)
---
diff --git a/data/ui/SongWidgetMenu.ui b/data/ui/SongWidgetMenu.ui
index 17c7a34a1..7a6079d05 100644
--- a/data/ui/SongWidgetMenu.ui
+++ b/data/ui/SongWidgetMenu.ui
@@ -11,6 +11,10 @@
       <attribute name="label" translatable="yes">_Play</attribute>
       <attribute name="action">songwidget.play</attribute>
     </item>
+    <item>
+      <attribute name="label" translatable="yes">_Edit Details…</attribute>
+      <attribute name="action">songwidget.edit_details</attribute>
+    </item>
     <item>
       <attribute name="label" translatable="yes">_Add to Playlist…</attribute>
       <attribute name="action">songwidget.add_playlist</attribute>
diff --git a/gnomemusic/widgets/songwidgetmenu.py b/gnomemusic/widgets/songwidgetmenu.py
index 0384b09a4..b1f6e54b7 100644
--- a/gnomemusic/widgets/songwidgetmenu.py
+++ b/gnomemusic/widgets/songwidgetmenu.py
@@ -31,6 +31,7 @@ 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.songeditordialog import SongEditorDialog
 if typing.TYPE_CHECKING:
     from gnomemusic.application import Application
     from gnomemusic.corealbum import CoreAlbum
@@ -65,10 +66,12 @@ class SongWidgetMenu(Gtk.PopoverMenu):
         self._coresong = song_widget.props.coresong
 
         self._playlist_dialog: Optional[PlaylistDialog] = None
+        self._song_editor_dialog: Optional[SongEditorDialog] = None
 
         action_group = Gio.SimpleActionGroup()
         action_entries = [
             ("play", self._play_song),
+            ("edit_details", self._edit_details),
             ("add_playlist", self._add_to_playlist)
         ]
         if (isinstance(self._coreobject, Playlist)
@@ -76,7 +79,7 @@ class SongWidgetMenu(Gtk.PopoverMenu):
             action_entries.append(
                 ("remove_playlist", self._remove_from_playlist))
         elif not isinstance(self._coreobject, Playlist):
-            self.props.menu_model.remove(2)
+            self.props.menu_model.remove(3)
 
         for name, callback in action_entries:
             action = Gio.SimpleAction.new(name, None)
@@ -97,6 +100,22 @@ class SongWidgetMenu(Gtk.PopoverMenu):
             "playlist-loaded", _on_playlist_loaded)
         self._coremodel.props.active_core_object = self._coreobject
 
+    def _edit_details(self, action: Gio.Simple, param: Any) -> None:
+
+        def on_response(dialog: PlaylistDialog, response_id: int) -> None:
+            if not self._song_editor_dialog:
+                return
+
+            self._song_editor_dialog.destroy()
+            self._song_editor_dialog = None
+
+        self.popdown()
+        self._song_editor_dialog = SongEditorDialog(
+            self._application, self._coresong)
+        self._song_editor_dialog.props.transient_for = self._window
+        self._song_editor_dialog.connect("response", on_response)
+        self._song_editor_dialog.present()
+
     def _add_to_playlist(self, action: Gio.Simple, param: Any) -> None:
 
         def on_response(dialog: PlaylistDialog, response_id: int) -> None:


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