tootle-linux-client/src/Views/Lists.vala

75 lines
1.6 KiB
Vala
Raw Normal View History

2020-07-28 20:30:45 +02:00
using Gtk;
2021-07-23 13:41:03 +02:00
// TODO: Lists is borken
2020-07-28 20:30:45 +02:00
public class Tootle.Views.Lists : Views.Timeline {
[GtkTemplate (ui = "/com/github/bleakgrey/tootle/ui/widgets/list_item.ui")]
public class Row : ListBoxRow {
API.List? list;
2021-07-23 13:41:03 +02:00
[GtkChild] unowned Stack stack;
[GtkChild] unowned Label title;
2020-07-28 20:30:45 +02:00
public Row (API.List? list) {
this.list = list;
if (list == null)
stack.visible_child_name = "add";
else
list.bind_property ("title", title, "label", BindingFlags.SYNC_CREATE);
}
[GtkCallback]
void on_edit_clicked () {
new Dialogs.ListEditor (this.list);
}
[GtkCallback]
void on_remove_clicked () {
2020-07-30 21:02:03 +02:00
var remove = app.question (
2020-07-28 20:30:45 +02:00
_("Delete \"%s\"?").printf (list.title),
_("This action cannot be reverted.")
);
2020-07-30 21:02:03 +02:00
if (remove) {
2020-07-28 20:30:45 +02:00
new Request.DELETE (@"/api/v1/lists/$(list.id)")
.with_account (accounts.active)
.then (() => { this.destroy (); })
.exec ();
}
}
public virtual signal void open () {
if (this.list == null)
return;
var view = new Views.List (list);
2021-07-23 13:41:03 +02:00
app.main_window.open_view (view);
2020-07-28 20:30:45 +02:00
}
}
public new bool empty {
get { return false; }
}
public Lists () {
Object (
url: @"/api/v1/lists",
label: _("Lists"),
icon: "view-list-symbolic"
);
accepts = typeof (API.List);
}
public override void on_request_finish () {
var add_row = new Row (null);
add_row.open.connect (() => {
var dlg = new Dialogs.ListEditor.empty ();
dlg.done.connect (on_refresh);
});
append (add_row);
on_content_changed ();
}
}