Search and replace routines are undertaken by jEdit's SearchAndReplace class.
The following static methods allow you to set or get the parameters for a search. You can do this prior to or even without activating the search dialog.
public static void setSearchString( | String | search) ; |
public static String getSearchString(
void)
;
public static void setReplaceString( | String | replace) ; |
public static String getReplaceString(
void)
;
public static void setIgnoreCase( | boolean | ignoreCase) ; |
public static boolean getIgnoreCase(
void)
;
public static void setRegexp( | boolean | regexp) ; |
public static boolean getRegexp(
void)
;
public static void setReverseSearch( | boolean | reverse) ; |
public static boolean getReverseSearch(
void)
;
Determines whether a reverse search will conducted from the current position to the beginning of a buffer. Note that reverse search and regular expression search is mutually exclusive; enabling one will disable the other.
public static void setBeanShellReplace( | boolean | beanshell) ; |
public static boolean getBeanShellReplace( | void) ; |
Determines whether the replace string will be interpreted as a BeanShell expression.
public static void setAutoWrapAround( | boolean | wrap) ; |
public static boolean getAutoWrapAround(
void)
;
Determines whether a search will automatically "wrap" to the beginning of a buffer after the search reaches the buffer's end. If this flag is set to false, a dialog will request confirmation of a wrap-around search.
public static void setSearchFileSet( | SearchFileSet | fileset) ; |
A SearchFileSet is an abstract class representing the set of files that are the subject of a search. There are four classes derived from SearchFileSet:
This represents a set of files taken from a directory. It can be extended recursively to include files in subdirectories. The constructor for this class has the following syntax:
public DirectoryListSet( | String | directory, |
String | glob, | |
boolean | recurse) ; |
The parameter glob is the glob pattern that determines which files from the directory will be selected (see Appendix D for information about glob patterns), and recurse determines whether the selection will recurse into subdirectories.
This class represents the set of all buffers currently open. The constructor for this class takes a file mask as a single parameter:
public AllBufferSet(
String glob)
;
This class represents a buffer set consisting of the current buffer only. The constructor has no parameters.
public CurrentBufferSet(
void)
;
The actual tasks of searching and replacing, based on these parameters, are performed by the following methods. The return value of each indicates whether the operation succeeded.
public static boolean find(
View view)
;
This will select the next instance of matching text if the search is successful.
public static boolean replace(
View view)
;
This will replace the each occurrence of the "search string" in selected text with the "replace string". If no text is selected, the method has no effect.
public static boolean replace( | View | view, |
Buffer | buffer, | |
int | start, | |
int | end) ; |
This will replace the each occurrence of the "search string" in the specified range with the "replace string".
public static boolean replaceAll( | View | view) ; |
This method performs a replacement in all buffers in the SearchFileSet. Text selection is ignored.
public static boolean hyperSearch( | View | view, |
boolean | selection) ; |
Performs a HyperSearch either in the current selection (if selection is true) or in the current SearchFileSet (if selection is false).
The "HyperSearch" and "Keep dialog" features, as reflected in checkbox options in the search dialog, are not handled from within SearchAndReplace. If you wish to have these options set before the search dialog appears, make a prior call to either or both of the following:
jEdit.setBooleanProperty("search.hypersearch.toggle",true); jEdit.setBooleanProperty("search.keepDialog.toggle",true); |
If you are not using the dialog to undertake a search or replace, you may call any of the search and replace methods (including hyperSearch()) without concern for the value of these properties.
To create and display the search and replace dialog, first assign desired values to the search settings using the methods described above. Then create a new SearchDialog object using the following static method in the SearchDialog class:
public static void showSearchDialog( | View | view, |
String | searchString, | |
int | searchIn) ; |
The parameter searchIn can take the defined constant values CURRENT_BUFFER, ALL_BUFFERS or DIRECTORY, defined in the SearchDialog class. This parameter determines which file set radio button to preselect in the dialog box.