diff --git a/plugin/components/modal_textinputbox.h b/plugin/components/modal_textinputbox.h index 9a73728..b95a8fa 100644 --- a/plugin/components/modal_textinputbox.h +++ b/plugin/components/modal_textinputbox.h @@ -18,7 +18,7 @@ class ExclusionFilter : public juce::TextEditor::InputFilter }; -static void show_async_text_input(juce::String title, juce::String message, std::function callback, std::optional> validator=std::nullopt) +static juce::AlertWindow* show_async_text_input(juce::String title, juce::String message, std::function callback, std::optional> validator=std::nullopt) { auto* window = new juce::AlertWindow(title, message, juce::AlertWindow::NoIcon); window->addTextEditor("textField", "", ""); @@ -39,10 +39,16 @@ static void show_async_text_input(juce::String title, juce::String message, std: } } - callback(textEditor->getText(), true); window->exitModalState(0); + callback(textEditor->getText(), true); + window->exitModalState(0); + window->setVisible(false); }; }; - auto finalize_cancel = [window, textEditor, callback]() { callback(textEditor->getText(), false); window->exitModalState(0); }; + auto finalize_cancel = [window, textEditor, callback]() { + callback(textEditor->getText(), false); + window->exitModalState(0); + window->setVisible(false); + }; textEditor->onReturnKey = finalize_success; window->addButton("Ok", 1); @@ -51,7 +57,9 @@ static void show_async_text_input(juce::String title, juce::String message, std: window->getButton("Cancel")->onClick = finalize_cancel; window->setAlwaysOnTop(true); - window->enterModalState(true, nullptr, true); + window->enterModalState(true, nullptr, false); textEditor->setWantsKeyboardFocus(true); textEditor->grabKeyboardFocus(); + + return window; } diff --git a/plugin/editor.cpp b/plugin/editor.cpp index f939d03..f4cabe7 100644 --- a/plugin/editor.cpp +++ b/plugin/editor.cpp @@ -41,6 +41,7 @@ struct YsfxEditor::Impl { YsfxInfo::Ptr m_info; YsfxCurrentPresetInfo::Ptr m_currentPresetInfo; ysfx_bank_shared m_bank; + std::unique_ptr m_editDialog; std::unique_ptr m_infoTimer; std::unique_ptr m_relayoutTimer; std::unique_ptr m_fileChooser; @@ -656,50 +657,54 @@ void YsfxEditor::Impl::popupPresetOptions() switch (index) { case 1: // Save - show_async_text_input( - "Enter preset name", - "", - [this](juce::String presetName, bool wantSave) { - std::string preset = presetName.toStdString(); - if (wantSave) { - if (m_proc->presetExists(preset.c_str())) { - juce::AlertWindow::showAsync( - juce::MessageBoxOptions() - .withTitle("Overwrite?") - .withMessage("Preset with that name already exists.\nAre you sure you want to overwrite the preset?") - .withButton("Yes") - .withButton("No") - .withParentComponent(this->m_self) - .withIconType(juce::MessageBoxIconType::NoIcon), - [this, preset](int result){ - if (result == 1) m_proc->saveCurrentPreset(preset.c_str()); - } - ); - } else { - m_proc->saveCurrentPreset(preset.c_str()); + m_editDialog.reset( + show_async_text_input( + "Enter preset name", + "", + [this](juce::String presetName, bool wantSave) { + std::string preset = presetName.toStdString(); + if (wantSave) { + if (m_proc->presetExists(preset.c_str())) { + juce::AlertWindow::showAsync( + juce::MessageBoxOptions() + .withTitle("Overwrite?") + .withMessage("Preset with that name already exists.\nAre you sure you want to overwrite the preset?") + .withButton("Yes") + .withButton("No") + .withParentComponent(this->m_self) + .withIconType(juce::MessageBoxIconType::NoIcon), + [this, preset](int result){ + if (result == 1) m_proc->saveCurrentPreset(preset.c_str()); + } + ); + } else { + m_proc->saveCurrentPreset(preset.c_str()); + } } } - } + ) ); return; case 2: // Rename - show_async_text_input( - "Enter new name", - "", - [this](juce::String presetName, bool wantRename) { - std::string preset = presetName.toStdString(); - if (wantRename) { - m_proc->renameCurrentPreset(preset.c_str()); - } - }, - [this](juce::String presetName) { - if (m_proc->presetExists(presetName.toStdString().c_str())) { - return juce::String("Preset with that name already exists.\nChoose a different name or click cancel."); - } else { - return juce::String(""); + m_editDialog.reset( + show_async_text_input( + "Enter new name", + "", + [this](juce::String presetName, bool wantRename) { + std::string preset = presetName.toStdString(); + if (wantRename) { + m_proc->renameCurrentPreset(preset.c_str()); + } + }, + [this](juce::String presetName) { + if (m_proc->presetExists(presetName.toStdString().c_str())) { + return juce::String("Preset with that name already exists.\nChoose a different name or click cancel."); + } else { + return juce::String(""); + } } - } + ) ); break; case 3: