package net.sourceforge.phpeclipse;
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
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.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;
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;
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;
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;
*/
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;
/**
//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;
/**
* The extension point registry for the
- * <code>org.eclipse.jdt.ui.javaFoldingStructureProvider</code> extension
+ * <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code> extension
* point.
*
* @since 3.0
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;
}
// }
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_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");
- 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) {
store.setDefault(EXTERNAL_BROWSER_PREF,
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)) {
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");
// 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();
*/
public void start(BundleContext context) throws Exception {
super.start(context);
-
+
// JavaCore.start(this, context);
final JavaModelManager manager = JavaModelManager.getJavaModelManager();
try {
// 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;
/**
* Returns the registry of the extensions to the
- * <code>org.eclipse.jdt.ui.javaFoldingStructureProvider</code> extension
+ * <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code> extension
* point.
*
* @return the registry of contributed
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