[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform] Re: Popup menu extension

"Douglas Pollock" <douglas.pollock@xxxxxxxx> wrote in message
news:dmlb5i$5sn$1@xxxxxxxxxxxxxxxxxxx
> Radovan Radic wrote:
> > What i want exactly is that when some user is using the text editor in
> > eclipse (with my plugin installed), and he can select, lets say, some
> > method or any piece of the code from the java class or any text file -
and
> > then right mouse click gives a standard popup menu in the java text
> > editor. There should appear my action, can be at the bottom of the menu,
> > "Send by email" and when user clicks it would give him some kind of
dialog
> > where he could pick one or more users (it would get this data from my
> > plugin and its data provider, this can be done) and send them email with
> > the selected text as email body.
> > I tried with org.eclipse.jface.text.ITextSelection as objectClass but it
> > doesnt work.
>
> The selection is a TextSelection, which does not implement
> IStructuredSelection.  For whatever reason (before my time), it seems that
> someone has decided that object contributions can only respond to
> IStructuredSelection.  See
> ObjectActionContributor.contributeObjectActions(...).
>
> The selection in a text editor is always a TextSelection anyway, so
there's
> no real value in testing to see if there is a text selection.  How about
> using the following:
>     objectClass="org.eclipse.core.resources.IFile"
>

I have tried this, but this way i can see my action in popup menu when i
click on file in package explorer. But i still cant use it on selected text.
I should be able to select any text in the editor and then execute my
action. Thanks for your help, but it seems i am not able to do it.
I tried setting objectClass to java.lang.Object and then action works this
way: I select file in the explorer left of the editor, then open it. When i
select some text in the editor, selectionChanged doesnt occur to this
selection, but selection remains opened file. I tried

/**
  * @see IActionDelegate#selectionChanged(IAction, ISelection)
  */
 public void selectionChanged(IAction action, ISelection selection) {
  currentSelection = selection;
 }

and currentSelection is IFile. When i do
((StructuredSelection)currentSelection).toString() i get /temp/test.txt
instead of my text selection.
Are there sources for PDE extenstions and their standard editor?

Thanks,
Radovan