User prompt to save the project before exiting (threads)


#1

Hi, I have small problem which I'm not sure how to tackle the best...

 

I have put some classic save handling (Save/Don't Save/Cancel) to tryToQuitApplication();

 

bool tryToQuitApplication(){        
        if (contentComponent->canQuit()) return true;
        
        int result = AlertWindow::showYesNoCancelBox(AlertWindow::AlertIconType::QuestionIcon, L"Save?", L"Do you want to save changes?", L"Save", L"Don't save", L"Cancel");
        switch (result)
        {
        case 0: return false;
        case 1: contentComponent->save(); return true;
        default:
            break;
        }
        //prompt to save
        return true;
    }

 

No I have a problem if user selects the option to save the project. The saving logic is implemented using threads (namely ThreadWithProgressWindow) because it takes some time. The problem is that the thread window is freed after threadComplete which is executed "next time" in the message thread. So I either need to somehow postpone the "application closing" or implement the whole thing again without the thread and use that just for the case of application exiting. What is the best way of implementing this?


#2

You should avoid blocking with modal loops, it's always better to make things happen asynchronously using Timers, CallbackMessages, etc.

And this is OT, but never write your strings with 'L' in front of them! See my coding standards page for more info.


#3

You should avoid blocking with modal loops, it's always better to make things happen asynchronously using Timers, CallbackMessages, etc.

You suggest not to use AlertWindow at all then? I am not sure now if you are refering to handling the saving (meaning to inform the app to close on message thread when the saving is done) or you don't like that modal AlertWindow there. Or both.

 

And this is OT, but never write your strings with 'L' in front of them! See my coding standards page for more info.

Got it. Thanks.


#4

You can use AlertWindows, but don't run a modal loop - make it modal asynchronously, and use a ModalComponentManager::Callback for it to tell you the result.