Re: adding menu items dynamically



Hi Jason,

On Fri, 2003-02-14 at 04:02, Jason Hildebrand wrote:
> I'm working on bonobo-izing vim, and I'm currently working on the
> menubars.

	Sounds fun :-)

> I'm familiar with bonobo_ui_util_set_ui() for setting an entire UI from
> an XML file, and I've also played around with bonobo_ui_component_set()
> to set an XML fragment into the UI tree.

	Good - you've seen it all then really.

> What I'd like to do is be able to add a menu item dynamically, without
> replacing that menu's current items.  If I have:
> 
>     bonobo_ui_component_set(ui_component, "/menu", 
>     "<submenu name=\"File\" _label=\"_File\">
>       <menuitem name=\"FileNew\" verb=\"FileNew\"/>
>     </submenu>", NULL );
> 
> and I do
> 
>     bonobo_ui_component_set(ui_component, "/menu/File", 
> 	"<menuitem name=\"FileOpen\" verb=\"FileOpen\"/>", NULL );
> 
> then the FileNew item is replaced by the FileOpen item (understandably
> so).

	It shouldn't be - the FileOpen item should be appended to the menu -
that is assuming the 'name's are different. If they are the same they
will be overridden [ a feature ].

> Is there a way to simply _add_ a menu item, short of
> generating/concatenating the XML fragments together and then calling
> bonobo_ui_component_set() on the whole menu?  

	Nope, I'm afraid at the end of the day - what happens on the wire is an
XML fragment gets passed from A->B. The choice is between generating one
large fragment yourself and sending it in a batch, and some other more
painful process :-)

	So - yes; I'm afraid you need to generate them yourself.

> Since the menus are user-defined in vim there are not fixed and must be
> generated programmatically.  Is there are better way to do this than the
> above strategy?

	Nope; you're going to have to convert them to XML somehow, and push
them across. You prolly should poke at 'Placeholders' if some parts of
the menu are static, and some are not; you might also want to do:

	bonobo_ui_component_freeze  - stop flicker / speed up things
	bonobo_ui_component_rm      - remove old UI
	bonobo_ui_component_set_xml - merge new
	bonobo_ui_component_thaw ...

	How does that sound ?

	Regards,

		Michael.

-- 
 mmeeks gnu org  <><, Pseudo Engineer, itinerant idiot




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