[gnome-music/wip/jfelder/songeditor-gtk4: 25/32] selectiontoolbar: Add support to launch song editor dialog
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/songeditor-gtk4: 25/32] selectiontoolbar: Add support to launch song editor dialog
- Date: Fri, 11 Feb 2022 22:47:47 +0000 (UTC)
commit c3c34b6df85e3eb8095f18b7fd4341baa6048671
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 | 8 ++++++++
gnomemusic/widgets/selectiontoolbar.py | 16 +++++++++++-----
gnomemusic/window.py | 21 +++++++++++++++++++++
3 files changed, 40 insertions(+), 5 deletions(-)
---
diff --git a/data/ui/SelectionToolbar.ui b/data/ui/SelectionToolbar.ui
index 852b73676..b1f4dd18d 100644
--- a/data/ui/SelectionToolbar.ui
+++ b/data/ui/SelectionToolbar.ui
@@ -12,5 +12,13 @@
<signal name="clicked" handler="_on_add_to_playlist_button_clicked" swapped="no"/>
</object>
</child>
+ <child>
+ <object class="GtkButton" id="_edit_details_button">
+ <property name="label" translatable="yes">Edit Details</property>
+ <property name="sensitive">False</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked" handler="_on_edit_tags_button_clicked" swapped="no"/>
+ </object>
+ </child>
</template>
</interface>
diff --git a/gnomemusic/widgets/selectiontoolbar.py b/gnomemusic/widgets/selectiontoolbar.py
index f3a34bc4a..439b50f7a 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_songs_count = GObject.Property(type=int, default=0, minimum=0)
@@ -50,8 +52,12 @@ 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_songs_selection_changed(self, widget, data):
- if self.props.selected_songs_count > 0:
- self._add_to_playlist_button.props.sensitive = True
- else:
- self._add_to_playlist_button.props.sensitive = False
+ selection_size: int = self.props.selected_songs_count
+
+ self._add_to_playlist_button.props.sensitive = (selection_size > 0)
+ self._edit_details_button.props.sensitive = (selection_size == 1)
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index a79753817..a48187f55 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -44,6 +44,7 @@ from gnomemusic.widgets.playertoolbar import PlayerToolbar # noqa: F401
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
@@ -165,6 +166,7 @@ class Window(Adw.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
@@ -471,6 +473,25 @@ class Window(Adw.ApplicationWindow):
self._playlist_dialog.connect("response", on_response)
self._playlist_dialog.present()
+ def _on_edit_tags(self, widget: SelectionToolbar) -> None:
+ def on_response(dialog: PlaylistDialog, response_id: int) -> None:
+ self.props.selection_mode = False
+ song_editor_dialog.destroy()
+
+ if self._stack.get_visible_child() == self.views[View.PLAYLIST]:
+ return
+
+ coreselection = self._app.props.coreselection
+ selected_songs = coreselection.props.selected_songs
+
+ if len(selected_songs) < 1:
+ return
+
+ song_editor_dialog = SongEditorDialog(self._app, selected_songs[0])
+ song_editor_dialog.props.transient_for = self
+ song_editor_dialog.connect("response", on_response)
+ song_editor_dialog.present()
+
def set_player_visible(self, visible):
"""Set PlayWidget action visibility
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]