"Universal" solution for Apply vs Try/Revert vs ...




On Sun, 21 Nov 1999, Sarel J. Botha wrote:

> On Fri, Nov 19, 1999 at 02:53:32PM +0100, Federico Cozzi wrote:
> > Mhhh... what does "close" mean, this way? "keep changes" or "discard"?
> > Why not an "OK" button? I think every dialog should share the same set of
> > basic button ("OK" and "Cancel"), plus some special button (i.e.
> > "Try"/"Revert") when needed. As in the current gnomecc.
> > 
> 
> I like Try, Revert, Ok, Cancel. (That's all I think I need to say. This
> issue has been discussed MANY times and the only thing that matters now is
> how many people like each different way)
> 

A proposal: define a standard API for interaction with dialogs and let the
user choose the paradigm.

[ Sorry: this is a long post ... ]

Explanation: 
Suppose all the options you can modify with the dialog are internally
stored in a certain struct:

typedef struct {
	gboolean espresso, addSugar; /* for checkbuttons */
	gint temperature;	     /* sliders, etc. */
	gint kindOfMug;		     /* lists, etc. */
	gchar comments[100];	     /* text entry */
	...
} coffeeOptions;

the application that wants to use a Gnome dialog defines the following
functions:

gpointer get_data_from_dialog(GnomeDialog *d, gpointer user_data)
{
	coffeeOptions *opts = g_malloc(..);
	opts->temperature = gtk_list_get...();
	...
	return opts;
}

void free_data(gpointer *opts, gpointer user_data)
{
	g_free(opts);
}

void set_data_in_dialog(Gnomedialog *d, gpoiter opt, gpointer user_data)
{
	coffeeOptions *opts = opt;
	gtk_list_set...(opts->temperature,...);
	...
}

void apply_data(Gnomedialog *d, gpoiter opt, gpointer user_data)
{
  ... /* really use the new temperature, etc. */
}

(The API could be slightly different, of course! But you get the idea.)

This requires a bit of effort from the programmer, but I don't think it's
much harder than the current way.

Now: the application pass to gnome_dialog_run the pointers to
get_data_from_dialog, free_data, set_data_in_dialog, apply_data and 
the dialog itself _without buttons_ (i.e. without the current GnomeDialog
action_area).

Now the gnome libs add the buttons to the action area according to a
global setting (set in Gnome Control Center): here is shown the actions
taken by gnome libs.

Apply paradigm:
--------------

Add Buttons: OK, Apply, Close

if OK:		get_data_from_dialog
		apply_data
		free_data
		gnome_dialog_close

if Apply:	get_data_from_dialog
                apply_data
                free_data

if Close:	gnome_dialog_close

Try/Revert (1st flavour) paradigm:
---------------------------------

Add Buttons:	Try, Revert, OK, Cancel

on creation:	old = get_data_from_dialog

if Try:		new = get_data_from_dialog
		apply_data(new,..)
		free_data(new)

if Revert:	set_data_in_dialog(old,...)
		apply_data(old,...)

if OK:		new = get_data_from_dialog
		apply_data(new,..)
                free_data(new)
		free_data(old)
		gnome_dialog_close

if Cancel:	apply_data(old)
		free_data(old)
		gnome_dialog_close

Try/Revert (2nd flavour) paradigm:
---------------------------------

Add Buttons:    Try, Revert, Close

on creation:    old = get_data_from_dialog

if Try:         new = get_data_from_dialog
                apply_data(new,..)
                free_data(new)

if Revert:      set_data_in_dialog(old,...)
                apply_data(old,...)  
                
if Close:       new = get_data_from_dialog
                apply_data(new,..)
                free_data(new)
                free_data(old)
                gnome_dialog_close
                
Ok/Cancel paradigm:
------------------

This is left as an exercise for the reader ;-)

Any comment?
Zun.



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