Re: [gtk-list] Proper App Behaviour: Sensitivity Strategy?



Derek Simkowiak <dereks@kd-dev.com> writes: 
> 	I was hoping there was some way I could have the menuitem "watch"
> a particular variable, and then become insensitive automatically.
> 

A GtkBoolean object?

> 	What about a GtkAdjustment widget?  If it works for a "range" with
> scrollbars, couldn't it work for a boolean on a menuitem or button on a
> toolbar?  Then I could have my "Save" callback set that GtkAdjustment to
> "FALSE" (or 0.0, whatever) and all the items that depend on that-- the

Well:
 a) GtkAdjustment isn't a widget
 b) 0.0 is not FALSE

So you have two rather alarming type errors there. :-)

I think emitting a signal when sensitivity should change is a very
good idea though, if you drop the GtkAdjustment part. I would either
add an appropriate signal to some relevant object already in your app,
or write a GtkBoolean object (world's heaviest way to store one bit!).

A more trivial solution:

static gboolean foo = FALSE;
static GSList* widgets = NULL;

gboolean get_foo_setting()
{
 return foo;
}

void     set_foo_setting(gboolean value)
{
 GSList *iter;

 foo = value;

 iter = widgets;
 while (iter != NULL)  {
   gtk_widget_set_sensitive(GTK_WIDGET(iter->data), 
                            foo); /* or !foo, to taste */
   iter = g_slist_next(iter);
 }
}
void     watch_foo_setting(GtkWidget* widget)
{
 gtk_widget_set_sensitive(widget, foo);
 widgets = g_slist_prepend(widgets, widget);
/* maybe on widget destroy, remove it from the list */
}

void unwatch_foo_setting(GtkWidget* iwdget)
{
 widgets = g_slist_remove(widgets, widget);
}

Forgive the indentation, I'm not in cc-mode.

Havoc






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