From: jsurfer Date: Thu, 2 Sep 2004 18:25:06 +0000 (+0000) Subject: intial source from htp://www.sf.net/projects/wdte X-Git-Url: http://git.phpeclipse.com intial source from htp://www.sf.net/projects/wdte --- diff --git a/net.sourceforge.phpeclipse.smarty.ui/.classpath b/net.sourceforge.phpeclipse.smarty.ui/.classpath new file mode 100644 index 0000000..065ac06 --- /dev/null +++ b/net.sourceforge.phpeclipse.smarty.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/net.sourceforge.phpeclipse.smarty.ui/.cvsignore b/net.sourceforge.phpeclipse.smarty.ui/.cvsignore new file mode 100644 index 0000000..ba077a4 --- /dev/null +++ b/net.sourceforge.phpeclipse.smarty.ui/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/net.sourceforge.phpeclipse.smarty.ui/.project b/net.sourceforge.phpeclipse.smarty.ui/.project new file mode 100644 index 0000000..c1e772b --- /dev/null +++ b/net.sourceforge.phpeclipse.smarty.ui/.project @@ -0,0 +1,31 @@ + + + net.sourceforge.phpeclipse.smarty.ui + + + net.sf.wdte.ui + net.sf.wdte.xml.core + net.sf.wdte.xml.ui + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/net.sourceforge.phpeclipse.smarty.ui/build.properties b/net.sourceforge.phpeclipse.smarty.ui/build.properties new file mode 100644 index 0000000..d13b964 --- /dev/null +++ b/net.sourceforge.phpeclipse.smarty.ui/build.properties @@ -0,0 +1,4 @@ +source.htmlui.jar = src/ +output.htmlui.jar = bin/ +bin.includes = plugin.xml,\ + htmlui.jar diff --git a/net.sourceforge.phpeclipse.smarty.ui/icons/full/obj16/html.png b/net.sourceforge.phpeclipse.smarty.ui/icons/full/obj16/html.png new file mode 100644 index 0000000..178c947 Binary files /dev/null and b/net.sourceforge.phpeclipse.smarty.ui/icons/full/obj16/html.png differ diff --git a/net.sourceforge.phpeclipse.smarty.ui/plugin.xml b/net.sourceforge.phpeclipse.smarty.ui/plugin.xml new file mode 100644 index 0000000..342f9ff --- /dev/null +++ b/net.sourceforge.phpeclipse.smarty.ui/plugin.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/HTMLUI.java b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/HTMLUI.java new file mode 100644 index 0000000..ec255d5 --- /dev/null +++ b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/HTMLUI.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: HTMLUI.java,v 1.1 2004-09-02 18:25:04 jsurfer Exp $ + */ + +package net.sourceforge.phpdt.smarty.ui; + +import org.eclipse.ui.plugin.AbstractUIPlugin; + +/** + * The main plugin class to be used in the desktop. + */ +public class HTMLUI extends AbstractUIPlugin { + + // Class Variables --------------------------------------------------------- + + /** The shared instance. */ + private static HTMLUI plugin; + + // Constructors ------------------------------------------------------------ + + /** + * The constructor. + */ + public HTMLUI() { + plugin = this; + } + + // Public Methods ---------------------------------------------------------- + + /** + * Returns the shared instance. + */ + public static HTMLUI getDefault() { + return plugin; + } +} diff --git a/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/HTMLUIMessages.java b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/HTMLUIMessages.java new file mode 100644 index 0000000..c7536ed --- /dev/null +++ b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/HTMLUIMessages.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: HTMLUIMessages.java,v 1.1 2004-09-02 18:25:05 jsurfer Exp $ + */ + +package net.sourceforge.phpdt.smarty.ui.internal; + +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * Utility class that provides easy access to externalized strings. + */ +public final class HTMLUIMessages { + + // Constants --------------------------------------------------------------- + + /** + * Qualified name of the resource bundle containing the localized messages. + */ + private static final String RESOURCE_BUNDLE = + "net.sourceforge.phpdt.smarty.ui.internal.HTMLUIMessages"; //$NON-NLS-1$ + + // Class Variables --------------------------------------------------------- + + /** + * The resource bundle. + */ + private static ResourceBundle resourceBundle = + ResourceBundle.getBundle(RESOURCE_BUNDLE); + + // Constructors ------------------------------------------------------------ + + /** + * Hidden constructor. + */ + private HTMLUIMessages() { + // Hidden + } + + // Public Methods ---------------------------------------------------------- + + /** + * Returns the resource bundle. + * + * @return the resource bundle + */ + public static ResourceBundle getResourceBundle() { + return resourceBundle; + } + + /** + * Returns the message identified by the specified key. + * + * @param key the message key + * @return the localized message, or the key enclosed by exclamation marks + * if no message was found for the key + */ + public static String getString(String key) { + try { + return resourceBundle.getString(key); + } catch (MissingResourceException e) { + return "!" + key + "!"; //$NON-NLS-2$ //$NON-NLS-1$ + } + } + + /** + * Returns the message identified by the specified key, replacing a single + * parameter with the provided value. + * + * @param key the message key + * @param arg the parameter value + * @return the formatted string, or the key enclosed by exclamation marks + * if no message was found for the key + */ + public static String getString(String key, String arg) { + return getString(key, new String[] { arg }); + } + + /** + * Returns the message identified by the specified key, replacing all + * parameters with the provided values. + * + * @param key the message key + * @param args the parameter values + * @return the formatted string, or the key enclosed by exclamation marks + * if no message was found for the key + */ + public static String getString(String key, String[] args) { + return MessageFormat.format(getString(key), args); + } + +} diff --git a/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/HTMLUIMessages.properties b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/HTMLUIMessages.properties new file mode 100644 index 0000000..2bca3aa --- /dev/null +++ b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/HTMLUIMessages.properties @@ -0,0 +1,12 @@ +# +# Copyright (c) 2004 Christopher Lenz and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Common Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/cpl-v10.html +# +# Contributors: +# Christopher Lenz - initial english resources +# +# $Id: HTMLUIMessages.properties,v 1.1 2004-09-02 18:25:05 jsurfer Exp $ +# diff --git a/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/editor/HTMLDocumentProvider.java b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/editor/HTMLDocumentProvider.java new file mode 100644 index 0000000..8213ad2 --- /dev/null +++ b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/editor/HTMLDocumentProvider.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial API and implementation + * + * $Id: HTMLDocumentProvider.java,v 1.1 2004-09-02 18:25:05 jsurfer Exp $ + */ + +package net.sourceforge.phpdt.smarty.ui.internal.editor; + +import net.sourceforge.phpeclipse.xml.ui.internal.editor.XMLDocumentProvider; + + +/** + * Document provider for HTML files. + */ +public class HTMLDocumentProvider extends XMLDocumentProvider { + +} diff --git a/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/editor/HTMLDocumentSetupParticipant.java b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/editor/HTMLDocumentSetupParticipant.java new file mode 100644 index 0000000..f76eb1b --- /dev/null +++ b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/editor/HTMLDocumentSetupParticipant.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial implementation + * + * $Id: HTMLDocumentSetupParticipant.java,v 1.1 2004-09-02 18:25:05 jsurfer Exp $ + */ + +package net.sourceforge.phpdt.smarty.ui.internal.editor; + +import net.sourceforge.phpeclipse.xml.ui.internal.editor.XMLDocumentSetupParticipant; + + +/** + * Document setup participant that sets up the HTML specific partitioning. + */ +public class HTMLDocumentSetupParticipant extends XMLDocumentSetupParticipant { + +} diff --git a/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/editor/HTMLEditor.java b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/editor/HTMLEditor.java new file mode 100644 index 0000000..dc96755 --- /dev/null +++ b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/editor/HTMLEditor.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial implementation + * + * $Id: HTMLEditor.java,v 1.1 2004-09-02 18:25:05 jsurfer Exp $ + */ + +package net.sourceforge.phpdt.smarty.ui.internal.editor; + +import java.net.MalformedURLException; +import java.net.URL; + +import net.sourceforge.phpdt.smarty.ui.internal.preview.HTMLPreviewPage; +import net.sourceforge.phpdt.smarty.ui.internal.text.HTMLConfiguration; +import net.sourceforge.phpeclipse.ui.views.preview.IBrowserPreviewPage; +import net.sourceforge.phpeclipse.xml.ui.XMLPlugin; +import net.sourceforge.phpeclipse.xml.ui.internal.editor.XMLDocumentProvider; +import net.sourceforge.phpeclipse.xml.ui.internal.editor.XMLEditor; +import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools; + +import org.eclipse.core.resources.IFile; +import org.eclipse.jface.action.IAction; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.texteditor.ContentAssistAction; +import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; + + +/** + * HTML editor implementation. + */ +public class HTMLEditor extends XMLEditor { + + // Instance Variables ------------------------------------------------------ + + /** The associated preview page. */ + private HTMLPreviewPage previewPage; + + // XMLEditor Implementation ------------------------------------------------ + + /* + * @see org.eclipse.ui.texteditor.AbstractTextEditor#editorSaved() + */ + protected void editorSaved() { + if (previewPage != null) { + previewPage.update(); + } + } + + /* + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) + */ + public Object getAdapter(Class adapter) { + if (adapter == IBrowserPreviewPage.class) { + if (previewPage == null) { + previewPage = createPreviewPage(); + } + return previewPage; + } + return super.getAdapter(adapter); + } + + // Private Methods --------------------------------------------------------- + + /** + * Creates the HTML preview page. + */ + private HTMLPreviewPage createPreviewPage() { + IEditorInput input = getEditorInput(); + if (input instanceof IFileEditorInput) { + IFile file = ((IFileEditorInput) input).getFile(); + try { + URL location = file.getLocation().toFile().toURL(); + return new HTMLPreviewPage(location); + } catch (MalformedURLException e) { } + } + return null; + } + protected void createActions() { + super.createActions(); + + IAction action = new ContentAssistAction(HTMLEditorMessages.getResourceBundle(), + "ContentAssistProposal.", this); //$NON-NLS-1$ + action + .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); + setAction("ContentAssistProposal", action); //$NON-NLS-1$ + markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$ + +// IAction action= new TextOperationAction( +// TemplateMessages.getResourceBundle(), +// "Editor." + TEMPLATE_PROPOSALS + ".", //$NON-NLS-1$ //$NON-NLS-2$ +// this, +// ISourceViewer.CONTENTASSIST_PROPOSALS); +// action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); +// setAction(TEMPLATE_PROPOSALS, action); +// markAsStateDependentAction(TEMPLATE_PROPOSALS, true); + } + /* + * @see org.eclipse.ui.editors.text.TextEditor#initializeEditor() + */ + protected void initializeEditor() { + super.initializeEditor(); + + XMLTextTools xmlTextTools = XMLPlugin.getDefault().getXMLTextTools(); + setSourceViewerConfiguration(new HTMLConfiguration(xmlTextTools, this)); + setDocumentProvider(new XMLDocumentProvider()); + } +} diff --git a/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/editor/HTMLEditorMessages.java b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/editor/HTMLEditorMessages.java new file mode 100644 index 0000000..05117e4 --- /dev/null +++ b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/editor/HTMLEditorMessages.java @@ -0,0 +1,45 @@ +/********************************************************************** +Copyright (c) 2000, 2002 IBM Corp. and others. +All rights reserved. This program and the accompanying materials +are made available under the terms of the Common Public License v1.0 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/cpl-v10.html + +Contributors: + IBM Corporation - Initial implementation + Klaus Hartlage - www.eclipseproject.de +**********************************************************************/ +package net.sourceforge.phpdt.smarty.ui.internal.editor; + +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class HTMLEditorMessages { + + private static final String RESOURCE_BUNDLE= "net.sourceforge.phpdt.smarty.ui.internal.editor.HTMLEditorMessages";//$NON-NLS-1$ + + private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE); + + private HTMLEditorMessages() { + } + + public static String getString(String key) { + try { + return fgResourceBundle.getString(key); + } catch (MissingResourceException e) { + return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$ + } + } + + /** + * Gets a string from the resource bundle and formats it with arguments + */ + public static String getFormattedString(String key, Object[] args) { + return MessageFormat.format(getString(key), args); + } + + public static ResourceBundle getResourceBundle() { + return fgResourceBundle; + } +} diff --git a/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/editor/HTMLEditorMessages.properties b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/editor/HTMLEditorMessages.properties new file mode 100644 index 0000000..bea66ef --- /dev/null +++ b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/editor/HTMLEditorMessages.properties @@ -0,0 +1,10 @@ +############################################################# +# +# (c) Copyright IBM Corp. 2000, 2001. +# All Rights Reserved. +# +############################################################# +ContentAssistProposal.label=Content Assist@Ctrl+SPACE +ContentAssistProposal.tooltip=Content Assist +ContentAssistProposal.image= +ContentAssistProposal.description=Content Assist diff --git a/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/preview/HTMLPreviewPage.java b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/preview/HTMLPreviewPage.java new file mode 100644 index 0000000..c60bcab --- /dev/null +++ b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/preview/HTMLPreviewPage.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial implementation + * + * $Id: HTMLPreviewPage.java,v 1.1 2004-09-02 18:25:05 jsurfer Exp $ + */ + +package net.sourceforge.phpdt.smarty.ui.internal.preview; + +import java.net.URL; + +import net.sourceforge.phpeclipse.ui.views.preview.IBrowserPreviewPage; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.browser.LocationAdapter; +import org.eclipse.swt.browser.LocationEvent; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.part.Page; +import org.eclipse.ui.texteditor.IUpdate; + +/** + * Provides a HTML preview page based on the SWT browser control. + */ +public class HTMLPreviewPage extends Page + implements IBrowserPreviewPage, IUpdate { + + // Instance Variables ------------------------------------------------------ + + /** The browser widget. */ + private Browser browser; + + /** The URL of the resource to preview. */ + private URL location; + + // Constructors ------------------------------------------------------------ + + /** + * Constructor. + * + * @param location the URL of the resource to preview + */ + public HTMLPreviewPage(URL location) { + this.location = location; + } + + // IPage Implementation ---------------------------------------------------- + + /* + * @see org.eclipse.ui.part.IPage#createControl(Composite) + */ + public void createControl(Composite parent) { + browser = new Browser(parent, SWT.NONE); + browser.setLayout(new FillLayout()); + browser.setUrl(location.toString()); + browser.addLocationListener(new LocationAdapter() { + public void changing(LocationEvent event) { + if (event.location != null) { + event.doit = false; + } + } + }); + } + + /* + * @see org.eclipse.ui.part.IPage#getControl() + */ + public Control getControl() { + return browser; + } + + /* + * @see org.eclipse.ui.part.IPage#setFocus() + */ + public void setFocus() { + browser.setFocus(); + } + + // IUpdate Implementation -------------------------------------------------- + + /* + * @see IUpdate#update() + */ + public void update() { + browser.refresh(); + } + +} diff --git a/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/text/HTMLCompletionProcessor.java b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/text/HTMLCompletionProcessor.java new file mode 100644 index 0000000..9cff545 --- /dev/null +++ b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/text/HTMLCompletionProcessor.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package net.sourceforge.phpdt.smarty.ui.internal.text; + +import net.sourceforge.phpeclipse.ui.WebUI; +import net.sourceforge.phpeclipse.ui.templates.template.BasicCompletionProcessor; +import net.sourceforge.phpeclipse.ui.templates.template.HTMLContextType; + +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.templates.TemplateContextType; + + +/** + * A completion processor for XML templates. + */ +public class HTMLCompletionProcessor extends BasicCompletionProcessor { + + /** + * Return the XML context type that is supported by this plugin. + */ + protected TemplateContextType getContextType(ITextViewer viewer, IRegion region) { + return WebUI.getDefault().getContextTypeRegistry().getContextType(HTMLContextType.HTML_CONTEXT_TYPE); + } + + +} diff --git a/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/text/HTMLConfiguration.java b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/text/HTMLConfiguration.java new file mode 100644 index 0000000..aec204a --- /dev/null +++ b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/text/HTMLConfiguration.java @@ -0,0 +1,123 @@ +/* + * Created on 25.08.2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package net.sourceforge.phpdt.smarty.ui.internal.text; + +import java.util.Map; + +import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLConfiguration; +import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner; +import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools; + +import org.eclipse.jface.text.IDocument; +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.presentation.IPresentationReconciler; +import org.eclipse.jface.text.presentation.PresentationReconciler; +import org.eclipse.jface.text.rules.DefaultDamagerRepairer; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.ui.texteditor.ITextEditor; + +/** + * @author khartlage + * + * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates + */ +public class HTMLConfiguration extends XMLConfiguration { + private SmartyTagScanner smartyTagScanner; + public HTMLConfiguration(XMLTextTools tools) { + this(tools, null); + } + + public HTMLConfiguration(XMLTextTools tools, ITextEditor editor) { + super(tools, editor); + Map tokens = tools.getTokens(); + smartyTagScanner = new SmartyTagScanner(tokens); + } + + public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { + ContentAssistant assistant = new ContentAssistant(); + assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); + + IContentAssistProcessor processor = new HTMLCompletionProcessor(); + assistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE); + assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_TAG); + assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_PI); + assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_COMMENT); + assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_DECL); + assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_TAG); + assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_ATTRIBUTE); + assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_CDATA); + + assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE); + assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer)); + + return assistant; + } + /** + * Returns a scanner which is configured to scan XML text. + * + * @return an XML text scanner + */ + public SmartyTagScanner getSmartyScanner() { + return smartyTagScanner; + } + /* + * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(ISourceViewer) + */ + public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { + PresentationReconciler reconciler = new PresentationReconciler(); + + DefaultDamagerRepairer dr; + + dr = new DefaultDamagerRepairer(getSmartyScanner()); + reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); + reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); + + dr = new DefaultDamagerRepairer(xmlTextTools.getDTDTextScanner()); + reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL); + reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL); + + dr = new DefaultDamagerRepairer(xmlTextTools.getXMLPIScanner()); + + reconciler.setDamager(dr, XMLPartitionScanner.XML_PI); + reconciler.setRepairer(dr, XMLPartitionScanner.XML_PI); + reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL_PI); + reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL_PI); + + dr = new DefaultDamagerRepairer(xmlTextTools.getXMLCommentScanner()); + + reconciler.setDamager(dr, XMLPartitionScanner.XML_COMMENT); + reconciler.setRepairer(dr, XMLPartitionScanner.XML_COMMENT); + reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL_COMMENT); + reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL_COMMENT); + + dr = new DefaultDamagerRepairer(xmlTextTools.getXMLDeclScanner()); + + reconciler.setDamager(dr, XMLPartitionScanner.XML_DECL); + reconciler.setRepairer(dr, XMLPartitionScanner.XML_DECL); + reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL_DECL); + reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL_DECL); + + dr = new DefaultDamagerRepairer(xmlTextTools.getXMLTagScanner()); + + reconciler.setDamager(dr, XMLPartitionScanner.XML_TAG); + reconciler.setRepairer(dr, XMLPartitionScanner.XML_TAG); + + dr = new DefaultDamagerRepairer(xmlTextTools.getXMLAttributeScanner()); + + reconciler.setDamager(dr, XMLPartitionScanner.XML_ATTRIBUTE); + reconciler.setRepairer(dr, XMLPartitionScanner.XML_ATTRIBUTE); + + dr = new DefaultDamagerRepairer(xmlTextTools.getXMLCDATAScanner()); + + reconciler.setDamager(dr, XMLPartitionScanner.XML_CDATA); + reconciler.setRepairer(dr, XMLPartitionScanner.XML_CDATA); + + return reconciler; + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/text/SmartyTagRule.java b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/text/SmartyTagRule.java new file mode 100644 index 0000000..f1a71f6 --- /dev/null +++ b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/text/SmartyTagRule.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2002-2004 Widespace, OU and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Igor Malinin - initial contribution + * + * $Id: SmartyTagRule.java,v 1.1 2004-09-02 18:25:04 jsurfer Exp $ + */ + +package net.sourceforge.phpdt.smarty.ui.internal.text; + +import org.eclipse.jface.text.rules.ICharacterScanner; +import org.eclipse.jface.text.rules.IRule; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.Token; + +/** + * Rule detecting XML tag brackets and name. + * + * @author Igor Malinin + */ +public class SmartyTagRule implements IRule { + + private IToken token; + + public SmartyTagRule(IToken token) { + this.token = token; + } + + public IToken evaluate(ICharacterScanner scanner) { + int ch = scanner.read(); + if (ch == '}') { + return token; + } + if (ch == '/') { + ch = scanner.read(); + if (ch == '}') { + return token; + } + + scanner.unread(); + scanner.unread(); + return Token.UNDEFINED; + } + if (ch == '{') { + ch = scanner.read(); + if (ch == '/') { + ch = scanner.read(); + } + loop: while (true) { + switch (ch) { + case ICharacterScanner.EOF: + case 0x09: + case 0x0A: + case 0x0D: + case 0x20: + scanner.unread(); + break loop; + case '}': + break loop; + } + + ch = scanner.read(); + } + return token; + } + scanner.unread(); + return Token.UNDEFINED; + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/text/SmartyTagScanner.java b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/text/SmartyTagScanner.java new file mode 100644 index 0000000..22be5dc --- /dev/null +++ b/net.sourceforge.phpeclipse.smarty.ui/src/net/sourceforge/phpdt/smarty/ui/internal/text/SmartyTagScanner.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2002-2004 Widespace, OU and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Igor Malinin - initial contribution + * + * $Id: SmartyTagScanner.java,v 1.1 2004-09-02 18:25:04 jsurfer Exp $ + */ + +package net.sourceforge.phpdt.smarty.ui.internal.text; + +import java.util.Map; + +import net.sourceforge.phpeclipse.xml.ui.internal.text.NameDetector; +import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLTagRule; +import net.sourceforge.phpeclipse.xml.ui.text.IXMLSyntaxConstants; + +import org.eclipse.jface.text.rules.BufferedRuleBasedScanner; +import org.eclipse.jface.text.rules.IRule; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.jface.text.rules.WordRule; + +/** + * @author Igor Malinin + */ +public class SmartyTagScanner extends BufferedRuleBasedScanner { + + /** + * Creates a color token scanner. + */ + public SmartyTagScanner(Map tokens) { + setDefaultReturnToken((Token) tokens.get( + IXMLSyntaxConstants.XML_DEFAULT)); + + IToken tag = (Token) tokens.get(IXMLSyntaxConstants.XML_TAG); + IToken smartyTag = (Token) tokens.get(IXMLSyntaxConstants.XML_SMARTY); + IToken attribute = (Token) tokens.get(IXMLSyntaxConstants.XML_ATT_NAME); + + IRule[] rules = { + new XMLTagRule(tag), + new SmartyTagRule(smartyTag), + new WordRule(new NameDetector(), attribute),}; + + setRules(rules); + } +}