Label::setText and editorAboutToBeHidden

Hi,

I’ve a chicken and egg issue with those method. I’ve overload a label, and in the editorAboutToBeHidden() method, I’m formatting the text of the label, thus calling Label::setText.
But, since the editor is still no hidden in there, it’s calling editorA…hidden() again, and overflow the stack.

I’ve tried to change the text of the TextEditor component, but it’s ignored when returning from the editorAb…dden() method.
I can add an asynchronous change, but it’s a PITA for such a simple operation.

So, I think the code in juce for juce_Label.cpp should read instead:

void Label::setText (const String& newText,
                     const bool broadcastChangeMessage)
{
    if (isBeingEdited())
        hideEditor (true);

    if (lastTextValue != newText)
    {

and 
void Label::hideEditor (const bool discardCurrentEditorContents)
{
    if (editor != 0)
    {
        WeakReference<Component> deletionChecker (this);

        ScopedPointer<TextEditor> temporaryEditor(editor.release());
        editorAboutToBeHidden (temporaryEditor);

        const bool changed = (! discardCurrentEditorContents)
                               && updateFromTextEditorContents(temporaryEditor);

        temporaryEditor = 0;
        repaint();

and 
void Label::textEditorReturnKeyPressed (TextEditor& ed)
{
    if (editor != 0)
    {
        jassert (&ed == editor);
        (void) ed;

        const bool changed = updateFromTextEditorContents(editor);

and 
bool Label::updateFromTextEditorContents(TextEditor * _editor)
{
    jassert (_editor != 0);
    const String newText (_editor->getText());

    if (textValue.toString() != newText)
    {

Thanks… I think that seems to make sense, I’ll see what I can do.

I can’t see why you changed this bit though:

if (isBeingEdited()) hideEditor (true);

…it doesn’t seem to make any difference?

If you don’t add the check, then setText() calls hideEditor() which in turns call editorAboutToBeHidden().
The idea of this change is that, as soon as you enter hideEditor(), the method isBeingEdited() returns false (and not when the editor is actually deleted).

To do so, instead of adding an additional “bool isInsideHideEditor” member, I’ve changed the code so that the “editor” member is reset to 0 in hideEditor (transfered to a temporary TextEditor scopedpointer), so that isBeingEdited returns false. The only impact is on the updateFromTextEditorContents() which I needed now to pass the TextEditor as a member (ideally, we could even pass a “const String & text” parameter instead and avoid using a TextEditor pointer at all).

I hope I’m clear.

Well, I think I got you now. Yes, isBeingEdited() call is useless since hideEditor checks for the “editor” member.