Re: Integrating EggMenu code into GTK+



Am Sam, 2003-08-16 um 16.22 schrieb Havoc Pennington:

>  - Say I have one GtkPlug inside another GtkPlug inside a toplevel, 
>    for example nested Bonobo components.
> 
>    So I would imagine each plug and the toplevel have a
>    GtkMenuMerge. How does the UI from the innermost plug get
>    propagated to the toplevel?
> 
>    It seems like the plug in the middle would have to merge in the UI
>    from the innermost plug, then propagate the merged XML and actions
>    list to the toplevel.
> 
>    I don't see API right now to convert GtkMenuMerge into a serialized
>    form that could then be merged into another GtkMenuMerge.
>    I would expect maybe gtk_menu_merge_get_actions() (gets a 
>    flattened view of all actions) and gtk_menu_merge_get_ui() 
>    (gets XML representing merged UI). Also, a signal emitted 
>    when these change.
> 
>  - But another problem: the GtkMenuMerge that does the merge logic
>    always creates widgets. So it can only be on a toplevel, not on a
>    GtkPlug. Perhaps the merging and the widgeting need to be split
>    apart? Or gtk_menu_merge_set_no_widgets()?

Here is one part of this riddle: create an xml representation of the
merged ui:

static const gchar *open_tag_format[] = {
  "%*s<UNDECIDED>\n",
  "%*s<Root>\n",
  "%*s<menu name=\"%s\">\n",  
  "%*s<submenu name=\"%s\" verb=\"%s\">\n",
  "%*s<dockitem name=\"%s\">\n",
  "%*s<placeholder name=\"%s\">\n",
  "%*s<placeholder name=\"%s\">\n",
  "%*s<popups>\n",
  "%*s<menuitem name=\"%s\" verb=\"%s\"/>\n", 
  "%*s<toolitem name=\"%s\" verb=\"%s\"/>\n", 
  "%*s<separator/>\n"
};

static const gchar *close_tag_format[] = {
  "%*s</UNDECIDED>\n",
  "%*s</Root>\n",
  "%*s</menu>\n",
  "%*s</submenu>\n",
  "%*s</dockitem>\n",
  "%*s</placeholder>\n",
  "%*s</placeholder>\n",
  "%*s</popups>\n",
  "",
  "",
  ""
};

static void
print_node (GtkMenuMerge *self, 
	    GNode        *node, 
	    gint          indent_level,
	    GString      *buffer)
{
  gint i;
  GtkMenuMergeNode *mnode;
  GNode *child;

  mnode = node->data;

  g_string_append_printf (buffer, open_tag_format[mnode->type],
			  indent_level, "",
			  mnode->name, 
			  g_quark_to_string (mnode->action_name));

  for (child = node->children; child != NULL; child = child->next) 
    print_node (self, child, indent_level + 2, buffer);

  g_string_append_printf (buffer, close_tag_format[mnode->type],
			  indent_level, "");

}

/**
 * gtk_menu_merge_get_ui:
 * @self: a #GtkMenuMerge
 * 
 * Creates an XML representation of the merged ui.
 * 
 * Return value: A newly allocated string containing an XML
representation of 
 * the merged ui.
 **/
gchar*
gtk_menu_merge_get_ui (GtkMenuMerge   *self)
{
  GString *buffer;

  buffer = g_string_new (NULL);

  gtk_menu_merge_ensure_update (self); 
 
  print_node (self, self->private_data->root_node, 0, buffer);  

  return g_string_free (buffer, FALSE);
}







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