Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

focus bug when accessing main menu from floating pane #7952

Open
nmatt opened this issue Nov 10, 2024 · 6 comments · May be fixed by #8288
Open

focus bug when accessing main menu from floating pane #7952

nmatt opened this issue Nov 10, 2024 · 6 comments · May be fixed by #8288
Labels
kind:bug Bug report or fix UI User Interface
Milestone

Comments

@nmatt
Copy link

nmatt commented Nov 10, 2024

Apache NetBeans version

Apache NetBeans 23

What happened

Summary: When making a pane in the NetBeans UI a floating pane (basically a separate window), then invoking the main menu via keyboard from the floating pane changes the focus back to the main window, and the menu loses keyboard focus. In consequence, it's impossible to perform menu actions for items in a floating pane.

This is a regression in NetBeans 16-23. This had worked since at least NetBeans 8 up to NetBeans 15, and stopped working with NetBeans 16.

This bug makes it impractical to use floating panes in conjunction with keyboard navigation and/or to select actions from the main menu that work on items in the floating pane, such as "Close " in the "How to reproduce" example below, or also actions like Team > Commit.

Language / Project Type / NetBeans Component

NetBeans UI, any project type

How to reproduce

What works:

  • Open a project in NetBeans, open one of its source files in the editor.
  • Press Ctrl+0 to focus the editor, then press Ctrl+1 to focus the Projects pane.
  • While the keyboard focus is in the Projects pane, press Alt+F to open the file menu.
  • Press cursor Up/Down to navigate in the File menu, finally press C to close the current project.
  • Alternatively, while the keyboard focus is in the Projects pane, open the File menu with the mouse, and select "Close " to close the project.

What does NOT work:

  • Open a project in NetBeans, open one of its source files in the editor.
  • Make the Projects pane a floating pane, either by dragging it out of the main window, or by selecting "Float" in the context menu.
  • Press Ctrl+0 to focus the editor, then press Ctrl+1 to focus the Projects pane.
  • While the keyboard focus is in the Projects pane, press Alt+F to open the file menu.
  • Bug 1: Press cursor Up/Down and/or press C => These keyboard presses don't take effect in the menu (despite the menu being open), but in the editor pane.
  • Bug 2: While the keyboard focus is in the Projects pane, open the File menu with the mouse => "Close " is grayed out and can't be selected, presumably because the corresponding item in the Projects view lost the focus.

Did this work correctly in an earlier version?

Apache NetBeans 15

Operating System

Windows 10

JDK

Any JDK, specifically tested under 8, 11, 17, and 21

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

This bug may be a side effect of #4603. I had originally already reported this as #5062.

I'm willing to help any way I can in implementing a fix. This is an important issue to me and has held me back from upgrading from NetBeans 15.

Are you willing to submit a pull request?

Not at the moment, but possibly eventually.

@nmatt nmatt added kind:bug Bug report or fix needs:triage Requires attention from one of the committers labels Nov 10, 2024
@nmatt
Copy link
Author

nmatt commented Nov 10, 2024

@errael: It would be great if you could take a look at this, if it's an unintended side effect of #4437.

@mbien mbien added the UI User Interface label Nov 11, 2024
@neilcsmith-net neilcsmith-net removed the needs:triage Requires attention from one of the committers label Nov 11, 2024
@neilcsmith-net neilcsmith-net added this to the NB25 milestone Nov 11, 2024
@neilcsmith-net
Copy link
Member

Can reproduce. Added the NB25 milestone. Don't think it's urgent enough for NB24.

At a guess, if this is caused by #4603 , it might be due to either listening on the wrong property (should be permanent focus owner?) and/or not checking that the focused component is inside a TopComponent.

@mbien mbien changed the title Critical focus bug when accessing main menu from floating pane focus bug when accessing main menu from floating pane Jan 15, 2025
@neilcsmith-net neilcsmith-net modified the milestones: NB25, NB26 Feb 28, 2025
errael added a commit to errael/netbeans that referenced this issue Mar 2, 2025
@errael
Copy link
Contributor

errael commented Mar 2, 2025

At a guess, if this is caused by #4603 , it might be due to either listening on the wrong property (should be permanent focus owner?) and/or not checking that the focused component is inside a TopComponent.

These didn't seem to offer a way out.

@errael
Copy link
Contributor

errael commented Mar 2, 2025

There's #8285 which is pretty small (lots of logging stuff for removal before a final PR); assuming nothing better comes along...

Look at HookFileMenu and the early return in propertyChange() for the PR.

Basic problem is that Alt-F handling, when starting in a detached window, intermediately transfers focus to a TopComponent. See the "With Activation (behavior after #4603)" log data below; notice that the tc.requestActivation() processing happens after the Alt-F handling which leaves the focus in the wrong spot.

I don't particularly like this solution. But can't think of anything better, possibly a custom focus manager (ouch).


Skip Activation (behavior before #4603)

Docked

Ctrl-0

: PropChange: (60) MainWin JFrame@425473fa, KBFocusWin JFrame@425473fa
:         currentTC NewClass.java:MultiViewCloneableTopComponent@24687610, TCWin JFrame@425473fa
:         old ExplorerTree@4464d834, new (null)
: PermanentFocusOwner: old ExplorerTree@4464d834, new (null)
: PropChange: (61) MainWin JFrame@425473fa, KBFocusWin JFrame@425473fa
:         currentTC NewClass.java:MultiViewCloneableTopComponent@24687610, TCWin JFrame@425473fa
:         old (null), new QuietEditorPane@2dc11d2b
: PermanentFocusOwner: old (null), new QuietEditorPane@2dc11d2b
trackTC: activated oldTC: null:ProjectTab@5493c897 'explorer' : nPanes = 0
trackTC: activated newTC: NewClass.java:MultiViewCloneableTopComponent@24687610 'editor' : nPanes = 1

Ctrl-1

: PropChange: (62) MainWin JFrame@425473fa, KBFocusWin JFrame@425473fa
:         currentTC null:ProjectTab@5493c897, TCWin JFrame@425473fa
:         old QuietEditorPane@2dc11d2b, new (null)
: PermanentFocusOwner: old QuietEditorPane@2dc11d2b, new (null)
: PropChange: (63) MainWin JFrame@425473fa, KBFocusWin JFrame@425473fa
:         currentTC null:ProjectTab@5493c897, TCWin JFrame@425473fa
:         old (null), new ExplorerTree@4464d834
: PermanentFocusOwner: old (null), new ExplorerTree@4464d834
trackTC: activated oldTC: NewClass.java:MultiViewCloneableTopComponent@24687610 'editor' : nPanes = 1
trackTC: activated newTC: null:ProjectTab@5493c897 'explorer' : nPanes = 0

Alt-F

: PropChange: (64) MainWin JFrame@425473fa, KBFocusWin JFrame@425473fa
:         currentTC null:ProjectTab@5493c897, TCWin JFrame@425473fa
:         old ExplorerTree@4464d834, new (null)
: PropChange: (65) MainWin JFrame@425473fa, KBFocusWin JFrame@425473fa
:         currentTC null:ProjectTab@5493c897, TCWin JFrame@425473fa
:         old (null), new JRootPane@71996adf

Floating

Ctrl-0

: PropChange: (110) MainWin JFrame@425473fa, KBFocusWin ModeDialog@69af4248
:         currentTC NewClass.java:MultiViewCloneableTopComponent@24687610, TCWin JFrame@425473fa
:         old ExplorerTree@4464d834, new (null)
: PropChange: (111) MainWin JFrame@425473fa, KBFocusWin JFrame@425473fa
:         currentTC NewClass.java:MultiViewCloneableTopComponent@24687610, TCWin JFrame@425473fa
:         old (null), new QuietEditorPane@2dc11d2b
: PermanentFocusOwner: old ExplorerTree@4464d834, new QuietEditorPane@2dc11d2b
trackTC: activated oldTC: null:ProjectTab@5493c897 'anonymousMode_1' : nPanes = 0
trackTC: activated newTC: NewClass.java:MultiViewCloneableTopComponent@24687610 'editor' : nPanes = 1

Ctrl-1

: PropChange: (112) MainWin JFrame@425473fa, KBFocusWin JFrame@425473fa
:         currentTC null:ProjectTab@5493c897, TCWin ModeDialog@69af4248
:         old QuietEditorPane@2dc11d2b, new (null)
:     invoke handleActivation
:     SKIP ACTIVATION (null)
: PropChange: (113) MainWin JFrame@425473fa, KBFocusWin ModeDialog@69af4248
:         currentTC null:ProjectTab@5493c897, TCWin ModeDialog@69af4248
:         old (null), new ExplorerTree@4464d834
: PermanentFocusOwner: old QuietEditorPane@2dc11d2b, new ExplorerTree@4464d834
trackTC: activated oldTC: NewClass.java:MultiViewCloneableTopComponent@24687610 'editor' : nPanes = 1
trackTC: activated newTC: null:ProjectTab@5493c897 'anonymousMode_1' : nPanes = 0

Alt-F

: PropChange: (114) MainWin JFrame@425473fa, KBFocusWin ModeDialog@69af4248
:         currentTC null:ProjectTab@5493c897, TCWin ModeDialog@69af4248
:         old ExplorerTree@4464d834, new (null)
: PropChange: (115) MainWin JFrame@425473fa, KBFocusWin JFrame@425473fa
:         currentTC null:ProjectTab@5493c897, TCWin ModeDialog@69af4248
:         old (null), new QuietEditorPane@2dc11d2b
:     invoke handleActivation
:     SKIP ACTIVATION QuietEditorPane@2dc11d2b
: PermanentFocusOwner: old ExplorerTree@4464d834, new QuietEditorPane@2dc11d2b
: PropChange: (116) MainWin JFrame@425473fa, KBFocusWin JFrame@425473fa
:         currentTC null:ProjectTab@5493c897, TCWin ModeDialog@69af4248
:         old QuietEditorPane@2dc11d2b, new (null)
:     invoke handleActivation
:     SKIP ACTIVATION (null)
: PermanentFocusOwner: old QuietEditorPane@2dc11d2b, new (null)
: PropChange: (117) MainWin JFrame@425473fa, KBFocusWin JFrame@425473fa
:         currentTC null:ProjectTab@5493c897, TCWin ModeDialog@69af4248
:         old (null), new JRootPane@71996adf
:     invoke handleActivation
:     SKIP ACTIVATION JRootPane@71996adf
: PermanentFocusOwner: old (null), new JRootPane@71996adf

With Activation (behavior after #4603)

Floating

Ctrl-0

: PropChange: (206) MainWin JFrame@425473fa, KBFocusWin ModeDialog@37cb1fdf
:         currentTC NewClass.java:MultiViewCloneableTopComponent@24687610, TCWin JFrame@425473fa
:         old ExplorerTree@4464d834, new (null)
: PropChange: (207) MainWin JFrame@425473fa, KBFocusWin JFrame@425473fa
:         currentTC NewClass.java:MultiViewCloneableTopComponent@24687610, TCWin JFrame@425473fa
:         old (null), new QuietEditorPane@2dc11d2b
: PermanentFocusOwner: old ExplorerTree@4464d834, new QuietEditorPane@2dc11d2b
trackTC: activated oldTC: null:ProjectTab@5493c897 'anonymousMode_1' : nPanes = 0
trackTC: activated newTC: NewClass.java:MultiViewCloneableTopComponent@24687610 'editor' : nPanes = 1

Ctrl-1

: PropChange: (208) MainWin JFrame@425473fa, KBFocusWin JFrame@425473fa
:         currentTC null:ProjectTab@5493c897, TCWin ModeDialog@37cb1fdf
:         old QuietEditorPane@2dc11d2b, new (null)
:     invoke handleActivation
: handleActivation: evtObject (null)
: PropChange: (209) MainWin JFrame@425473fa, KBFocusWin ModeDialog@37cb1fdf
:         currentTC null:ProjectTab@5493c897, TCWin ModeDialog@37cb1fdf
:         old (null), new ExplorerTree@4464d834
: PermanentFocusOwner: old QuietEditorPane@2dc11d2b, new ExplorerTree@4464d834
trackTC: activated oldTC: NewClass.java:MultiViewCloneableTopComponent@24687610 'editor' : nPanes = 1
trackTC: activated newTC: null:ProjectTab@5493c897 'anonymousMode_1' : nPanes = 0

Alt-F

: PropChange: (210) MainWin JFrame@425473fa, KBFocusWin ModeDialog@37cb1fdf
:         currentTC null:ProjectTab@5493c897, TCWin ModeDialog@37cb1fdf
:         old ExplorerTree@4464d834, new (null)
: PropChange: (211) MainWin JFrame@425473fa, KBFocusWin JFrame@425473fa
:         currentTC null:ProjectTab@5493c897, TCWin ModeDialog@37cb1fdf
:         old (null), new QuietEditorPane@2dc11d2b
:     invoke handleActivation
: handleActivation: evtObject QuietEditorPane@2dc11d2b                              ##### focus change later
: PermanentFocusOwner: old ExplorerTree@4464d834, new QuietEditorPane@2dc11d2b
: PropChange: (212) MainWin JFrame@425473fa, KBFocusWin JFrame@425473fa
:         currentTC NewClass.java:MultiViewCloneableTopComponent@24687610, TCWin JFrame@425473fa
:         old QuietEditorPane@2dc11d2b, new (null)
: PermanentFocusOwner: old QuietEditorPane@2dc11d2b, new (null)
: PropChange: (213) MainWin JFrame@425473fa, KBFocusWin JFrame@425473fa
:         currentTC NewClass.java:MultiViewCloneableTopComponent@24687610, TCWin JFrame@425473fa
:         old (null), new JRootPane@71996adf
: PermanentFocusOwner: old (null), new JRootPane@71996adf
: PropChange: (214) MainWin JFrame@425473fa, KBFocusWin JFrame@425473fa             ##### by earlier activation
:         currentTC NewClass.java:MultiViewCloneableTopComponent@24687610, TCWin JFrame@425473fa
:         old JRootPane@71996adf, new (null)
: PermanentFocusOwner: old JRootPane@71996adf, new (null)
: PropChange: (215) MainWin JFrame@425473fa, KBFocusWin JFrame@425473fa
:         currentTC NewClass.java:MultiViewCloneableTopComponent@24687610, TCWin JFrame@425473fa
:         old (null), new QuietEditorPane@2dc11d2b
: PermanentFocusOwner: old (null), new QuietEditorPane@2dc11d2b
trackTC: activated oldTC: null:ProjectTab@5493c897 'anonymousMode_1' : nPanes = 0
trackTC: activated newTC: NewClass.java:MultiViewCloneableTopComponent@24687610 'editor' : nPanes = 1

errael added a commit to errael/netbeans that referenced this issue Mar 2, 2025
errael added a commit to errael/netbeans that referenced this issue Mar 2, 2025
Fix apache#7952.

Use invokeLater() so KeyboardFocusManager changes are finished.
Use "permanentFocusOwner" property (instead of "focusOwner") for minor optimization.
@errael errael linked a pull request Mar 2, 2025 that will close this issue
4 tasks
@errael
Copy link
Contributor

errael commented Mar 2, 2025

Sleeping on it revealed a better (I think) solution. See #8288.

@errael
Copy link
Contributor

errael commented Mar 2, 2025

This issue should be linked to the proper PR.

errael added a commit to errael/netbeans that referenced this issue Mar 2, 2025
Fix apache#7952.

Use invokeLater() so KeyboardFocusManager changes are finished.
Use "permanentFocusOwner" property (instead of "focusOwner") for minor optimization.
errael added a commit to errael/netbeans that referenced this issue Mar 3, 2025
Fix apache#7952.

Use invokeLater() so KeyboardFocusManager changes are finished.
Use "permanentFocusOwner" property (instead of "focusOwner") for minor optimization.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Bug report or fix UI User Interface
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants