From 809760cd3b6c0b24a62336800367f81eb26fecdf Mon Sep 17 00:00:00 2001 From: William Hua Date: Thu, 27 Mar 2014 10:56:42 +1300 Subject: Export separate menus for desktop and greeter. --- lib/main.vala | 108 ++++++++++++++-------------------------------------------- 1 file changed, 25 insertions(+), 83 deletions(-) (limited to 'lib/main.vala') diff --git a/lib/main.vala b/lib/main.vala index f012ecb0..473c52d1 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -44,9 +44,8 @@ public class Indicator.Keyboard.Service : Object { private SimpleActionGroup? action_group; private SimpleAction? indicator_action; - private MenuModel? menu_model; - private Menu? sources_menu; - private IBusMenu? ibus_menu; + private IndicatorMenu? desktop_menu; + private IndicatorMenu? desktop_greeter_menu; private UnityGreeter? unity_greeter; private string? greeter_user; @@ -70,8 +69,12 @@ public class Indicator.Keyboard.Service : Object { } } - if (sources_menu != null) { - update_sources_menu (); + if (desktop_menu != null) { + get_desktop_menu ().set_sources (get_sources ()); + } + + if (desktop_greeter_menu != null) { + get_desktop_greeter_menu ().set_sources (get_sources ()); } if (indicator_action != null) { @@ -597,7 +600,7 @@ public class Indicator.Keyboard.Service : Object { } panel_timeout = Timeout.add (PROPERTIES_DELAY, () => { - update_ibus_menu (list); + get_desktop_menu ().set_properties (list); panel_timeout = 0; return false; }); @@ -605,7 +608,7 @@ public class Indicator.Keyboard.Service : Object { [DBus (visible = false)] private void handle_updated_property (IBus.Property property) { - get_ibus_menu ().update_property (property); + get_desktop_menu ().update_property (property); } [DBus (visible = false)] @@ -705,91 +708,28 @@ public class Indicator.Keyboard.Service : Object { } [DBus (visible = false)] - private void update_sources_menu () { - if (sources_menu != null) { - var menu = get_sources_menu (); - menu.remove_all (); - - var sources = get_sources (); - for (var i = 0; i < sources.length; i++) { - var item = new MenuItem (sources[i].name, "indicator.current"); - item.set_attribute (Menu.ATTRIBUTE_TARGET, "u", i); - - var icon = sources[i].icon; - if (icon != null) { - item.set_icon ((!) icon); - } - - menu.append_item (item); - } - } else { - get_sources_menu (); - } - } - - [DBus (visible = false)] - private Menu get_sources_menu () { - if (sources_menu == null) { - sources_menu = new Menu (); - update_sources_menu (); - } - - return (!) sources_menu; - } - - [DBus (visible = false)] - private void update_ibus_menu (IBus.PropList list) { - get_ibus_menu ().set_properties (list); - } - - [DBus (visible = false)] - private IBusMenu get_ibus_menu () { - if (ibus_menu == null) { - ibus_menu = new IBusMenu (get_action_group ()); - ((!) ibus_menu).activate.connect ((property, state) => { + public IndicatorMenu get_desktop_menu () { + if (desktop_menu == null) { + desktop_menu = new IndicatorMenu (get_action_group ()); + ((!) desktop_menu).set_sources (get_sources ()); + ((!) desktop_menu).activate.connect ((property, state) => { if (panel_service != null) { ((!) panel_service).property_activate (property.key, state); } }); } - return (!) ibus_menu; - } - - [DBus (visible = false)] - protected virtual MenuModel create_menu_model (MenuModel sources_menu, MenuModel ibus_menu) { - var menu = new Menu (); - - var submenu = new Menu (); - - submenu.append_section (null, sources_menu); - submenu.append_section (null, ibus_menu); - - if (!is_login_user ()) { - var section = new Menu (); - section.append (_ ("Character Map"), "indicator.map"); - section.append (_ ("Keyboard Layout Chart"), "indicator.chart"); - section.append (_ ("Text Entry Settings..."), "indicator.settings"); - submenu.append_section (null, section); - } - - var indicator = new MenuItem.submenu ("x", submenu); - indicator.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.root"); - indicator.set_attribute ("x-canonical-secondary-action", "s", "indicator.next"); - indicator.set_attribute ("x-canonical-scroll-action", "s", "indicator.scroll"); - indicator.set_detailed_action ("indicator.indicator"); - menu.append_item (indicator); - - return menu; + return (!) desktop_menu; } [DBus (visible = false)] - public MenuModel get_menu_model () { - if (menu_model == null) { - menu_model = create_menu_model (get_sources_menu (), get_ibus_menu ()); + public IndicatorMenu get_desktop_greeter_menu () { + if (desktop_greeter_menu == null) { + desktop_greeter_menu = new IndicatorMenu (get_action_group (), IndicatorMenu.Options.NONE); + ((!) desktop_greeter_menu).set_sources (get_sources ()); } - return (!) menu_model; + return (!) desktop_greeter_menu; } [DBus (visible = false)] @@ -807,7 +747,8 @@ public class Indicator.Keyboard.Service : Object { private void handle_changed_sources (string key) { sources = null; - update_sources_menu (); + get_desktop_menu ().set_sources (get_sources ()); + get_desktop_greeter_menu ().set_sources (get_sources ()); update_indicator_action (); update_login_layout (); } @@ -897,7 +838,8 @@ public class Indicator.Keyboard.Service : Object { private void handle_bus_acquired (DBusConnection connection, string name) { try { connection.export_action_group ("/com/canonical/indicator/keyboard", get_action_group ()); - connection.export_menu_model ("/com/canonical/indicator/keyboard/desktop", get_menu_model ()); + connection.export_menu_model ("/com/canonical/indicator/keyboard/desktop", get_desktop_menu ()); + connection.export_menu_model ("/com/canonical/indicator/keyboard/desktop_greeter", get_desktop_greeter_menu ()); } catch (Error error) { warning ("error: %s", error.message); } -- cgit v1.2.3