[gnome-music/wip/mschraal/playlistcontrols-actions-rework] playlistcontextmenu: Move action creation



commit 7782350be1ce2156139a50bc385c723c986cfd09
Author: Marinus Schraal <mschraal gnome org>
Date:   Sun Jan 5 15:23:15 2020 +0100

    playlistcontextmenu: Move action creation

 gnomemusic/views/playlistsview.py         | 18 +++++++-----------
 gnomemusic/widgets/playlistcontextmenu.py | 20 ++++++++++++++++++--
 2 files changed, 25 insertions(+), 13 deletions(-)
---
diff --git a/gnomemusic/views/playlistsview.py b/gnomemusic/views/playlistsview.py
index d2f30472..54cf5a37 100644
--- a/gnomemusic/views/playlistsview.py
+++ b/gnomemusic/views/playlistsview.py
@@ -62,21 +62,17 @@ class PlaylistsView(BaseView):
         self._window = application.props.window
         self._player = player
 
-        self._song_popover = PlaylistContextMenu(self._view)
+        self._song_popover = PlaylistContextMenu(application, self._view)
 
-        play_song = Gio.SimpleAction.new('play_song', None)
-        play_song.connect('activate', self._play_song)
-        self._window.add_action(play_song)
+        play_song = self._window.lookup_action("play_song")
+        play_song.connect("activate", self._play_song)
 
-        add_song_to_playlist = Gio.SimpleAction.new(
-            'add_song_to_playlist', None)
-        add_song_to_playlist.connect('activate', self._add_song_to_playlist)
-        self._window.add_action(add_song_to_playlist)
+        add_song = self._window.lookup_action("add_song_to_playlist")
+        add_song.connect("activate", self._add_song_to_playlist)
 
-        self._remove_song_action = Gio.SimpleAction.new('remove_song', None)
+        self._remove_song_action = self._window.lookup_action("remove_song")
         self._remove_song_action.connect(
-            'activate', self._stage_song_for_deletion)
-        self._window.add_action(self._remove_song_action)
+            "activate", self._stage_song_for_deletion)
 
         self._pl_ctrls = PlaylistControls(application)
         self._grid.insert_row(0)
diff --git a/gnomemusic/widgets/playlistcontextmenu.py b/gnomemusic/widgets/playlistcontextmenu.py
index 5e52b591..e0cd8f2c 100644
--- a/gnomemusic/widgets/playlistcontextmenu.py
+++ b/gnomemusic/widgets/playlistcontextmenu.py
@@ -22,7 +22,7 @@
 # code, but you are not obligated to do so.  If you do not wish to do so,
 # delete this exception statement from your version.
 
-from gi.repository import Gtk
+from gi.repository import Gio, Gtk
 
 from gnomemusic import log
 
@@ -38,8 +38,24 @@ class PlaylistContextMenu(Gtk.Popover):
         return '<PlaylistContextMenu>'
 
     @log
-    def __init__(self, view):
+    def __init__(self, application, view):
+        """Initialize
+
+        :param GtkApplication application: The Application object
+        :param GtkListBox view: The view the popup is relative to
+        """
         super().__init__()
 
+        window = application.props.window
+
         self.props.relative_to = view
         self.bind_model(self._song_menu, None)
+
+        add_song = Gio.SimpleAction.new("add_song_to_playlist", None)
+        window.add_action(add_song)
+
+        play_song = Gio.SimpleAction.new("play_song", None)
+        window.add_action(play_song)
+
+        remove_song = Gio.SimpleAction.new("remove_song", None)
+        window.add_action(remove_song)


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