How to focus TexEditor in modal dialog

Hi jucers,
well the title is self explaining. I have a simple modal dialog on which there is a TextEditor. When I display the dialog I want to be able to type in the TextEditor right away without having to click on it first. This seems like a trivial task but I am just not able to do this. Probably I (yet again) miss some basic juce principle.

I create the dialog like this:

Component* component = new EditTimeSignatureDialog(this, e);

DialogWindow::LaunchOptions options;
options.dialogTitle = TRANS("Edit time signature event");
options.resizable = false;
options.content.setOwned(component);
options.launchAsync();

Inside my EditTimeSignatureDialog, first I tried to call textEditor->grabKeyboardFocus() directly but that was no good because when the object is constructed the Component is not yet visible therefore it fails in grabFocusInternal on the first line (isShowing()).

So I changed it a bit so that the grabKeyboardFocus is called from visibilityChanged() callback of my dialog component. And… it still fails in isShowing(), only this time it falls through the whole function to the return false line at the end.

I can see in the code, why it does not work, but I just don’t see, how am I supposed to achieve what I want then. This is a pretty common thing so I guess there will be a simple answer.

Thanks a lot!
Aros

//edit: This is probably the same problem as in:

Just to conclude this thread. Since I got no better suggestion, I ended up using the solution from the thread linked above - a Timer set to 100 ms.

1 Like