Small close button on editor tab is interestingly powerful, but functionality
click = close this document
Shift + click = Close All Documents
Alt + click = Close other documents
Therefore, add following tooltip on close button:
"Shift + click to close all documents, Alt + click to close other documents"
Easy to do, TM to 7.0
David Simonek agreed that he would review and integrate a patch for this issue contributed by the NetFIX  team.
I'm working on this issue and I was just wondering about the shortcuts; In my version 'close All Documents' as a
shortcut of 'Ctrl+Shift+W' and 'close other Documents' has no shortcut at all. If I should implement this issue, I guess
I have to go by the default shortcuts. Don't you think? Please let me know.
Well, I'm not sure I understand - it seems like you extended feature request and you would like to mention also
shortcuts in tooltip, is that right?
Personally I'd stick with simple solution and don't include shortcuts in tooltip, as shortcuts can be discovered in
popup menu of editor tab.
....but if you feel shortcuts should be mentioned in tooltip, then go for it - but it's not that easy. You shouldn't
hardcode shortcuts as they may vary across platforms etc. You will need:
1) Get access to action instance
2) retrieve shortcut from action's ACCELERATOR_KEY property (see javax.swing.Action)
3) convert KeyStroke to meaningful text -- see in spi.quicksearch module, class SearchResultRender, method
getKeyStrokeAsText(...) for example how this can be done.
...or did you mean something different? :)
Btw thanks for you help to make NetBeans better.
I think you didn't understand what I meant. The requirement says, put a tooltip to the close button that will say:
"Shift + click to close all documents, Alt + click to close other documents" whenever the mouse is over that button. Now
my question is, 'close all documents' has a shortcut of 'Ctrl+Shift+W' NOT 'Shift+Click' and 'close other documents' has
no shortcut at all. The reason of my post was that I was just wondering whether the 'Shift+click' shortcut was
mistakenly mentioned; if that's the case, then my tooltip will be 'Ctrl+Shift+W to close all documents' and I will not
put any tooltip for 'close other documents' since that option, by default, doesn't have a shortcut. However, if it's the
case that the requirement had no mistake, then my question will be should I have to create, on top of displaying the
tooltip, shortcuts for 'close all documents'(Shift+Click) and 'close other documents'(Alt+Click)?
I see, sorry for misunderstanding.
Situation is actually quite simple: request has no mistake and you should *not* create new shortcuts. Alt + clicking on
close button and Shift + clicking on close button is just another way to close documents, tied directly to close button.
Shortcuts are intended to be keyboard only, not keyboard + mouse mixture.
Meaning of this enhancement is purely to raise discoverability, as said in first comment. I doubt anybody knows about
this hidden functionality.
Can you please tell me which module in the NB code deal with this issue? Thanks.
Yes, it is o.n.swing.tabcontrol. Namely packages org.netbeans.swing.tabcontrol and org.netbeans.swing.tabcontrol.plaf.
I wanted to give you some more pointers and I found out that fix will not be trivial as I thought. Sadly, implementation
of close button on editor tabs is strange and complicated. There is no JButton for close "button", it is just image
drawn. Therefore, you'll need to watch mouse position and return tooltip for close button only when mouse is hovering
above the area of close button image.
Perhaps it could be done in this (little bit ugly, but the easiest) way:
- TabDisplayer.getToolTipText will need to recognize if mouse is in close button area. For that, you'll probably need
- add public method to BasicTabDisplayerUI, that will ask its tab renderer - use AbstractTabCellRenderer.inCloseButton()
Hope this helped.
Thank you for the pointers. If I have more questions, I'll let you know.
Created attachment 86137 [details]
Patch for the requested issue
I have attached the patch for the implementation of the requested feature.
I had to change the visibility of two methods from protected to public for this fix.
AbstractTabCellRenderer::inCloseButton and BasicTabDisplayerUI::getTabCellRenderer. Are these type of access mode
changes allowed for this API? If not then I can introduce new methods in those classes doing the same thing, but those
methods are needed for this solution.
The solution works as expected for all editor tab close buttons.
Tushar Joshi, Nagpur
Dafe, will you please review and integrate Tushar's patch in case his implementation looks good to you? Thanks!
dafe doesn't work on window system any more
i've committed a slightly modified patch to core-main e4953f712809
Integrated into 'main-golden', will be available in build *200908130201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
User: S. Aubrecht <firstname.lastname@example.org>
Log: #78896 - Add tooltip for close button on editor tab