After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 668696 - GtkBuilder: change format of menus
GtkBuilder: change format of menus
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Class: GtkBuilder
unspecified
Other All
: Normal normal
: ---
Assigned To: GtkBuilder maintainers
GtkBuilder maintainers
Depends on:
Blocks:
 
 
Reported: 2012-01-25 23:27 UTC by Allison Karlitskaya (desrt)
Modified: 2012-01-27 13:35 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GtkBuilder: change format of menus (26.82 KB, patch)
2012-01-25 23:27 UTC, Allison Karlitskaya (desrt)
committed Details | Review
xslt transform for converting menus to the new format (1.23 KB, text/plain)
2012-01-25 23:28 UTC, Allison Karlitskaya (desrt)
  Details

Description Allison Karlitskaya (desrt) 2012-01-25 23:27:54 UTC
This change has been discussed for some time and recommended by many.  I
initially resisted it because it's much harder to hand-write the new
format.  Long story short is that I was foolish to try to create a
human-writable XML format in the first place...
Comment 1 Allison Karlitskaya (desrt) 2012-01-25 23:27:55 UTC
Created attachment 206141 [details] [review]
GtkBuilder: change format of menus

Change the format of GtkBuilder <menu> to be more in-line with the style
of the rest of GtkBuilder so that we can do translation in a consistent
way.

The format is now substantially more difficult to hand-write, but tools
should be along soon.

There is an xslt program attached to the bug to help you convert your
existing .ui files from the old format to the new one.
Comment 2 Allison Karlitskaya (desrt) 2012-01-25 23:28:40 UTC
Created attachment 206142 [details]
xslt transform for converting menus to the new format
Comment 3 Matthias Clasen 2012-01-26 00:20:12 UTC
Review of attachment 206141 [details] [review]:

Otherwise, looks fine to me. Any idea what to do with the xslt - just post it to the list, maybe ?

::: gtk/gtkbuilder-menus.c
@@ +341,3 @@
+  g_free (state->context);
+
+  g_slice_free (GtkBuilderMenuState, state);

Should this print out some error message ?
What does the rest of gtkbuilder do ?
Comment 4 Allison Karlitskaya (desrt) 2012-01-26 00:41:53 UTC
Review of attachment 206141 [details] [review]:

::: gtk/gtkbuilder-menus.c
@@ +341,3 @@
+  g_free (state->context);
+
+  g_slice_free (GtkBuilderMenuState, state);

This is the subparser error handler.  Its job is to clean up the data allocated by the subparser.  The error is still reported to the error function of the main parser and returned from g_markup_parse_context_parse() in the usual way.
Comment 5 Allison Karlitskaya (desrt) 2012-01-26 00:42:36 UTC
Attachment 206141 [details] pushed as eed3077 - GtkBuilder: change format of menus
Comment 6 Allison Karlitskaya (desrt) 2012-01-26 00:53:08 UTC
(In reply to comment #3)
> Otherwise, looks fine to me. Any idea what to do with the xslt - just post it
> to the list, maybe ?

I wrote a mail to the list: https://mail.gnome.org/archives/gtk-devel-list/2012-January/msg00118.html
Comment 7 Paolo Borelli 2012-01-26 08:39:05 UTC
Since we are changing the format and moving the code to gtk, can you also consider the use of <object type=menu> instead of <menu>? When we chatted on irc you said that the main reason to use a different tag not consistent with gtk_builder_get_object() was that the code was in glib...
Comment 8 Allison Karlitskaya (desrt) 2012-01-26 14:28:17 UTC
I was going to do it like:

  <object type='GMenu'>

but I didn't like that for two reasons.

The first is that GMenu doesn't (really, can't) implement GtkBuildable, so it would still be an exceptional case without looking like one.

The second issue is that it would clash with the nesting of menus as submenus or sections -- <submenu> <section> or <link> can all result in the creation of a new GMenu.

The content of the section is also syntactically distinct, which implies (at least to me) that there should be a different tag to introduce it -- from the standpoint of trying to specify the syntax of the file format in a DTD, for example.  I don't consider this to be a substantial point since other uses of GtkBuildable are already breaking this rule...

glade is going to have to be taught about the new format as it is, so I don't see any harm in having a slightly different way of introducing the section.  The main difficulty with the old format (life being miserable for translators) has been overcome with this change.
Comment 9 Tristan Van Berkom 2012-01-27 08:36:40 UTC
(In reply to comment #8)
> I was going to do it like:
> 
>   <object type='GMenu'>
> 
> but I didn't like that for two reasons.
> 
> The first is that GMenu doesn't (really, can't) implement GtkBuildable, so it
> would still be an exceptional case without looking like one.

Firstly, objects don't have to be buildable to be built by the builder
(I know everyone knows that already anyway) and secondly, this would be
a perfect time to pull back GtkBuilder/GtkBuildable interface into
the glib stack.

I don't have the irc log on hand, but I distinctly recall that an
excuse for rushing GtkBuilder apis into the GTK+ (2.10 ?) release
was that "even though we all agree this api belongs in glib, we
can always pull it back into glib and wrap these apis with the
GtkBuilder/GtkBuildable apis", GtkBuildable could essentially
just be a forward declaration/typedef.

Pulling these apis back into say, libgio or libgobject constitutes
no real coding work anyway, it's really just a matter of simply wrapping
the GtkBuilder api from GTK+ and editing some makefiles...

> 
> The second issue is that it would clash with the nesting of menus as submenus
> or sections -- <submenu> <section> or <link> can all result in the creation of
> a new GMenu.

This sounds like perfectly valid GtkBuilder syntax to me, this type of
case is exactly why we introduced <child type="keyword"> apis at the
GtkBuilder level (and handle that with the
GtkBuildable->add_child (buildable, child_type, child) method).

In normal GtkBuilder terms you would simply define <child type="section">
or <child type="submenu"> to distinguish in what context the child GMenu
would be added to it's parent menu.

> The content of the section is also syntactically distinct, which implies (at
> least to me) that there should be a different tag to introduce it -- from the
> standpoint of trying to specify the syntax of the file format in a DTD, for
> example.  I don't consider this to be a substantial point since other uses of
> GtkBuildable are already breaking this rule...
> 
> glade is going to have to be taught about the new format as it is, so I don't
> see any harm in having a slightly different way of introducing the section. 
> The main difficulty with the old format (life being miserable for translators)
> has been overcome with this change.

Integrating GMenu into Glade using normal builder syntax will probably cost
25% of the effort of integrating GMenu into Glade using a custom syntax
(that's modest, it could be more like 10%).

The hard parts consist of:
  a.) Special casing the different contexts in which to add submenus,
      at least we have machinery to handle the regular <child type="foo">
      in place already.

  b.) What object is created by this builder fragment ? is it just some
      kind of metadata that is "there" ? in any case from Glade's POV
      there must be an object type involve which it's building, possibly
      this is the custom content of a GtkMenuBar ?

      Even so, managing the whole "menu hierarchy" as a custom hierarchy
      from Glade is a very nonsensical thing to to, instead handling
      the addition and removal of individual GMenu objects, handling
      their own custom syntaxes when they come up, makes much more sense
      and constitutes less code to write.
Comment 10 Allison Karlitskaya (desrt) 2012-01-27 13:35:31 UTC
It's not possible to use the normal syntax because the children of a GMenu are not GObjects.