Re: When is a UIComponent hooked?



Hi Federico,

On Wed, 23 May 2001, Federico Mena Quintero wrote:
> In the Evolution calendar I have the task list component, which embeds
> itself as a control inside the Evolution shell.  If zero tasks are
> selected I want the Edit/Delete and toolbar/Delete items to be
> insensitive; if one or more tasks are selected, I want them to be
> enabled.

	Great, so the task list component should be merging itself over
these items [ if they existed before ] and then it should be setting state
on them.

> However, it seems that I can get notifications about changes in the
> selection *before* the task list control binds itself to the parent
> container.  If I then call bonobo_ui_component_set_prop() before it is
> hooked to its parent, I get warning spewage.

	Correct. And for good reason - it is entirely possible that
another component, merged before you - has the same verb names,
eg. TasksDelete, and when you merge over the top these are concealed until
de-merge. Of course, if you set 'insensitive' on TasksDelete before you
are merged you go trampling on what is some other components setting -
which it [ reasonably ] assumes is sensitive. Upon de-merge you will have
inconsistant state underneath.

	Consequently you should be only poking at items that you have
merged really - unless there is some extra good reason. Anyway, the
original question was:

> > > Is there a way to know when a BonoboUIComponent gets connected to the
> > > parent Bonobo_UIContainer?  If I could get notification about this I
> > > could set the sensitivity of my commands as soon as I can.

	And the answer is yes - of course, you add the UIComponent
yourself to the remote container inside the 'activate' signal on the
control, so it's all in-proc with your selection handler.

> I had to fetch the container and test for it being non-NIL.
> 
> static void
> selection_changed_cb (ETasks *tasks, int n_selected, gpointer data)
> {
> 	BonoboControl *control;
> 	BonoboUIComponent *uic;
> 	Bonobo_UIContainer ui_container;
> 
> 	control = BONOBO_CONTROL (data);
> 
> 	uic = bonobo_control_get_ui_component (control);
> 	g_assert (uic != NULL);
> 
> 	ui_container = bonobo_ui_component_get_container (uic);
> 	if (ui_container == CORBA_OBJECT_NIL)
> 		return;
> 
> 	bonobo_ui_component_set_prop (uic, "/commands/TasksDelete", "sensitive",
> 				      n_selected == 0 ? "0" : "1",
> 				      NULL);
> }
> 
> but that sucks.

	It amazes me that your control can have its selection changed
before it has a view, and before it has been activated and merged its
menus. It sounds wierd to me.

	Regards,

		Michael.

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





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