Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-dev] Finding ITextSelection's document and file


Hello fellow Eclipsoids;

This code is straight out of Chapter 21; The Java Developer's Guide to
Eclips.   See below...

I am building a plug-in that generates makefiles.  What I need to know
is, what path and filename is associated with the test the user
selected.

There doesn't seem to be a way to get from ITestSelection, or Action to
the actual path and filename is.  One would think you could call
getDocument on ITestSelection and go from there, but the interface is
very narrow.  I can see via the debugger that the selection knows what
Doc and file it belongs to, but all that info seems to be private.

Perhaps there's a static way...   Eclipse.getCurrentDocument.. or
something.

There's gotta be a way to get the current editor, and from there, the
filename and path.

Any help would be appreciated.
Thanks;
-Chris


-- Code snippet ---






private	void	processSelection (IAction action, ISelection selection)
{
		
		// If we have clicked in an editor, we need to dig for
the 
		// file and pathname...  maybe this way???
		if ( action != null ){
			if (action instanceof EditorPluginAction){
				EditorPluginAction ea =
(EditorPluginAction)action;
			}
		}
		
		
		if (selection != null){
			if (selection instanceof IStructuredSelection){
				IStructuredSelection ss =
(IStructuredSelection)selection;
				if (ss.isEmpty()) {
					System.out.println("  Selection
is empty ");
				} else {
					System.out.println ("  First
element is " +
	
ss.getFirstElement().getClass()  );
				}
				
				fFunctionName =
ss.getFirstElement().toString();
			} 
			else if (selection instanceof ITextSelection) {
				ITextSelection ts = (ITextSelection)
selection;
				System.out.println("Selected text is ["
+ ts.getText() + "]" );
				fFunctionName = ts.getText();
			}

			
		} else {
			System.out.println("Empty selection");
		}












Christopher Hull
Altera Santa Cruz Technology Center
Office: 408 544 8526
Cell: 415 385 HTML
chull@xxxxxxxxxx
 
"If you're tired of Santa Cruz, you're tired of life!"




Back to the top