2020-05-29 14:19:35 +02: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 12:28:35 +02: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 14:19:35 +02:00
|
|
|
|
|
|
|
[GtkChild]
|
|
|
|
protected ScrolledWindow scrolled;
|
|
|
|
[GtkChild]
|
|
|
|
protected Box view;
|
|
|
|
[GtkChild]
|
2020-06-02 11:35:29 +02:00
|
|
|
protected Hdy.Column column;
|
|
|
|
[GtkChild]
|
|
|
|
protected Box column_view;
|
|
|
|
[GtkChild]
|
2020-05-29 14:19:35 +02:00
|
|
|
protected Stack states;
|
|
|
|
[GtkChild]
|
|
|
|
protected Box content;
|
|
|
|
[GtkChild]
|
2020-06-02 11:35:29 +02:00
|
|
|
protected ListBox content_list;
|
|
|
|
[GtkChild]
|
2020-05-29 14:19:35 +02:00
|
|
|
protected Button status_button;
|
|
|
|
[GtkChild]
|
2020-05-31 12:28:35 +02:00
|
|
|
Stack status_stack;
|
|
|
|
[GtkChild]
|
|
|
|
Label status_message_label;
|
2020-05-29 14:19:35 +02:00
|
|
|
|
|
|
|
public string state { get; set; default = "status"; }
|
|
|
|
public string status_message { get; set; default = STATUS_EMPTY; }
|
|
|
|
public bool allow_closing { get; set; default = true; }
|
|
|
|
|
|
|
|
public bool empty {
|
|
|
|
get {
|
2020-06-02 11:35:29 +02:00
|
|
|
return content_list.get_children ().length () <= 0;
|
2020-05-29 14:19:35 +02: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 11:35:29 +02:00
|
|
|
content_list.remove.connect (() => on_content_changed ());
|
2020-05-29 14:19:35 +02: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 12:28:35 +02:00
|
|
|
notify["current"].connect (() => {
|
|
|
|
if (current)
|
|
|
|
on_shown ();
|
|
|
|
else
|
|
|
|
on_hidden ();
|
|
|
|
});
|
2020-06-02 11:35:29 +02:00
|
|
|
|
|
|
|
size_allocate.connect (on_resized);
|
|
|
|
get_style_context ().add_class (Dialogs.MainWindow.ZOOM_CLASS);
|
2020-05-29 14:19:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void clear (){
|
2020-06-02 11:35:29 +02:00
|
|
|
content_list.forall (widget => {
|
2020-05-29 14:19:35 +02:00
|
|
|
widget.destroy ();
|
|
|
|
});
|
|
|
|
state = "status";
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void on_bottom_reached () {}
|
2020-05-31 12:28:35 +02:00
|
|
|
public virtual void on_shown () {}
|
|
|
|
public virtual void on_hidden () {}
|
2020-05-29 14:19:35 +02: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 11:35:29 +02:00
|
|
|
protected void on_resized () {
|
|
|
|
Allocation alloc;
|
|
|
|
get_allocation (out alloc);
|
|
|
|
|
|
|
|
var target_w = column.maximum_width;
|
|
|
|
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-05-29 14:19:35 +02:00
|
|
|
}
|