-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
167 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2021 elementary, Inc. (https://elementary.io) | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
*/ | ||
|
||
public class Access.Choice : Gtk.Box { | ||
public Variant? options { get; construct; } | ||
public string label { get; set; } | ||
public string selected { get; set; } | ||
|
||
public Choice.from_variant (Variant variant) requires ( | ||
variant.is_of_type (new VariantType ("(ssa(ss)s)")) | ||
) { | ||
string id, label, selected; | ||
Variant? options; | ||
|
||
variant.get ("(ss@a(ss)s)", out id, out label, out options, out selected); | ||
|
||
Object (name: id, label: label, options: options, selected: selected); | ||
} | ||
|
||
construct { | ||
orientation = Gtk.Orientation.VERTICAL; | ||
halign = Gtk.Align.START; | ||
spacing = 6; | ||
|
||
var label = new Gtk.Label (label); | ||
bind_property ("label", label, "label", BindingFlags.DEFAULT); | ||
add (label); | ||
|
||
if (options.n_children () == 0) { | ||
var check = new Gtk.CheckButton (); | ||
bind_property ( | ||
"selected", check, "active", BindingFlags.BIDIRECTIONAL, | ||
(b, s, ref t) => { | ||
t.set_boolean (bool.parse ((string) s)); | ||
return true; | ||
}, | ||
(b, s, ref t) => { | ||
t.set_string (((bool) s).to_string ()); | ||
return true; | ||
} | ||
); | ||
|
||
add (check); | ||
} else { | ||
var combo = new Gtk.ComboBoxText (); | ||
var iter = options.iterator (); | ||
string key, val; | ||
|
||
while (iter.next ("(ss)", out key, out val)) { | ||
combo.append (key, val); | ||
} | ||
|
||
bind_property ("selected", combo, "active-id", BindingFlags.BIDIRECTIONAL); | ||
add (combo); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters