Text Editor without dirty bit

$Adam's icon

Dear Developers,

I'm developing a non-UI external that extracts the spectral peaks and does envelope following based on the content of a given buffer. During this process, I'd like to show a text editor window with the actual analysis and let the user refine the results manually before proceeding. My problem is that by using the suggested way of the SDK (creating a text editor with object_new(CLASS_NOBOX, gensym("jed"), (t_object *)x, 0) and then implementing the edclose method), if I modify the content of the window (so that I set the dirty bit) I'm always getting a popup window asking me whether I wanted to save the text file or not when I close the text editor. Is there a way to create a text editor that wouldn't care for the dirty bit?

Thanks,
Ádám

danieleghisi's icon

I'm doing this by adding an okclose method, like this:

void yourobj_okclose(t_yourobj *x, char *s, short *result)
{
    *result = 3;
}

Don't ask me the reason for the 3: I probably found it somewhere in the sdk, but I don't remember where :-)

Daniele

Luigi Castelli's icon

Here is the code that calls the 'okclose' method.

JKC was nice enough to post it in some other thread.

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;
}

Cheers.

- Luigi