Hey there, I’ve currently got an issue in a preset manager I’m making. Below is the implementation of the deletePreset function that should delete the selected preset.
The alert window doesnt return true no matter what button I click.
It worked fine before adding the showOkCancelBox logic (ie it immediately deleted the file), but now that I want to add the confirmation box the code never runs since the Alert Window never returns true.
For some context (if it even helps), my PresetManager is defined in the Plugin Processor as follows
// in the PluginProcessor constructor
presetManager = std::make_unique<Service::PresetManager>(apvts);
And below is the deletePreset implementation
void PresetManager::deletePreset(const String& presetName)
{
if (presetName.isEmpty())
return;
const auto presetFile = defaultDirectory.getChildFile(presetName + "." + extension);
if (!presetFile.existsAsFile())
{
DBG("Preset file " + presetFile.getFullPathName() + " does not exist");
jassertfalse;
return;
}
// Show confirmation before deleting
bool actuallyDelete = AlertWindow::showOkCancelBox(
AlertWindow::WarningIcon,
"Delete Preset",
"Are you sure you want to delete the preset \"" + presetName + "\"?",
"Delete",
"Cancel",
nullptr,
nullptr
);
DBG(presetFile.getFullPathName());
DBG( (actuallyDelete ? "Deleting" : "Not deleting") );
// we do actually want to delete the file
if (actuallyDelete)
{
presetFile.setReadOnly(false);
if (!presetFile.deleteFile())
{
DBG("Preset file " + presetFile.getFullPathName() + " could not be deleted");
jassertfalse;
return;
} else {
DBG("Preset file " + presetFile.getFullPathName() + " deleted");
}
currentPreset.setValue("");
}
}
