Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Ctrl + A in SourceViewer returns empty TextSelection
Ctrl + A in SourceViewer returns empty TextSelection [message #1277761] Wed, 26 March 2014 12:35 Go to next message
Stephan Druskat is currently offline Stephan DruskatFriend
Messages: 104
Registered: October 2011
Location: Berlin, Germany
Senior Member

I have an 3.7 RCP application with a View and a SourceViewer. I also have a command which can be called from the View's context menu with a visibleWhen directive testing for a non-empty text selection (source below). It works fine when I select text in the SourceViewer per mouse or Shift+Arrow, i.e., the PropertyTester's test() method returns true.

However, when I press CTRL + A to select all text in the SourceViewer, TextSelection.getText().isEmpty() returns true. I.e., the popup menu doesn't show.

Why is this, and how can I solve the problem so that CTRL + A returns a TextSelection including all text from the viewer?

Below sources are also on github: https://github.com/newcodeontheblock/blog/tree/master/net.sdruskat.blog.foobar.textselection.popupmenu.

Source of PropertyTester's test() method below. Please let me know should I have to add other sources.

public class SelectionTester extends PropertyTester {

	@Override
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
	    if ("hasNonEmptyTextSelection".equals(property)) {
	        if (receiver instanceof Collection) {
	            @SuppressWarnings("unchecked")
	            Collection<Object> receiverCollection = (Collection<Object>) receiver;
	            TextSelection selection;
	            if (receiverCollection.toArray().length != 0 && receiverCollection.toArray()[0] instanceof TextSelection)  {
	            	selection = (TextSelection) receiverCollection.toArray()[0];
	                if (!selection.getText().equals("")) {
	                	return true;
	                }
	            }
	        }
	    }
	    return false;
	}

}
Re: Ctrl + A in SourceViewer returns empty TextSelection [message #1277771 is a reply to message #1277761] Wed, 26 March 2014 12:55 Go to previous message
Stephan Druskat is currently offline Stephan DruskatFriend
Messages: 104
Registered: October 2011
Location: Berlin, Germany
Senior Member

Interestingly enough, when the RCP loses and re-gains focus, the selection is registered...
So perhaps I'd need to redefine CTRL+A for the view, guessing that CTRL + A works over the complete workbench?

Update:
When I register a SelectionChangedListener on the View, it correctly identifies the selection with CTRL + A. Not sure what to do with this though. I could get the activePart in the SelectionTester, get its SelectionChangedListener and intercept the SelectionChangedEvent, but this is surely beyond clean coding...

[Updated on: Wed, 26 March 2014 13:02]

Report message to a moderator

Previous Topic:Keyboard accessibility on TableViewerColumn with a combo box
Next Topic:Boolean in ComboBoxCellEditor
Goto Forum:
  


Current Time: Thu Apr 18 05:18:36 GMT 2024

Powered by FUDForum. Page generated in 0.02784 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top