Static Custom AlertWindow

gui
#1

Hi, in my iPad app I created this class to enter some text from virtual keyboard.
How you can see in my class I inherit “KeyListener” class, because I want to remove from screen this window when I press enter key. The strange thing is that every time (after the first time I create this window) I press my enter key, the button that if clicked on my mainComponent shows up this window is pressed:

HERE MY WINDOW CLASS:

class EnterTextDialogWindow : public AlertWindow, public KeyListener
{
public:
    // pass directly this static function to change a string (it create from himself the dialog window and when you press escape or return it pass what you have just wrote
    static String showEnterTextDialogWindow(String windowTitle)
    {
        
        ScopedPointer<EnterTextDialogWindow> enterTextDialog = new EnterTextDialogWindow {windowTitle};
        
        enterTextDialog->addKeyListener(enterTextDialog);
        enterTextDialog->runModalLoop();
        enterTextDialog->removeKeyListener(enterTextDialog);
        return enterTextDialog->getTextEditorContents(windowTitle);
    }
    
    EnterTextDialogWindow(String dialogTitle) : AlertWindow{dialogTitle, "", AlertWindow::NoIcon}
    {
        addTextEditor(dialogTitle, "enter-text");
        getTextEditor(dialogTitle)->setJustification(Justification::centred);
    }
    
    ~EnterTextDialogWindow() {}
    
private:
    
#if JUCE_IOS
    void resized() override
    {
        setTopLeftPosition(getX(), getY()/2);
    }
#endif
    
    bool keyPressed (const KeyPress& key, Component* originatingComponent) override
    {
        if (key == KeyPress::returnKey)
        {
            exitModalState(0);
        }
    }
    
#if JUCE_IOS
    void mouseDrag (const MouseEvent& event) override{}
#endif
    
};

HERE WHERE I USE IT:

void MainComponent::buttonClicked (Button* b)
{
if (b == &myTextButton)
{
    String name = EnterTextDialogWindow::showEnterTextDialogWindow("SetName");
    myOtherComponent.addItem(name, -1);
    myOtherComponent.getItemIstance(myOtherComponent.getNumOfItems() - 1)->changeName(name);
}

Any Ideas?
Thank you in advice!