Commit b193419a authored by Alberts Muktupāvels's avatar Alberts Muktupāvels

panel: remove old main menu button

parent 71a0ad1d
......@@ -17,7 +17,6 @@ gsettings_SCHEMAS = \
org.gnome.gnome-panel.applet.initial-settings.gschema.xml \
org.gnome.gnome-panel.gschema.xml \
org.gnome.gnome-panel.launcher.gschema.xml \
org.gnome.gnome-panel.menu-button.gschema.xml \
org.gnome.gnome-panel.object.gschema.xml \
org.gnome.gnome-panel.toplevel.gschema.xml \
$(NULL)
......
<schemalist gettext-domain="gnome-panel">
<schema id="org.gnome.gnome-panel.menu-button">
<key name="tooltip" type="s">
<default>''</default>
<summary>Tooltip displayed for menu</summary>
<description>The text to display in a tooltip for this menu.</description>
</key>
<key name="custom-icon" type="s">
<default>''</default>
<summary>Icon used for button</summary>
<description>The location of the image file used as the icon for the object's button. If empty, the default icon for the menu will be used.</description>
</key>
<key name="menu-path" type="s">
<default>''</default>
<summary>Menu content path</summary>
<description>The path from which the menu contents is constructed. If empty, the menu will be the default applications menu.</description>
</key>
</schema>
</schemalist>
......@@ -37,7 +37,6 @@ panel_sources = \
panel-stock-icons.c \
panel-action-button.c \
panel-image-menu-item.c \
panel-menu-button.c \
panel-menu-items.c \
panel-recent.c \
panel-action-protocol.c \
......@@ -72,7 +71,6 @@ panel_headers = \
panel-stock-icons.h \
panel-action-button.h \
panel-image-menu-item.h \
panel-menu-button.h \
panel-menu-items.h \
panel-recent.h \
panel-action-protocol.h \
......
......@@ -26,7 +26,6 @@
#include "panel-action-button.h"
#include "panel-toplevel.h"
#include "panel-util.h"
#include "panel-menu-button.h"
#include "panel-layout.h"
#include "panel-lockdown.h"
#include "panel-schemas.h"
......@@ -50,10 +49,6 @@ panel_applet_set_dnd_enabled (AppletInfo *info,
gboolean dnd_enabled)
{
switch (info->type) {
case PANEL_OBJECT_MENU:
panel_menu_button_set_dnd_enabled (PANEL_MENU_BUTTON (info->widget),
dnd_enabled);
break;
case PANEL_OBJECT_LAUNCHER:
panel_launcher_set_dnd_enabled (info->data, dnd_enabled);
break;
......@@ -168,10 +163,6 @@ applet_callback_callback (GtkWidget *widget,
else if (!strcmp (menu->name, "properties"))
launcher_properties (menu->info->data);
break;
case PANEL_OBJECT_MENU:
panel_menu_button_invoke_menu (
PANEL_MENU_BUTTON (menu->info->widget), menu->name);
break;
case PANEL_OBJECT_ACTION:
panel_action_button_invoke_menu (
PANEL_ACTION_BUTTON (menu->info->widget), menu->name);
......
......@@ -37,7 +37,6 @@
#include "panel.h"
#include "panel-stock-icons.h"
#include "panel-action-button.h"
#include "panel-menu-button.h"
#include "panel-menu-items.h"
#include "panel-run-dialog.h"
#include "panel-lockdown.h"
......
......@@ -34,7 +34,6 @@
#include "panel-util.h"
#include "panel-force-quit.h"
#include "panel-run-dialog.h"
#include "panel-menu-button.h"
static Atom atom_gnome_panel_action = None;
static Atom atom_gnome_panel_action_main_menu = None;
......@@ -48,18 +47,10 @@ panel_action_protocol_main_menu (GdkScreen *screen,
GSList *panels;
PanelWidget *panel_widget;
GtkWidget *menu;
AppletInfo *info;
if (panel_applet_activate_main_menu (activate_time))
return;
info = panel_applet_get_by_type (PANEL_OBJECT_MENU, screen);
if (info && panel_menu_button_is_main_menu (PANEL_MENU_BUTTON (info->widget))) {
panel_menu_button_popup_menu (PANEL_MENU_BUTTON (info->widget),
1, activate_time);
return;
}
panels = panel_widget_get_panels ();
panel_widget = panels->data;
menu = create_main_menu (panel_widget);
......
......@@ -37,7 +37,6 @@
#include "panel-applet-frame.h"
#include "panel-action-button.h"
#include "panel-toplevel.h"
#include "panel-menu-button.h"
#include "panel-layout.h"
#include "panel-lockdown.h"
#include "panel-util.h"
......
......@@ -32,7 +32,6 @@ G_BEGIN_DECLS
#define PANEL_VERTICAL_MASK (PANEL_ORIENTATION_LEFT | PANEL_ORIENTATION_RIGHT)
typedef enum {
PANEL_OBJECT_MENU,
PANEL_OBJECT_LAUNCHER,
PANEL_OBJECT_APPLET,
PANEL_OBJECT_ACTION
......
/*
* panel-menu-button.c: panel menu button
*
* Copyright (C) 2003 Sun Microsystems, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Mark McLoughlin <mark@skynet.ie>
*/
#include <config.h>
#include "panel-menu-button.h"
#include <string.h>
#include <glib/gi18n.h>
#include <gmenu-tree.h>
#include <libpanel-util/panel-error.h>
#include <libpanel-util/panel-glib.h>
#include <libpanel-util/panel-launch.h>
#include "applet.h"
#include "panel-widget.h"
#include "panel-util.h"
#include "menu.h"
#include "panel-lockdown.h"
#include "panel-a11y.h"
#include "panel-layout.h"
#include "panel-icon-names.h"
#include "panel-schemas.h"
G_DEFINE_TYPE (PanelMenuButton, panel_menu_button, BUTTON_TYPE_WIDGET)
#define PANEL_MENU_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PANEL_TYPE_MENU_BUTTON, PanelMenuButtonPrivate))
enum {
PROP_0,
PROP_MENU_PATH,
PROP_CUSTOM_ICON,
PROP_TOOLTIP,
PROP_DND_ENABLED
};
typedef enum {
FIRST_MENU,
APPLICATIONS_MENU,
#define DEFAULT_MENU APPLICATIONS_MENU
GNOMECC_MENU,
LAST_MENU
} MenuPathRoot;
typedef struct {
MenuPathRoot root_id;
char *scheme;
char *filename;
} MenuPathRootItem;
static MenuPathRootItem root_items [] = {
{ APPLICATIONS_MENU, "applications", "gnome-applications.menu" },
{ GNOMECC_MENU, "gnomecc", "gnomecc.menu" }
};
struct _PanelMenuButtonPrivate {
PanelToplevel *toplevel;
GSettings *settings_instance;
GtkWidget *menu;
char *menu_path;
char *custom_icon;
char *tooltip;
MenuPathRoot path_root;
guint dnd_enabled : 1;
};
static void panel_menu_button_set_icon (PanelMenuButton *button);
static AtkObject *panel_menu_button_get_accessible (GtkWidget *widget);
static void
fix_application_menu_name (void)
{
static gboolean updated = FALSE;
if (!updated) {
root_items [0].filename = get_applications_menu ();
updated = TRUE;
}
}
static const char *
panel_menu_path_root_to_filename (MenuPathRoot path_root)
{
const char *retval;
int i;
fix_application_menu_name ();
retval = NULL;
for (i = 0; i < G_N_ELEMENTS (root_items); i++) {
if (root_items [i].root_id == path_root) {
retval = root_items [i].filename;
break;
}
}
return retval;
}
static const char *
panel_menu_filename_to_scheme (const char *filename)
{
const char *retval;
int i;
fix_application_menu_name ();
retval = NULL;
if (!filename)
return retval;
for (i = 0; i < G_N_ELEMENTS (root_items); i++) {
if (root_items [i].filename &&
!strncmp (filename, root_items [i].filename,
strlen (root_items [i].filename))) {
retval = root_items [i].scheme;
break;
}
}
return retval;
}
static MenuPathRoot
panel_menu_scheme_to_path_root (const char *scheme)
{
MenuPathRoot retval;
int i;
fix_application_menu_name ();
retval = LAST_MENU;
if (!scheme)
return retval;
for (i = 0; i < G_N_ELEMENTS (root_items); i++) {
if (root_items [i].scheme &&
!strncmp (scheme, root_items [i].scheme,
strlen (root_items [i].scheme))) {
retval = root_items [i].root_id;
break;
}
}
return retval;
}
static void
panel_menu_button_init (PanelMenuButton *button)
{
button->priv = PANEL_MENU_BUTTON_GET_PRIVATE (button);
button->priv->toplevel = NULL;
button->priv->settings_instance = NULL;
button->priv->menu_path = NULL;
button->priv->custom_icon = NULL;
button->priv->tooltip = NULL;
button->priv->path_root = LAST_MENU;
}
static void
panel_menu_button_finalize (GObject *object)
{
PanelMenuButton *button = PANEL_MENU_BUTTON (object);
if (button->priv->menu) {
/* detaching the menu will kill our reference */
gtk_menu_detach (GTK_MENU (button->priv->menu));
button->priv->menu = NULL;
}
if (button->priv->settings_instance)
g_object_unref (button->priv->settings_instance);
button->priv->settings_instance = NULL;
g_free (button->priv->menu_path);
button->priv->menu_path = NULL;
g_free (button->priv->custom_icon);
button->priv->custom_icon = NULL;
g_free (button->priv->tooltip);
button->priv->tooltip = NULL;
G_OBJECT_CLASS (panel_menu_button_parent_class)->finalize (object);
}
static void
panel_menu_button_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
PanelMenuButton *button;
g_return_if_fail (PANEL_IS_MENU_BUTTON (object));
button = PANEL_MENU_BUTTON (object);
switch (prop_id) {
case PROP_MENU_PATH:
g_value_set_string (value, button->priv->menu_path);
break;
case PROP_CUSTOM_ICON:
g_value_set_string (value, button->priv->custom_icon);
break;
case PROP_TOOLTIP:
g_value_set_string (value, button->priv->tooltip);
break;
case PROP_DND_ENABLED:
g_value_set_boolean (value, button->priv->dnd_enabled);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
panel_menu_button_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
PanelMenuButton *button;
g_return_if_fail (PANEL_IS_MENU_BUTTON (object));
button = PANEL_MENU_BUTTON (object);
switch (prop_id) {
case PROP_MENU_PATH:
panel_menu_button_set_menu_path (button, g_value_get_string (value));
break;
case PROP_CUSTOM_ICON:
panel_menu_button_set_custom_icon (button, g_value_get_string (value));
break;
case PROP_TOOLTIP:
panel_menu_button_set_tooltip (button, g_value_get_string (value));
break;
case PROP_DND_ENABLED:
panel_menu_button_set_dnd_enabled (button, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
panel_menu_button_parent_set (GtkWidget *widget,
GtkWidget *previous_parent)
{
PanelMenuButton *button = PANEL_MENU_BUTTON (widget);
GtkWidget *parent;
parent = gtk_widget_get_parent (widget);
g_return_if_fail (!parent || PANEL_IS_WIDGET (parent));
if (parent)
button->priv->toplevel = PANEL_WIDGET (parent)->toplevel;
else
button->priv->toplevel = NULL;
panel_menu_button_set_icon (button);
if (GTK_WIDGET_CLASS (panel_menu_button_parent_class)->parent_set)
GTK_WIDGET_CLASS (panel_menu_button_parent_class)->parent_set (widget, previous_parent);
}
static void
panel_menu_button_drag_data_get (GtkWidget *widget,
GdkDragContext *context,
GtkSelectionData *selection_data,
guint info,
guint time)
{
char *drag_data;
g_return_if_fail (PANEL_IS_MENU_BUTTON (widget));
drag_data = g_strdup_printf ("MENU:%d", panel_find_applet_index (widget));
gtk_selection_data_set (
selection_data, gtk_selection_data_get_target (selection_data),
8, (guchar *) drag_data, strlen (drag_data));
g_free (drag_data);
}
static void
panel_menu_button_menu_deactivated (PanelMenuButton *button)
{
panel_toplevel_pop_autohide_disabler (button->priv->toplevel);
gtk_widget_unset_state_flags (GTK_WIDGET (button),
GTK_STATE_FLAG_PRELIGHT);
}
static void
panel_menu_button_menu_detacher (PanelMenuButton *button)
{
/*
* just in case someone still owns a reference to the
* menu (the menu may be up or some such other nonsense)
*/
g_signal_handlers_disconnect_by_func (button->priv->menu,
G_CALLBACK (panel_menu_button_menu_deactivated),
button);
button->priv->menu = NULL;
}
static GtkWidget *
panel_menu_button_create_menu (PanelMenuButton *button)
{
PanelWidget *panel_widget;
if (button->priv->menu)
return button->priv->menu;
if (!button->priv->toplevel)
return NULL;
panel_widget = panel_toplevel_get_panel_widget (button->priv->toplevel);
if (!PANEL_GLIB_STR_EMPTY (button->priv->menu_path) &&
button->priv->path_root > FIRST_MENU &&
button->priv->path_root < LAST_MENU) {
const char *filename;
filename = panel_menu_path_root_to_filename (button->priv->path_root);
button->priv->menu = create_applications_menu (filename,
button->priv->menu_path);
} else
button->priv->menu = create_main_menu (panel_widget);
gtk_menu_attach_to_widget (GTK_MENU (button->priv->menu),
GTK_WIDGET (button),
(GtkMenuDetachFunc) panel_menu_button_menu_detacher);
g_signal_connect_swapped (button->priv->menu, "deactivate",
G_CALLBACK (panel_menu_button_menu_deactivated),
button);
return button->priv->menu;
}
void
panel_menu_button_popup_menu (PanelMenuButton *button,
guint n_button,
guint32 activate_time)
{
GdkScreen *screen;
g_return_if_fail (PANEL_IS_MENU_BUTTON (button));
panel_menu_button_create_menu (button);
panel_toplevel_push_autohide_disabler (button->priv->toplevel);
screen = gtk_window_get_screen (GTK_WINDOW (button->priv->toplevel));
gtk_menu_set_screen (GTK_MENU (button->priv->menu), screen);
gtk_menu_popup (GTK_MENU (button->priv->menu),
NULL,
NULL,
(GtkMenuPositionFunc) panel_applet_position_menu,
GTK_WIDGET (button),
n_button,
activate_time);
}
static void
panel_menu_button_pressed (GtkButton *gtk_button)
{
PanelMenuButton *button;
g_return_if_fail (PANEL_IS_MENU_BUTTON (gtk_button));
button = PANEL_MENU_BUTTON (gtk_button);
if (GTK_BUTTON_CLASS (panel_menu_button_parent_class)->pressed)
GTK_BUTTON_CLASS (panel_menu_button_parent_class)->pressed (gtk_button);
panel_menu_button_popup_menu (button, 0, gtk_get_current_event_time());
}
static void
panel_menu_button_clicked (GtkButton *gtk_button)
{
PanelMenuButton *button;
GdkEvent *event;
g_return_if_fail (PANEL_IS_MENU_BUTTON (gtk_button));
button = PANEL_MENU_BUTTON (gtk_button);
if (GTK_BUTTON_CLASS (panel_menu_button_parent_class)->clicked)
GTK_BUTTON_CLASS (panel_menu_button_parent_class)->clicked (gtk_button);
if ((event = gtk_get_current_event ())) {
panel_menu_button_popup_menu (button,
event->button.button,
event->button.time);
gdk_event_free (event);
} else {
panel_menu_button_popup_menu (button, 1, GDK_CURRENT_TIME);
}
}
static void
panel_menu_button_class_init (PanelMenuButtonClass *klass)
{
GObjectClass *gobject_class = (GObjectClass *) klass;
GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
GtkButtonClass *button_class = (GtkButtonClass *) klass;
gobject_class->finalize = panel_menu_button_finalize;
gobject_class->get_property = panel_menu_button_get_property;
gobject_class->set_property = panel_menu_button_set_property;
widget_class->parent_set = panel_menu_button_parent_set;
widget_class->drag_data_get = panel_menu_button_drag_data_get;
widget_class->get_accessible = panel_menu_button_get_accessible;
button_class->clicked = panel_menu_button_clicked;
button_class->pressed = panel_menu_button_pressed;
g_type_class_add_private (klass, sizeof (PanelMenuButtonPrivate));
g_object_class_install_property (
gobject_class,
PROP_MENU_PATH,
g_param_spec_string ("menu-path",
"Menu Path",
"The path from which to construct the menu",
NULL,
G_PARAM_READWRITE));
g_object_class_install_property (
gobject_class,
PROP_CUSTOM_ICON,
g_param_spec_string ("custom-icon",
"Custom Icon",
"The custom icon for the menu",
NULL,
G_PARAM_READWRITE));
g_object_class_install_property (
gobject_class,
PROP_TOOLTIP,
g_param_spec_string ("tooltip",
"Tooltip",
"Tooltip displayed for the menu",
NULL,
G_PARAM_READWRITE));
g_object_class_install_property (
gobject_class,
PROP_DND_ENABLED,
g_param_spec_boolean ("dnd-enabled",
"Drag and drop enabled",
"Whether or not drag and drop is enabled on the widget",
FALSE,
G_PARAM_READWRITE));
}
static void
panel_menu_button_settings_changed (GSettings *settings,
char *key,
PanelMenuButton *button)
{
char *value = NULL;
if (g_strcmp0 (key, PANEL_MENU_BUTTON_MENU_PATH_KEY) == 0) {
value = g_settings_get_string (settings, key);
panel_menu_button_set_menu_path (button, value);
} else if (g_strcmp0 (key, PANEL_MENU_BUTTON_CUSTOM_ICON_KEY) == 0) {
value = g_settings_get_string (settings, key);
panel_menu_button_set_custom_icon (button, value);
} else if (g_strcmp0 (key, PANEL_MENU_BUTTON_TOOLTIP_KEY) == 0) {
value = g_settings_get_string (settings, key);
panel_menu_button_set_tooltip (button, value);
}
g_free (value);
}
static void
panel_menu_button_load_helper (const char *menu_path,
const char *custom_icon,
const char *tooltip,
PanelWidget *panel,
const char *id,
GSettings *settings)
{
PanelMenuButton *button;
AppletInfo *info;
g_return_if_fail (panel != NULL);
button = g_object_new (PANEL_TYPE_MENU_BUTTON,
"menu-path", menu_path,
"custom-icon", custom_icon,
"tooltip", tooltip,
"has-arrow", TRUE,
NULL);
info = panel_applet_register (GTK_WIDGET (button),
panel,
PANEL_OBJECT_MENU, id,
settings,
NULL, NULL);
if (!info) {
gtk_widget_destroy (GTK_WIDGET (button));
return;
}
if (panel_is_program_in_path ("alacarte") ||
panel_is_program_in_path ("gmenu-simple-editor"))
panel_applet_add_callback (info, "edit",
_("_Edit Menus"),
panel_lockdown_get_not_panels_locked_down_s);
panel_widget_set_applet_expandable (panel, GTK_WIDGET (button), FALSE, TRUE);
panel_widget_set_applet_size_constrained (panel, GTK_WIDGET (button), TRUE);
button->priv->settings_instance = panel_layout_get_instance_settings (
settings,
PANEL_MENU_BUTTON_SCHEMA);
g_signal_connect (button->priv->settings_instance, "changed",
G_CALLBACK (panel_menu_button_settings_changed),
button);
}
static GIcon *
panel_menu_button_get_icon (PanelMenuButton *button)
{
GMenuTreeDirectory *directory;
GIcon *retval;
retval = NULL;
if (!PANEL_GLIB_STR_EMPTY (button->priv->custom_icon))
retval = g_themed_icon_new (button->priv->custom_icon);
if (!retval &&
!PANEL_GLIB_STR_EMPTY (button->priv->menu_path) &&
panel_menu_button_create_menu (button)) {
directory = g_object_get_data (G_OBJECT (button->priv->menu),
"panel-menu-tree-directory");
if (!directory) {
GMenuTree *tree;
if ((tree = g_object_get_data (G_OBJECT (button->priv->menu),
"panel-menu-tree"))) {
directory = gmenu_tree_get_directory_from_path (tree,
button->priv->menu_path);
g_object_set_data_full (G_OBJECT (button->priv->menu),
"panel-menu-tree-directory",
directory,
(GDestroyNotify) gmenu_tree_item_unref);
}
}
if (directory)
retval = g_object_ref (gmenu_tree_directory_get_icon (directory));
}
if (!retval)
retval = g_themed_icon_new (PANEL_ICON_MAIN_MENU);
return retval;
}
static void
panel_menu_button_set_icon (PanelMenuButton *button)
{
GIcon *gicon;
char *icon;