[gnome-music/wip/mschraal/tageditor-13feb2020: 10/12] selectiontoolbar: Add support to launch song editor dialog



commit da08ba3f2479cdb8435b525689c0824ce9a3238c
Author: Sumaid Syed <sumaidsyed gmail com>
Date:   Thu Jan 23 14:18:55 2020 +0100

    selectiontoolbar: Add support to launch song editor dialog
    
    This dialog can be displayed if only one song is selected.
    
    Based on an initial patch by Jean Felder.

 data/ui/SelectionToolbar.ui            | 13 +++++++++++
 gnomemusic/widgets/selectiontoolbar.py | 41 +++++++++++++++++++++++++++++-----
 gnomemusic/window.py                   | 20 +++++++++++++++++
 3 files changed, 69 insertions(+), 5 deletions(-)
---
diff --git a/data/ui/SelectionToolbar.ui b/data/ui/SelectionToolbar.ui
index ec64876c..4f488e7a 100644
--- a/data/ui/SelectionToolbar.ui
+++ b/data/ui/SelectionToolbar.ui
@@ -17,5 +17,18 @@
         </style>
       </object>
     </child>
+    <child>
+      <object class="GtkButton" id="_edit_details_button">
+        <property name="label" translatable="yes">Edit Details</property>
+        <property name="visible">True</property>
+        <property name="sensitive">False</property>
+        <property name="can_focus">True</property>
+        <property name="receives_default">True</property>
+        <signal name="clicked" handler="_on_edit_tags_button_clicked" swapped="no"/>
+        <style>
+          <class name="text-button"/>
+        </style>
+      </object>
+    </child>
   </template>
 </interface>
diff --git a/gnomemusic/widgets/selectiontoolbar.py b/gnomemusic/widgets/selectiontoolbar.py
index b97c2d39..696136b3 100644
--- a/gnomemusic/widgets/selectiontoolbar.py
+++ b/gnomemusic/widgets/selectiontoolbar.py
@@ -31,9 +31,11 @@ class SelectionToolbar(Gtk.ActionBar):
     __gtype_name__ = 'SelectionToolbar'
 
     _add_to_playlist_button = Gtk.Template.Child()
+    _edit_details_button = Gtk.Template.Child()
 
     __gsignals__ = {
-        'add-to-playlist': (GObject.SignalFlags.RUN_FIRST, None, ())
+        'add-to-playlist': (GObject.SignalFlags.RUN_FIRST, None, ()),
+        "edit-details": (GObject.SignalFlags.RUN_FIRST, None, ())
     }
 
     selected_items_count = GObject.Property(type=int, default=0, minimum=0)
@@ -41,6 +43,8 @@ class SelectionToolbar(Gtk.ActionBar):
     def __init__(self):
         super().__init__()
 
+        self._stack = None
+
         self.connect(
             'notify::selected-items-count', self._on_item_selection_changed)
 
@@ -50,8 +54,35 @@ class SelectionToolbar(Gtk.ActionBar):
     def _on_add_to_playlist_button_clicked(self, widget):
         self.emit('add-to-playlist')
 
+    @Gtk.Template.Callback()
+    def _on_edit_tags_button_clicked(self, widget):
+        self.emit("edit-details")
+
     def _on_item_selection_changed(self, widget, data):
-        if self.props.selected_items_count > 0:
-            self._add_to_playlist_button.props.sensitive = True
-        else:
-            self._add_to_playlist_button.props.sensitive = False
+        selection_size = self.props.selected_items_count
+
+        self._add_to_playlist_button.props.sensitive = (selection_size > 0)
+        self._edit_details_button.props.sensitive = (selection_size == 1)
+
+    # FIXME: This is a workaround for not being able to pass the stack
+    # object via init when using Gtk.Builder.
+    @GObject.Property(type=Gtk.Stack, default=None)
+    def stack(self):
+        """The main GtkStack of the app
+
+        :return: main stack object
+        :rtype: GtkStack
+        """
+        return self._stack
+
+    @stack.setter
+    def stack(self, stack):
+        """Set the GtkStack object used
+
+        :param GtkStack stack: The GtkStack to use
+        """
+        if (stack is None
+                or (self._stack is not None
+                    and self._stack != stack)):
+            return
+        self._stack = stack
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index cfc62af9..33218f2d 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -43,6 +43,7 @@ from gnomemusic.widgets.playertoolbar import PlayerToolbar
 from gnomemusic.widgets.playlistdialog import PlaylistDialog
 from gnomemusic.widgets.searchheaderbar import SearchHeaderBar
 from gnomemusic.widgets.selectiontoolbar import SelectionToolbar  # noqa: F401
+from gnomemusic.widgets.songeditordialog import SongEditorDialog
 from gnomemusic.windowplacement import WindowPlacement
 
 
@@ -125,6 +126,8 @@ class Window(Gtk.ApplicationWindow):
         self._player_toolbar = PlayerToolbar()
         self._player_toolbar.props.player = self._player
 
+        self._selection_toolbar.props.stack = self._stack
+
         self._headerbar.connect(
             'back-button-clicked', self._switch_back_from_childview)
 
@@ -171,6 +174,7 @@ class Window(Gtk.ApplicationWindow):
 
         self._selection_toolbar.connect(
             'add-to-playlist', self._on_add_to_playlist)
+        self._selection_toolbar.connect("edit-details", self._on_edit_tags)
         self._search.connect("notify::state", self._on_search_state_changed)
 
         self._headerbar.props.state = HeaderBar.State.MAIN
@@ -478,6 +482,22 @@ class Window(Gtk.ApplicationWindow):
         self.props.selection_mode = False
         playlist_dialog.destroy()
 
+    def _on_edit_tags(self, widget):
+        if self._stack.get_visible_child() == self.views[View.PLAYLIST]:
+            return
+
+        selected_songs = self._app.props.coreselection.props.selected_items
+
+        if len(selected_songs) < 1:
+            return
+
+        grilo = self._app.props.coremodel.props.grilo
+        song_editor_dialog = SongEditorDialog(self, selected_songs[0], grilo)
+        song_editor_dialog.run()
+
+        self.props.selection_mode = False
+        song_editor_dialog.destroy()
+
     def set_player_visible(self, visible):
         """Set PlayWidget action visibility
 


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