diff --git a/plugin/components/modal_textinputbox.h b/plugin/components/modal_textinputbox.h index 975e3ef..529ef86 100644 --- a/plugin/components/modal_textinputbox.h +++ b/plugin/components/modal_textinputbox.h @@ -18,7 +18,7 @@ class ExclusionFilter : public juce::TextEditor::InputFilter }; -static juce::AlertWindow* 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, juce::Component* parent=nullptr) { auto* window = new juce::AlertWindow(title, message, juce::AlertWindow::NoIcon); window->addTextEditor("textField", "", ""); @@ -61,11 +61,15 @@ static juce::AlertWindow* show_async_text_input(juce::String title, juce::String textEditor->setWantsKeyboardFocus(true); textEditor->grabKeyboardFocus(); + if (parent) { + window->setCentrePosition(parent->getScreenPosition() + juce::Point{parent->getScreenBounds().getWidth() / 2, parent->getScreenBounds().getHeight() / 2}); + } + return window; } -static juce::AlertWindow* show_overwrite_window(juce::String title, juce::String message, std::vector buttons, std::function callback) +static juce::AlertWindow* show_option_window(juce::String title, juce::String message, std::vector buttons, std::function callback, juce::Component* parent=nullptr) { auto* window = new juce::AlertWindow(title, message, juce::AlertWindow::NoIcon); window->setMessage(message); @@ -89,5 +93,9 @@ static juce::AlertWindow* show_overwrite_window(juce::String title, juce::String window->grabKeyboardFocus(); window->setEscapeKeyCancels(true); + if (parent) { + window->setCentrePosition(parent->getScreenPosition() + juce::Point{parent->getScreenBounds().getWidth() / 2, parent->getScreenBounds().getHeight() / 2}); + } + return window; } diff --git a/plugin/components/rpl_view.cpp b/plugin/components/rpl_view.cpp index 7b04065..7b692fc 100644 --- a/plugin/components/rpl_view.cpp +++ b/plugin/components/rpl_view.cpp @@ -254,31 +254,27 @@ class LoadedBank : public juce::Component, public juce::DragAndDropContainer { if (names.empty()) return; - juce::AlertWindow::showAsync - ( - juce::MessageBoxOptions() - .withTitle("Are you certain?") - .withMessage( + m_confirmDialog.reset( + show_option_window( + TRANS("Are you certain?"), TRANS("Are you certain you want to delete ") + ((names.size() > 1) ? TRANS("several presets") : names[0]) - + "\n" + TRANS("This operation cannot be undone!") - ) - .withButton("Yes") - .withButton("No") - .withParentComponent(this) - .withIconType(juce::MessageBoxIconType::NoIcon), - [this, names](int result){ - if (result == 1) { - for (auto name : names) - { - m_bank.reset(ysfx_delete_preset_from_bank(m_bank.get(), name.c_str())); - } + + "?\n" + TRANS("This operation cannot be undone!"), + std::vector{"Yes", "No"}, + [this, names](int result){ + if (result == 1) { + for (auto name : names) + { + m_bank.reset(ysfx_delete_preset_from_bank(m_bank.get(), name.c_str())); + } - this->m_listBox->deselectAllRows(); - save_bank(m_file.getFullPathName().toStdString().c_str(), m_bank.get()); - if (m_bankUpdatedCallback) m_bankUpdatedCallback(); - } - } + this->m_listBox->deselectAllRows(); + save_bank(m_file.getFullPathName().toStdString().c_str(), m_bank.get()); + if (m_bankUpdatedCallback) m_bankUpdatedCallback(); + } + }, + this + ) ); } @@ -413,7 +409,7 @@ class LoadedBank : public juce::Component, public juce::DragAndDropContainer { if (ysfx_preset_exists(m_bank.get(), src_bank->presets[idx].name) && !force_accept) { // Ask for overwrite m_confirmDialog.reset( - show_overwrite_window( + show_option_window( TRANS("Are you certain?"), TRANS("Are you certain you want to overwrite the preset named ") + juce::String(src_bank->presets[idx].name) + "?", std::vector{"Yes", "No", "Yes to all", "Cancel"}, diff --git a/plugin/editor.cpp b/plugin/editor.cpp index 9ac4cd4..10d04f7 100644 --- a/plugin/editor.cpp +++ b/plugin/editor.cpp @@ -42,6 +42,7 @@ struct YsfxEditor::Impl { YsfxCurrentPresetInfo::Ptr m_currentPresetInfo; ysfx_bank_shared m_bank; std::unique_ptr m_editDialog; + std::unique_ptr m_modalAlert; std::unique_ptr m_infoTimer; std::unique_ptr m_relayoutTimer; std::unique_ptr m_fileChooser; @@ -70,6 +71,7 @@ struct YsfxEditor::Impl { void switchEditor(bool showGfx); void openCodeEditor(); void openPresetWindow(); + void quickAlertBox(bool confirmationRequired, std::function callbackOnSuccess, juce::Component* parent); static juce::File getAppDataDirectory(); static juce::File getDefaultEffectsDirectory(); juce::RecentlyOpenedFilesList loadRecentFiles(); @@ -433,20 +435,19 @@ void YsfxEditor::Impl::updateInfo() relayoutUILater(); } -void _quickAlertBox(bool confirmationRequired, std::function callbackOnSuccess, juce::Component* parent) +void YsfxEditor::Impl::quickAlertBox(bool confirmationRequired, std::function callbackOnSuccess, juce::Component* parent) { if (confirmationRequired) { - juce::AlertWindow::showAsync( - juce::MessageBoxOptions() - .withTitle("Are you certain?") - .withMessage("Are you certain you want to (re)load the plugin?\n\nNote that you will lose your current preset.") - .withButton("Yes") - .withButton("No") - .withParentComponent(parent) - .withIconType(juce::MessageBoxIconType::NoIcon), - [callbackOnSuccess](int result){ - if (result == 1) callbackOnSuccess(); - } + m_modalAlert.reset( + show_option_window( + "Are you certain?", + "Are you certain you want to (re)load the plugin?\n\nNote that you will lose your current preset.", + std::vector{"Yes", "No"}, + [callbackOnSuccess](int result){ + if (result == 1) callbackOnSuccess(); + }, + parent + ) ); } else { callbackOnSuccess(); @@ -490,7 +491,7 @@ void YsfxEditor::Impl::chooseFileAndLoad() [this, normalLoad, mustAskConfirmation](const juce::FileChooser &chooser) { juce::File result = chooser.getResult(); if (result != juce::File()) { - _quickAlertBox( + quickAlertBox( mustAskConfirmation, [this, normalLoad, result]() { if (normalLoad) saveScaling(); @@ -598,7 +599,7 @@ void YsfxEditor::Impl::popupRecentFiles() m_recentFilesPopup->showMenuAsync(popupOptions, [this, recent](int index) { if (index != 0) { juce::File selectedFile = recent.getFile(index - 100); - _quickAlertBox( + quickAlertBox( ysfx_is_compiled(m_info->effect.get()), [this, selectedFile]() { saveScaling(); @@ -675,23 +676,24 @@ void YsfxEditor::Impl::popupPresetOptions() 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()); - } + this->m_modalAlert.reset( + show_option_window( + "Overwrite?", + "Preset with that name already exists.\nAre you sure you want to overwrite the preset?", + std::vector{"Yes", "No"}, + [this, preset](int result){ + if (result == 1) m_proc->saveCurrentPreset(preset.c_str()); + }, + this->m_self + ) ); } else { m_proc->saveCurrentPreset(preset.c_str()); } } - } + }, + std::nullopt, + this->m_self ) ); return; @@ -713,7 +715,8 @@ void YsfxEditor::Impl::popupPresetOptions() } else { return juce::String(""); } - } + }, + this->m_self ) ); break; @@ -725,17 +728,16 @@ void YsfxEditor::Impl::popupPresetOptions() break; case 5: // Delete - juce::AlertWindow::showAsync( - juce::MessageBoxOptions() - .withTitle("Delete?") - .withMessage("Are you sure you want to delete the preset named " + m_currentPresetInfo->m_lastChosenPreset + "?") - .withButton("Yes") - .withButton("No") - .withParentComponent(this->m_self) - .withIconType(juce::MessageBoxIconType::NoIcon), + this->m_modalAlert.reset( + show_option_window( + "Delete?", + "Are you sure you want to delete the preset named " + m_currentPresetInfo->m_lastChosenPreset + "?", + std::vector{"Yes", "No"}, [this](int result) { if (result == 1) m_proc->deleteCurrentPreset(); - } + }, + this->m_self + ) ); break; case 6: @@ -958,7 +960,7 @@ void YsfxEditor::Impl::connectUI() YsfxInfo::Ptr info = m_info; ysfx_t *fx = info->effect.get(); juce::File file{juce::CharPointer_UTF8{ysfx_get_file_path(fx)}}; - _quickAlertBox( + quickAlertBox( ysfx_is_compiled(fx), [this, file]() { resetScaling(file);