Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove playlist Item #164

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/Widgets/Player/Playlist.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
});
}
}
39 changes: 39 additions & 0 deletions src/Widgets/Player/PlaylistItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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 ();
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/Widgets/Player/PlaylistPopover.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down