From f39f5ac3f95d34e178cb358c03da186b9080a273 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 14 Feb 2018 23:57:34 +0300 Subject: [PATCH] Enable compact mode and bold appname settings. Fixes #81 --- data/CMakeLists.txt | 3 +++ lib/CMakeLists.txt | 1 - lib/budgie-plugin-appmenu.vala | 21 ++++++++++++++-- lib/mate-plugin-appmenu.vala | 30 ++++++++++++++++++++-- lib/menu-widget.vala | 15 +++++------ lib/valapanel-plugin-appmenu.vala | 40 ++++++++++++++++++++++++++++++ lib/xfce4-plugin-appmenu.vala | 41 +++++++++++++++++++++++++++++-- 7 files changed, 137 insertions(+), 14 deletions(-) diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index c0d48b7e..078e887b 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -2,14 +2,17 @@ if (ENABLE_XFCE) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/appmenu.desktop DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/xfce4/panel/plugins) endif() if (ENABLE_MATE) + add_schema("org.valapanel.appmenu.gschema.xml") configure_file(${CMAKE_SOURCE_DIR}/data/appmenu-mate.desktop.plugin.in ${CMAKE_SOURCE_DIR}/data/appmenu-mate.desktop.in) configure_file(${CMAKE_SOURCE_DIR}/data/appmenu-mate.service.in ${CMAKE_BINARY_DIR}/data/appmenu-mate.serivce) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/appmenu-mate.serivce DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/dbus-1/services/ RENAME org.mate.panel.applet.AppmenuAppletFactory.service) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/appmenu-mate.desktop DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/mate-panel/applets/ RENAME org.vala-panel.appmenu.mate-panel-applet) endif() if (ENABLE_VALAPANEL) + add_schema("org.valapanel.appmenu.gschema.xml") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/appmenu.plugin DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/vala-panel/applets/) endif() if (ENABLE_BUDGIE) + add_schema("org.valapanel.appmenu.gschema.xml") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/appmenu-budgie.plugin DESTINATION ${CMAKE_INSTALL_LIBDIR}/budgie-desktop/plugins/budgie-vala-panel-appmenu-plugin) endif() diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f2ad374b..2d832ba4 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -29,7 +29,6 @@ OPTIONS --gresources=${CMAKE_CURRENT_SOURCE_DIR}/libappmenu.gresource.xml --thread ${WNCK_DEFINE} - ${BOLD_DEFINE} GENERATE_VAPI vala-panel-appmenu ) diff --git a/lib/budgie-plugin-appmenu.vala b/lib/budgie-plugin-appmenu.vala index f7dc0dc3..e97b7a0e 100644 --- a/lib/budgie-plugin-appmenu.vala +++ b/lib/budgie-plugin-appmenu.vala @@ -45,24 +45,41 @@ public class GlobalMenuApplet: Applet context.add_class("budgie-menubar"); } } - + public override Widget? get_settings_ui() + { + var dlg = new Gtk.Box(Gtk.Orientation.VERTICAL,0); + var entry = new CheckButton.with_label(_("Use Compact mode (all menus in application menu)")); + this.settings.bind(Key.COMPACT_MODE,entry,"active",SettingsBindFlags.DEFAULT); + dlg.pack_start(entry,false,false,2); + entry = new CheckButton.with_label(_("Use bold application name")); + this.settings.bind(Key.BOLD_APPLICATION_NAME,entry,"active",SettingsBindFlags.DEFAULT); + dlg.pack_start(entry,false,false,2); + dlg.show_all(); + return dlg; + } public override bool supports_settings() { - return false; + return true; } public GlobalMenuApplet (string uuid) { Object(uuid: uuid); + settings_schema = "org.valapanel.appmenu"; + settings_prefix = "/com/solus-project/budgie-panel/instance/appmenu"; + settings = get_applet_settings(uuid); var layout = new Appmenu.MenuWidget(); layout.add.connect_after((w)=>{ add_budgie_style(layout); }); + settings.bind(Key.COMPACT_MODE,layout,Key.COMPACT_MODE,SettingsBindFlags.DEFAULT); + settings.bind(Key.BOLD_APPLICATION_NAME,layout,Key.BOLD_APPLICATION_NAME,SettingsBindFlags.DEFAULT); this.add(layout); this.hexpand_set = true; this.vexpand_set = true; add_budgie_style(layout); show_all(); } + private GLib.Settings settings; } // End class [ModuleInit] diff --git a/lib/mate-plugin-appmenu.vala b/lib/mate-plugin-appmenu.vala index fa405266..cc8e7a84 100644 --- a/lib/mate-plugin-appmenu.vala +++ b/lib/mate-plugin-appmenu.vala @@ -24,12 +24,38 @@ private bool factory_callback(MatePanel.Applet applet, string iid) if (iid != "AppmenuApplet") { return false; } - applet.flags = MatePanel.AppletFlags.HAS_HANDLE | MatePanel.AppletFlags.EXPAND_MAJOR; - var layout = new Appmenu.MenuWidget(); + var settings = MatePanel.AppletSettings.@new(applet,"org.valapanel.appmenu"); + settings.bind(Key.COMPACT_MODE,layout,Key.COMPACT_MODE,SettingsBindFlags.DEFAULT); + settings.bind(Key.BOLD_APPLICATION_NAME,layout,Key.BOLD_APPLICATION_NAME,SettingsBindFlags.DEFAULT); applet.add(layout); applet.show_all(); + var action_group = new Gtk.ActionGroup ("AppmenuApplet Menu Actions"); + action_group.set_translation_domain (Config.GETTEXT_PACKAGE); + Gtk.Action a = new Gtk.Action("AppMenuAppletPreferences",N_("_Preferences"),null,Gtk.Stock.PREFERENCES); + a.activate.connect(()=> + { + var dlg = new Gtk.Dialog.with_buttons( _("Configure AppMenu"), layout.get_toplevel() as Window, + DialogFlags.DESTROY_WITH_PARENT, + _("_Close"), + ResponseType.CLOSE, + null ); + Gtk.Box dlg_vbox = dlg.get_content_area() as Gtk.Box; + var entry = new CheckButton.with_label(_("Use Compact mode (all menus in application menu")); + settings.bind(Key.COMPACT_MODE,entry,"active",SettingsBindFlags.DEFAULT); + dlg_vbox.pack_start(entry,false,false,2); + entry = new CheckButton.with_label(_("Use bold application name")); + settings.bind(Key.BOLD_APPLICATION_NAME,entry,"active",SettingsBindFlags.DEFAULT); + dlg_vbox.pack_start(entry,false,false,2); + dlg.show_all(); + dlg.present(); + dlg.response.connect(()=>{ + dlg.destroy(); + }); + }); + action_group.add_action (a); + applet.setup_menu("""""",action_group); return true; } diff --git a/lib/menu-widget.vala b/lib/menu-widget.vala index d62b7de7..16232b09 100644 --- a/lib/menu-widget.vala +++ b/lib/menu-widget.vala @@ -18,6 +18,12 @@ using GLib; +namespace Key +{ + public const string COMPACT_MODE = "compact-mode"; + public const string BOLD_APPLICATION_NAME = "bold-application-name"; +} + namespace Appmenu { [Compact] @@ -35,8 +41,8 @@ namespace Appmenu } public class MenuWidget: Gtk.Bin { - public bool compact_mode {get; set;} - public bool bold_application_name {get; set;} + public bool compact_mode {get; set; default = false;} + public bool bold_application_name {get; set; default = false;} private Gtk.Adjustment? scroll_adj = null; private Gtk.ScrolledWindow? scroller = null; private Gtk.CssProvider provider; @@ -51,11 +57,6 @@ namespace Appmenu unowned Gtk.StyleContext context = this.get_style_context(); context.add_class("-vala-panel-appmenu-core"); unowned Gtk.StyleContext mcontext = mwidget.get_style_context(); -#if BOLD - this.bold_application_name = true; -#else - this.bold_application_name = false; -#endif this.notify.connect(()=>{ this.restock(); }); diff --git a/lib/valapanel-plugin-appmenu.vala b/lib/valapanel-plugin-appmenu.vala index bfe1880f..5017ffbb 100644 --- a/lib/valapanel-plugin-appmenu.vala +++ b/lib/valapanel-plugin-appmenu.vala @@ -35,7 +35,12 @@ public class AppmenuApplet : AppletPlugin, Peas.ExtensionBase } } public class GlobalMenuApplet: Applet +#if NEW +#else + , AppletConfigurable +#endif { + unowned MenuWidget layout; #if NEW public GlobalMenuApplet (Toplevel top, GLib.Settings? settings, string number) #else @@ -44,15 +49,50 @@ public class GlobalMenuApplet: Applet { base(top,settings,number); #if NEW + (this.action_group.lookup_action(AppletAction.CONFIGURE) as SimpleAction).set_enabled(true); #else } public override void create() { #endif var layout = new Appmenu.MenuWidget(); + this.layout = layout; + settings.bind(Key.COMPACT_MODE,layout,Key.COMPACT_MODE,SettingsBindFlags.DEFAULT); + settings.bind(Key.BOLD_APPLICATION_NAME,layout,Key.BOLD_APPLICATION_NAME,SettingsBindFlags.DEFAULT); this.add(layout); show_all(); } +#if NEW + public override Widget get_settings_ui() + { + var dlg = new Gtk.Box(Gtk.Orientation.VERTICAL,0); + var entry = new CheckButton.with_label(_("Use Compact mode (all menus in application menu)")); + this.settings.bind(Key.COMPACT_MODE,entry,"active",SettingsBindFlags.DEFAULT); + dlg.pack_start(entry,false,false,2); + entry = new CheckButton.with_label(_("Use bold application name")); + this.settings.bind(Key.BOLD_APPLICATION_NAME,entry,"active",SettingsBindFlags.DEFAULT); + dlg.pack_start(entry,false,false,2); + dlg.show_all(); + return dlg; + } +#else + public Dialog get_config_dialog() + { + var dlg = new Gtk.Dialog.with_buttons( _("Configure AppMenu"), toplevel, DialogFlags.DESTROY_WITH_PARENT, + _("_Close"), + ResponseType.CLOSE, + null ); + Gtk.Box dlg_vbox = dlg.get_content_area() as Gtk.Box; + var entry = new CheckButton.with_label(_("Use Compact mode (all menus in application menu)")); + this.settings.bind(Key.COMPACT_MODE,entry,"active",SettingsBindFlags.DEFAULT); + dlg_vbox.pack_start(entry,false,false,2); + entry = new CheckButton.with_label(_("Use bold application name")); + this.settings.bind(Key.BOLD_APPLICATION_NAME,entry,"active",SettingsBindFlags.DEFAULT); + dlg_vbox.pack_start(entry,false,false,2); + dlg_vbox.show_all(); + return dlg; + } +#endif } // End class [ModuleInit] diff --git a/lib/xfce4-plugin-appmenu.vala b/lib/xfce4-plugin-appmenu.vala index f3ae4ba4..b5786807 100644 --- a/lib/xfce4-plugin-appmenu.vala +++ b/lib/xfce4-plugin-appmenu.vala @@ -17,6 +17,7 @@ */ using GLib; +using Gtk; using Appmenu; using Xfce; @@ -27,14 +28,50 @@ public class AppmenuPlugin : Xfce.PanelPlugin { GLib.Intl.bindtextdomain(Config.GETTEXT_PACKAGE,Config.LOCALE_DIR); GLib.Intl.bind_textdomain_codeset(Config.GETTEXT_PACKAGE,"UTF-8"); GLib.Intl.textdomain(Config.GETTEXT_PACKAGE); - widget = new MenuWidget(); + var layout = new MenuWidget(); + widget = layout; add(widget); add_action_widget(widget); this.width_request = -1; + try{ + Xfconf.init(); + channel = this.get_channel(); + Xfconf.Property.bind(channel,this.get_property_base()+"/"+Key.COMPACT_MODE,typeof(bool),widget,Key.COMPACT_MODE); + Xfconf.Property.bind(channel,this.get_property_base()+"/"+Key.BOLD_APPLICATION_NAME,typeof(bool),widget,Key.BOLD_APPLICATION_NAME); + Xfconf.Property.bind(channel,this.get_property_base()+"/expand",typeof(bool),widget,"hexpand"); + this.menu_show_configure(); + } catch (Xfconf.Error e) { + stderr.printf("Xfconf init failed. Configuration will not be saved.\n"); + } + this.shrink = true; this.set_expand(true); widget.show_all(); } - private Gtk.Widget widget; + public override void configure_plugin() + { + var dlg = new Gtk.Dialog.with_buttons( _("Configure AppMenu"), this.get_toplevel() as Window, + DialogFlags.DESTROY_WITH_PARENT, + _("_Close"), + ResponseType.CLOSE, + null ); + Gtk.Box dlg_vbox = dlg.get_content_area() as Gtk.Box; + var entry = new CheckButton.with_label(_("Use Compact mode (all menus in application menu")); + entry.bind_property("active",widget,Key.COMPACT_MODE,BindingFlags.SYNC_CREATE); + dlg_vbox.pack_start(entry,false,false,2); + entry = new CheckButton.with_label(_("Use bold application name")); + entry.bind_property("active",widget,Key.BOLD_APPLICATION_NAME,BindingFlags.SYNC_CREATE); + dlg_vbox.pack_start(entry,false,false,2); + entry = new CheckButton.with_label(_("Expand plugin on panel")); + entry.bind_property("active",widget,"hexpand",BindingFlags.SYNC_CREATE); + dlg_vbox.pack_start(entry,false,false,2); + dlg.show_all(); + dlg.present(); + dlg.unmap.connect(()=>{ + dlg.destroy(); + }); + } + private Xfconf.Channel channel; + private unowned MenuWidget widget; } [ModuleInit]