This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 144753 - [68cat] Context menu on multi-selection appears at wrong position when invoked by keyboard (Search Results output window)
Summary: [68cat] Context menu on multi-selection appears at wrong position when invoke...
Status: RESOLVED FIXED
Alias: None
Product: utilities
Classification: Unclassified
Component: Search (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P4 blocker (vote)
Assignee: Jaroslav Havlin
URL:
Keywords: UI
Depends on:
Blocks:
 
Reported: 2008-08-21 18:57 UTC by matthies
Modified: 2011-10-10 12:26 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description matthies 2008-08-21 18:57:07 UTC
In the Search Results output window, when multiple items are selected and opening the context menu by keyboard, the 
context menu appears at the positon of the mouse pointer instead of at the position of the items.

(When only one item is selected, the context menu correctly appears at the position of the item when it is invoked by 
keyboard. See also issue 134374.)
Comment 1 Marian Petras 2008-08-21 19:05:42 UTC
Specification copied from issue #134374:

Context menus should appear at the position where they were invoked. When invoked with the mouse, 
this is the mouse position. When invoked by keyboard, this is the position of the keybord focus or selection. The 
context menu for single-selection gets this right, the one for multi-selection does not. I'm actually surprised that 
this needs to be custom-coded; I would have expected there's a global function like "open context menu for this UI 
element" which takes care of these details.
Comment 2 matthies 2008-08-21 19:26:58 UTC
To be absolutely precise, the following is the behavior used by Windows (for example in Windows Exporer) for context 
menus opened by keyboard:
- If the keyboard focus is on an item that is part of the current selection, open the context menu at the position of 
that item.
- If the keyboard focus is on an item not within the current selection, open the context menu at the position of the 
first selected item.
(Rationale: The context menu applies to the selected items even if the keyboard focus is on some other item.)
With regard to the question of selection vs. keyboard focus, maybe other platforms handle this differently. If 
Swing/NetBeans have a policy on this then that should be preferred of course.
Comment 3 Marian Petras 2008-08-21 19:33:51 UTC
Unfortunately, there is no API (in other words, a global action) for this that I would know of.

Now, back to the specification - there are pending questions:

- What if a non-selected line has a focus?
- What if an invisible item (outside of visible area of a scroll pane) has a focus?
There may be other corner cases.

This is how it is implemented now in the NetBeans Search Results window:
- If there is only one line selected, the pop-up appears above the selected line, no matter whether it is focused or
  not.
- If there are multiple lines selected, then:
    - If the mouse cursor is above the tree view, the pop-up is displayed at the position of the mouse cursor.
    - Otherwise, the pop-up is displayed in the centre of the tree view.

This is how it works in Windows Vista:
- If there is only one line selected, the pop-up appears above the selected line, no matter whether it is focused or
  not (this seems conventional and consistent across various desktop environments).
- If there are multiple lines selected, then:
    - If the focused line is one of the selected lines, then the pop-up is displayed above this focused line.
      If the focused line is not selected, then the pop-up is displayed above the topmost selected line.
            - If the target line is out of visible area of a scroll pane, the pop-up is still displayed above the
              assumed position of the line, i.e. outside the visible part of the tree view, possibly outside the
              parent window of the tree view. If the assumed position of the line would cause the pop-up to appear out
              of the desktop boundaries, the pop-up is displayed at the respective boundary of the desktop.

I have not checked other desktop environments like Windows XP, KDE, Mac OS X, XFCE, etc.
Comment 4 matthies 2008-08-21 20:26:59 UTC
With a bit rephrasing, we can turn this into three independent questions:

1) What is the context of the context menu if the keyboard focus is outside of the selection? In other words, what 
items should the entries of the context menu apply to in that situation?

2) Where should the context menu appear if its context differs from the keyboard focus?

3) If the item where the context menu would normally appear is invisible, should the position of the context menu be 
adjusted to the visible viewport (or the viewport be scrolled, or something else)?

Question 2 is the easiest I think: The context menu should appear at the context, not at the keyboard focus, to make 
clear what the context is.

With regard to question 1, the behavior of Windows, of the NetBeans Search Results window and of all other treeviews I 
checked in NetBeans is to always use the selection as the context regardless of the keyboard focus. This appears to be 
quite sensible, I don't see a compelling reason to deviate from this behavior.

This leaves question 3. Windows XP matches your description of Windows Vista. The Files and Projects treeviews in 
NetBeans also have this same behavior. I also think it makes some sense, because the possibly unusual position of the 
context menu calls attention to the fact that its context is not visible.
Comment 5 Jaroslav Havlin 2011-10-07 09:24:49 UTC
core-main/rev/90e47da1a1c6

Fixed. I hope the behavior is more intuitive now.

1) The context is the selection, not focused node.
2) Context menu should appear at the context (if possible).
3) If the item is invisible, context menu is shown at the top-left corner of the panel.
Comment 6 Quality Engineering 2011-10-10 12:26:13 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/90e47da1a1c6
User: Jaroslav Havlin <jhavlin@netbeans.org>
Log: #144753 - [68cat] Context menu on multi-selection appears at wrong position when invoked by keyboard (Search Results output window)