1 11 12 package org.eclipse.ui.texteditor; 13 14 import org.eclipse.swt.graphics.Color; 15 import org.eclipse.swt.graphics.Point; 16 17 import org.eclipse.jface.text.IFindReplaceTarget; 18 import org.eclipse.jface.text.IFindReplaceTargetExtension; 19 import org.eclipse.jface.text.IFindReplaceTargetExtension3; 20 import org.eclipse.jface.text.IRegion; 21 22 26 class FindReplaceTarget implements IFindReplaceTarget, IFindReplaceTargetExtension, IFindReplaceTargetExtension2, IFindReplaceTargetExtension3 { 27 28 29 private AbstractTextEditor fEditor; 30 31 private IFindReplaceTarget fTarget; 32 33 39 public FindReplaceTarget(AbstractTextEditor editor, IFindReplaceTarget target) { 40 fEditor= editor; 41 fTarget= target; 42 } 43 44 49 private IFindReplaceTarget getTarget() { 50 return fTarget; 51 } 52 53 58 private IFindReplaceTargetExtension getExtension() { 59 if (fTarget instanceof IFindReplaceTargetExtension) 60 return (IFindReplaceTargetExtension) fTarget; 61 return null; 62 } 63 64 67 public boolean canPerformFind() { 68 if (getTarget() != null) 69 return getTarget().canPerformFind(); 70 return false; 71 } 72 73 76 public int findAndSelect(int offset, String findString, boolean searchForward, boolean caseSensitive, boolean wholeWord) { 77 if (getTarget() != null) 78 return getTarget().findAndSelect(offset, findString, searchForward, caseSensitive, wholeWord); 79 return -1; 80 } 81 82 86 public int findAndSelect(int offset, String findString, boolean searchForward, boolean caseSensitive, boolean wholeWord, boolean regExSearch) { 87 if (getTarget() instanceof IFindReplaceTargetExtension3) 88 return ((IFindReplaceTargetExtension3)getTarget()).findAndSelect(offset, findString, searchForward, caseSensitive, wholeWord, regExSearch); 89 90 if (!regExSearch && getTarget() != null) 92 return getTarget().findAndSelect(offset, findString, searchForward, caseSensitive, wholeWord); 93 94 return -1; 95 } 96 97 100 public Point getSelection() { 101 if (getTarget() != null) 102 return getTarget().getSelection(); 103 return null; 104 } 105 106 109 public String getSelectionText() { 110 if (getTarget() != null) 111 return getTarget().getSelectionText(); 112 return null; 113 } 114 115 118 public boolean isEditable() { 119 if (getTarget() != null) { 120 if (getTarget().isEditable()) 121 return true; 122 return fEditor.isEditorInputModifiable(); 123 } 124 return false; 125 } 126 127 130 public void replaceSelection(String text) { 131 if (getTarget() != null) 132 getTarget().replaceSelection(text); 133 } 134 135 139 public void replaceSelection(String text, boolean regExReplace) { 140 if (getTarget() instanceof IFindReplaceTargetExtension3) { 141 ((IFindReplaceTargetExtension3)getTarget()).replaceSelection(text, regExReplace); 142 return; 143 } 144 145 if (!regExReplace && getTarget() != null) 147 getTarget().replaceSelection(text); 148 } 149 150 153 public void beginSession() { 154 if (getExtension() != null) 155 getExtension().beginSession(); 156 } 157 158 161 public void endSession() { 162 if (getExtension() != null) 163 getExtension().endSession(); 164 } 165 166 169 public IRegion getScope() { 170 if (getExtension() != null) 171 return getExtension().getScope(); 172 return null; 173 } 174 175 178 public void setScope(IRegion scope) { 179 if (getExtension() != null) 180 getExtension().setScope(scope); 181 } 182 183 186 public Point getLineSelection() { 187 if (getExtension() != null) 188 return getExtension().getLineSelection(); 189 return null; 190 } 191 192 195 public void setSelection(int offset, int length) { 196 if (getExtension() != null) 197 getExtension().setSelection(offset, length); 198 } 199 200 203 public void setScopeHighlightColor(Color color) { 204 if (getExtension() != null) 205 getExtension().setScopeHighlightColor(color); 206 } 207 208 211 public void setReplaceAllMode(boolean replaceAll) { 212 if (getExtension() != null) 213 getExtension().setReplaceAllMode(replaceAll); 214 } 215 216 219 public boolean validateTargetState() { 220 return fEditor.validateEditorInputState(); 221 } 222 } 223 | Popular Tags |