~parnold-x/wingpanel-indicator-ayatana/restrict_loading

« back to all changes in this revision

Viewing changes to src/AyatanaIndicator.vala

  • Committer: Djax
  • Date: 2015-06-04 19:25:51 UTC
  • Revision ID: parnold@gmx.de-20150604192551-9ph1l0f2xygntmuz
detect all types right, show all icons with better margins

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
public class AyatanaCompatibility.Indicator : Wingpanel.Indicator {
19
19
        private IndicatorButton icon;
20
20
 
 
21
        private Gtk.Stack main_stack;
21
22
        private Gtk.Grid main_grid;
22
23
 
23
24
        private unowned IndicatorAyatana.ObjectEntry entry;
26
27
        private string entry_name_hint;
27
28
 
28
29
        private Gee.HashMap<Gtk.Widget,Gtk.Widget> menu_map;
 
30
        private Gee.HashMap<Gtk.Widget,Gtk.Widget> submenu_map;
29
31
 
30
32
        const int MAX_ICON_SIZE = 24;
31
33
 
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> ();
40
43
 
41
44
                unowned string name_hint = entry.name_hint;
42
45
                if (name_hint == null)
56
59
                // trigger entry-removed after entry-added, which means that the previous
57
60
                // parent is still in the panel when the new one is added.
58
61
                if (entry.menu.get_attach_widget () != null)
59
 
                    entry.menu.detach ();
 
62
                        entry.menu.detach ();
60
63
 
61
64
                this.visible = true;
62
65
        }
113
116
 
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);
118
123
 
119
124
                        foreach (var item in entry.menu.get_children ()) {
120
125
                                on_menu_widget_insert (item);
124
129
                        entry.menu.remove.connect (on_menu_widget_remove);
125
130
                }
126
131
 
127
 
                return main_grid;
 
132
                return main_stack;
128
133
        }
129
134
 
130
135
        private void on_menu_widget_insert (Gtk.Widget item) {
168
173
 
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);
173
 
                }
 
176
                label = label.replace ("_", "");
 
177
 
 
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 ();
174
184
 
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));
186
196
                        }
187
197
                }
188
 
                // TODO detect if a item should show a checkbox
189
 
                // Workaround show switch when active is true to indicate that it is on
190
 
                if (active) {
 
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);
198
206
                }
199
207
                // convert menuitem to a indicatorbutton
200
208
                if (item is Gtk.MenuItem) {
201
 
                        Wingpanel.Widgets.IndicatorButton button;
 
209
                        Gtk.Button button;
 
210
                        if (image != null && image.pixbuf == null && image.icon_name != null) {
 
211
                                try {
 
212
                                        Gtk.IconTheme icon_theme = Gtk.IconTheme.get_default ();
 
213
                                        image.pixbuf = icon_theme.load_icon (image.icon_name, 16, 0);
 
214
                                } catch (Error e) {
 
215
                                        warning (e.message);
 
216
                                }
 
217
                        }
202
218
                        if (image != null && image.pixbuf != null) {
203
219
                                button = new Wingpanel.Widgets.IndicatorButton.with_image (label, image.pixbuf);
204
220
                        } else {
206
222
                        }
207
223
                        button.set_sensitive (sensitive);
208
224
                        if (sensitive) {
209
 
                                var submenu = (item as Gtk.MenuItem).get_submenu ();
 
225
                                var submenu = (item as Gtk.MenuItem).submenu;
210
226
                                if (submenu != null) {
211
 
                                        // submenu
212
 
                                        // TODO allow submenu entries
213
 
                                        return null;
 
227
                                        // TODO make this better
 
228
 
 
229
                                        // int pos = 0;
 
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);
 
234
                                        // });
 
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 ()) {
 
243
                                        //      print ("a");
 
244
                                        //      if (sub_item is Gtk.SeparatorMenuItem) {
 
245
                                        //              var ww = new Wingpanel.Widgets.IndicatorSeparator ();
 
246
                                        //              sub_stack.attach (ww, 0, pos++, 1, 1);
 
247
                                        //      } else {
 
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);
 
252
                                        //      }
 
253
                                        // }
 
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 ();
 
262
                                                // close ();
 
263
                                                // (item as Gtk.MenuItem).activate_item ();
 
264
                                        });
214
265
                                } else {
215
266
                                        button.clicked.connect (() => {
216
267
                                                close ();