Hot Door CORE Forum

Full Version: modal dialog preview
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How could one add a preview option to a modal dialog to show the result of its settings before the user commits with the OK button? Perhaps a future CORE release could demonstrate that in the Tool sample project.
(01-17-2018, 11:43 AM)Rick Johnson Wrote: [ -> ]How could one add a preview option to a modal dialog to show the result of its settings before the user commits with the OK button? Perhaps a future CORE release could demonstrate that in the Tool sample project.

This isn't possible in Illustrator. A modal dialog, by definition, blocks the main thread of the app, and it is within this thread that all communication with Illustrator must occur. If it works for your use case, a floating dialog can be used instead, since it does not block the main thread (we do this in a plugin or two ourselves).
Hmmm, that confirms my understanding of a modal dialog, but I'm stumped by the preview option in Illustrator's Transform Each, Path > Simplify, and other windows. I wonder how they did that, and if a similar behavior could be accomplished entirely, or at least mostly, within CORE.
Wait, it CAN be done!

In a callback for e.g. a text field called when settings change, add something like this:

Code:
    this->myModalDlg.dismiss();
    goDrawStuff();
    HDI_CORE_ILLUSTRATOR->currentDocument()->redraw();
    this->myModalDlg.show();

Of course, you'll want to add more code so the temporary art is removed after each update or cancel, but kept if the user clicks OK. At least with simple art redraws there's no discernible flickering of the dialog.

Simple, but by golly, it works! :-)
I implemented a checkbox to turn previewing on, but its behavior is a bit erratic. The checkbox's callback dismisses and then shows the dialog, then it seems to forget it has a callback until clicked again several times. When it does get called, it works correctly. Reassigning the callback with PreviewChk.setClickCallback(...)) at the end of the callback doesn't help. The stepper widget may provide some clues. If the dialog is dismissed and then shown again, on the first click it gets "stuck" in the pressed position, then the second click calls the callback just fine.

Code:
// some variables declared in the .hpp header
hdi::core::ModalDialog modalDlg
hdi::core::Checkbox PreviewChk
hdi::core::Art previewArt
bool PreviewOn;
hdi::core::Art goDrawSomething();

// the checkbox's callback in the .cpp file
void thePlugin::Plugin::__doPreviewChkCB(){
    this->modalDlg.dismiss();
    this->PreviewOn = (this->PreviewChk.state() == hdi::core::Checkbox::StateOn);
    if (!this->previewArt.isEmpty())
        this->previewArt.dispose();
    if (this->PreviewOn)
        this->previewArt = goDrawSomething();
    HDI_CORE_ILLUSTRATOR->currentDocument()->redraw();
    this->modalDlg.show();
}

Is it possible that some context operations could solve this issue? Hot Door's NitPicker has a preview function; is that done with annotations?

For the benefit of others, the OK and Cancel callbacks work fine. The callback for Cancel deletes this->previewArt if it exists. The callback for OK deletes this->previewArt if it exists, then calls goDrawSomething();