unfocusAllComponents on textEditorReturnKeyPressed


#1

EDIT: Posted wrong thing last time.

So the behavior I'm looking for is to unfocus, and return the value to the label after being in a textEditor and hitting the return key. I have a custom label class. I have tried adding the unfocus call inside the custom label class, and in the parent component and neither works. Here is what it looks like inside the parent component:

 

void TestProcessorEditor::editorShown (Label * l, TextEditor & ed){
    ed.addListener(this);
}

void TestAudioProcessorEditor::editorHidden (Label * l, TextEditor & ed){
    ed.removeListener(this);
}

void TestAudioProcessorEditor::textEditorReturnKeyPressed (TextEditor & ed){
    unfocusAllComponents();
}

On top of that, I get a strange behavior where the first time I open the plugin window and change a value, then hit enter, the value does change, but not until the next timer callback. After the first time, it doesn't work anymore. I've debugged it and confirmed that unfocusAllComponents is in fact being called, but it doesn't do anything.


#2

So making a custom label class, I made a new textEditorReturnKeyPressed method, and added a listener to the text editor. I finally figured out that this method is being called, but not when hitting the return key, it only gets called when you click out of the box to get focus on another object.

 

TextEditor* CustomLabel::createEditorComponent(){
    TextEditor* const ed = new TextEditor (getName());
    ed->setEscapeAndReturnKeysConsumed(false);
    ed->applyFontToAllText (getLookAndFeel().getLabelFont (*this));
    ed->setInputRestrictions(4,"1234567890.-");
    ed->TextEditor::addListener(this);
    
    copyAllExplicitColoursTo (*ed);
    
    copyColourIfSpecified (*this, *ed, textWhenEditingColourId, TextEditor::textColourId);
    copyColourIfSpecified (*this, *ed, backgroundWhenEditingColourId, TextEditor::backgroundColourId);
    copyColourIfSpecified (*this, *ed, outlineWhenEditingColourId, TextEditor::outlineColourId);
    return ed;
}

void CustomLabel::textEditorReturnKeyPressed (TextEditor & te){
    
    Label::textEditorReturnKeyPressed(te);
    unfocusAllComponents();
}

Any help? I have no idea why this method doesn't get called when return is pressed.