Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Text selection question
Text selection question [message #10289] Thu, 24 April 2003 09:59 Go to next message
Eclipse UserFriend
Originally posted by: wehbymj.hotmail.com

How do I determine what text the user has highlighted when they click on a
button I added to the toolbar? I really only care about the java editor.

Thanks
Re: Text selection question [message #10455 is a reply to message #10289] Thu, 24 April 2003 10:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: daniel.megert.gmx.net

Mark Wehby wrote:

>How do I determine what text the user has highlighted when they click on a
>button I added to the toolbar? I really only care about the java editor.
>
>Thanks
>
>
Normally you do not have to ask for the selection but should store it
when IActionDelegate.selectionChanged gets called on your action delegate.

Dani
Re: Text selection question [message #10683 is a reply to message #10455] Thu, 24 April 2003 10:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wehbymj.hotmail.com

Here is what I am trying to get too. I want to have a button in the
toolbar. I want the user to be able to highlight some java code and hit the
button. Once the button is hit, I want to determine what is highlighted,
modify it and display it in a dialog box.

I am using eclipse 2.1 and I used the Hello World template to get me
started. I have been reading api documents and what not. I came across the
IActionDelegate stuff. Why would the frame work call my selectionChanged
method if the action is called after the text has been selected. So, the
text isn't being highlighted after the button, but before.

Maybe someone could point out a article or a list of classes in the api
documentation for me to read.

Thanks




"Daniel Megert" <daniel.megert@gmx.net> wrote in message
news:b88r15$2v2$1@rogue.oti.com...
> Mark Wehby wrote:
>
> >How do I determine what text the user has highlighted when they click on
a
> >button I added to the toolbar? I really only care about the java editor.
> >
> >Thanks
> >
> >
> Normally you do not have to ask for the selection but should store it
> when IActionDelegate.selectionChanged gets called on your action delegate.
>
> Dani
>
Re: Text selection question [message #13069 is a reply to message #10683] Thu, 24 April 2003 15:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: genadyb.inter.net.il

It calls your "selectionChanged" method each time the selection is changed.
The other way is to check what is the current editor and then if it is a
text editor, check its selection.

Genady

Mark Wehby wrote:
> Here is what I am trying to get too. I want to have a button in the
> toolbar. I want the user to be able to highlight some java code and hit the
> button. Once the button is hit, I want to determine what is highlighted,
> modify it and display it in a dialog box.
>
> I am using eclipse 2.1 and I used the Hello World template to get me
> started. I have been reading api documents and what not. I came across the
> IActionDelegate stuff. Why would the frame work call my selectionChanged
> method if the action is called after the text has been selected. So, the
> text isn't being highlighted after the button, but before.
>
> Maybe someone could point out a article or a list of classes in the api
> documentation for me to read.
>
> Thanks
>
>
>
>
> "Daniel Megert" <daniel.megert@gmx.net> wrote in message
> news:b88r15$2v2$1@rogue.oti.com...
>
>>Mark Wehby wrote:
>>
>>
>>>How do I determine what text the user has highlighted when they click on
>
> a
>
>>>button I added to the toolbar? I really only care about the java editor.
>>>
>>>Thanks
>>>
>>>
>>
>>Normally you do not have to ask for the selection but should store it
>>when IActionDelegate.selectionChanged gets called on your action delegate.
>>
>>Dani
>>
>
>
>
Re: Text selection question [message #13126 is a reply to message #10683] Thu, 24 April 2003 15:13 Go to previous messageGo to next message
Eclipse UserFriend
Mark Wehby wrote:
> Maybe someone could point out a article or a list of classes in the api
> documentation for me to read.

Read the documentation for the org.eclipse.ui.editorActions extension point.

Jeff
Re: Text selection question [message #13156 is a reply to message #13069] Thu, 24 April 2003 15:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wehbymj.hotmail.com

Thanks for your reply. I believe I want the second option. So, if the run
method is being called when the button is pushed, how do I get the current
editor and see what type it is. I have a lot of java experience, but no
eclipse experience, so you can be tech. in your reply.

Thanks

public class SampleAction implements IWorkbenchWindowActionDelegate {

private IWorkbenchWindow window;


public SampleAction() {

}



public void run(IAction action) {

}

}









"Genady" <genadyb@inter.net.il> wrote in message
news:b89ctj$jni$1@rogue.oti.com...
> It calls your "selectionChanged" method each time the selection is
changed.
> The other way is to check what is the current editor and then if it is a
> text editor, check its selection.
>
> Genady
>
> Mark Wehby wrote:
> > Here is what I am trying to get too. I want to have a button in the
> > toolbar. I want the user to be able to highlight some java code and hit
the
> > button. Once the button is hit, I want to determine what is
highlighted,
> > modify it and display it in a dialog box.
> >
> > I am using eclipse 2.1 and I used the Hello World template to get me
> > started. I have been reading api documents and what not. I came across
the
> > IActionDelegate stuff. Why would the frame work call my
selectionChanged
> > method if the action is called after the text has been selected. So,
the
> > text isn't being highlighted after the button, but before.
> >
> > Maybe someone could point out a article or a list of classes in the api
> > documentation for me to read.
> >
> > Thanks
> >
> >
> >
> >
> > "Daniel Megert" <daniel.megert@gmx.net> wrote in message
> > news:b88r15$2v2$1@rogue.oti.com...
> >
> >>Mark Wehby wrote:
> >>
> >>
> >>>How do I determine what text the user has highlighted when they click
on
> >
> > a
> >
> >>>button I added to the toolbar? I really only care about the java
editor.
> >>>
> >>>Thanks
> >>>
> >>>
> >>
> >>Normally you do not have to ask for the selection but should store it
> >>when IActionDelegate.selectionChanged gets called on your action
delegate.
> >>
> >>Dani
> >>
> >
> >
> >
>
Re: Text selection question [message #13320 is a reply to message #13156] Thu, 24 April 2003 15:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: genadyb.inter.net.il

Here is an excerpt from something I wrote:

public class CompletionAction implements IWorkbenchWindowActionDelegate {

/** The window where the action appears */
private IWorkbenchWindow activeWindow = null;

public void init(IWorkbenchWindow window) {
activeWindow = window;
}

/**
* Run the action. First check whether we can continue
* the previous completion operation. If not,
* create new completion operation and invoke it.
*/
public void run(IAction proxyAction) {

IEditorPart editor = activeWindow.getActivePage().getActiveEditor();
ITextEditor textEditor;
if (editor instanceof ITextEditor) {
textEditor = (ITextEditor)editor;
} else {
activeWindow.getShell().getDisplay().beep();
return;
}
ITextSelection sel =
((ITextSelection)textEditor.getSelectionProvider().getSelect ion());
}
}

Genady

Mark Wehby wrote:
> Thanks for your reply. I believe I want the second option. So, if the run
> method is being called when the button is pushed, how do I get the current
> editor and see what type it is. I have a lot of java experience, but no
> eclipse experience, so you can be tech. in your reply.
>
> Thanks
>
> public class SampleAction implements IWorkbenchWindowActionDelegate {
>
> private IWorkbenchWindow window;
>
>
> public SampleAction() {
>
> }
>
>
>
> public void run(IAction action) {
>
> }
>
> }
>
>
>
>
>
>
>
>
>
> "Genady" <genadyb@inter.net.il> wrote in message
> news:b89ctj$jni$1@rogue.oti.com...
>
>>It calls your "selectionChanged" method each time the selection is
>
> changed.
>
>>The other way is to check what is the current editor and then if it is a
>> text editor, check its selection.
>>
>>Genady
>>
>>Mark Wehby wrote:
>>
>>>Here is what I am trying to get too. I want to have a button in the
>>>toolbar. I want the user to be able to highlight some java code and hit
>
> the
>
>>>button. Once the button is hit, I want to determine what is
>
> highlighted,
>
>>>modify it and display it in a dialog box.
>>>
>>>I am using eclipse 2.1 and I used the Hello World template to get me
>>>started. I have been reading api documents and what not. I came across
>
> the
>
>>>IActionDelegate stuff. Why would the frame work call my
>
> selectionChanged
>
>>>method if the action is called after the text has been selected. So,
>
> the
>
>>>text isn't being highlighted after the button, but before.
>>>
>>>Maybe someone could point out a article or a list of classes in the api
>>>documentation for me to read.
>>>
>>>Thanks
>>>
>>>
>>>
>>>
>>>"Daniel Megert" <daniel.megert@gmx.net> wrote in message
>>>news:b88r15$2v2$1@rogue.oti.com...
>>>
>>>
>>>>Mark Wehby wrote:
>>>>
>>>>
>>>>
>>>>>How do I determine what text the user has highlighted when they click
>
> on
>
>>>a
>>>
>>>
>>>>>button I added to the toolbar? I really only care about the java
>
> editor.
>
>>>>>Thanks
>>>>>
>>>>>
>>>>
>>>>Normally you do not have to ask for the selection but should store it
>>>>when IActionDelegate.selectionChanged gets called on your action
>
> delegate.
>
>>>>Dani
>>>>
>>>
>>>
>>>
>
>
Re: Text selection question [message #13407 is a reply to message #10683] Thu, 24 April 2003 16:06 Go to previous message
Eclipse UserFriend
Originally posted by: knut_radloff.oti.com

The article "Contributing Actions to the Eclipse Workbench" on http://www.eclipse.org/articles/index.html is one of my favorites and
is a must read if you want to add any kind of action.
As an alternative to recording the selection as it changes via selectionChanged you can store the active editor set in
IEditorActionDelegate.setActiveEditor and get the selection via the editor part/editor site/selection provider when you need it.

Knut

"Mark Wehby" <wehbymj@hotmail.com> wrote in message news:b88t6c$501$1@rogue.oti.com...
> Here is what I am trying to get too. I want to have a button in the
> toolbar. I want the user to be able to highlight some java code and hit the
> button. Once the button is hit, I want to determine what is highlighted,
> modify it and display it in a dialog box.
>
> I am using eclipse 2.1 and I used the Hello World template to get me
> started. I have been reading api documents and what not. I came across the
> IActionDelegate stuff. Why would the frame work call my selectionChanged
> method if the action is called after the text has been selected. So, the
> text isn't being highlighted after the button, but before.
>
> Maybe someone could point out a article or a list of classes in the api
> documentation for me to read.
>
> Thanks
>
>
>
>
> "Daniel Megert" <daniel.megert@gmx.net> wrote in message
> news:b88r15$2v2$1@rogue.oti.com...
> > Mark Wehby wrote:
> >
> > >How do I determine what text the user has highlighted when they click on
> a
> > >button I added to the toolbar? I really only care about the java editor.
> > >
> > >Thanks
> > >
> > >
> > Normally you do not have to ask for the selection but should store it
> > when IActionDelegate.selectionChanged gets called on your action delegate.
> >
> > Dani
> >
>
>
Previous Topic:Linking from a feature.xml to help content
Next Topic:java source
Goto Forum:
  


Current Time: Tue Jul 08 22:42:09 EDT 2025

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

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

Back to the top