Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Find/Replace in editor
Find/Replace in editor [message #462252] Thu, 25 January 2007 12:28 Go to next message
Eclipse UserFriend
Originally posted by: Thorsten.Meister.softwareag.com

This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C74084.AEE80350
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

Hi

I have implemented an Editor called "ValueEditor". Its context-menu is
filled by "editorContextMenuAboutToShow".
Because i wanted to have "Find/Replace"-option in the context menu, i
added "menu.add(ActionFactory.FIND.create(window))". When i enter
context menu, there's an option "Find/Replace..." but it's disabled. If
enabled manually, it does nothing when clicked.

I read somewhere that I have to retarget the find/replace-action
somehow, e.g. by "new FindReplaceAction(ResourceBundle bundle,String
prefix, WorkbenchPart part)".
I've been trying for hours now to get this to work, because I dont have
anything like a ResourceBundle declared somewhere.

So how can I get a simple Find/Replace-Action in my editor to work? By
the way, pressing "Strg+F" does the job fine, dialog pops up etc, but I
want that action too via the context menu.
Thx a lot.

regards
TM

------=_NextPart_000_0005_01C74084.AEE80350
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
6.5.7638.1">
<TITLE>Find/Replace in editor</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->

<P><FONT SIZE=3D2 FACE=3D"Arial">Hi</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">I have implemented an Editor called =
&quot;ValueEditor&quot;. Its context-menu is filled by =
&quot;editorContextMenuAboutToShow&quot;.</FONT>

<BR><FONT SIZE=3D2 FACE=3D"Arial">Because i wanted to have =
&quot;Find/Replace&quot;-option in the context menu, i added =
&quot;menu.add(ActionFactory.FIND.create(window))&qu ot;. When i enter =
context menu, there's an option &quot;Find/Replace...&quot;&nbsp; but =
it's disabled. If enabled manually, it does nothing when =
clicked.</FONT></P>

<P><FONT SIZE=3D2 FACE=3D"Arial">I read somewhere that I have to =
retarget the find/replace-action somehow, e.g. by &quot;new =
FindReplaceAction(ResourceBundle bundle,String prefix, WorkbenchPart =
part)&quot;.</FONT></P>

<P><FONT SIZE=3D2 FACE=3D"Arial">I've been trying for&nbsp; hours now to =
get this to work, because I dont have anything like a ResourceBundle =
declared somewhere.</FONT></P>

<P><FONT SIZE=3D2 FACE=3D"Arial">So how can I get a simple =
Find/Replace-Action in my editor to work? By the way, pressing =
&quot;Strg+F&quot; does the job fine, dialog pops up etc, but I want =
that action too via the context menu.</FONT></P>

<P><FONT SIZE=3D2 FACE=3D"Arial">Thx a lot.</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">regards</FONT>

<BR><FONT SIZE=3D2 FACE=3D"Arial">TM</FONT>
</P>

</BODY>
</HTML>
------=_NextPart_000_0005_01C74084.AEE80350--
Re: Find/Replace in editor [message #462272 is a reply to message #462252] Thu, 25 January 2007 15:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: peter_ossipov.mail.ru

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Well, a simple way is to do this:<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; InputStream in = null;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; String resource = "resource.properties";<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ClassLoader loader = this.getClass().getClassLoader();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (loader != null) <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; in = loader.getResourceAsStream(resource);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; in = ClassLoader.getSystemResourceAsStream(resource);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; return new PropertyResourceBundle(in); // your beloved and
seeked <font face="Arial" size="2">ResourceBundle </font><br>
<br>
the class you are calling all this stuff from must be in the same
package with the file resource.properties where you define the
following:<br>
actions.find_and_replace.label = &amp;Find/Replace...<br>
actions.find_and_replace.description = Find and Replace Text<br>
actions.find_and_replace.tooltip = Find and Replace Text<br>
<br>
and<br>
actions.find_and_replace. - is your prefix to pass to <br>
<font face="Arial" size="2">FindReplaceAction(ResourceBundle
bundle,String prefix, WorkbenchPart part) constructor.<br>
<br>
As simple as that...&nbsp;<span class="moz-smiley-s3"><span> ;-) </span></span></font><br>
Meister,Thorsten wrote:
<blockquote cite="mid000901c7407c$4d2d3840$ab7a140a@eur.ad.sag"
type="cite">
<meta http-equiv="Content-Type" content="text/html; ">
<meta name="Generator" content="MS Exchange Server version 6.5.7638.1">
<title>Find/Replace in editor</title>
<!-- Converted from text/rtf format -->
<p><font face="Arial" size="2">Hi</font>
</p>
<p><font face="Arial" size="2">I have implemented an Editor called
"ValueEditor". Its context-menu is filled by
"editorContextMenuAboutToShow".</font>
<br>
<font face="Arial" size="2">Because i wanted to have
"Find/Replace"-option in the context menu, i added
"menu.add(ActionFactory.FIND.create(window))". When i enter context
menu, there's an option "Find/Replace..."&nbsp; but it's disabled. If
enabled manually, it does nothing when clicked.</font></p>
<p><font face="Arial" size="2">I read somewhere that I have to
retarget the find/replace-action somehow, e.g. by "new
FindReplaceAction(ResourceBundle bundle,String prefix, WorkbenchPart
part)".</font></p>
<p><font face="Arial" size="2">I've been trying for&nbsp; hours now to get
this to work, because I dont have anything like a ResourceBundle
declared somewhere.</font></p>
<p><font face="Arial" size="2">So how can I get a simple
Find/Replace-Action in my editor to work? By the way, pressing "Strg+F"
does the job fine, dialog pops up etc, but I want that action too via
the context menu.</font></p>
<p><font face="Arial" size="2">Thx a lot.</font>
</p>
<p><font face="Arial" size="2">regards</font>
<br>
<font face="Arial" size="2">TM</font>
</p>
</blockquote>
<br>
</body>
</html>
Re: Find/Replace in editor [message #462310 is a reply to message #462272] Fri, 26 January 2007 11:50 Go to previous message
Eclipse UserFriend
Originally posted by: Thorsten.Meister.softwareag.com

Hey thx a lot for that hint. It works now :)

But i had to change some thing to get it working.

That "ClassLoader.getResourceAsStream(resource)" didn't work out for me,
"new PropertyResourceBundle(in)" always threw a nullpointer-exception.

So i changed it this way:

IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IPath rootPath = root.getLocation();

String resource = rootPath.toString() + RELATIVE_FILE_LOCATION;
File file = new File(resource);
java.net.URL url =file.toURL();

InputStream in = url.openStream();
ResourceBundle bundle= new PropertyResourceBundle(in);


Maybe a little circuitous , but it works
thx
regards
TM




________________________________

From: Peter Osipov [mailto:peter_ossipov@mail.ru]
Posted At: Donnerstag, 25. Januar 2007 16:23
Posted To: eclipse.platform.rcp
Conversation: Find/Replace in editor
Subject: Re: Find/Replace in editor


Well, a simple way is to do this:
InputStream in = null;
String resource = "resource.properties";
ClassLoader loader = this.getClass().getClassLoader();
if (loader != null)
{
in = loader.getResourceAsStream(resource);
}
else
{
in = ClassLoader.getSystemResourceAsStream(resource);
}
return new PropertyResourceBundle(in); // your beloved and
seeked ResourceBundle

the class you are calling all this stuff from must be in the same
package with the file resource.properties where you define the
following:
actions.find_and_replace.label = &Find/Replace...
actions.find_and_replace.description = Find and Replace Text
actions.find_and_replace.tooltip = Find and Replace Text

and
actions.find_and_replace. - is your prefix to pass to
FindReplaceAction(ResourceBundle bundle,String prefix, WorkbenchPart
part) constructor.

As simple as that... ;-)
Meister,Thorsten wrote:

Hi

I have implemented an Editor called "ValueEditor". Its
context-menu is filled by "editorContextMenuAboutToShow".
Because i wanted to have "Find/Replace"-option in the context
menu, i added "menu.add(ActionFactory.FIND.create(window))". When i
enter context menu, there's an option "Find/Replace..." but it's
disabled. If enabled manually, it does nothing when clicked.

I read somewhere that I have to retarget the find/replace-action
somehow, e.g. by "new FindReplaceAction(ResourceBundle bundle,String
prefix, WorkbenchPart part)".

I've been trying for hours now to get this to work, because I
dont have anything like a ResourceBundle declared somewhere.

So how can I get a simple Find/Replace-Action in my editor to
work? By the way, pressing "Strg+F" does the job fine, dialog pops up
etc, but I want that action too via the context menu.

Thx a lot.

regards
TM
Previous Topic:TextEditor missing
Next Topic:[Jobs] JobErrorDialog does not appear in 3.3
Goto Forum:
  


Current Time: Thu Sep 12 12:29:31 GMT 2024

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

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

Back to the top