tags:

views:

106

answers:

1

How do I launch a find and replace command without the user clicking edit->find replace or ctrl+F? I need to do this with a plug-in written in Java.

+1  A: 

The action that launches the dialog is FindInFileActionDelegate (it has a few sister types for different scopes), this is found in the org.eclipse.search plugin.

The delegates all inherit from a common parent called RetrieverAction. The RetrieverAction's run() method shows the dialog and runs the query. You can take the relevant processing from this method. You may need to register as an ISelectionListener to track the active selection.

public void run() {
    IWorkbenchPage page= getWorkbenchPage();
    if (page == null) {
        return;
    }
    TextSearchQueryProvider provider= TextSearchQueryProvider.getPreferred();
    String searchForString= getSearchForString(page);
    if (searchForString.length() == 0) {
        MessageDialog.openInformation(getShell(), SearchMessages.RetrieverAction_dialog_title, SearchMessages.RetrieverAction_empty_selection);
        return;
    }
    try {
        ISearchQuery query= createQuery(provider, searchForString);
        if (query != null) {
            NewSearchUI.runQueryInBackground(query);
        }
    } catch (OperationCanceledException ex) {
        // action cancelled
    } catch (CoreException e) {
        ErrorDialog.openError(getShell(), SearchMessages.RetrieverAction_error_title, SearchMessages.RetrieverAction_error_message, e.getStatus());
    }
}
Rich Seller
where do i get the plugin?please write the command that launches find replace window
Catalin Adam
It is part of Eclipse, you can import it into your workspace by doing File->Import...->Plug-in Development->Plug-ins and Fragments and selecting the plugin from the list
Rich Seller