To do so, I derived a new class from TextEditor and ActionBroadcaster. I overrode inputAttemptWhenModal() to get the text from the TextEditor, and send it as an action message to a listener.
The code to edit the tab then looked like this:
mEditLabel = new CTabLabelTextEditor(T("Tab Label"));
mTabLabelBeingEdited = tabIndex;
mEditLabel->setText(tabName);
addAndMakeVisible(mEditLabel);
mEditLabel->setBounds(theLabelXPos, Ypos, w, h);
mEditLabel->setSelectAllWhenFocused(true);
mEditLabel->grabKeyboardFocus();
mEditLabel->enterModalState(); //make the editor modal, so clicks outside the box will delete it
mEditLabel->addActionListener(this); //listen to messages from the text editor
You can’t trigger the editing with a click or double click (that changes tabs!), so I used a right click to allow editing, and put this code into an overridden popupMenuClickOnTab() method in my tab class.
Igor, thanks for your code… I’ll try it but i don’t know if is exactly what i want.
What i exactly want is that when i create a new tab, or when i double click in one, the name of the tab becomes editable so you can change it directly on the tab, not in a new popup window.
And auspuff, what means +1? It means that you want do the same? Sorry, I’m new with juce and in the forum i maybe i dont understand
[quote=“loca”]Hi
What i exactly want is […] when i double click in one, the name of the tab becomes editable
[/quote]
You’re going to get in trouble there. How will juce know if you’re intending to click on a tab to change to a new tab, or if you’re intending to edit the name. I think you’ll be better off finding another way (like a right click) to indicate that you want to change the tab name
The above code will do that. You can set the TextEdit component that appears to sit right on top of the tab’s name, and type into that. It will give the illusion of editing the name directly, and won’t as if you’ve opened a new window.