Skip to content

Commit a2d904a

Browse files
authored
TrackRow: remove song from context menu (#797)
1 parent 62892b6 commit a2d904a

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/PlaybackManager.vala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ public class Music.PlaybackManager : Object {
151151
queue_liststore.remove_all ();
152152
}
153153

154+
public void remove (AudioObject song) {
155+
if (song == current_audio) {
156+
playbin.set_state (Gst.State.NULL);
157+
current_audio = null;
158+
}
159+
160+
uint position;
161+
queue_liststore.find (song, out position);
162+
queue_liststore.remove (position);
163+
}
164+
154165
private void update_metadata (Gst.PbUtils.DiscovererInfo info, Error? err) {
155166
string uri = info.get_uri ();
156167
switch (info.get_result ()) {

src/Widgets/TrackRow.vala

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,51 @@ public class Music.TrackRow : Gtk.ListBoxRow {
7373
}
7474
});
7575

76+
var action_remove = new SimpleAction ("remove", null);
77+
action_remove.activate.connect (() => {
78+
playback_manager.remove (this.audio_object);
79+
});
80+
81+
var row_action_group = new SimpleActionGroup ();
82+
row_action_group.add_action (action_remove);
83+
84+
insert_action_group ("trackrow", row_action_group);
85+
add_binding_action (Gdk.Key.Delete, Gdk.ModifierType.NO_MODIFIER_MASK, "trackrow.remove", null);
86+
87+
var menu = new Menu ();
88+
menu.append (_("Remove"), "trackrow.remove");
89+
90+
var context_menu = new Gtk.PopoverMenu.from_model (menu) {
91+
halign = Gtk.Align.START,
92+
has_arrow = false,
93+
position = Gtk.PositionType.BOTTOM
94+
};
95+
context_menu.set_parent (this);
96+
97+
var right_click = new Gtk.GestureClick () {
98+
button = Gdk.BUTTON_SECONDARY
99+
};
100+
right_click.pressed.connect ((n_press, x, y) => {
101+
var rect = Gdk.Rectangle () {
102+
x = (int) x,
103+
y = (int) y
104+
};
105+
context_menu.pointing_to = rect;
106+
context_menu.popup ();
107+
});
108+
109+
var long_press = new Gtk.GestureLongPress ();
110+
long_press.pressed.connect ((x, y) => {
111+
var rect = Gdk.Rectangle () {
112+
x = (int) x,
113+
y = (int) y
114+
};
115+
context_menu.pointing_to = rect;
116+
context_menu.popup ();
117+
});
118+
119+
add_controller (right_click);
120+
add_controller (long_press);
76121
}
77122

78123
private void update_playing (bool playing) {

0 commit comments

Comments
 (0)