Need help creating first modal

I want the user to be able to give a name of his choosing to each playlist he may create, typed in from the keyboard. The name he adds will also be the name of the xml file that holds the list of audio files.

I am trying to do this with a modal. My problem is I cannot get the modal to show itself.

The modal should open immediately after the user closes the file chooser, from which he selected multiple audio files for the playlist.

This is the state of my modal code, which does compile:

    setOpaque(true);
    std::unique_ptr<AlertWindow> alertWindow = std::make_unique<AlertWindow>("Name",
                                                                                  "enter a name for the new playlist",
                                                                                  MessageBoxIconType::NoIcon);
    
    alertWindow->getLookAndFeel();
    addAndMakeVisible(alertWindow.get());
    alertWindow.get()->setVisible(true);
    alertWindow->addTextEditor("text", "enter some text here", "text field:");
    alertWindow->addButton("OK", 1, KeyPress(KeyPress::returnKey, 0, 0));
    alertWindow->addButton("Cancel", 0, KeyPress(KeyPress::escapeKey, 0, 0));
    alertWindow->enterModalState();
    alertWindow->setVisible(true);
    String plName = alertWindow->getTextEditorContents("text");
    alertWindow->setVisible(false);
    alertWindow->exitModalState(0);

All the tricks I have tried - approaching different ways to make it visible, making sure it has a colour scheme, making sure it is opaque, etc. - have failed.

What is the proper way to execute this simple task?

The content of your unique_ptr will get destroyed right after your function or block of code have been executed and therefore there will be nothing left to display. Try something like this instead:

				auto alertWindow = new AlertWindow("Name", "enter a name for the new playlist",	MessageBoxIconType::NoIcon);
				alertWindow->addButton("OK", 1, KeyPress(KeyPress::returnKey, 0, 0));
				alertWindow->addButton("Cancel", 0, KeyPress(KeyPress::escapeKey, 0, 0));
				alertWindow->enterModalState(true, nullptr, true);

You might want to replace the nullptr in the enterModalState call with a callback function to handle the users choice. Just have a look in Component.h