@@ -460,40 +460,53 @@ void DraggableTabComponent::popupMenuClickOnTab (int tabIndex, const String& tab
460460void DraggableTabComponent::showTabNameEditor (int tabIndex, const String& tabName)
461461{
462462 auto * tabButton = getTabbedButtonBar ().getTabButton (tabIndex);
463- int nodeId = tabNodeIds[tabIndex];
463+ const int nodeId = tabNodeIds[tabIndex];
464464
465465 // create a label to edit the name
466466 Label* editNameLabel = new Label (" EditName" , tabName);
467467 editNameLabel->setFont (FontOptions (" Inter" , " Regular" , 16 .0f ));
468468 editNameLabel->setEditable (true , false , true );
469469 editNameLabel->setSize (100 , 20 );
470470 editNameLabel->setColour (Label::backgroundColourId, findColour (ThemeColours::widgetBackground));
471- editNameLabel->showEditor ();
472471
473- // set the text change callback
474- editNameLabel->onTextChange = [this , tabIndex, nodeId, editNameLabel]()
472+ editNameLabel->onEditorHide = [this , nodeId, editNameLabel]()
475473 {
476- setTabName (tabIndex, editNameLabel->getText ());
477- getTabbedButtonBar ().getTabButton (tabIndex)->setName (editNameLabel->getText ());
474+ const int currentTabIndex = tabNodeIds.indexOf (nodeId);
475+
476+ if (currentTabIndex < 0 )
477+ {
478+ return ;
479+ }
480+
481+ const String newTabName = editNameLabel->getText ();
482+ setTabName (currentTabIndex, newTabName);
478483
479484 // update the tab text in the VisualizerEditor
480485 GenericProcessor* processor = AccessClass::getProcessorGraph ()->getProcessorWithNodeId (nodeId);
481486 if (processor != nullptr && processor->getEditor ()->isVisualizerEditor ())
482487 {
483488 VisualizerEditor* editor = (VisualizerEditor*) processor->getEditor ();
484- editor->tabText = editNameLabel-> getText () ;
489+ editor->tabText = newTabName ;
485490 }
486-
487- // dismiss the callout box
488- if (auto * parent = editNameLabel->getParentComponent ())
489- parent->exitModalState (0 );
490491 };
491492
492493 auto tabBounds = tabButton->getScreenBounds ().withTrimmedBottom (tabButton->getHeight () / 2 );
493494
494495 // launch the callout box at the tab button's center position
495496 auto & editBox = CallOutBox::launchAsynchronously (std::unique_ptr<Component> (editNameLabel), tabBounds, nullptr );
496497 editBox.setDismissalMouseClicksAreAlwaysConsumed (true );
498+
499+ Component::SafePointer<Label> safeEditNameLabel (editNameLabel);
500+ MessageManager::callAsync ([safeEditNameLabel]()
501+ {
502+ if (safeEditNameLabel != nullptr )
503+ {
504+ safeEditNameLabel->showEditor ();
505+
506+ if (auto * editor = safeEditNameLabel->getCurrentTextEditor ())
507+ editor->selectAll ();
508+ }
509+ });
497510}
498511
499512void DraggableTabComponent::takeComponentSnapshot (int tabIndex, const String& tabName)
0 commit comments