diff --git a/src/Widgets/Player/Playlist.vala b/src/Widgets/Player/Playlist.vala index 3a9138bd4..569fdcfac 100644 --- a/src/Widgets/Player/Playlist.vala +++ b/src/Widgets/Player/Playlist.vala @@ -52,9 +52,13 @@ public class Audience.Widgets.Playlist : Gtk.ListBox { save_playlist (); } - public bool next () { + public bool next (bool update_current = true) { var children = get_children (); - current++; + + if (update_current) { + current++; + } + if (current >= children.length ()) { current = 0; return false; @@ -100,6 +104,7 @@ public class Audience.Widgets.Playlist : Gtk.ListBox { var row = new PlaylistItem (Audience.get_title (path.get_basename ()), path.get_uri ()); add (row); item_added (); + connect_row_signals (row); } public void remove_item (File path) { @@ -219,4 +224,15 @@ public class Audience.Widgets.Playlist : Gtk.ListBox { remove (source); insert (source, new_position); } + + private void connect_row_signals (PlaylistItem row) { + row.remove_item.connect (() => { + remove_item (File.new_for_path (row.filename)); + remove (row); + + if (row.is_playing) { + next (false); + } + }); + } } diff --git a/src/Widgets/Player/PlaylistItem.vala b/src/Widgets/Player/PlaylistItem.vala index d297435ef..1cd188f0c 100644 --- a/src/Widgets/Player/PlaylistItem.vala +++ b/src/Widgets/Player/PlaylistItem.vala @@ -19,6 +19,7 @@ */ public class Audience.Widgets.PlaylistItem : Gtk.ListBoxRow { + public signal void remove_item (); public bool is_playing { get; set; } public string title { get; construct; } public string filename { get; construct; } @@ -44,12 +45,29 @@ public class Audience.Widgets.PlaylistItem : Gtk.ListBoxRow { var track_name_label = new Gtk.Label (title); track_name_label.ellipsize = Pango.EllipsizeMode.MIDDLE; + var delete_button = new Gtk.Image.from_icon_name ("edit-delete-symbolic", Gtk.IconSize.BUTTON); + delete_button.tooltip_text = _("Remove video from playlist"); + delete_button.halign = Gtk.Align.END; + delete_button.expand = true; + + var remove_item_event_box = new Gtk.EventBox (); + remove_item_event_box.add (delete_button); + remove_item_event_box.button_release_event.connect (on_button_released); + + var action_revealer = new Gtk.Revealer (); + action_revealer.transition_type = Gtk.RevealerTransitionType.CROSSFADE; + action_revealer.add (remove_item_event_box); + action_revealer.transition_duration = 1000; + action_revealer.show_all (); + action_revealer.set_reveal_child (false); + var grid = new Gtk.Grid (); grid.margin = 3; grid.margin_bottom = grid.margin_top = 6; grid.column_spacing = 6; grid.add (play_revealer); grid.add (track_name_label); + grid.add (action_revealer); // Drag source must have a GdkWindow. GTK4 will remove the limitation. var dnd_event_box = new Gtk.EventBox (); @@ -59,6 +77,22 @@ public class Audience.Widgets.PlaylistItem : Gtk.ListBoxRow { Gtk.drag_source_set (dnd_event_box, Gdk.ModifierType.BUTTON1_MASK, TARGET_ENTRIES, Gdk.DragAction.MOVE); + dnd_event_box.add_events (Gdk.EventMask.ENTER_NOTIFY_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK); + + dnd_event_box.enter_notify_event.connect (event => { + action_revealer.set_reveal_child (true); + return Gdk.EVENT_PROPAGATE; + }); + + dnd_event_box.leave_notify_event.connect (event => { + if (event.detail == Gdk.NotifyType.INFERIOR) { + return Gdk.EVENT_PROPAGATE; + } + + action_revealer.set_reveal_child (false); + return Gdk.EVENT_PROPAGATE; + }); + set_tooltip_text (title); add (dnd_event_box); @@ -92,4 +126,9 @@ public class Audience.Widgets.PlaylistItem : Gtk.ListBoxRow { Gdk.Atom.intern_static_string ("PLAYLIST_ITEM"), 32, data ); } + + private bool on_button_released (Gtk.Widget sender, Gdk.EventButton event) { + remove_item (); + return Gdk.EVENT_STOP; + } } diff --git a/src/Widgets/Player/PlaylistPopover.vala b/src/Widgets/Player/PlaylistPopover.vala index 084730a05..51c4ff449 100644 --- a/src/Widgets/Player/PlaylistPopover.vala +++ b/src/Widgets/Player/PlaylistPopover.vala @@ -46,7 +46,7 @@ public class Audience.Widgets.PlaylistPopover : Gtk.Popover { playlist_scrolled = new Gtk.ScrolledWindow (null, null); playlist_scrolled.min_content_height = 100; - playlist_scrolled.min_content_width = 260; + playlist_scrolled.min_content_width = 300; playlist_scrolled.propagate_natural_height = true; playlist = new Playlist ();