2020-05-29 12:19:35 +00:00
|
|
|
using Gtk;
|
|
|
|
|
|
|
|
[GtkTemplate (ui = "/com/github/bleakgrey/tootle/ui/views/base.ui")]
|
|
|
|
public class Tootle.Views.Base : Box {
|
|
|
|
|
|
|
|
public static string STATUS_EMPTY = _("Nothing to see here");
|
|
|
|
public static string STATUS_LOADING = " ";
|
|
|
|
|
2020-05-31 10:28:35 +00:00
|
|
|
public int stack_pos { get; set; default = -1; }
|
|
|
|
public string? icon { get; set; default = null; }
|
|
|
|
public string label { get; set; default = ""; }
|
|
|
|
public bool needs_attention { get; set; default = false; }
|
|
|
|
public bool current { get; set; default = false; }
|
2020-05-29 12:19:35 +00:00
|
|
|
|
|
|
|
[GtkChild]
|
|
|
|
protected ScrolledWindow scrolled;
|
|
|
|
[GtkChild]
|
|
|
|
protected Box view;
|
|
|
|
[GtkChild]
|
2020-07-06 16:55:13 +00:00
|
|
|
protected Hdy.Clamp clamp;
|
2020-06-02 09:35:29 +00:00
|
|
|
[GtkChild]
|
|
|
|
protected Box column_view;
|
|
|
|
[GtkChild]
|
2020-05-29 12:19:35 +00:00
|
|
|
protected Stack states;
|
|
|
|
[GtkChild]
|
|
|
|
protected Box content;
|
|
|
|
[GtkChild]
|
2020-06-02 09:35:29 +00:00
|
|
|
protected ListBox content_list;
|
|
|
|
[GtkChild]
|
2020-05-29 12:19:35 +00:00
|
|
|
protected Button status_button;
|
|
|
|
[GtkChild]
|
2020-05-31 10:28:35 +00:00
|
|
|
Stack status_stack;
|
|
|
|
[GtkChild]
|
|
|
|
Label status_message_label;
|
2020-05-29 12:19:35 +00:00
|
|
|
|
|
|
|
public string state { get; set; default = "status"; }
|
|
|
|
public string status_message { get; set; default = STATUS_EMPTY; }
|
|
|
|
|
|
|
|
public bool empty {
|
|
|
|
get {
|
2020-06-02 09:35:29 +00:00
|
|
|
return content_list.get_children ().length () <= 0;
|
2020-05-29 12:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
construct {
|
|
|
|
status_button.label = _("Reload");
|
|
|
|
bind_property ("state", states, "visible-child-name", BindingFlags.SYNC_CREATE);
|
|
|
|
scrolled.edge_reached.connect (pos => {
|
|
|
|
if (pos == PositionType.BOTTOM)
|
|
|
|
on_bottom_reached ();
|
|
|
|
});
|
|
|
|
content.remove.connect (() => on_content_changed ());
|
2020-06-02 09:35:29 +00:00
|
|
|
content_list.remove.connect (() => on_content_changed ());
|
2020-07-05 07:42:00 +00:00
|
|
|
content_list.row_activated.connect (on_content_item_activated);
|
2020-05-29 12:19:35 +00:00
|
|
|
|
|
|
|
notify["status-message"].connect (() => {
|
|
|
|
status_message_label.label = @"<span size='large'>$status_message</span>";
|
|
|
|
status_stack.visible_child_name = status_message == STATUS_LOADING ? "spinner" : "message";
|
|
|
|
});
|
|
|
|
|
2020-05-31 10:28:35 +00:00
|
|
|
notify["current"].connect (() => {
|
|
|
|
if (current)
|
|
|
|
on_shown ();
|
|
|
|
else
|
|
|
|
on_hidden ();
|
|
|
|
});
|
2020-06-02 09:35:29 +00:00
|
|
|
|
|
|
|
size_allocate.connect (on_resized);
|
|
|
|
get_style_context ().add_class (Dialogs.MainWindow.ZOOM_CLASS);
|
2020-05-29 12:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void clear (){
|
2020-07-10 14:22:38 +00:00
|
|
|
content_list.forall (w => {
|
|
|
|
w.destroy ();
|
2020-05-29 12:19:35 +00:00
|
|
|
});
|
|
|
|
state = "status";
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void on_bottom_reached () {}
|
2020-05-31 10:28:35 +00:00
|
|
|
public virtual void on_shown () {}
|
|
|
|
public virtual void on_hidden () {}
|
2020-05-29 12:19:35 +00:00
|
|
|
|
|
|
|
public virtual void on_content_changed () {
|
|
|
|
if (empty) {
|
|
|
|
status_message = STATUS_EMPTY;
|
|
|
|
state = "status";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
state = "content";
|
|
|
|
}
|
|
|
|
check_resize ();
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void on_error (int32 code, string reason) {
|
|
|
|
status_message = reason;
|
|
|
|
status_button.visible = true;
|
|
|
|
status_button.sensitive = true;
|
|
|
|
state = "status";
|
|
|
|
}
|
|
|
|
|
2020-06-02 09:35:29 +00:00
|
|
|
protected void on_resized () {
|
|
|
|
Allocation alloc;
|
|
|
|
get_allocation (out alloc);
|
|
|
|
|
2020-07-06 16:55:13 +00:00
|
|
|
var target_w = clamp.maximum_size;
|
2020-06-02 09:35:29 +00:00
|
|
|
var view_w = alloc.width;
|
|
|
|
|
|
|
|
var ctx = view.get_style_context ();
|
|
|
|
if (view_w <= target_w && ctx.has_class ("padded"))
|
|
|
|
ctx.remove_class ("padded");
|
|
|
|
if (view_w > target_w && !ctx.has_class ("padded"))
|
|
|
|
ctx.add_class ("padded");
|
|
|
|
}
|
|
|
|
|
2020-07-05 07:42:00 +00:00
|
|
|
public virtual void on_content_item_activated (ListBoxRow row) {
|
|
|
|
Signal.emit_by_name (row, "open");
|
|
|
|
}
|
|
|
|
|
2020-05-29 12:19:35 +00:00
|
|
|
}
|