Tooth/src/Views/ContentBase.vala

69 lines
1.4 KiB
Vala
Raw Normal View History

2021-07-23 11:41:03 +00:00
using Gtk;
2022-11-13 20:57:43 +00:00
public class Tooth.Views.ContentBase : Views.Base {
2021-07-23 11:41:03 +00:00
2021-07-25 18:15:59 +00:00
public GLib.ListStore model;
2021-07-23 11:41:03 +00:00
protected ListBox content;
public bool empty {
2021-07-25 15:35:51 +00:00
get { return model.get_n_items () <= 0; }
2021-07-23 11:41:03 +00:00
}
construct {
model = new GLib.ListStore (typeof (Widgetizable));
model.items_changed.connect (() => on_content_changed ());
content = new ListBox () {
selection_mode = SelectionMode.NONE,
can_focus = false
};
content_box.append (content);
content.add_css_class ("content");
content.add_css_class ("ttl-content");
2021-07-23 11:41:03 +00:00
content.row_activated.connect (on_content_item_activated);
content.bind_model (model, on_create_model_widget);
scrolled.edge_reached.connect (pos => {
if (pos == PositionType.BOTTOM)
on_bottom_reached ();
});
}
~ContentBase () {
message ("Destroying ContentBase");
}
public override void dispose () {
if (content != null)
content.bind_model (null, null);
base.dispose ();
}
public override void clear () {
base.clear ();
model.remove_all ();
}
public override void on_content_changed () {
if (empty) {
status_message = STATUS_EMPTY;
state = "status";
}
else {
state = "content";
}
}
public virtual Widget on_create_model_widget (Object obj) {
return (obj as Widgetizable).to_widget ();
}
public virtual void on_bottom_reached () {}
public virtual void on_content_item_activated (ListBoxRow row) {
Signal.emit_by_name (row, "open");
}
}