Author: jannis Date: 2007-03-19 12:52:26 +0000 (Mon, 19 Mar 2007) New Revision: 25219
Modified: libfrap/trunk/libfrap/menu/ChangeLog libfrap/trunk/libfrap/menu/frap-menu-layout.c libfrap/trunk/libfrap/menu/frap-menu.c libfrap/trunk/libfrap/menu/frap-menu.h libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c Log: * frap-menu.{c,h}: Add frap_menu_has_layout(). Return NULL from frap_menu_get_layout_nodes() if a menu has no layout. Disable crappy submenu consolidation code for now as it didn't preserve menu layouts. Sort submenus in frap_menu_get_menus() and items in frap_menu_get_items(), so API users don't have to do this. * tests/test-display-root-menu.c: Update test program to be in sync with the latest API changes. Modified: libfrap/trunk/libfrap/menu/ChangeLog =================================================================== --- libfrap/trunk/libfrap/menu/ChangeLog 2007-03-19 08:31:01 UTC (rev 25218) +++ libfrap/trunk/libfrap/menu/ChangeLog 2007-03-19 12:52:26 UTC (rev 25219) @@ -1,3 +1,14 @@ +2007-03-19 Jannis Pohlmann <[EMAIL PROTECTED]> + + * frap-menu.{c,h}: Add frap_menu_has_layout(). Return NULL + from frap_menu_get_layout_nodes() if a menu has no layout. + Disable crappy submenu consolidation code for now as it + didn't preserve menu layouts. + Sort submenus in frap_menu_get_menus() and items in + frap_menu_get_items(), so API users don't have to do this. + * tests/test-display-root-menu.c: Update test program to be + in sync with the latest API changes. + 2007-03-18 Jannis Pohlmann <[EMAIL PROTECTED]> * frap-menu-item.c: Replace g_return_val_if_fail() calls in Modified: libfrap/trunk/libfrap/menu/frap-menu-layout.c =================================================================== --- libfrap/trunk/libfrap/menu/frap-menu-layout.c 2007-03-19 08:31:01 UTC (rev 25218) +++ libfrap/trunk/libfrap/menu/frap-menu-layout.c 2007-03-19 12:52:26 UTC (rev 25219) @@ -230,8 +230,6 @@ node->type = FRAP_MENU_LAYOUT_NODE_FILENAME; node->data.filename = g_strdup (filename); - g_debug ("frap_menu_layout_add_filename ('%s')", filename); - /* Append node to the list */ layout->priv->nodes = g_slist_append (layout->priv->nodes, node); } @@ -250,8 +248,6 @@ node->type = FRAP_MENU_LAYOUT_NODE_MENUNAME; node->data.menuname = g_strdup (menuname); - g_debug ("frap_menu_layout_add_menuname ('%s')", menuname); - /* Append node to the list */ layout->priv->nodes = g_slist_append (layout->priv->nodes, node); } @@ -267,8 +263,6 @@ FrapMenuLayoutNode *node = g_new0 (FrapMenuLayoutNode, 1); node->type = FRAP_MENU_LAYOUT_NODE_SEPARATOR; - g_debug ("frap_menu_layout_add_separator ()"); - /* Append node to the list */ layout->priv->nodes = g_slist_append (layout->priv->nodes, node); } @@ -286,8 +280,6 @@ node->type = FRAP_MENU_LAYOUT_NODE_MERGE; node->data.merge_type = type; - g_debug ("frap_menu_layout_add_merge (%d)", type); - /* Append node to the list */ layout->priv->nodes = g_slist_append (layout->priv->nodes, node); } Modified: libfrap/trunk/libfrap/menu/frap-menu.c =================================================================== --- libfrap/trunk/libfrap/menu/frap-menu.c 2007-03-19 08:31:01 UTC (rev 25218) +++ libfrap/trunk/libfrap/menu/frap-menu.c 2007-03-19 12:52:26 UTC (rev 25219) @@ -1886,8 +1886,17 @@ GSList* frap_menu_get_menus (FrapMenu *menu) { + GSList *menus; + g_return_val_if_fail (FRAP_IS_MENU (menu), NULL); - return g_slist_copy (menu->priv->submenus); + + /* Copy submenu list */ + menus = g_slist_copy (menu->priv->submenus); + + /* Sort submenus */ + menus = g_slist_sort (menus, (GCompareFunc) frap_menu_compare_items); + + return menus; } @@ -2077,6 +2086,7 @@ FrapMenu *submenu; FrapMenu *merged_menu; +#if 0 g_return_if_fail (FRAP_IS_MENU (menu)); /* Setup the hash table */ @@ -2138,6 +2148,8 @@ #else g_hash_table_destroy (groups); #endif + +#endif } @@ -2760,6 +2772,9 @@ /* Collect the items in the pool */ frap_menu_item_pool_foreach (menu->priv->pool, (GHFunc) items_collect, &items); + /* Sort items */ + items = g_slist_sort (items, (GCompareFunc) frap_menu_compare_items); + return items; } @@ -2794,6 +2809,24 @@ } + +gboolean +frap_menu_has_layout (FrapMenu *menu) +{ + GSList *nodes; + + g_return_val_if_fail (FRAP_IS_MENU (menu), FALSE); + g_return_val_if_fail (FRAP_IS_MENU_LAYOUT (menu->priv->layout), FALSE); + + /* Fetch layout nodes */ + nodes = frap_menu_layout_get_nodes (menu->priv->layout); + + /* Menu is supposed to have no layout when the nodes list is empty */ + return g_slist_length (nodes) > 0; +} + + + GSList* frap_menu_get_layout_items (FrapMenu *menu) { @@ -2804,104 +2837,93 @@ g_return_val_if_fail (FRAP_IS_MENU (menu), NULL); + /* Return NULL if there is no layout */ + if (G_UNLIKELY (!frap_menu_has_layout (menu))) + return NULL; + /* Fetch layout nodes */ nodes = frap_menu_layout_get_nodes (menu->priv->layout); - /* Only process layout if there are any layout information at all */ - if (G_UNLIKELY (nodes != NULL && g_slist_length (nodes) != 0)) + /* Process layout nodes in order */ + for (iter = nodes; iter != NULL; iter = g_slist_next (iter)) { - g_debug ("Menu has layout"); + FrapMenuLayoutNode *node = (FrapMenuLayoutNode *)iter->data; + FrapMenuLayoutNodeType type; + FrapMenuLayoutMergeType merge_type; + FrapMenuItem *item; + FrapMenu *submenu; + FrapMenuSeparator *separator; - /* Process layout nodes in order */ - for (iter = nodes; iter != NULL; iter = g_slist_next (iter)) + /* Determine layout node type */ + type = frap_menu_layout_node_get_type (node); + + if (type == FRAP_MENU_LAYOUT_NODE_FILENAME) { - FrapMenuLayoutNode *node = (FrapMenuLayoutNode *)iter->data; - FrapMenuLayoutNodeType type; - FrapMenuLayoutMergeType merge_type; - FrapMenuItem *item; - FrapMenu *submenu; - FrapMenuSeparator *separator; + /* Search for desktop ID in the item pool */ + item = frap_menu_item_pool_lookup (menu->priv->pool, frap_menu_layout_node_get_filename (node)); - /* Determine layout node type */ - type = frap_menu_layout_node_get_type (node); + /* If the item with this desktop ID is included in the menu, append it to the list */ + if (G_LIKELY (item != NULL)) + items = g_slist_append (items, item); + } + if (type == FRAP_MENU_LAYOUT_NODE_MENUNAME) + { + /* Search submenu with this name */ + submenu = frap_menu_get_menu_with_name (menu, frap_menu_layout_node_get_menuname (node)); - if (type == FRAP_MENU_LAYOUT_NODE_FILENAME) + /* If there is such a menu, append it to the list */ + if (G_LIKELY (submenu != NULL)) + items = g_slist_append (items, submenu); + } + else if (type == FRAP_MENU_LAYOUT_NODE_SEPARATOR) + { + /* Append separator to the list */ + items = g_slist_append (items, frap_menu_separator_get_default ()); + } + else if (type == FRAP_MENU_LAYOUT_NODE_MERGE) + { + /* Determine merge type */ + merge_type = frap_menu_layout_node_get_merge_type (node); + + if (merge_type == FRAP_MENU_LAYOUT_MERGE_ALL) { - /* Search for desktop ID in the item pool */ - item = frap_menu_item_pool_lookup (menu->priv->pool, frap_menu_layout_node_get_filename (node)); + /* Get all menu items of this menu */ + menu_items = frap_menu_get_items (menu); + + /* Append submenus */ + menu_items = g_slist_concat (menu_items, frap_menu_get_menus (menu)); - /* If the item with this desktop ID is included in the menu, append it to the list */ - if (G_LIKELY (item != NULL)) - items = g_slist_append (items, item); + /* Sort menu items */ + menu_items = g_slist_sort (menu_items, (GCompareFunc) frap_menu_compare_items); + + /* Append menu items to the returned item list */ + layout_items_collect (&items, menu_items, menu->priv->layout); } - if (type == FRAP_MENU_LAYOUT_NODE_MENUNAME) + else if (merge_type == FRAP_MENU_LAYOUT_MERGE_FILES) { - /* Search submenu with this name */ - submenu = frap_menu_get_menu_with_name (menu, frap_menu_layout_node_get_menuname (node)); + /* Get all menu items of this menu */ + menu_items = frap_menu_get_items (menu); - /* If there is such a menu, append it to the list */ - if (G_LIKELY (submenu != NULL)) - items = g_slist_append (items, submenu); + /* Sort menu items */ + menu_items = g_slist_sort (menu_items, (GCompareFunc) frap_menu_compare_items); + + /* Append menu items to the returned item list */ + layout_items_collect (&items, menu_items, menu->priv->layout); } - else if (type == FRAP_MENU_LAYOUT_NODE_SEPARATOR) + else if (merge_type == FRAP_MENU_LAYOUT_MERGE_MENUS) { - /* Append separator to the list */ - items = g_slist_append (items, frap_menu_separator_get_default ()); - } - else if (type == FRAP_MENU_LAYOUT_NODE_MERGE) - { - /* Determine merge type */ - merge_type = frap_menu_layout_node_get_merge_type (node); + /* Get all submenus */ + menu_items = frap_menu_get_menus (menu); - if (merge_type == FRAP_MENU_LAYOUT_MERGE_ALL) - { - /* Get all menu items of this menu */ - menu_items = frap_menu_get_items (menu); - - /* Append submenus */ - menu_items = g_slist_concat (menu_items, frap_menu_get_menus (menu)); + /* Sort menu items */ + menu_items = g_slist_sort (menu_items, (GCompareFunc) frap_menu_compare_items); - /* Sort menu items */ - menu_items = g_slist_sort (menu_items, (GCompareFunc) frap_menu_compare_items); - - /* Append menu items to the returned item list */ - layout_items_collect (&items, menu_items, menu->priv->layout); - } - else if (merge_type == FRAP_MENU_LAYOUT_MERGE_FILES) - { - /* Get all menu items of this menu */ - menu_items = frap_menu_get_items (menu); - - /* Sort menu items */ - menu_items = g_slist_sort (menu_items, (GCompareFunc) frap_menu_compare_items); - - /* Append menu items to the returned item list */ - layout_items_collect (&items, menu_items, menu->priv->layout); - } - else if (merge_type == FRAP_MENU_LAYOUT_MERGE_MENUS) - { - /* Get all submenus */ - menu_items = frap_menu_get_menus (menu); - - /* Sort menu items */ - menu_items = g_slist_sort (menu_items, (GCompareFunc) frap_menu_compare_items); - - /* Append submenus to the returned item list */ - layout_items_collect (&items, menu_items, menu->priv->layout); - } + /* Append submenus to the returned item list */ + layout_items_collect (&items, menu_items, menu->priv->layout); } } } - else - { - /* No layout used. Fetch items, menus and sort them */ - items = frap_menu_get_items (menu); - items = g_slist_concat (items, frap_menu_get_menus (menu)); - items = g_slist_sort (items, (GCompareFunc) frap_menu_compare_items); - } - - g_debug ("%s: %d layout items", frap_menu_get_name (menu), g_slist_length (items)); - + return items; } Modified: libfrap/trunk/libfrap/menu/frap-menu.h =================================================================== --- libfrap/trunk/libfrap/menu/frap-menu.h 2007-03-19 08:31:01 UTC (rev 25218) +++ libfrap/trunk/libfrap/menu/frap-menu.h 2007-03-19 12:52:26 UTC (rev 25219) @@ -77,6 +77,7 @@ FrapMenu *frap_menu_get_parent (FrapMenu *menu); FrapMenuItemPool *frap_menu_get_item_pool (FrapMenu *menu); GSList *frap_menu_get_items (FrapMenu *menu); +gboolean frap_menu_has_layout (FrapMenu *menu); GSList *frap_menu_get_layout_items (FrapMenu *menu); G_END_DECLS; Modified: libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c =================================================================== --- libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c 2007-03-19 08:31:01 UTC (rev 25218) +++ libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c 2007-03-19 12:52:26 UTC (rev 25219) @@ -126,9 +126,11 @@ g_object_unref (G_OBJECT (old)); } +#if 0 /* 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)"); +#endif return pixbuf; } @@ -211,7 +213,17 @@ GtkIconTheme *icon_theme = gtk_icon_theme_get_default (); /* Get submenus and items based on the menu layout */ - items = frap_menu_get_layout_items (menu); + if (G_UNLIKELY (frap_menu_has_layout (menu))) + { + /* Get layout items */ + items = frap_menu_get_layout_items (menu); + } + else + { + /* Concat menus and items */ + items = frap_menu_get_menus (menu); + items = g_slist_concat (items, frap_menu_get_items (menu)); + } /* Iterate over children */ for (iter = items; iter != NULL; iter = g_slist_next (iter)) @@ -223,21 +235,24 @@ } else if (FRAP_IS_MENU (iter->data)) { - g_debug ("generating widgets for submenu"); + FrapMenu *child_menu = FRAP_MENU (iter->data); + const gchar *menu_name; - FrapMenu *child_menu = FRAP_MENU (iter->data); - /* Get menu directory */ directory = frap_menu_get_directory (FRAP_MENU (child_menu)); +#if 0 /* Skip if menu has no directory (and thus, no display information) */ if (G_UNLIKELY (directory == NULL)) g_warning ("Submenu '%s' is missing a menu directory", frap_menu_get_name (child_menu)); +#endif /* Skip if menu is empty */ if (frap_menu_item_pool_get_empty (frap_menu_get_item_pool (child_menu))) { +#if 0 g_debug ("Skipping submenu '%s' because it has no children", frap_menu_get_name (child_menu)); +#endif continue; } @@ -245,7 +260,9 @@ * this one */ if (directory != NULL && !frap_menu_directory_show_in_environment (directory)) { +#if 0 g_debug ("skipping submenu '%s' because it is not displayed in this environment", frap_menu_get_name (child_menu)); +#endif continue; } @@ -260,11 +277,11 @@ /* Create image widget */ image = gtk_image_new_from_pixbuf (pixbuf); + /* Determine menu name */ + menu_name = directory != NULL ? frap_menu_directory_get_name (directory) : frap_menu_get_name (child_menu); + /* Create menu item */ - if (directory != NULL) - menu_item = gtk_image_menu_item_new_with_label (frap_menu_directory_get_name (directory)); - else - menu_item = gtk_image_menu_item_new_with_label (frap_menu_get_name (child_menu)); + menu_item = gtk_image_menu_item_new_with_label (menu_name); 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); _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits