blob: 6b578d44bc05bdf1946087299fac9b8627befd04 (
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
using GLib;
namespace Caribou {
public class GroupModel : Object, IKeyboardObject {
public string active_level { get; private set; }
public string group;
public string variant;
private string default_level;
private Gee.HashMap<string, LevelModel> levels;
public GroupModel (string group, string variant) {
this.group = group;
this.variant = variant;
levels = new Gee.HashMap<string, LevelModel> (str_hash, str_equal);
active_level = default_level;
}
public static string create_group_name (string group, string variant) {
if (variant != "")
return @"$(group)_$(variant)";
else
return group;
}
internal void add_level (string lname, LevelModel level) {
levels.set (lname, level);
level.level_toggled.connect (on_level_toggled);
level.key_activated.connect ((k) => { key_activated (k); });
if (level.mode == "default") {
default_level = lname;
active_level = lname;
}
}
public string[] get_levels () {
return (string[]) levels.keys.to_array ();
}
public LevelModel get_level (string level_name) {
return levels.get (level_name);
}
private void on_level_toggled (string new_level) {
if (new_level == "default")
active_level = default_level;
else
active_level = new_level;
}
public IKeyboardObject[] get_children () {
return (IKeyboardObject[]) levels.values.to_array ();
}
}
}
|