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 net.sourceforge.phpeclipse.phpeditor.WorkingCopyManager;
import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
-import org.eclipse.core.internal.runtime.InternalPlatform;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
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
// 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();
/**
* 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