gnome-menus r876 - in trunk: . libmenu python



Author: vuntz
Date: Sat Apr 12 01:09:48 2008
New Revision: 876
URL: http://svn.gnome.org/viewvc/gnome-menus?rev=876&view=rev

Log:
2008-04-12  Vincent Untz  <vuntz gnome org>

	Do not show unless specifically asked separators at the beginning of a
	menu, or at the end of a menu, or after another separator.
	Fix bug #497399.

	* python/gmenu.c: (initgmenu): add new flag
	* libmenu/gmenu-tree.[ch]: add new GMENU_TREE_FLAGS_SHOW_ALL_SEPARATORS
	flag
	(check_pending_separator): append a separator to a menu if there's a
	pending one
	(merge_subdir):
	(merge_entry): add calls to check_pending_separator()
	(process_layout_info): implement logic to add a separator if
	GMENU_TREE_FLAGS_SHOW_ALL_SEPARATORS is specified or add a pending one
	if it will be useful


Modified:
   trunk/ChangeLog
   trunk/libmenu/gmenu-tree.c
   trunk/libmenu/gmenu-tree.h
   trunk/python/gmenu.c

Modified: trunk/libmenu/gmenu-tree.c
==============================================================================
--- trunk/libmenu/gmenu-tree.c	(original)
+++ trunk/libmenu/gmenu-tree.c	Sat Apr 12 01:09:48 2008
@@ -101,6 +101,7 @@
   guint only_unallocated : 1;
   guint is_root : 1;
   guint is_nodisplay : 1;
+  guint layout_pending_separator : 1;
 };
 
 typedef struct
@@ -3423,6 +3424,19 @@
 				 GMenuTreeDirectory *directory);
 
 static void
+check_pending_separator (GMenuTreeDirectory *directory)
+{
+  if (directory->layout_pending_separator)
+    {
+      menu_verbose ("Adding pending separator in '%s'\n", directory->name);
+
+      directory->contents = g_slist_append (directory->contents,
+					    gmenu_tree_separator_new (directory));
+      directory->layout_pending_separator = FALSE;
+    }
+}
+
+static void
 merge_subdir (GMenuTree          *tree,
 	      GMenuTreeDirectory *directory,
 	      GMenuTreeDirectory *subdir,
@@ -3447,6 +3461,8 @@
     }
   else if (layout_values->inline_menus)
     {
+      check_pending_separator (directory);
+
       if (layout_values->inline_alias && g_slist_length (subdir->contents) == 1)
 	{
 	  GMenuTreeAlias *alias;
@@ -3504,6 +3520,7 @@
     }
   else
     {
+      check_pending_separator (directory);
       directory->contents = g_slist_append (directory->contents,
 					    gmenu_tree_item_ref (subdir));
     }
@@ -3545,6 +3562,7 @@
   menu_verbose ("Merging entry '%s' in directory '%s'\n",
 		entry->desktop_file_id, directory->name);
 
+  check_pending_separator (directory);
   directory->contents = g_slist_append (directory->contents,
 					gmenu_tree_item_ref (entry));
 }
@@ -3844,6 +3862,7 @@
 		   NULL);
   g_slist_free (directory->contents);
   directory->contents = NULL;
+  directory->layout_pending_separator = FALSE;
 
   if ((layout_info = get_layout_info (directory)) == NULL)
     {
@@ -3883,9 +3902,28 @@
 	      break;
 
 	    case MENU_LAYOUT_NODE_SEPARATOR:
-	      menu_verbose ("Adding a separator in '%s'\n", directory->name);
-	      directory->contents = g_slist_append (directory->contents,
-						    gmenu_tree_separator_new (directory));
+	      /* Unless explicitly told to show all separators, do not show a
+	       * separator at the beginning of a menu. Note that we don't add
+	       * the separators now, and instead make it pending. This way, we
+	       * won't show two consecutive separators nor will we show a
+	       * separator at the end of a menu. */
+              if (tree->flags & GMENU_TREE_FLAGS_SHOW_ALL_SEPARATORS)
+		{
+		  directory->layout_pending_separator = TRUE;
+		  check_pending_separator (directory);
+		}
+	      else if (directory->contents)
+		{
+		  menu_verbose ("Adding a potential separator in '%s'\n",
+				directory->name);
+
+		  directory->layout_pending_separator = TRUE;
+		}
+	      else
+		{
+		  menu_verbose ("Skipping separator at the beginning of '%s'\n",
+				directory->name);
+		}
 	      break;
 
 	    case MENU_LAYOUT_NODE_MERGE:

Modified: trunk/libmenu/gmenu-tree.h
==============================================================================
--- trunk/libmenu/gmenu-tree.h	(original)
+++ trunk/libmenu/gmenu-tree.h	Sat Apr 12 01:09:48 2008
@@ -58,11 +58,12 @@
 
 typedef enum
 {
-  GMENU_TREE_FLAGS_NONE              = 0,
-  GMENU_TREE_FLAGS_INCLUDE_EXCLUDED  = 1 << 0,
-  GMENU_TREE_FLAGS_SHOW_EMPTY        = 1 << 1,
-  GMENU_TREE_FLAGS_INCLUDE_NODISPLAY = 1 << 2,
-  GMENU_TREE_FLAGS_MASK              = 0x07
+  GMENU_TREE_FLAGS_NONE                = 0,
+  GMENU_TREE_FLAGS_INCLUDE_EXCLUDED    = 1 << 0,
+  GMENU_TREE_FLAGS_SHOW_EMPTY          = 1 << 1,
+  GMENU_TREE_FLAGS_INCLUDE_NODISPLAY   = 1 << 2,
+  GMENU_TREE_FLAGS_SHOW_ALL_SEPARATORS = 1 << 3,
+  GMENU_TREE_FLAGS_MASK                = 0x0f
 } GMenuTreeFlags;
 
 GMenuTree *gmenu_tree_lookup (const char     *menu_file,

Modified: trunk/python/gmenu.c
==============================================================================
--- trunk/python/gmenu.c	(original)
+++ trunk/python/gmenu.c	Sat Apr 12 01:09:48 2008
@@ -1785,8 +1785,9 @@
   PyModule_AddIntConstant (mod, "TYPE_HEADER",    GMENU_TREE_ITEM_HEADER);
   PyModule_AddIntConstant (mod, "TYPE_ALIAS",     GMENU_TREE_ITEM_ALIAS);
 
-  PyModule_AddIntConstant (mod, "FLAGS_NONE",              GMENU_TREE_FLAGS_NONE);
-  PyModule_AddIntConstant (mod, "FLAGS_INCLUDE_EXCLUDED",  GMENU_TREE_FLAGS_INCLUDE_EXCLUDED);
-  PyModule_AddIntConstant (mod, "FLAGS_SHOW_EMPTY",        GMENU_TREE_FLAGS_SHOW_EMPTY);
-  PyModule_AddIntConstant (mod, "FLAGS_INCLUDE_NODISPLAY", GMENU_TREE_FLAGS_INCLUDE_NODISPLAY);
+  PyModule_AddIntConstant (mod, "FLAGS_NONE",                GMENU_TREE_FLAGS_NONE);
+  PyModule_AddIntConstant (mod, "FLAGS_INCLUDE_EXCLUDED",    GMENU_TREE_FLAGS_INCLUDE_EXCLUDED);
+  PyModule_AddIntConstant (mod, "FLAGS_SHOW_EMPTY",          GMENU_TREE_FLAGS_SHOW_EMPTY);
+  PyModule_AddIntConstant (mod, "FLAGS_INCLUDE_NODISPLAY",   GMENU_TREE_FLAGS_INCLUDE_NODISPLAY);
+  PyModule_AddIntConstant (mod, "FLAGS_SHOW_ALL_SEPARATORS", GMENU_TREE_FLAGS_SHOW_ALL_SEPARATORS);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]