1 11 package org.eclipse.ui.internal.texteditor; 12 13 import java.util.HashSet ; 14 import java.util.Iterator ; 15 import java.util.Set ; 16 17 import org.osgi.framework.BundleContext; 18 19 import org.eclipse.core.runtime.Assert; 20 import org.eclipse.core.runtime.IRegistryChangeEvent; 21 import org.eclipse.core.runtime.IRegistryChangeListener; 22 import org.eclipse.core.runtime.Platform; 23 24 import org.eclipse.jface.action.IAction; 25 26 27 import org.eclipse.ui.internal.texteditor.quickdiff.QuickDiffExtensionsRegistry; 28 import org.eclipse.ui.internal.texteditor.spelling.SpellingEngineRegistry; 29 import org.eclipse.ui.plugin.AbstractUIPlugin; 30 31 44 public final class TextEditorPlugin extends AbstractUIPlugin implements IRegistryChangeListener { 45 46 47 private static TextEditorPlugin fgPlugin; 48 49 50 private EditPosition fLastEditPosition; 51 52 private Set fLastEditPositionDependentActions; 53 54 58 private QuickDiffExtensionsRegistry fQuickDiffExtensionRegistry; 59 60 64 private SpellingEngineRegistry fSpellingEngineRegistry; 65 66 69 public TextEditorPlugin() { 70 super(); 71 Assert.isTrue(fgPlugin == null); 72 fgPlugin= this; 73 } 74 75 81 public static TextEditorPlugin getDefault() { 82 return fgPlugin; 83 } 84 85 88 public static final String PLUGIN_ID= "org.eclipse.ui.workbench.texteditor"; 90 95 public static final String REFERENCE_PROVIDER_EXTENSION_POINT= "quickDiffReferenceProvider"; 97 103 EditPosition getLastEditPosition() { 104 return fLastEditPosition; 105 } 106 107 113 public void setLastEditPosition(EditPosition lastEditPosition) { 114 fLastEditPosition= lastEditPosition; 115 if (fLastEditPosition != null && fLastEditPositionDependentActions != null) { 116 Iterator iter= fLastEditPositionDependentActions.iterator(); 117 while (iter.hasNext()) 118 ((IAction)iter.next()).setEnabled(true); 119 fLastEditPositionDependentActions= null; 120 } 121 } 122 123 128 void addLastEditPositionDependentAction(IAction action) { 129 if (fLastEditPosition != null) 130 return; 131 if (fLastEditPositionDependentActions == null) 132 fLastEditPositionDependentActions= new HashSet (); 133 fLastEditPositionDependentActions.add(action); 134 } 135 136 141 void removeLastEditPositionDependentAction(IAction action) { 142 if (fLastEditPosition != null) 143 return; 144 if (fLastEditPositionDependentActions != null) 145 fLastEditPositionDependentActions.remove(action); 146 } 147 148 149 153 public void start(BundleContext context) throws Exception { 154 super.start(context); 155 fQuickDiffExtensionRegistry= new QuickDiffExtensionsRegistry(); 156 fSpellingEngineRegistry= new SpellingEngineRegistry(); 157 Platform.getExtensionRegistry().addRegistryChangeListener(this, PLUGIN_ID); 158 } 159 160 164 public void stop(BundleContext context) throws Exception { 165 Platform.getExtensionRegistry().removeRegistryChangeListener(this); 166 fQuickDiffExtensionRegistry= null; 167 fSpellingEngineRegistry= null; 168 super.stop(context); 169 } 170 171 175 public void registryChanged(IRegistryChangeEvent event) { 176 if (fQuickDiffExtensionRegistry != null && event.getExtensionDeltas(PLUGIN_ID, REFERENCE_PROVIDER_EXTENSION_POINT).length > 0) 177 fQuickDiffExtensionRegistry.reloadExtensions(); 178 if (fSpellingEngineRegistry != null && event.getExtensionDeltas(PLUGIN_ID, SpellingEngineRegistry.SPELLING_ENGINE_EXTENSION_POINT).length > 0) 179 fSpellingEngineRegistry.reloadExtensions(); 180 } 181 182 188 public QuickDiffExtensionsRegistry getQuickDiffExtensionRegistry() { 189 return fQuickDiffExtensionRegistry; 190 } 191 192 198 public SpellingEngineRegistry getSpellingEngineRegistry() { 199 return fSpellingEngineRegistry; 200 } 201 } 202 | Popular Tags |