diff --git a/ChangeLog b/ChangeLog index 5c6c97649f3a73cbc2e609522419e7108be3b13b..b205410d4d10b9f3ecca05aa10151db1ed93e58f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,20 @@ +2008-01-02 Jannis Pohlmann <jannis@xfce.org> + + * libxfce4menu/xfce-menu-item.{c,h}: Add support for the Comment field + via xfce_menu_item_get_comment(). + +2007-12-29 Jannis Pohlmann <jannis@xfce.org> + + * libxfce4menu/xfce-menu-monitor.{c,h}: Add support for defining what + kind of files/directories are monitored (XfceMenuMonitorFlags, + xfce_menu_monitor_set_flags(), xfce_menu_monitor_get_flags(), + xfce_menu_monitor_has_flags()). + * libxfce4menu/xfce-menu.c: Check monitor flags before adding + files/directories to the monitoring system. + * tests/test-display-menu.c: Center window on screen. + 2007-12-27 Jannis Pohlmann <jannis@xfce.org> + * libxfce4menu/xfce-menu-monitor.c: Use the KEY, not the VALUE pointer to remove items from the shared handle hash table. In this case, use the directory string instead of the shared handle. This should fix diff --git a/libxfce4menu/xfce-menu-item.c b/libxfce4menu/xfce-menu-item.c index ddd26ef5c262a2f081d923183e5e97060c0edc93..e95fa6ec30a8ba675e5e324b2f0f2b2306a05af7 100644 --- a/libxfce4menu/xfce-menu-item.c +++ b/libxfce4menu/xfce-menu-item.c @@ -47,6 +47,7 @@ enum PROP_STARTUP_NOTIFICATION, PROP_NAME, PROP_GENERIC_NAME, + PROP_COMMENT, PROP_ICON_NAME, PROP_COMMAND, PROP_TRY_EXEC, @@ -103,6 +104,9 @@ struct _XfceMenuItemPrivate /* Generic name of the menu item */ gchar *generic_name; + /* Comment/description of the item */ + gchar *comment; + /* Command to be executed when the menu item is clicked */ gchar *command; @@ -285,6 +289,20 @@ xfce_menu_item_class_init (XfceMenuItemClass *klass) NULL, G_PARAM_READWRITE)); + /** + * XfceMenuItem:comment: + * + * Comment/description for the application. To be displayed e.g. in tooltips of + * GtkMenuItems. + **/ + g_object_class_install_property (gobject_class, + PROP_COMMENT, + g_param_spec_string ("comment", + "Comment", + "Comment/description for the application", + NULL, + G_PARAM_READWRITE)); + /** * XfceMenuItem:command: * @@ -356,6 +374,7 @@ xfce_menu_item_init (XfceMenuItem *item) item->priv->desktop_id = NULL; item->priv->name = NULL; item->priv->generic_name = NULL; + item->priv->comment = NULL; item->priv->filename = NULL; item->priv->command = NULL; item->priv->try_exec = NULL; @@ -377,6 +396,7 @@ xfce_menu_item_finalize (GObject *object) g_free (item->priv->desktop_id); g_free (item->priv->name); g_free (item->priv->generic_name); + g_free (item->priv->comment); g_free (item->priv->filename); g_free (item->priv->command); g_free (item->priv->try_exec); @@ -413,6 +433,10 @@ xfce_menu_item_get_property (GObject *object, g_value_set_string (value, xfce_menu_item_get_filename (item)); break; + case PROP_COMMENT: + g_value_set_string (value, xfce_menu_item_get_comment (item)); + break; + case PROP_REQUIRES_TERMINAL: case PROP_NO_DISPLAY: case PROP_STARTUP_NOTIFICATION: @@ -473,6 +497,10 @@ xfce_menu_item_set_property (GObject *object, xfce_menu_item_set_generic_name (item, g_value_get_string (value)); break; + case PROP_COMMENT: + xfce_menu_item_set_comment (item, g_value_get_string (value)); + break; + case PROP_COMMAND: xfce_menu_item_set_command (item, g_value_get_string (value)); break; @@ -505,6 +533,7 @@ xfce_menu_item_new (const gchar *filename) const gchar *path; const gchar *name; const gchar *generic_name; + const gchar *comment; const gchar *exec; const gchar *try_exec; const gchar *icon; @@ -537,6 +566,7 @@ xfce_menu_item_new (const gchar *filename) /* Parse name, exec command and icon name */ name = xfce_rc_read_entry (rc, "Name", NULL); generic_name = xfce_rc_read_entry (rc, "GenericName", NULL); + comment = xfce_rc_read_entry (rc, "Comment", NULL); exec = xfce_rc_read_entry (rc, "Exec", NULL); try_exec = xfce_rc_read_entry (rc, "TryExec", NULL); icon = xfce_rc_read_entry (rc, "Icon", NULL); @@ -557,6 +587,7 @@ xfce_menu_item_new (const gchar *filename) "try-exec", try_exec, "name", name, "generic-name", generic_name, + "comment", comment, "icon-name", icon, "requires-terminal", terminal, "no-display", no_display, @@ -836,6 +867,40 @@ xfce_menu_item_set_generic_name (XfceMenuItem *item, +const gchar* +xfce_menu_item_get_comment (XfceMenuItem *item) +{ + g_return_val_if_fail (XFCE_IS_MENU_ITEM (item), NULL); + return item->priv->comment; +} + + + +void +xfce_menu_item_set_comment (XfceMenuItem *item, + const gchar *comment) +{ + g_return_if_fail (XFCE_IS_MENU_ITEM (item)); + + if (G_UNLIKELY (item->priv->comment != NULL)) + { + /* Abort if old and new comment are equal */ + if (G_UNLIKELY (g_utf8_collate (item->priv->comment, comment) == 0)) + return; + + /* Otherwise free old comment */ + g_free (item->priv->comment); + } + + /* Assign new comment */ + item->priv->comment = g_strdup (comment); + + /* Notify listeners */ + g_object_notify (G_OBJECT (item), "comment"); +} + + + const gchar* xfce_menu_item_get_icon_name (XfceMenuItem *item) { diff --git a/libxfce4menu/xfce-menu-item.h b/libxfce4menu/xfce-menu-item.h index e4742c7cbc6f4015b1aa9225a25af04a0619757c..dd29030a36816e7a6c8807f3bccf0982e3f35886 100644 --- a/libxfce4menu/xfce-menu-item.h +++ b/libxfce4menu/xfce-menu-item.h @@ -65,6 +65,9 @@ void xfce_menu_item_set_name (XfceMenuItem *it const gchar *xfce_menu_item_get_generic_name (XfceMenuItem *item); void xfce_menu_item_set_generic_name (XfceMenuItem *item, const gchar *generic_name); +const gchar *xfce_menu_item_get_comment (XfceMenuItem *item); +void xfce_menu_item_set_comment (XfceMenuItem *item, + const gchar *comment); const gchar *xfce_menu_item_get_icon_name (XfceMenuItem *item); void xfce_menu_item_set_icon_name (XfceMenuItem *item, const gchar *icon_name); diff --git a/libxfce4menu/xfce-menu-monitor.c b/libxfce4menu/xfce-menu-monitor.c index efff07a9b2f06fa5e59c7b3158dade01e134b0cc..698f9a41916f3931720531d4e0f4c97dc8eec911 100644 --- a/libxfce4menu/xfce-menu-monitor.c +++ b/libxfce4menu/xfce-menu-monitor.c @@ -37,6 +37,9 @@ static XfceMenuMonitorVTable xfce_menu_monitor_vtable = { NULL, }; +/* Monitor flags */ +static XfceMenuMonitorFlags xfce_menu_monitor_flags; + /* User data as provided by the client */ static gpointer xfce_menu_monitor_user_data = NULL; @@ -62,6 +65,7 @@ _xfce_menu_monitor_init (void) /* Initialize hash tables */ xfce_menu_monitor_item_handles = g_hash_table_new (NULL, NULL); xfce_menu_monitor_shared_handles = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + xfce_menu_monitor_flags = XFCE_MENU_MONITOR_DIRECTORIES|XFCE_MENU_MONITOR_MENU_FILES|XFCE_MENU_MONITOR_DIRECTORY_FILES|XFCE_MENU_MONITOR_DESKTOP_FILES; } @@ -330,3 +334,27 @@ xfce_menu_monitor_remove_file (XfceMenu *menu, } } } + + + +void +xfce_menu_monitor_set_flags (XfceMenuMonitorFlags flags) +{ + xfce_menu_monitor_flags = flags; +} + + + +XfceMenuMonitorFlags +xfce_menu_monitor_get_flags (void) +{ + return xfce_menu_monitor_flags; +} + + + +gboolean +xfce_menu_monitor_has_flags (XfceMenuMonitorFlags flags) +{ + return (xfce_menu_monitor_flags & flags) != 0; +} diff --git a/libxfce4menu/xfce-menu-monitor.h b/libxfce4menu/xfce-menu-monitor.h index ff272a089c37fac810d3849cbd4f1dce06157cbc..80c3ee30552583cd3cb7b24436bf019f93d2216e 100644 --- a/libxfce4menu/xfce-menu-monitor.h +++ b/libxfce4menu/xfce-menu-monitor.h @@ -32,22 +32,33 @@ G_BEGIN_DECLS; +typedef enum +{ + XFCE_MENU_MONITOR_DIRECTORIES = 1 << 0, + XFCE_MENU_MONITOR_MENU_FILES = 1 << 1, + XFCE_MENU_MONITOR_DIRECTORY_FILES = 1 << 2, + XFCE_MENU_MONITOR_DESKTOP_FILES = 1 << 3 +} XfceMenuMonitorFlags; + typedef struct _XfceMenuMonitorVTable XfceMenuMonitorVTable; -void xfce_menu_monitor_set_vtable (XfceMenuMonitorVTable *vtable, - gpointer user_data); -gpointer xfce_menu_monitor_add_item (XfceMenu *menu, - XfceMenuItem *item); -void xfce_menu_monitor_remove_item (XfceMenu *menu, - XfceMenuItem *item); -gpointer xfce_menu_monitor_add_directory (XfceMenu *menu, - const gchar *directory); -void xfce_menu_monitor_remove_directory (XfceMenu *menu, - const gchar *directory); -gpointer xfce_menu_monitor_add_file (XfceMenu *menu, - const gchar *filename); -void xfce_menu_monitor_remove_file (XfceMenu *menu, - const gchar *filename); +void xfce_menu_monitor_set_vtable (XfceMenuMonitorVTable *vtable, + gpointer user_data); +gpointer xfce_menu_monitor_add_item (XfceMenu *menu, + XfceMenuItem *item); +void xfce_menu_monitor_remove_item (XfceMenu *menu, + XfceMenuItem *item); +gpointer xfce_menu_monitor_add_directory (XfceMenu *menu, + const gchar *directory); +void xfce_menu_monitor_remove_directory (XfceMenu *menu, + const gchar *directory); +gpointer xfce_menu_monitor_add_file (XfceMenu *menu, + const gchar *filename); +void xfce_menu_monitor_remove_file (XfceMenu *menu, + const gchar *filename); +void xfce_menu_monitor_set_flags (XfceMenuMonitorFlags flags); +XfceMenuMonitorFlags xfce_menu_monitor_get_flags (void); +gboolean xfce_menu_monitor_has_flags (XfceMenuMonitorFlags flags); /** * XfceMenuMonitorVTable: diff --git a/libxfce4menu/xfce-menu.c b/libxfce4menu/xfce-menu.c index 81c58a148534ecb9867ecd14546c0cd66d50cf95..50f89e1de88e5489f27dee74d8b99990d507f895 100644 --- a/libxfce4menu/xfce-menu.c +++ b/libxfce4menu/xfce-menu.c @@ -3155,18 +3155,21 @@ xfce_menu_monitor_start (XfceMenu *menu) g_return_if_fail (XFCE_IS_MENU (menu)); /* Monitor the menu file */ - xfce_menu_monitor_add_file (menu, menu->priv->filename); + if (G_LIKELY (xfce_menu_monitor_has_flags (XFCE_MENU_MONITOR_MENU_FILES))) + xfce_menu_monitor_add_file (menu, menu->priv->filename); /* Monitor the menu directory file */ - if (XFCE_IS_MENU_DIRECTORY (menu->priv->directory)) + if (G_LIKELY (XFCE_IS_MENU_DIRECTORY (menu->priv->directory) && xfce_menu_monitor_has_flags (XFCE_MENU_MONITOR_DIRECTORY_FILES))) xfce_menu_monitor_add_file (menu, xfce_menu_directory_get_filename (menu->priv->directory)); /* Monitor the application directories */ - for (iter = menu->priv->app_dirs; iter != NULL; iter = g_slist_next (iter)) - xfce_menu_monitor_add_directory (menu, (const gchar *)iter->data); + if (G_LIKELY (xfce_menu_monitor_has_flags (XFCE_MENU_MONITOR_DIRECTORIES))) + for (iter = menu->priv->app_dirs; iter != NULL; iter = g_slist_next (iter)) + xfce_menu_monitor_add_directory (menu, (const gchar *)iter->data); /* Monitor items in the menu pool */ - xfce_menu_item_pool_foreach (menu->priv->pool, (GHFunc) item_monitor_start, menu); + if (G_LIKELY (xfce_menu_monitor_has_flags (XFCE_MENU_MONITOR_DESKTOP_FILES))) + xfce_menu_item_pool_foreach (menu->priv->pool, (GHFunc) item_monitor_start, menu); /* Monitor items in submenus */ for (iter = menu->priv->submenus; iter != NULL; iter = g_slist_next (iter)) diff --git a/tests/test-display-menu.c b/tests/test-display-menu.c index fedff2dfcd5ffdbae16e286678fb51587b455e55..eaef8c67b754a17c7ab1d11aaef5134f44b47834 100644 --- a/tests/test-display-menu.c +++ b/tests/test-display-menu.c @@ -351,6 +351,7 @@ create_main_window (void) /* Create main window */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), _("XfceMenu: Display Menu Test")); + gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER); gtk_container_set_border_width (GTK_CONTAINER (window), 12); gtk_widget_show (window);