[Xfce4-commits] r23280 - in libfrap/trunk/libfrap/menu: . tests
Jannis Pohlmann
jannis at xfce.org
Wed Oct 4 16:33:25 UTC 2006
Author: jannis
Date: 2006-10-04 16:33:23 +0000 (Wed, 04 Oct 2006)
New Revision: 23280
Modified:
libfrap/trunk/libfrap/menu/ChangeLog
libfrap/trunk/libfrap/menu/frap-menu-item-pool.c
libfrap/trunk/libfrap/menu/frap-menu-item-pool.h
libfrap/trunk/libfrap/menu/frap-menu-item.c
libfrap/trunk/libfrap/menu/frap-menu.c
libfrap/trunk/libfrap/menu/tests/Makefile.am
libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c
Log:
* frap-menu-item-pool.c: Add frap_menu_item_pool_get_empty function.
* tests/Makefile.am, tests/test-display-root-menu.c: Link against
libxfcegui4. Do not display empty menus. Improve icon loading again
and execute item command when menu items are clicked.
* frap-menu-item.c: Leave Exec/TryExec command as is (do not modify the
url(s)/file(s) parameter.
* frap-menu.c: Respect <OnlyAllocated /> item when resolve menu items.
Modified: libfrap/trunk/libfrap/menu/ChangeLog
===================================================================
--- libfrap/trunk/libfrap/menu/ChangeLog 2006-10-04 10:25:00 UTC (rev 23279)
+++ libfrap/trunk/libfrap/menu/ChangeLog 2006-10-04 16:33:23 UTC (rev 23280)
@@ -1,3 +1,13 @@
+2006-10-04 Jannis Pohlmann <jannis at xfce.org>
+
+ * frap-menu-item-pool.c: Add frap_menu_item_pool_get_empty function.
+ * tests/Makefile.am, tests/test-display-root-menu.c: Link against
+ libxfcegui4. Do not display empty menus. Improve icon loading again
+ and execute item command when menu items are clicked.
+ * frap-menu-item.c: Leave Exec/TryExec command as is (do not modify the
+ url(s)/file(s) parameter.
+ * frap-menu.c: Respect <OnlyAllocated /> item when resolve menu items.
+
2006-10-03 Jannis Pohlmann <jannis at xfce.org>
* STATUS: Updated the implementation status.
Modified: libfrap/trunk/libfrap/menu/frap-menu-item-pool.c
===================================================================
--- libfrap/trunk/libfrap/menu/frap-menu-item-pool.c 2006-10-04 10:25:00 UTC (rev 23279)
+++ libfrap/trunk/libfrap/menu/frap-menu-item-pool.c 2006-10-04 16:33:23 UTC (rev 23280)
@@ -152,6 +152,9 @@
/* Insert into the hash table and remove old item (if any) */
g_hash_table_replace (pool->priv->items, g_strdup (frap_menu_item_get_desktop_id (item)), item);
+ /* Set allocation state of the item */
+ frap_menu_item_set_allocated (item, TRUE);
+
/* Grab a reference on the item */
g_object_ref (G_OBJECT (item));
}
@@ -226,3 +229,12 @@
else
return frap_menu_rules_match (rules, item);
}
+
+
+
+gboolean
+frap_menu_item_pool_get_empty (FrapMenuItemPool *pool)
+{
+ g_return_val_if_fail (FRAP_IS_MENU_ITEM_POOL (pool), TRUE);
+ return (g_hash_table_size (pool->priv->items) == 0);
+}
Modified: libfrap/trunk/libfrap/menu/frap-menu-item-pool.h
===================================================================
--- libfrap/trunk/libfrap/menu/frap-menu-item-pool.h 2006-10-04 10:25:00 UTC (rev 23279)
+++ libfrap/trunk/libfrap/menu/frap-menu-item-pool.h 2006-10-04 16:33:23 UTC (rev 23280)
@@ -54,6 +54,7 @@
gpointer user_data);
void frap_menu_item_pool_apply_rules (FrapMenuItemPool *pool,
GSList *rules);
+gboolean frap_menu_item_pool_get_empty (FrapMenuItemPool *pool);
G_END_DECLS;
Modified: libfrap/trunk/libfrap/menu/frap-menu-item.c
===================================================================
--- libfrap/trunk/libfrap/menu/frap-menu-item.c 2006-10-04 10:25:00 UTC (rev 23279)
+++ libfrap/trunk/libfrap/menu/frap-menu-item.c 2006-10-04 16:33:23 UTC (rev 23280)
@@ -473,11 +473,14 @@
/* Validate Name and Exec fields */
if (G_LIKELY (exec != NULL && name != NULL && g_utf8_validate (name, -1, NULL)))
{
+#if 0
/* Append %f to the exec command if the application hasn't set anything else */
if (strstr (exec, "%f") == NULL && strstr (exec, "%F") == NULL && strstr (exec, "%u") == NULL && strstr (exec, "%U") == NULL)
- command = g_strconcat (exec, "%f", NULL);
+ command = g_strconcat (exec, " %f", NULL);
else
command = g_strdup (exec);
+#endif
+ command = g_strdup (exec);
/* Determine other application properties */
terminal = xfce_rc_read_bool_entry (rc, "Terminal", FALSE);
Modified: libfrap/trunk/libfrap/menu/frap-menu.c
===================================================================
--- libfrap/trunk/libfrap/menu/frap-menu.c 2006-10-04 10:25:00 UTC (rev 23279)
+++ libfrap/trunk/libfrap/menu/frap-menu.c 2006-10-04 16:33:23 UTC (rev 23280)
@@ -1750,11 +1750,16 @@
if (G_LIKELY (item != NULL))
{
- /* Assign the desktop id to the item */
- frap_menu_item_set_desktop_id (item, desktop_id);
+ /* Only include item if menu not only includes unallocated items
+ * or if the item is not allocated yet */
+ if (!menu->priv->only_unallocated || frap_menu_item_get_allocated (item))
+ {
+ /* Assign the desktop id to the item */
+ frap_menu_item_set_desktop_id (item, desktop_id);
- /* Add the new item to the pool (replace the old one if needed) */
- frap_menu_item_pool_insert (menu->priv->pool, item);
+ /* Add the new item to the pool (replace the old one if needed) */
+ frap_menu_item_pool_insert (menu->priv->pool, item);
+ }
}
/* Free desktop id */
Modified: libfrap/trunk/libfrap/menu/tests/Makefile.am
===================================================================
--- libfrap/trunk/libfrap/menu/tests/Makefile.am 2006-10-04 10:25:00 UTC (rev 23279)
+++ libfrap/trunk/libfrap/menu/tests/Makefile.am 2006-10-04 16:33:23 UTC (rev 23280)
@@ -7,6 +7,7 @@
$(GLIB_CFLAGS) \
$(GTHREAD_CFLAGS) \
$(LIBXFCE4UTIL_CFLAGS) \
+ $(LIBXFCEGUI4_CFLAGS) \
$(GTK_CFLAGS) \
-I$(top_builddir)/libfrap/menu/ \
-DG_LOG_DOMAIN=\"tests\"
@@ -15,6 +16,7 @@
$(GLIB_LIBS) \
$(GTHREAD_LIBS) \
$(LIBXFCE4UTIL_LIBS) \
+ $(LIBXFCEGUI4_LIBS) \
$(GTK_LIBS) \
$(top_builddir)/libfrap/menu/libfrapmenu.la
Modified: libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c
===================================================================
--- libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c 2006-10-04 10:25:00 UTC (rev 23279)
+++ libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c 2006-10-04 16:33:23 UTC (rev 23280)
@@ -27,6 +27,7 @@
#include <gtk/gtk.h>
#include <libxfce4util/libxfce4util.h>
+#include <libxfcegui4/libxfcegui4.h>
#include <libfrapmenu.h>
@@ -66,22 +67,21 @@
GdkPixbuf*
create_icon_for_item (FrapMenuItem *item)
{
- GdkPixbuf *pixbuf = NULL;
- const gchar *icon_name = frap_menu_item_get_icon_name (item);
- const gchar *item_name = frap_menu_item_get_name (item);
+ GtkIconTheme *icon_theme = gtk_icon_theme_get_default ();
+ GdkPixbuf *pixbuf = NULL;
+ const gchar *icon_name = frap_menu_item_get_icon_name (item);
+ const gchar *item_name = frap_menu_item_get_name (item);
if (icon_name == NULL)
return NULL;
/* Check if we have an absolute filename */
if (g_path_is_absolute (icon_name))
- {
- pixbuf = gdk_pixbuf_new_from_file_at_scale (icon_name, ICON_SIZE, ICON_SIZE, TRUE, NULL);
- }
+ pixbuf = gdk_pixbuf_new_from_file_at_scale (icon_name, ICON_SIZE, ICON_SIZE, TRUE, NULL);
else
{
/* Try to directly load the icon name first */
- pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), icon_name, ICON_SIZE, GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
+ pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name, ICON_SIZE, GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
/* Afterwards try removing the filename extension if there is one */
if (!pixbuf)
@@ -99,7 +99,7 @@
gchar *new_icon_name = g_utf8_strncpy (icon_name, basename, g_utf8_strlen (basename, -1) - g_utf8_strlen (extension, -1));
/* Try to load the pixbuf using the new icon name */
- pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), new_icon_name, ICON_SIZE, GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
+ pixbuf = gtk_icon_theme_load_icon (icon_theme, new_icon_name, ICON_SIZE, GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
/* Free new icon name */
g_free (new_icon_name);
@@ -121,19 +121,48 @@
}
/* Scale pixbuf (if needed) */
- if (pixbuf)
+ if (pixbuf != NULL)
{
GdkPixbuf *old = pixbuf;
pixbuf = gdk_pixbuf_scale_simple (old, ICON_SIZE, ICON_SIZE, GDK_INTERP_BILINEAR);
gdk_pixbuf_unref (old);
}
+ /* Print icon name if icon could not be loaded */
+ if (pixbuf == NULL && icon_name != NULL)
+ g_debug ("%s could not be found", icon_name != NULL ? icon_name : "(null)");
+
return pixbuf;
}
void
+execute_command_for_item (GtkWidget *widget,
+ FrapMenuItem *item)
+{
+ const gchar *command = frap_menu_item_get_command (item);
+ gboolean terminal = frap_menu_item_requires_terminal (item);
+ gboolean startup_notification = frap_menu_item_supports_startup_notification (item);
+ GError *error = NULL;
+
+ /* Abort if no command was defined for this item */
+ if (G_UNLIKELY (command == NULL))
+ return;
+
+ /* Try to execute the command and display the error message if that failed */
+ if (!xfce_exec_on_screen (gdk_screen_get_default (), command, terminal, startup_notification, &error))
+ {
+ xfce_err (error->message);
+
+ /* Free the error */
+ g_error_free (error);
+ }
+}
+
+
+
+void
create_item_widgets_for_menu (const gchar *desktop_id,
FrapMenuItem *item,
GtkWidget *widget)
@@ -154,6 +183,9 @@
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
gtk_menu_shell_append (GTK_MENU_SHELL (widget), menu_item);
gtk_widget_show (menu_item);
+
+ /* Execute command if item is clicked */
+ g_signal_connect (menu_item, "activate", G_CALLBACK (execute_command_for_item), item);
}
@@ -169,6 +201,9 @@
GtkWidget *image;
GSList *iter;
GSList *menus;
+ GtkIconTheme *icon_theme = gtk_icon_theme_get_default ();
+ const gchar *icon_name;
+ GdkPixbuf *pixbuf;
/* Create sorted copy of the submenu list */
menus = g_slist_sort (g_slist_copy (frap_menu_get_menus (menu)), (GCompareFunc) compare_menus);
@@ -178,12 +213,25 @@
/* Get menu directory */
directory = frap_menu_get_directory (FRAP_MENU (iter->data));
+ /* Skip if menu has no directory (and thus, no display information) */
if (G_UNLIKELY (directory == NULL))
continue;
- /* Create menu icon */
- image = gtk_image_new_from_icon_name (frap_menu_directory_get_icon (directory), GTK_ICON_SIZE_SMALL_TOOLBAR);
+ /* Skip if menu is empty */
+ if (frap_menu_item_pool_get_empty (frap_menu_get_item_pool (iter->data)))
+ continue;
+ /* Determine icon name */
+ icon_name = frap_menu_directory_get_icon (directory);
+
+ /* Load menu icon */
+ pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name, ICON_SIZE, GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
+ if (G_UNLIKELY (pixbuf == NULL))
+ pixbuf = gtk_icon_theme_load_icon (icon_theme, "applications-other", ICON_SIZE, GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
+
+ /* Create image widget */
+ image = gtk_image_new_from_pixbuf (pixbuf);
+
/* Create menu item */
menu_item = gtk_image_menu_item_new_with_label (frap_menu_directory_get_name (directory));
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
More information about the Xfce4-commits
mailing list