18
18
public class AyatanaCompatibility.Indicator : Wingpanel.Indicator {
19
19
private IndicatorButton icon;
21
private Gtk.Stack main_stack;
21
22
private Gtk.Grid main_grid;
23
24
private unowned IndicatorAyatana.ObjectEntry entry;
26
27
private string entry_name_hint;
28
29
private Gee.HashMap<Gtk.Widget,Gtk.Widget> menu_map;
30
private Gee.HashMap<Gtk.Widget,Gtk.Widget> submenu_map;
30
32
const int MAX_ICON_SIZE = 24;
37
39
this.indicator = indicator;
38
40
this.parent_object = obj;
39
41
this.menu_map = new Gee.HashMap<Gtk.Widget,Gtk.Widget> ();
42
this.submenu_map = new Gee.HashMap<Gtk.Widget,Gtk.Widget> ();
41
44
unowned string name_hint = entry.name_hint;
42
45
if (name_hint == null)
114
117
int position = 0;
115
118
public override Gtk.Widget? get_widget () {
116
if (main_grid == null) {
119
if (main_stack == null) {
120
main_stack = new Gtk.Stack ();
117
121
main_grid = new Gtk.Grid ();
122
main_stack.add (main_grid);
119
124
foreach (var item in entry.menu.get_children ()) {
120
125
on_menu_widget_insert (item);
169
174
// all other items are genericmenuitems
170
175
string label = (item as Gtk.MenuItem).get_label ();
171
if (label.has_prefix ("_")) {
172
label = label.substring (1);
176
label = label.replace ("_", "");
178
// get item type from atk accessibility
179
// 34 = MENU_ITEM 8 = CHECKBOX 32 = SUBMENU 44 = RADIO
180
var atk = item.get_accessible ();
181
Value val = Value (typeof (int));
182
atk.get_property ("accessible_role",ref val);
183
var item_type = val.get_int ();
175
185
var sensitive = item.get_sensitive ();
176
186
var active = (item as Gtk.CheckMenuItem).get_active ();
185
195
image = check_for_image ((child as Gtk.Container));
188
// TODO detect if a item should show a checkbox
189
// Workaround show switch when active is true to indicate that it is on
198
if (item_type == 8) {
191
199
var button = new Wingpanel.Widgets.IndicatorSwitch (label, active);
192
200
button.get_switch ().state_set.connect ((b) => {
193
201
(item as Gtk.CheckMenuItem).set_active (b);
199
207
// convert menuitem to a indicatorbutton
200
208
if (item is Gtk.MenuItem) {
201
Wingpanel.Widgets.IndicatorButton button;
210
if (image != null && image.pixbuf == null && image.icon_name != null) {
212
Gtk.IconTheme icon_theme = Gtk.IconTheme.get_default ();
213
image.pixbuf = icon_theme.load_icon (image.icon_name, 16, 0);
202
218
if (image != null && image.pixbuf != null) {
203
219
button = new Wingpanel.Widgets.IndicatorButton.with_image (label, image.pixbuf);
207
223
button.set_sensitive (sensitive);
209
var submenu = (item as Gtk.MenuItem).get_submenu ();
225
var submenu = (item as Gtk.MenuItem).submenu;
210
226
if (submenu != null) {
212
// TODO allow submenu entries
227
// TODO make this better
230
// var sub_stack = new Gtk.Grid ();
231
// var w = new Wingpanel.Widgets.IndicatorButton ("Back");
232
// w.clicked.connect (() => {
233
// main_stack.set_visible_child (main_grid);
235
// sub_stack.attach (w, 0, pos++, 1, 1);
236
// sub_stack.attach (new Wingpanel.Widgets.IndicatorSeparator (), 0, pos++, 1, 1);
237
// var par = submenu.parent;
238
// new Gtk.OffscreenWindow ()
239
// submenu.reparent ();
240
// (item as Gtk.MenuItem).activate_item ();
241
// submenu = (item as Gtk.MenuItem).submenu;
242
// foreach (var sub_item in submenu.get_children ()) {
244
// if (sub_item is Gtk.SeparatorMenuItem) {
245
// var ww = new Wingpanel.Widgets.IndicatorSeparator ();
246
// sub_stack.attach (ww, 0, pos++, 1, 1);
248
// string label2 = (item as Gtk.MenuItem).get_label ();
249
// label2 = label2.replace ("_", "");
250
// var ww = new Wingpanel.Widgets.IndicatorButton (label2);
251
// sub_stack.attach (ww, 0, pos++, 1, 1);
254
// submenu.destroy ();
255
// main_stack.add (sub_stack);
256
// submenu_map.set (button, sub_stack);
257
button = new SubMenuButton (label);
258
button.clicked.connect (() => {
259
warning ("Not supported yet");
260
// main_stack.set_visible_child (submenu_map.get (button));
261
// main_stack.show_all ();
263
// (item as Gtk.MenuItem).activate_item ();
215
266
button.clicked.connect (() => {