Forums > Dev

okclose

May 3, 2011 | 4:57 pm

Hi.

I want an external to display a text editor, and – when the editor gets closed – behave more or less like coll.

I had a look at the coll source file, in the 4.5.5 SDK, and found there is an "okclose". I’d love to have more info about it:

- how does the "result" argument behave?

- In the example, the otherwise undocumented advise() function is called (prototyped in ext_proto.h). A quick search in the Max 5.1.7 framework shows two other seemingly related functions: advise_explain() (also in ext_proto.h) and wind_advise() (in ext_wind.h). Which one should I use in a "new style" object? Would advise_explain() (my favorite one, with custom text for the buttons) be ok?

Thank you very much!
aa


May 8, 2011 | 8:24 pm

Here’s the code which calls it, which should be self explanatory.

Have fun!

-Joshua

sprintf(msg, "Save changes to "%s" before closing?", filename->s_name);
// give our owner a chance to take control
okclose = zgetfn(p->v_owner, gensym("okclose"));
if (okclose) {
	short result = 0;	// changed from long to short to fix ppc bug
	object_method(p->v_owner, gensym("okclose"), msg, &result);
	switch (result) {
		case 0:		/* normal thing */
		case 1:		/* they changed the string */
			break;
		case 2:		/* don't put up a dialog, clear dirty bit */
			object_attr_setchar(p->v_owner, ps_dirty, 0);
		case 3:		/* don't put up a dialog */
			goto skipalert;
		case 4:		/* act as though user "cancelled" */
			return (void*) -1;
		default:
			break;
	}
}
res = wind_advise((t_object*) p, msg);
switch (res) {
	case ADVISE_SAVE:
		if (jwind_save(p))
			return (void*) -1;		// error saving, treat as cancel
		break;
	case ADVISE_CANCEL:
		return (void*) -1;
	case ADVISE_DISCARD:
		object_attr_setchar(p->v_owner, ps_dirty, 0);
		break;
}

May 8, 2011 | 8:24 pm

Here’s the code which calls it, which should be self explanatory.

Have fun!

-Joshua

sprintf(msg, "Save changes to "%s" before closing?", filename->s_name);
// give our owner a chance to take control
okclose = zgetfn(p->v_owner, gensym("okclose"));
if (okclose) {
	short result = 0;	// changed from long to short to fix ppc bug
	object_method(p->v_owner, gensym("okclose"), msg, &result);
	switch (result) {
		case 0:		/* normal thing */
		case 1:		/* they changed the string */
			break;
		case 2:		/* don't put up a dialog, clear dirty bit */
			object_attr_setchar(p->v_owner, ps_dirty, 0);
		case 3:		/* don't put up a dialog */
			goto skipalert;
		case 4:		/* act as though user "cancelled" */
			return (void*) -1;
		default:
			break;
	}
}
res = wind_advise((t_object*) p, msg);
switch (res) {
	case ADVISE_SAVE:
		if (jwind_save(p))
			return (void*) -1;		// error saving, treat as cancel
		break;
	case ADVISE_CANCEL:
		return (void*) -1;
	case ADVISE_DISCARD:
		object_attr_setchar(p->v_owner, ps_dirty, 0);
		break;
}

May 9, 2011 | 7:34 am

thank you Joshua!
aa


May 9, 2011 | 7:34 am

thank you Joshua!
aa


Viewing 5 posts - 1 through 5 (of 5 total)