TextEditor: No Listener callbacks


#1

I have added one TextEditor UI element with the Introjucer as a subcomponent. All the other UI subcomponents automatically added a listener (and the needed inheritances) but not with the TextEditor. So I tried to do that manually with inherit from TextEditor::Listener and adding the method "textEditorReturnKeyPressed(TextEditor* textEditorThatWasChanged)" for example.

But this did not work at all (but the program compiled without any warnings or errors).

After looking for any kind of similar problems via google and inside the Juce forum I did not came accross anything that would help me understand my problem.

For the record, by adding the TextEditor UI subcomponent with the Introjucer, the following code was automatically generated:

addAndMakeVisible (source_id_text_editor = new TextEditor ("source_id_text_editor"));
source_id_text_editor->setMultiLine (false);
source_id_text_editor->setReturnKeyStartsNewLine (false);
source_id_text_editor->setReadOnly (false);
source_id_text_editor->setScrollbarsShown (true);
source_id_text_editor->setCaretVisible (true);
source_id_text_editor->setPopupMenuEnabled (true);
source_id_text_editor->setText (String::empty);

Does anyone have an idea why:

1. The introjucer did not automatically add the inheritance from TextEditor::Listener or TextEditorListener (deprecated)

2. If I add the inheritance, add a Listener to the source_id_text_editor and implement textEditorReturnKeyPressed(TextEditor* textEditorThatWasChanged) manually why the function does not get called

I am using the architecture from the redwoodaudio tutorial: http://www.redwoodaudio.net/Tutorials/juce_for_vst_development__intro.html. Adding Sliders, Buttons or a ComboBox for example works perfectly and the Introjucer adds the needed setup code with "addListener(..)" functions and the needed inheritance except with the TextEditor UI component.


#2

I think you may be forgetting to add your component as one of the TextEditor's Listeners. In the component's constructor you'd have to add something like:


//[UserPreSize]
source_id_text_editor->addListener(this);
//[/UserPreSize]

Here's a project where the callbacks work: https://www.dropbox.com/s/v4m49ezbtoa5g0d/TextEdit.zip?dl=0

Not sure why it doesn't get automatically generated. It's pretty painless to do manually though so no worries.

Let me know if that works.

Cheers

m


#3

No, adding the Listener manually does not change anything -> callback functions are not called.

I am using the JUCE Audio Plugin Host for testing, I will try on another Host just for being sure its the same result.


#4

After manually implementing everything that is needed for the TextEditor I saw that the function to override does not look like:

textEditorReturnKeyPressed(TextEditor* textEditorThatWasChanged)

Instead, the Listener calles this function by reference:

textEditorReturnKeyPressed(TextEditor &textEditorThatWasChanged)

As any other component I used till now, the Listener callbacks look like:

callbackFunction(Type* object)

This is not the case with the callback function of TextEditor::Listener. Happy to have a working callback now and maybe reading the doc more carefully I would have never had this problem ;-)


#5

This is exactly why you should always use the override keyword :)