X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java index b094bc7..b0b2811 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java @@ -12,6 +12,7 @@ package net.sourceforge.phpeclipse; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -28,16 +29,17 @@ import net.sourceforge.phpdt.core.JavaCore; import net.sourceforge.phpdt.core.WorkingCopyOwner; import net.sourceforge.phpdt.externaltools.internal.model.ColorManager; import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsPlugin; -import net.sourceforge.phpdt.externaltools.internal.model.VariableContextManager; import net.sourceforge.phpdt.internal.core.BatchOperation; import net.sourceforge.phpdt.internal.core.JavaModelManager; -import net.sourceforge.phpdt.internal.core.util.Util; +import net.sourceforge.phpdt.internal.corext.template.php.CodeTemplateContextType; +import net.sourceforge.phpdt.internal.corext.template.php.HTMLContextType; +import net.sourceforge.phpdt.internal.corext.template.php.JavaContextType; +import net.sourceforge.phpdt.internal.corext.template.php.JavaDocContextType; import net.sourceforge.phpdt.internal.ui.IJavaStatusConstants; import net.sourceforge.phpdt.internal.ui.JavaElementAdapterFactory; import net.sourceforge.phpdt.internal.ui.ResourceAdapterFactory; import net.sourceforge.phpdt.internal.ui.preferences.MembersOrderPreferenceCache; import net.sourceforge.phpdt.internal.ui.preferences.MockupPreferenceStore; -import net.sourceforge.phpdt.internal.ui.preferences.TemplatePreferencePage; import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter; import net.sourceforge.phpdt.internal.ui.text.folding.JavaFoldingStructureProviderRegistry; import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor; @@ -77,7 +79,6 @@ import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.Separator; @@ -86,6 +87,8 @@ import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.templates.ContextTypeRegistry; +import org.eclipse.jface.text.templates.persistence.TemplateStore; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.graphics.RGB; @@ -100,6 +103,8 @@ import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.editors.text.EditorsUI; +import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry; +import org.eclipse.ui.editors.text.templates.ContributionTemplateStore; import org.eclipse.ui.ide.IDE; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; @@ -134,6 +139,28 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements */ public final static int MAX_PROPOSALS = 200; + /** + * The key to store customized templates. + * @since 3.0 + */ + private static final String TEMPLATES_KEY= "net.sourceforge.phpdt.ui.text.custom_templates"; //$NON-NLS-1$ + /** + * The key to store customized code templates. + * @since 3.0 + */ + private static final String CODE_TEMPLATES_KEY= "net.sourceforge.phpdt.ui.text.custom_code_templates"; //$NON-NLS-1$ + /** + * The key to store whether the legacy templates have been migrated + * @since 3.0 + */ +// private static final String TEMPLATES_MIGRATION_KEY= "net.sourceforge.phpdt.ui.text.templates_migrated"; //$NON-NLS-1$ + /** + * The key to store whether the legacy code templates have been migrated + * @since 3.0 + */ +// private static final String CODE_TEMPLATES_MIGRATION_KEY= "net.sourceforge.phpdt.ui.text.code_templates_migrated"; //$NON-NLS-1$ + + private static ExternalToolsPlugin externalTools; /** @@ -173,6 +200,28 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements //The shared instance. private static PHPeclipsePlugin plugin; + /** + * The template context type registry for the java editor. + * @since 3.0 + */ + private ContextTypeRegistry fContextTypeRegistry; + /** + * The code template context type registry for the java editor. + * @since 3.0 + */ + private ContextTypeRegistry fCodeTemplateContextTypeRegistry; + + /** + * The template store for the java editor. + * @since 3.0 + */ + private TemplateStore fTemplateStore; + /** + * The coded template store for the java editor. + * @since 3.0 + */ + private TemplateStore fCodeTemplateStore; + /** Windows 9x */ private static final int WINDOWS_9x = 6; @@ -224,7 +273,7 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements /** * The extension point registry for the - * org.eclipse.jdt.ui.javaFoldingStructureProvider extension + * net.sourceforge.phpdt.ui.javaFoldingStructureProvider extension * point. * * @since 3.0 @@ -606,9 +655,15 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements return fProblemMarkerManager; } + // public synchronized JavaTextTools getJavaTextTools() { + // if (fJavaTextTools == null) + // fJavaTextTools = new JavaTextTools(getPreferenceStore()); + // return fJavaTextTools; + // } public synchronized JavaTextTools getJavaTextTools() { if (fJavaTextTools == null) - fJavaTextTools = new JavaTextTools(getPreferenceStore()); + fJavaTextTools = new JavaTextTools(getPreferenceStore(), JavaCore + .getPlugin().getPluginPreferences()); return fJavaTextTools; } @@ -636,15 +691,22 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements // } protected void initializeDefaultPreferences(IPreferenceStore store) { // windows preferences: - store.setDefault(LOCALHOST_PREF, "http://localhost"); + // store.setDefault(LOCALHOST_PREF, "http://localhost"); + // store.setDefault(DOCUMENTROOT_PREF, + // getWorkspace().getRoot().getLocation().toString()); +// store.setDefault(PHP_LOCALHOST_PREF, "http://localhost"); +// store.setDefault(PHP_DOCUMENTROOT_PREF, getWorkspace().getRoot() +// .getLocation().toString()); + // store.setDefault(SHOW_EXTERNAL_PREVIEW_PREF, "true"); store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false"); store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true"); store.setDefault(PHP_OBFUSCATOR_DEFAULT, "c:\\temp"); - store.setDefault(PHP_BOOKMARK_DEFAULT, ""); - - store.setDefault(PHP_AUTO_PREVIEW_DEFAULT, "true"); - store.setDefault(PHP_BRING_TO_TOP_PREVIEW_DEFAULT, "true"); +// store.setDefault(PHP_BOOKMARK_DEFAULT, ""); +// +// store.setDefault(PHP_AUTO_PREVIEW_DEFAULT, "true"); +// store.setDefault(PHP_BRING_TO_TOP_PREVIEW_DEFAULT, "true"); +// store.setDefault(PHP_SHOW_HTML_FILES_LOCAL, "true"); String windowsSystem = Platform.getWS(); if (jvm == WINDOWS_9x) { @@ -660,8 +722,6 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements store.setDefault(PHP_OBFUSCATOR_DEFAULT, "/tmp"); store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}"); } - store.setDefault(DOCUMENTROOT_PREF, getWorkspace().getRoot().getLocation() - .toString()); // if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) { // if (windowsSystem.equals(Platform.WS_WIN32)) { @@ -683,9 +743,9 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements store.setDefault(APACHE_START_BACKGROUND, "true"); store.setDefault(APACHE_STOP_BACKGROUND, "true"); store.setDefault(APACHE_RESTART_BACKGROUND, "true"); - store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER); - store.setDefault(PHP_INTERNAL_PARSER, "false"); - store.setDefault(PHP_EXTERNAL_PARSER, "true"); + // store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER); + // store.setDefault(PHP_INTERNAL_PARSER, "false"); + // store.setDefault(PHP_EXTERNAL_PARSER, "true"); // store.setDefault(PHP_PARSE_ON_SAVE, "true"); // show line numbers: // store.setDefault(LINE_NUMBER_RULER, "false"); @@ -769,7 +829,7 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements // store.setDefault(RESOURCE_BUNDLE_DE, "false"); // store.setDefault(RESOURCE_BUNDLE_FR, "false"); // store.setDefault(RESOURCE_BUNDLE_ES, "false"); - TemplatePreferencePage.initDefaults(store); +// TemplatePreferencePage.initDefaults(store); //this will initialize the static fields in the syntaxrdr class new PHPSyntaxRdr(); JavaCore.initializeDefaultPluginPreferences(); @@ -1110,7 +1170,7 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements */ public void start(BundleContext context) throws Exception { super.start(context); - + // JavaCore.start(this, context); final JavaModelManager manager = JavaModelManager.getJavaModelManager(); try { @@ -1125,46 +1185,46 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements // manager.loadVariablesAndContainers(); final IWorkspace workspace = ResourcesPlugin.getWorkspace(); - workspace.addResourceChangeListener(manager.deltaState, - IResourceChangeEvent.PRE_BUILD | IResourceChangeEvent.POST_BUILD - | IResourceChangeEvent.POST_CHANGE - | IResourceChangeEvent.PRE_DELETE - | IResourceChangeEvent.PRE_CLOSE); - - // startIndexing(); - - // process deltas since last activated in indexer thread so that indexes - // are up-to-date. - // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38658 - Job processSavedState = new Job(Util.bind("savedState.jobName")) { //$NON-NLS-1$ - protected IStatus run(IProgressMonitor monitor) { - try { - // add save participant and process delta atomically - // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59937 - workspace.run(new IWorkspaceRunnable() { - public void run(IProgressMonitor progress) throws CoreException { - ISavedState savedState = workspace.addSaveParticipant( - PHPeclipsePlugin.this, manager); - if (savedState != null) { - // the event type coming from the saved state is always - // POST_AUTO_BUILD - // force it to be POST_CHANGE so that the delta processor can - // handle it - manager.deltaState.getDeltaProcessor().overridenEventType = IResourceChangeEvent.POST_CHANGE; - savedState.processResourceChangeEvents(manager.deltaState); - } - } - }, monitor); - } catch (CoreException e) { - return e.getStatus(); - } - return Status.OK_STATUS; - } - }; - processSavedState.setSystem(true); - processSavedState.setPriority(Job.SHORT); // process asap - processSavedState.schedule(); - + workspace.addResourceChangeListener( + manager.deltaState, + IResourceChangeEvent.PRE_BUILD + | IResourceChangeEvent.POST_BUILD + | IResourceChangeEvent.POST_CHANGE + | IResourceChangeEvent.PRE_DELETE + | IResourceChangeEvent.PRE_CLOSE); + +// startIndexing(); + ISavedState savedState = workspace.addSaveParticipant(PHPeclipsePlugin.this, manager); + + // process deltas since last activated in indexer thread so that indexes are up-to-date. + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38658 +// Job processSavedState = new Job(Util.bind("savedState.jobName")) { //$NON-NLS-1$ +// protected IStatus run(IProgressMonitor monitor) { +// try { +// // add save participant and process delta atomically +// // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59937 +// workspace.run( +// new IWorkspaceRunnable() { +// public void run(IProgressMonitor progress) throws CoreException { +// ISavedState savedState = workspace.addSaveParticipant(PHPeclipsePlugin.this, manager); +// if (savedState != null) { +// // the event type coming from the saved state is always POST_AUTO_BUILD +// // force it to be POST_CHANGE so that the delta processor can handle it +// manager.deltaState.getDeltaProcessor().overridenEventType = IResourceChangeEvent.POST_CHANGE; +// savedState.processResourceChangeEvents(manager.deltaState); +// } +// } +// }, +// monitor); +// } catch (CoreException e) { +// return e.getStatus(); +// } +// return Status.OK_STATUS; +// } +// }; +// processSavedState.setSystem(true); +// processSavedState.setPriority(Job.SHORT); // process asap +// processSavedState.schedule(); } catch (RuntimeException e) { manager.shutdown(); throw e; @@ -1317,7 +1377,7 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements /** * Returns the registry of the extensions to the - * org.eclipse.jdt.ui.javaFoldingStructureProvider extension + * net.sourceforge.phpdt.ui.javaFoldingStructureProvider extension * point. * * @return the registry of contributed @@ -1414,4 +1474,96 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements monitor); } } + + /** + * Returns the template context type registry for the java plugin. + * + * @return the template context type registry for the java plugin + * @since 3.0 + */ + public ContextTypeRegistry getTemplateContextRegistry() { + if (fContextTypeRegistry == null) { + fContextTypeRegistry= new ContributionContextTypeRegistry(); + + fContextTypeRegistry.addContextType(new JavaContextType()); + fContextTypeRegistry.addContextType(new JavaDocContextType()); + fContextTypeRegistry.addContextType(new HTMLContextType()); + } + + return fContextTypeRegistry; + } + + /** + * Returns the template store for the java editor templates. + * + * @return the template store for the java editor templates + * @since 3.0 + */ + public TemplateStore getTemplateStore() { + if (fTemplateStore == null) { +// boolean alreadyMigrated= getPreferenceStore().getBoolean(TEMPLATES_MIGRATION_KEY); +// if (alreadyMigrated) + fTemplateStore= new ContributionTemplateStore(getTemplateContextRegistry(), getPreferenceStore(), TEMPLATES_KEY); +// else { +// fTemplateStore= new CompatibilityTemplateStore(getTemplateContextRegistry(), getPreferenceStore(), TEMPLATES_KEY, Templates.getInstance()); +// getPreferenceStore().setValue(TEMPLATES_MIGRATION_KEY, true); +// } + + try { + fTemplateStore.load(); + } catch (IOException e) { + log(e); + } + } + + return fTemplateStore; + } + + /** + * Returns the template context type registry for the code generation + * templates. + * + * @return the template context type registry for the code generation + * templates + * @since 3.0 + */ + public ContextTypeRegistry getCodeTemplateContextRegistry() { + if (fCodeTemplateContextTypeRegistry == null) { + fCodeTemplateContextTypeRegistry= new ContributionContextTypeRegistry(); + + CodeTemplateContextType.registerContextTypes(fCodeTemplateContextTypeRegistry); + } + + return fCodeTemplateContextTypeRegistry; + } + + /** + * Returns the template store for the code generation templates. + * + * @return the template store for the code generation templates + * @since 3.0 + */ + public TemplateStore getCodeTemplateStore() { + if (fCodeTemplateStore == null) { +// boolean alreadyMigrated= getPreferenceStore().getBoolean(CODE_TEMPLATES_MIGRATION_KEY); +// if (alreadyMigrated) + fCodeTemplateStore= new ContributionTemplateStore(getCodeTemplateContextRegistry(), getPreferenceStore(), CODE_TEMPLATES_KEY); +// else { +// fCodeTemplateStore= new CompatibilityTemplateStore(getCodeTemplateContextRegistry(), getPreferenceStore(), CODE_TEMPLATES_KEY, CodeTemplates.getInstance()); +// getPreferenceStore().setValue(CODE_TEMPLATES_MIGRATION_KEY, true); +// } + + try { + fCodeTemplateStore.load(); + } catch (IOException e) { + log(e); + } + + // compatibility / bug fixing code for duplicated templates + // TODO remove for 3.0 +// CompatibilityTemplateStore.pruneDuplicates(fCodeTemplateStore, true); + } + + return fCodeTemplateStore; + } } \ No newline at end of file