aboutsummaryrefslogtreecommitdiff
path: root/main/src/windows/preferences_window/tweaks_preferences_page.vala
blob: 906ca1ae26a11008f0ec8e1d1144577fa85a1637 (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
using Gtk;

public class Dino.Ui.ViewModel.TweaksPreferencesPage : Object {
    public int avatar_roundness { get; set; }
    public string custom_css { get; set; default = ""; }
}

[GtkTemplate (ui = "/im/dino/Dino/preferences_window/tweaks_preferences_page.ui")]
public class Dino.Ui.TweaksPreferencesPage : Adw.PreferencesPage {
    [GtkChild] private unowned Adw.SpinRow avatar_roundness_row;
    [GtkChild] private unowned Gtk.TextBuffer custom_css_buffer;

    public ViewModel.TweaksPreferencesPage model { get; set; default = new ViewModel.TweaksPreferencesPage(); }
    private Binding[] model_bindings = new Binding[0];

    construct {
        this.notify["model"].connect(on_model_changed);
    }

    private void on_model_changed() {
        foreach (Binding binding in model_bindings) {
            binding.unbind();
        }
        if (model != null) {
            model_bindings = new Binding[] {
                model.bind_property("avatar-roundness", avatar_roundness_row, "value", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL),
                model.bind_property("custom-css", custom_css_buffer, "text", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL)
            };
        } else {
            model_bindings = new Binding[0];
        }
    }
}