summaryrefslogtreecommitdiff
path: root/core/src/widget/stack.vala
blob: e9a2bd27a15cbc98aa7180d3f3983e581e2a7de9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class Astal.Stack : Gtk.Stack {
    /**
     * whether to implicity destroy previous children when setting them
     */
    public bool no_implicit_destroy { get; set; default = false; }

    public string shown {
        get { return visible_child_name; }
        set { visible_child_name = value; }
    }

    public List<weak Gtk.Widget> children {
        set { _set_children(value); }
        owned get { return get_children(); }
    }

    private void _set_children(List<weak Gtk.Widget> arr) {
        foreach(var child in get_children()) {
            if (no_implicit_destroy)
                remove(child);
            else if (arr.find(child).length() == 0)
                child.destroy();
        }

        var i = 0;
        foreach(var child in arr) {
            if (child.name != null) {
                add_named(child, child.name);
            } else {
                add_named(child, (++i).to_string());
            }
        }
    }
}