Java Code Examples for org.eclipse.jface.text.IFindReplaceTarget#findAndSelect()
The following examples show how to use
org.eclipse.jface.text.IFindReplaceTarget#findAndSelect() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QuickXFind.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
/** * Searches for a string starting at the given offset and using the specified search * directives. If a string has been found it is selected and its start offset is * returned. * * @param target the target for finding string * @param offset the offset at which searching starts * @param findString the string which should be found * @param forwardSearch the direction of the search * @return the position of the specified string, or -1 if the string has not been found */ private static int findAndSelect( IFindReplaceTarget target , int offset, String findString , boolean forwardSearch ) { boolean caseSensitive = true; boolean wholeWord = XFindUtils.isWord(findString); boolean regExSearch = false; try { if (target instanceof IFindReplaceTargetExtension3) { return ((IFindReplaceTargetExtension3)target).findAndSelect( offset, findString, forwardSearch, caseSensitive, wholeWord, regExSearch ); } return target.findAndSelect( offset, findString, forwardSearch, caseSensitive, wholeWord ); } catch (Exception e){ return -1; } }
Example 2
Source File: EditorSearchHyperlink.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
public void open() { try { final IFileStore store = EFS.getStore(document); // Now open an editor to this file (and highlight the occurrence if possible) IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IEditorPart part = IDE.openEditorOnFileStore(page, store); // Now select the occurrence if we can IFindReplaceTarget target = (IFindReplaceTarget) part.getAdapter(IFindReplaceTarget.class); if (target != null && target.canPerformFind()) { target.findAndSelect(0, searchString, true, caseSensitive, wholeWord); } } catch (Exception e) { IdeLog.logError(CommonEditorPlugin.getDefault(), e); } }
Example 3
Source File: SearchReplaceMinibuffer.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * Case-based replacement - after the initial find has already happened * * @param replacer - the replacement string (may be regexp) * @param index - offset of find * @param all - all if true, else initial * @return - the replacement region * * @throws BadLocationException */ private IRegion caseReplace(String replacer, int index, boolean all) throws BadLocationException { IRegion result = null; IDocumentUndoManager undoer = DocumentUndoManagerRegistry.getDocumentUndoManager(getDocument()); try { if (!isReplaceAll() && undoer != null) { undoer.beginCompoundChange(); } IFindReplaceTarget target = getTarget(); // first replace with (possible regexp) string ((IFindReplaceTargetExtension3)target).replaceSelection(replacer, isRegexp()); // adjust case of actual replacement string replacer = target.getSelectionText(); String caseReplacer = replacer; if (all) { caseReplacer = caseReplacer.toUpperCase(); } else { caseReplacer = caseReplacer.trim(); caseReplacer = Character.toUpperCase(caseReplacer.charAt(0)) + caseReplacer.substring(1,caseReplacer.length()).toString(); // now update the replacement string with the re-cased part caseReplacer = replacer.replaceFirst(replacer.trim(), caseReplacer); } int ind = target.findAndSelect(index, replacer, true, false, false); if (ind > -1) { target.replaceSelection(caseReplacer); } } finally { if (!isReplaceAll() && undoer != null) { undoer.endCompoundChange(); } } return result; }
Example 4
Source File: JSSearchStringHyperlink.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
public void open() { AbstractThemeableEditor editor = getEditor(); if (editor != null) { // grab AST, making sure the file has been parsed IParseNode ast = editor.getAST(); // assume no target identifier JSIdentifierNode targetIdentifier = null; // try to locate the target identifier in the AST if (ast instanceof JSParseRootNode) { // collect all identifiers that match the search string JSIdentifierCollector collector = new JSIdentifierCollector(searchString); ((JSParseRootNode) ast).accept(collector); List<JSIdentifierNode> identifiers = collector.getIdentifiers(); // try to refine the selection based on link type if (INVOCATION_TYPE.equals(getTypeLabel())) { for (JSIdentifierNode identifier : identifiers) { if (identifier.getParent().getNodeType() == IJSNodeTypes.FUNCTION) { targetIdentifier = identifier; break; } } } // assume first item in list, as a fallback. This is only slightly better than performing a plain-text // search if (targetIdentifier == null && !CollectionsUtil.isEmpty(identifiers)) { targetIdentifier = identifiers.get(0); } } if (targetIdentifier != null) { // show the identifier we ended up with editor.selectAndReveal(targetIdentifier.getStart(), targetIdentifier.getLength()); } else { IFindReplaceTarget target = (IFindReplaceTarget) editor.getAdapter(IFindReplaceTarget.class); if (target != null && target.canPerformFind()) { // do a standard search (forward from 0 offset, case sensitive, whole word) target.findAndSelect(0, searchString, true, true, true); } else { // as a last resort, show the editor. Not sure this will ever happen, but here just in case editor.selectAndReveal(0, 0); } } } }