1 11 package org.eclipse.ui.editors.text; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IStatus; 15 16 import org.eclipse.jface.action.IAction; 17 import org.eclipse.jface.action.IMenuManager; 18 import org.eclipse.jface.util.PropertyChangeEvent; 19 20 import org.eclipse.jface.text.source.ISourceViewer; 21 import org.eclipse.jface.text.source.ISourceViewerExtension2; 22 23 import org.eclipse.ui.IEditorInput; 24 import org.eclipse.ui.internal.editors.text.EditorsPlugin; 25 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor; 26 import org.eclipse.ui.texteditor.ITextEditorActionConstants; 27 import org.eclipse.ui.texteditor.IUpdate; 28 import org.eclipse.ui.texteditor.spelling.SpellingProblem; 29 import org.eclipse.ui.texteditor.spelling.SpellingService; 30 31 32 44 public class TextEditor extends AbstractDecoratedTextEditor { 45 46 50 protected DefaultEncodingSupport fEncodingSupport; 51 52 53 56 public TextEditor() { 57 super(); 58 if (getSourceViewerConfiguration() == null) { 59 setSourceViewerConfiguration(new TextSourceViewerConfiguration(getPreferenceStore())); 61 } 62 63 } 64 65 73 protected void initializeEditor() { 74 setEditorContextMenuId("#TextEditorContext"); setRulerContextMenuId("#TextRulerContext"); setHelpContextId(ITextEditorHelpContextIds.TEXT_EDITOR); 77 setPreferenceStore(EditorsPlugin.getDefault().getPreferenceStore()); 78 configureInsertMode(SMART_INSERT, false); 79 setInsertMode(INSERT); 80 } 81 82 86 public void dispose() { 87 if (fEncodingSupport != null) { 88 fEncodingSupport.dispose(); 89 fEncodingSupport= null; 90 } 91 92 super.dispose(); 93 } 94 95 103 protected void installEncodingSupport() { 104 fEncodingSupport= new DefaultEncodingSupport(); 105 fEncodingSupport.initialize(this); 106 } 107 108 111 public boolean isSaveAsAllowed() { 112 return true; 113 } 114 115 119 protected void createActions() { 120 installEncodingSupport(); 121 super.createActions(); 122 } 123 124 128 protected String getStatusHeader(IStatus status) { 129 if (fEncodingSupport != null) { 130 String message= fEncodingSupport.getStatusHeader(status); 131 if (message != null) 132 return message; 133 } 134 return super.getStatusHeader(status); 135 } 136 137 141 protected String getStatusBanner(IStatus status) { 142 if (fEncodingSupport != null) { 143 String message= fEncodingSupport.getStatusBanner(status); 144 if (message != null) 145 return message; 146 } 147 return super.getStatusBanner(status); 148 } 149 150 154 protected String getStatusMessage(IStatus status) { 155 if (fEncodingSupport != null) { 156 String message= fEncodingSupport.getStatusMessage(status); 157 if (message != null) 158 return message; 159 } 160 return super.getStatusMessage(status); 161 } 162 163 167 protected void doSetInput(IEditorInput input) throws CoreException { 168 super.doSetInput(input); 169 if (fEncodingSupport != null) 170 fEncodingSupport.reset(); 171 } 172 173 177 public Object getAdapter(Class adapter) { 178 if (IEncodingSupport.class.equals(adapter)) 179 return fEncodingSupport; 180 return super.getAdapter(adapter); 181 } 182 183 187 protected void updatePropertyDependentActions() { 188 super.updatePropertyDependentActions(); 189 if (fEncodingSupport != null) 190 fEncodingSupport.reset(); 191 } 192 193 197 protected void handlePreferenceStoreChanged(PropertyChangeEvent event) { 198 if (event.getProperty().equals(SpellingService.PREFERENCE_SPELLING_ENABLED)) { 199 ISourceViewer viewer= getSourceViewer(); 200 201 if (!(viewer instanceof ISourceViewerExtension2)) 202 return; 204 ((ISourceViewerExtension2)viewer).unconfigure(); 206 viewer.configure(getSourceViewerConfiguration()); 207 208 if (Boolean.FALSE.equals(event.getNewValue())) 209 SpellingProblem.removeAllInActiveEditor(this, null); 210 211 IAction quickAssistAction= getAction(ITextEditorActionConstants.QUICK_ASSIST); 212 if (quickAssistAction instanceof IUpdate) 213 ((IUpdate)quickAssistAction).update(); 214 215 return; 216 } 217 super.handlePreferenceStoreChanged(event); 218 } 219 220 224 protected void editorContextMenuAboutToShow(IMenuManager menu) { 225 super.editorContextMenuAboutToShow(menu); 226 addAction(menu, ITextEditorActionConstants.GROUP_EDIT, ITextEditorActionConstants.SHIFT_RIGHT); 227 addAction(menu, ITextEditorActionConstants.GROUP_EDIT, ITextEditorActionConstants.SHIFT_LEFT); 228 } 229 } 230 | Popular Tags |