* merge with HEAD
diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/templates/CodeTemplateSourceViewerConfigurationAdapter.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/templates/CodeTemplateSourceViewerConfigurationAdapter.java
new file mode 100644
index 0000000..fbd46c4
--- /dev/null
+++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/templates/CodeTemplateSourceViewerConfigurationAdapter.java
@@ -0,0 +1,145 @@
+package org.eclipse.dltk.ui.templates;
+
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.jface.text.ITextDoubleClickStrategy;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.IUndoManager;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.formatter.IContentFormatter;
+import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
+import org.eclipse.jface.text.hyperlink.IHyperlinkPresenter;
+import org.eclipse.jface.text.information.IInformationPresenter;
+import org.eclipse.jface.text.presentation.IPresentationReconciler;
+import org.eclipse.jface.text.quickassist.IQuickAssistAssistant;
+import org.eclipse.jface.text.reconciler.IReconciler;
+import org.eclipse.jface.text.source.IAnnotationHover;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+
+public class CodeTemplateSourceViewerConfigurationAdapter extends
+ SourceViewerConfiguration {
+ private SourceViewerConfiguration fConfig;
+ private IContentAssistProcessor fContentAssistProcessor;
+
+ public CodeTemplateSourceViewerConfigurationAdapter(
+ SourceViewerConfiguration config,
+ IContentAssistProcessor contentAssistProcessor) {
+ fConfig = config;
+ fContentAssistProcessor = contentAssistProcessor;
+ }
+
+ public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
+ ContentAssistant assistant = new ContentAssistant();
+ assistant.enableAutoActivation(true);
+ assistant.enableAutoInsert(true);
+ assistant.setContentAssistProcessor(fContentAssistProcessor,
+ IDocument.DEFAULT_CONTENT_TYPE);
+ return assistant;
+ }
+
+ public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
+ return fConfig.getAnnotationHover(sourceViewer);
+ }
+
+ public IAutoEditStrategy[] getAutoEditStrategies(
+ ISourceViewer sourceViewer, String contentType) {
+ return fConfig.getAutoEditStrategies(sourceViewer, contentType);
+ }
+
+ public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
+ return fConfig.getConfiguredContentTypes(sourceViewer);
+ }
+
+ public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
+ return fConfig.getConfiguredDocumentPartitioning(sourceViewer);
+ }
+
+ public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer,
+ String contentType) {
+ return fConfig.getConfiguredTextHoverStateMasks(sourceViewer,
+ contentType);
+ }
+
+ public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
+ return fConfig.getContentFormatter(sourceViewer);
+ }
+
+ public String[] getDefaultPrefixes(ISourceViewer sourceViewer,
+ String contentType) {
+ return fConfig.getDefaultPrefixes(sourceViewer, contentType);
+ }
+
+ public ITextDoubleClickStrategy getDoubleClickStrategy(
+ ISourceViewer sourceViewer, String contentType) {
+ return fConfig.getDoubleClickStrategy(sourceViewer, contentType);
+ }
+
+ public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
+ return fConfig.getHyperlinkDetectors(sourceViewer);
+ }
+
+ public IHyperlinkPresenter getHyperlinkPresenter(ISourceViewer sourceViewer) {
+ return fConfig.getHyperlinkPresenter(sourceViewer);
+ }
+
+ public int getHyperlinkStateMask(ISourceViewer sourceViewer) {
+ return fConfig.getHyperlinkStateMask(sourceViewer);
+ }
+
+ public String[] getIndentPrefixes(ISourceViewer sourceViewer,
+ String contentType) {
+ return fConfig.getIndentPrefixes(sourceViewer, contentType);
+ }
+
+ public IInformationControlCreator getInformationControlCreator(
+ ISourceViewer sourceViewer) {
+ return fConfig.getInformationControlCreator(sourceViewer);
+ }
+
+ public IInformationPresenter getInformationPresenter(
+ ISourceViewer sourceViewer) {
+ return fConfig.getInformationPresenter(sourceViewer);
+ }
+
+ public IAnnotationHover getOverviewRulerAnnotationHover(
+ ISourceViewer sourceViewer) {
+ return fConfig.getOverviewRulerAnnotationHover(sourceViewer);
+ }
+
+ public IPresentationReconciler getPresentationReconciler(
+ ISourceViewer sourceViewer) {
+ return fConfig.getPresentationReconciler(sourceViewer);
+ }
+
+ public IQuickAssistAssistant getQuickAssistAssistant(
+ ISourceViewer sourceViewer) {
+ return fConfig.getQuickAssistAssistant(sourceViewer);
+ }
+
+ public IReconciler getReconciler(ISourceViewer sourceViewer) {
+ return fConfig.getReconciler(sourceViewer);
+ }
+
+ public int getTabWidth(ISourceViewer sourceViewer) {
+ return fConfig.getTabWidth(sourceViewer);
+ }
+
+ public ITextHover getTextHover(ISourceViewer sourceViewer,
+ String contentType, int stateMask) {
+ return fConfig.getTextHover(sourceViewer, contentType, stateMask);
+ }
+
+ public ITextHover getTextHover(ISourceViewer sourceViewer,
+ String contentType) {
+ return fConfig.getTextHover(sourceViewer, contentType);
+ }
+
+ public IUndoManager getUndoManager(ISourceViewer sourceViewer) {
+ return fConfig.getUndoManager(sourceViewer);
+ }
+
+}
diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/templates/ScriptTemplatePreferencePage.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/templates/ScriptTemplatePreferencePage.java
index 2199050..ca6078f 100644
--- a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/templates/ScriptTemplatePreferencePage.java
+++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/templates/ScriptTemplatePreferencePage.java
@@ -15,26 +15,74 @@
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.jface.text.templates.ContextTypeRegistry;
import org.eclipse.jface.text.templates.Template;
import org.eclipse.jface.text.templates.persistence.TemplatePersistenceData;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.texteditor.templates.TemplatePreferencePage;
public abstract class ScriptTemplatePreferencePage extends
TemplatePreferencePage implements IWorkbenchPreferencePage {
+ protected class ScriptEditTemplateDialog extends EditTemplateDialog {
+ public ScriptEditTemplateDialog(Shell parent, Template template,
+ boolean edit, boolean isNameModifiable,
+ ContextTypeRegistry registry) {
+ super(parent, template, edit, isNameModifiable, registry);
+ }
+
+ // protected SourceViewer createViewer(Composite parent) {
+ // return ScriptTemplatePreferencePage.this.createViewer(parent);
+ // }
+
+ /**
+ * Creates the viewer to be used to display the pattern. Subclasses may
+ * override.
+ *
+ * @param parent
+ * the parent composite of the viewer
+ * @return a configured <code>SourceViewer</code>
+ */
+ protected SourceViewer createViewer(Composite parent) {
+ IPreferenceStore store = getPreferenceStore();
+ SourceViewer viewer = new ScriptSourceViewer(parent, null, null,
+ false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, store);
+ SourceViewerConfiguration origConfig = createSourceViewerConfiguration();
+ SourceViewerConfiguration configuration = new CodeTemplateSourceViewerConfigurationAdapter(
+ origConfig, getTemplateProcessor());
+ IDocument document = new Document();
+ setDocumentParticioner(document);
+
+ viewer.configure(configuration);
+ viewer.setDocument(document);
+ return viewer;
+ }
+ }
+
+ protected Template editTemplate(Template template, boolean edit,
+ boolean isNameModifiable) {
+ EditTemplateDialog dialog = new ScriptEditTemplateDialog(getShell(),
+ template, edit, isNameModifiable, getContextTypeRegistry());
+ if (dialog.open() == Window.OK) {
+ return dialog.getTemplate();
+ }
+ return null;
+ }
protected SourceViewer createViewer(Composite parent) {
- IDocument document = new Document();
-
IPreferenceStore store = getPreferenceStore();
+ ScriptSourceViewerConfiguration configuration = createSourceViewerConfiguration();
- ScriptSourceViewerConfiguration configuration = createSourceViewerConfiguration(document);
-
+ IDocument document = new Document();
+ setDocumentParticioner(document);
+
SourceViewer viewer = new ScriptSourceViewer(parent, null, null, false,
SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, store);
@@ -50,7 +98,7 @@
// .getFont(TPreferenceConstants.EDITOR_TEXT_FONT);
// viewer.getTextWidget().setFont(font);
- //new ScriptSourcePreviewerUpdater(viewer, configuration, store);
+ // new ScriptSourcePreviewerUpdater(viewer, configuration, store);
return viewer;
}
@@ -88,6 +136,8 @@
return false;
}
- protected abstract ScriptSourceViewerConfiguration createSourceViewerConfiguration(
- IDocument document);
+ protected abstract ScriptSourceViewerConfiguration createSourceViewerConfiguration();
+
+ protected abstract void setDocumentParticioner(IDocument document);
+
}