[gnome-music/wip/mschraal/playlistcontrols-actions-rework] playlistscontrols: Move delete actions here



commit 23bf773760c15d47756af14016474129c1edd33a
Author: Marinus Schraal <mschraal gnome org>
Date:   Sat Jan 4 00:47:34 2020 +0100

    playlistscontrols: Move delete actions here
    
    Moved from PlaylistsView.

 gnomemusic/views/playlistsview.py      | 21 +--------------------
 gnomemusic/widgets/playlistcontrols.py | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 20 deletions(-)
---
diff --git a/gnomemusic/views/playlistsview.py b/gnomemusic/views/playlistsview.py
index a37c0e25..db615f88 100644
--- a/gnomemusic/views/playlistsview.py
+++ b/gnomemusic/views/playlistsview.py
@@ -29,10 +29,10 @@ from gi.repository import Gdk, GObject, Gio, Gtk
 from gnomemusic import log
 from gnomemusic.player import PlayerPlaylist
 from gnomemusic.views.baseview import BaseView
-from gnomemusic.widgets.notificationspopup import PlaylistNotification
 from gnomemusic.widgets.playlistcontextmenu import PlaylistContextMenu
 from gnomemusic.widgets.playlistcontrols import PlaylistControls
 from gnomemusic.widgets.playlistdialog import PlaylistDialog
+from gnomemusic.widgets.notificationspopup import PlaylistNotification
 from gnomemusic.widgets.playlisttile import PlaylistTile
 from gnomemusic.widgets.songwidget import SongWidget
 
@@ -84,8 +84,6 @@ class PlaylistsView(BaseView):
 
         self._playlist_delete_action = Gio.SimpleAction.new(
             'playlist_delete', None)
-        self._playlist_delete_action.connect(
-            'activate', self._stage_playlist_for_deletion)
         self._window.add_action(self._playlist_delete_action)
 
         self._playlist_rename_action = Gio.SimpleAction.new(
@@ -211,7 +209,6 @@ class PlaylistsView(BaseView):
 
         self._pl_ctrls.props.playlist = playlist
 
-        self._playlist_delete_action.set_enabled(not playlist.props.is_smart)
         self._remove_song_action.set_enabled(not playlist.props.is_smart)
 
     def _on_active_playlist_changed(self, klass, val):
@@ -296,22 +293,6 @@ class PlaylistsView(BaseView):
         """Indicate if renaming dialog is active"""
         return self._pl_ctrls.props.rename_active
 
-    @log
-    def _stage_playlist_for_deletion(self, menutime, data=None):
-        selected_row = self._sidebar.get_selected_row()
-        selected_playlist = selected_row.props.playlist
-
-        notification = PlaylistNotification(  # noqa: F841
-            self._window.notifications_popup, self._coremodel,
-            PlaylistNotification.Type.PLAYLIST, selected_playlist)
-
-        # FIXME: Should Check that the playlist is not playing
-        # playlist_id = selection.playlist.props.pl_id
-        # if self._player.playing_playlist(
-        #         PlayerPlaylist.Type.PLAYLIST, playlist_id):
-        #     self._player.stop()
-        #     self._window.set_player_visible(False)
-
     def _on_song_widget_moved(self, target, source_position):
         target_position = target.get_parent().get_index()
         selection = self._sidebar.get_selected_row()
diff --git a/gnomemusic/widgets/playlistcontrols.py b/gnomemusic/widgets/playlistcontrols.py
index 97d675c1..47cc0014 100644
--- a/gnomemusic/widgets/playlistcontrols.py
+++ b/gnomemusic/widgets/playlistcontrols.py
@@ -28,6 +28,7 @@ from gi.repository import Gdk, GObject, Gtk
 
 from gnomemusic import log
 from gnomemusic.grilowrappers.grltrackerplaylists import Playlist
+from gnomemusic.widgets.notificationspopup import PlaylistNotification
 
 
 @Gtk.Template(resource_path='/org/gnome/Music/ui/PlaylistControls.ui')
@@ -52,8 +53,11 @@ class PlaylistControls(Gtk.Grid):
         self._playlist = None
         self._count_id = 0
         self._binding_count = None
+        self._coremodel = application.props.coremodel
         self._window = application.props.window
 
+        self._delete_action = self._window.lookup_action("playlist_delete")
+        self._delete_action.connect("activate", self._on_delete_action)
         self._play_action = self._window.lookup_action("playlist_play")
         self._rename_action = self._window.lookup_action("playlist_rename")
         self._rename_action.connect("activate", self._on_rename_action)
@@ -61,6 +65,18 @@ class PlaylistControls(Gtk.Grid):
     def _on_rename_action(self, menuitem, data=None):
         self._enable_rename_playlist(self.props.playlist)
 
+    def _on_delete_action(self, menutime, data=None):
+        PlaylistNotification(
+            self._window.notifications_popup, self._coremodel,
+            PlaylistNotification.Type.PLAYLIST, self.props.playlist)
+
+        # FIXME: Should Check that the playlist is not playing
+        # playlist_id = selection.playlist.props.pl_id
+        # if self._player.playing_playlist(
+        #         PlayerPlaylist.Type.PLAYLIST, playlist_id):
+        #     self._player.stop()
+        #     self._window.set_player_visible(False)
+
     @Gtk.Template.Callback()
     @log
     def _on_rename_entry_changed(self, selection):
@@ -146,7 +162,9 @@ class PlaylistControls(Gtk.Grid):
 
         self._playlist = new_playlist
         self._disable_rename_playlist()
+        self._delete_action.props.enable = not self._playlist.props.is_smart
         self._rename_action.props.enabled = not self._playlist.props.is_smart
+
         self._binding_count = self._playlist.bind_property(
             "title", self._name_label, "label",
             GObject.BindingFlags.SYNC_CREATE)


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