Updating branch refs/heads/master to e9ed7f813e3b620676b656e617e32a9627ae247b (commit) from bcbf1b1ad560f6e4b90bbfe5be7e53fefc15db6e (commit)
commit e9ed7f813e3b620676b656e617e32a9627ae247b Author: Nick Schermer <n...@xfce.org> Date: Fri Nov 26 20:32:49 2010 +0100 Improve support for a menu editor in the applications menu. Add support for alacarte in the applications menu by supporting the applications.menu file and adding an "Edit Menu" button when alacarte is installed. Technically this is a new feature, but this is broken since 4.6 and I don't want it to be that worse in 4.8 since it is one of the most requested features in Xfce. .../applicationsmenu/applicationsmenu-dialog.glade | 67 +++++++-- plugins/applicationsmenu/applicationsmenu.c | 152 ++++++++++++++++---- 2 files changed, 177 insertions(+), 42 deletions(-) diff --git a/plugins/applicationsmenu/applicationsmenu-dialog.glade b/plugins/applicationsmenu/applicationsmenu-dialog.glade index e6f71ea..06f4379 100644 --- a/plugins/applicationsmenu/applicationsmenu-dialog.glade +++ b/plugins/applicationsmenu/applicationsmenu-dialog.glade @@ -195,8 +195,8 @@ <property name="orientation">vertical</property> <property name="spacing">6</property> <child> - <object class="GtkRadioButton" id="use-default-file"> - <property name="label" translatable="yes">Use _default menu file</property> + <object class="GtkRadioButton" id="use-xfce-menu"> + <property name="label" translatable="yes">Use the _Xfce menu</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">False</property> @@ -209,18 +209,55 @@ </packing> </child> <child> - <object class="GtkRadioButton" id="use-custom-file"> - <property name="label" translatable="yes">Use c_ustom menu file</property> + <object class="GtkHBox" id="hbox1"> + <property name="visible">True</property> + <property name="spacing">12</property> + <child> + <object class="GtkRadioButton" id="use-default-menu"> + <property name="label" translatable="yes">Use the _default menu</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="use_underline">True</property> + <property name="draw_indicator">True</property> + <property name="group">use-xfce-menu</property> + </object> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkButton" id="edit-menu-button"> + <property name="label" translatable="yes">Ed_it Menu</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="image">image1</property> + <property name="use_underline">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkRadioButton" id="use-custom-menu"> + <property name="label" translatable="yes">Use c_ustom menu file:</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">False</property> <property name="use_underline">True</property> <property name="active">True</property> <property name="draw_indicator">True</property> - <property name="group">use-default-file</property> + <property name="group">use-xfce-menu</property> </object> <packing> - <property name="position">1</property> + <property name="position">2</property> </packing> </child> <child> @@ -255,7 +292,7 @@ </child> </object> <packing> - <property name="position">2</property> + <property name="position">3</property> </packing> </child> </object> @@ -287,8 +324,8 @@ <property name="visible">True</property> <property name="layout_style">end</property> <child> - <object class="GtkButton" id="close-button"> - <property name="label">gtk-close</property> + <object class="GtkButton" id="help-button"> + <property name="label">gtk-help</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> @@ -298,11 +335,12 @@ <property name="expand">False</property> <property name="fill">False</property> <property name="position">0</property> + <property name="secondary">True</property> </packing> </child> <child> - <object class="GtkButton" id="help-button"> - <property name="label">gtk-help</property> + <object class="GtkButton" id="close-button"> + <property name="label">gtk-close</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> @@ -312,7 +350,6 @@ <property name="expand">False</property> <property name="fill">False</property> <property name="position">1</property> - <property name="secondary">True</property> </packing> </child> </object> @@ -325,9 +362,13 @@ </object> </child> <action-widgets> - <action-widget response="0">close-button</action-widget> <action-widget response="0">help-button</action-widget> + <action-widget response="0">close-button</action-widget> </action-widgets> </object> + <object class="GtkImage" id="image1"> + <property name="visible">True</property> + <property name="icon_name">alacarte</property> + </object> <object class="GtkSizeGroup" id="sizegroup1"/> </interface> diff --git a/plugins/applicationsmenu/applicationsmenu.c b/plugins/applicationsmenu/applicationsmenu.c index 902952a..3f8827d 100644 --- a/plugins/applicationsmenu/applicationsmenu.c +++ b/plugins/applicationsmenu/applicationsmenu.c @@ -38,7 +38,10 @@ #define DEFAULT_TITLE _("Applications Menu") #define DEFAULT_ICON_NAME "xfce4-panel-menu" #define DEFAULT_ICON_SIZE (16) -#define DEFAULT_MENU "menus" G_DIR_SEPARATOR_S "xfce-applications.menu" +#define DEFAULT_MENU "xfce-applications.menu" +#define APPLICATIONS_MENU "applications.menu" +#define CUSTOM_MENU "custom" + struct _ApplicationsMenuPluginClass @@ -62,7 +65,7 @@ struct _ApplicationsMenuPlugin guint show_button_title : 1; gchar *button_title; gchar *button_icon; - guint custom_menu : 1; + gchar *menu_file; gchar *custom_menu_file; /* temp item we store here when the @@ -79,7 +82,7 @@ enum PROP_SHOW_BUTTON_TITLE, PROP_BUTTON_TITLE, PROP_BUTTON_ICON, - PROP_CUSTOM_MENU, + PROP_MENU_FILE, PROP_CUSTOM_MENU_FILE }; @@ -182,10 +185,10 @@ applications_menu_plugin_class_init (ApplicationsMenuPluginClass *klass) EXO_PARAM_READWRITE)); g_object_class_install_property (gobject_class, - PROP_CUSTOM_MENU, - g_param_spec_boolean ("custom-menu", + PROP_MENU_FILE, + g_param_spec_string ("menu-file", NULL, NULL, - FALSE, + DEFAULT_MENU, EXO_PARAM_READWRITE)); g_object_class_install_property (gobject_class, @@ -209,6 +212,7 @@ applications_menu_plugin_init (ApplicationsMenuPlugin *plugin) { plugin->show_menu_icons = TRUE; plugin->show_button_title = TRUE; + plugin->menu_file = g_strdup (DEFAULT_MENU); garcon_set_environment ("XFCE"); @@ -272,8 +276,8 @@ applications_menu_plugin_get_property (GObject *object, DEFAULT_ICON_NAME : plugin->button_icon); break; - case PROP_CUSTOM_MENU: - g_value_set_boolean (value, plugin->custom_menu); + case PROP_MENU_FILE: + g_value_set_string (value, plugin->menu_file); break; case PROP_CUSTOM_MENU_FILE: @@ -336,8 +340,9 @@ applications_menu_plugin_set_property (GObject *object, exo_str_is_empty (plugin->button_icon) ? DEFAULT_ICON_NAME : plugin->button_icon); return; - case PROP_CUSTOM_MENU: - plugin->custom_menu = g_value_get_boolean (value); + case PROP_MENU_FILE: + g_free (plugin->menu_file); + plugin->menu_file = g_value_dup_string (value); break; case PROP_CUSTOM_MENU_FILE: @@ -367,7 +372,7 @@ applications_menu_plugin_construct (XfcePanelPlugin *panel_plugin) { "show-tooltips", G_TYPE_BOOLEAN }, { "button-title", G_TYPE_STRING }, { "button-icon", G_TYPE_STRING }, - { "custom-menu", G_TYPE_BOOLEAN }, + { "menu-file", G_TYPE_STRING }, { "custom-menu-file", G_TYPE_STRING }, { NULL } }; @@ -395,6 +400,7 @@ applications_menu_plugin_free_data (XfcePanelPlugin *panel_plugin) g_free (plugin->button_title); g_free (plugin->button_icon); g_free (plugin->custom_menu_file); + g_free (plugin->menu_file); } @@ -494,12 +500,59 @@ applications_menu_plugin_configure_plugin_icon_chooser (GtkWidget * static void +applications_menu_plugin_configure_plugin_edit (GtkWidget *button, + ApplicationsMenuPlugin *plugin) +{ + GError *error = NULL; + const gchar *command = "alacarte"; + + panel_return_if_fail (XFCE_IS_APPLICATIONS_MENU_PLUGIN (plugin)); + panel_return_if_fail (GTK_IS_WIDGET (button)); + + if (!gdk_spawn_command_line_on_screen (gtk_widget_get_screen (button), command, &error)) + { + xfce_dialog_show_error (NULL, error, _("Failed to execute command \"%s\"."), command); + g_error_free (error); + } +} + + + +static void +applications_menu_plugin_configure_plugin_menu_toggled (GtkWidget *button, + ApplicationsMenuPlugin *plugin) +{ + const gchar *name; + const gchar *file; + + panel_return_if_fail (XFCE_IS_APPLICATIONS_MENU_PLUGIN (plugin)); + panel_return_if_fail (GTK_IS_RADIO_BUTTON (button)); + + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) + { + name = gtk_buildable_get_name (GTK_BUILDABLE (button)); + + if (exo_str_is_equal (name, "use-custom-menu")) + file = CUSTOM_MENU; + else if (exo_str_is_equal (name, "use-default-menu")) + file = APPLICATIONS_MENU; + else + file = DEFAULT_MENU; + + g_object_set (G_OBJECT (plugin), "menu-file", file, NULL); + } +} + + + +static void applications_menu_plugin_configure_plugin (XfcePanelPlugin *panel_plugin) { ApplicationsMenuPlugin *plugin = XFCE_APPLICATIONS_MENU_PLUGIN (panel_plugin); GtkBuilder *builder; GObject *dialog, *object, *object2; guint i; + gchar *path; const gchar *check_names[] = { "show-generic-names", "show-menu-icons", "show-tooltips", "show-button-title" }; @@ -535,10 +588,44 @@ applications_menu_plugin_configure_plugin (XfcePanelPlugin *panel_plugin) g_object_add_weak_pointer (G_OBJECT (plugin->dialog_icon), (gpointer) &plugin->dialog_icon); gtk_widget_show (plugin->dialog_icon); - object = gtk_builder_get_object (builder, "use-custom-file"); + object = gtk_builder_get_object (builder, "use-xfce-menu"); + panel_return_if_fail (GTK_IS_RADIO_BUTTON (object)); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (object), + exo_str_is_equal (plugin->menu_file, DEFAULT_MENU)); + g_signal_connect (G_OBJECT (object), "toggled", + G_CALLBACK (applications_menu_plugin_configure_plugin_menu_toggled), plugin); + + object = gtk_builder_get_object (builder, "use-default-menu"); + panel_return_if_fail (GTK_IS_RADIO_BUTTON (object)); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (object), + exo_str_is_equal (plugin->menu_file, APPLICATIONS_MENU)); + g_signal_connect (G_OBJECT (object), "toggled", + G_CALLBACK (applications_menu_plugin_configure_plugin_menu_toggled), plugin); + + /* whether we show the edit menu button */ + object2 = gtk_builder_get_object (builder, "edit-menu-button"); + panel_return_if_fail (GTK_IS_BUTTON (object2)); + path = g_find_program_in_path ("alacarte"); + if (path != NULL) + { + exo_binding_new (G_OBJECT (object), "active", G_OBJECT (object2), "sensitive"); + g_signal_connect (G_OBJECT (object2), "clicked", + G_CALLBACK (applications_menu_plugin_configure_plugin_edit), plugin); + } + else + { + gtk_widget_hide (GTK_WIDGET (object2)); + } + g_free (path); + + object = gtk_builder_get_object (builder, "use-custom-menu"); panel_return_if_fail (GTK_IS_RADIO_BUTTON (object)); - exo_mutual_binding_new (G_OBJECT (plugin), "custom-menu", - G_OBJECT (object), "active"); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (object), + exo_str_is_equal (plugin->menu_file, CUSTOM_MENU)); + g_signal_connect (G_OBJECT (object), "toggled", + G_CALLBACK (applications_menu_plugin_configure_plugin_menu_toggled), plugin); + + /* sensitivity of custom file selector */ object2 = gtk_builder_get_object (builder, "custom-box"); panel_return_if_fail (GTK_IS_WIDGET (object2)); exo_binding_new (G_OBJECT (object), "active", G_OBJECT (object2), "sensitive"); @@ -928,6 +1015,7 @@ applications_menu_plugin_menu (GtkWidget *button, GError *error = NULL; gchar *filename; GFile *file; + gchar *path; panel_return_if_fail (XFCE_IS_APPLICATIONS_MENU_PLUGIN (plugin)); panel_return_if_fail (button == NULL || plugin->button == button); @@ -938,23 +1026,29 @@ applications_menu_plugin_menu (GtkWidget *button, if (plugin->menu == NULL) { - if (G_UNLIKELY (plugin->custom_menu - && plugin->custom_menu_file != NULL)) + if (G_LIKELY (!exo_str_is_empty (plugin->menu_file))) { - menu = garcon_menu_new_for_path (plugin->custom_menu_file); + if (G_UNLIKELY (strcmp (plugin->menu_file, CUSTOM_MENU) == 0 + && plugin->custom_menu_file != NULL)) + { + menu = garcon_menu_new_for_path (plugin->custom_menu_file); + } + else if (g_str_has_suffix (plugin->menu_file, ".menu")) + { + /* lookup the menu by file */ + filename = g_build_filename ("menus", plugin->menu_file, NULL); + path = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, filename); + g_free (filename); + + if (G_LIKELY (path != NULL)) + menu = garcon_menu_new_for_path (path); + g_free (path); + } } - else - { - /* lookup the xfce-applications.menu file */ - filename = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, DEFAULT_MENU); - if (G_LIKELY (filename != NULL)) - menu = garcon_menu_new_for_path (filename); - g_free (filename); - /* fallback to the default menu */ - if (G_UNLIKELY (menu == NULL)) - menu = garcon_menu_new_applications (); - } + /* fallback to the default menu */ + if (G_UNLIKELY (menu == NULL)) + menu = garcon_menu_new_applications (); if (menu != NULL && garcon_menu_load (menu, NULL, &error)) _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits