.
1 /*
2 Copyright (C) 2014 Johan Mattsson
3
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 3 of the
7 License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13 */
14
15 namespace BirdFont {
16
17 public class MenuItem : GLib.Object {
18
19 public signal void action ();
20 public Text label;
21 public string identifier;
22
23 public double y;
24
25 // key bindings
26 public uint modifiers = NONE;
27 public unichar key = '\0';
28
29 public Gee.ArrayList<string> displays = new Gee.ArrayList<string> ();
30
31 public MenuItem (string label, string identifier = "") {
32 this.label = new Text ();
33 this.label.set_text (label);
34 this.identifier = identifier;
35 y = 0;
36 }
37
38 public void add_display (string d) {
39 displays.add (d);
40 }
41
42 /** @return true if a key binding can be used in @param display. */
43 public bool in_display (string display) {
44 if (displays.size == 0) {
45 return true;
46 }
47
48 foreach (string d in displays) {
49 if (d == display) {
50 return true;
51 }
52 }
53
54 return false;
55 }
56
57 public string get_key_bindings () {
58 string key_binding = "";
59
60 if (key != '\0') {
61 key_binding += "(";
62
63 if ((modifiers & CTRL) > 0) {
64 key_binding += "Ctrl+";
65 }
66
67 if ((modifiers & ALT) > 0) {
68 key_binding += "Alt+";
69 }
70
71 if ((modifiers & LOGO) > 0) {
72 key_binding += "Command+";
73
74 }
75
76 if ((modifiers & SHIFT) > 0) {
77 key_binding += "Shift+";
78 }
79
80 switch (key) {
81 case Key.UP:
82 key_binding += t_("UP");
83 break;
84 case Key.DOWN:
85 key_binding += t_("DOWN");
86 break;
87 case Key.LEFT:
88 key_binding += t_("LEFT");
89 break;
90 case Key.RIGHT:
91 key_binding += t_("RIGHT");
92 break;
93 default:
94 key_binding += (!) key.to_string ();
95 break;
96 }
97
98 key_binding += ")";
99 }
100
101 return key_binding;
102 }
103 }
104
105 }
106