added TemplatePreferencePage
authorkhartlage <khartlage>
Thu, 2 Jan 2003 20:16:00 +0000 (20:16 +0000)
committerkhartlage <khartlage>
Thu, 2 Jan 2003 20:16:00 +0000 (20:16 +0000)
net.sourceforge.phpeclipse/plugin.xml
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/default-templates.xml
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/HTMLUnitContext.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/EditTemplateDialog.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/TemplatePreferencePage.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpparser/PHPParser.java

index ffa939f..dd10e7d 100644 (file)
@@ -2,7 +2,7 @@
 <plugin
    id="net.sourceforge.phpeclipse"
    name="%pluginName"
-   version="1.0.3"
+   version="1.0.4"
    provider-name="%providerName"
    class="net.sourceforge.phpeclipse.PHPeclipsePlugin">
 
                value="net.sourceforge.phpeclipse.phpnature">
          </filter>
       </page>
-      <page
+         <page
             objectClass="net.sourceforge.phpeclipse.PHPProject"
             name="%propertyPagePHPProject.name"
             class="net.sourceforge.phpeclipse.preferences.PHPProjectPropertyPage"
             class="net.sourceforge.phpeclipse.PHPSyntaxPreferencePage"
             id="net.sourceforge.phpeclipse.preference.PHPSyntaxPreferencePage">
       </page>
+      <page name="Templates"
+               id = "net.sourceforge.phpdt.internal.ui.preferences.TemplatePreferencePage"
+               class="net.sourceforge.phpdt.internal.ui.preferences.TemplatePreferencePage"
+               category= "net.sourceforge.phpeclipse.preference.PHPEclipsePreferencePage">
+         </page>
    </extension>
    <extension
          point="org.eclipse.ui.documentProviders">
index 2a1d730..4f29b3a 100644 (file)
  */</template>
  <template name="echo" description="echo a string" context="php" enabled="true">echo "${string}";
   ${cursor}</template>
-  
-  
-  <template name="&amp;nbsp" description="no-break space " context="html" enabled="true">&amp;nbsp
-  </template>
 
   <template name="&lt;html" description="html page with head,title,body" context="html" enabled="true">
   &lt;html&gt;
   <template name="&lt;blockquote" description="blockquoted text" context="html" enabled="true">
   &lt;blockquote&gt;${cursor}&lt;/blockquote&gt;
   </template>
- </templates>
\ No newline at end of file
+  
+  <template name="&amp;quot" description="quot" context="html" enabled="true">&amp;quot;</template>
+  <template name="&amp;amp" description="ampersand" context="html" enabled="true">&amp;amp;</template>
+  <template name="&amp;lt" description="less than" context="html" enabled="true">&amp;lt;</template>
+  <template name="&amp;gt" description="greater than" context="html" enabled="true">&amp;gt;</template>
+  
+  <template name="&amp;nbsp" description="no-break space" context="html" enabled="true">&amp;nbsp;</template>
+  <template name="&amp;iexcl" description="iexcl" context="html" enabled="true">&amp;iexcl;</template>
+  <template name="&amp;cent" description="cent" context="html" enabled="true">&amp;cent;</template>
+  <template name="&amp;pound" description="pound" context="html" enabled="true">&amp;pound;</template>
+  <template name="&amp;curren" description="curren" context="html" enabled="true">&amp;curren;</template>
+  <template name="&amp;yen" description="yen" context="html" enabled="true">&amp;yen;</template>
+  <template name="&amp;brvbar" description="brvbar" context="html" enabled="true">&amp;brvbar;</template>
+  <template name="&amp;brkbar" description="brkbar" context="html" enabled="true">&amp;brkbar;</template>
+  <template name="&amp;sect" description="sect" context="html" enabled="true">&amp;sect;</template>
+  <template name="&amp;uml" description="uml" context="html" enabled="true">&amp;uml;</template>
+  <template name="&amp;die" description="die" context="html" enabled="true">&amp;die;</template>
+  <template name="&amp;copy" description="copy" context="html" enabled="true">&amp;copy;</template>
+  <template name="&amp;ordf" description="ordf" context="html" enabled="true">&amp;ordf;</template>
+  <template name="&amp;laquo" description="laquo" context="html" enabled="true">&amp;laquo;</template>
+  <template name="&amp;not" description="not" context="html" enabled="true">&amp;not;</template>
+  <template name="&amp;shy" description="shy" context="html" enabled="true">&amp;shy;</template>
+  <template name="&amp;reg" description="reg" context="html" enabled="true">&amp;reg;</template>
+  <template name="&amp;macr" description="macr" context="html" enabled="true">&amp;macr;</template>
+  <template name="&amp;hibar" description="hibar" context="html" enabled="true">&amp;hibar;</template>
+  <template name="&amp;deg" description="deg" context="html" enabled="true">&amp;deg;</template>
+  <template name="&amp;plusmn" description="plusmn" context="html" enabled="true">&amp;plusmn;</template>
+  <template name="&amp;sup2" description="sup2" context="html" enabled="true">&amp;sup2;</template>
+  <template name="&amp;sup3" description="sup3" context="html" enabled="true">&amp;sup3;</template>
+  <template name="&amp;acute" description="acute" context="html" enabled="true">&amp;acute;</template>
+  <template name="&amp;micro" description="micro" context="html" enabled="true">&amp;micro;</template>
+  <template name="&amp;para" description="para" context="html" enabled="true">&amp;para;</template>
+  <template name="&amp;middot" description="middot" context="html" enabled="true">&amp;middot;</template>
+  <template name="&amp;cedil" description="cedil" context="html" enabled="true">&amp;cedil;</template>
+  <template name="&amp;sup1" description="sup1" context="html" enabled="true">&amp;sup1;</template>
+  <template name="&amp;ordm" description="ordm" context="html" enabled="true">&amp;ordm;</template>
+  <template name="&amp;raquo" description="raquo" context="html" enabled="true">&amp;raquo;</template>
+  <template name="&amp;frac14" description="frac14" context="html" enabled="true">&amp;frac14;</template>
+  <template name="&amp;frac12" description="frac12" context="html" enabled="true">&amp;frac12;</template>
+  <template name="&amp;frac34" description="frac34" context="html" enabled="true">&amp;frac34;</template>
+  <template name="&amp;iquest" description="iquest" context="html" enabled="true">&amp;iquest;</template>
+  <template name="&amp;Agrave" description="Agrave" context="html" enabled="true">&amp;Agrave;</template>
+  <template name="&amp;Aacute" description="Aacute" context="html" enabled="true">&amp;Aacute;</template>
+  <template name="&amp;Acirc" description="Acirc" context="html" enabled="true">&amp;Acirc;</template>
+  <template name="&amp;Atilde" description="Atilde" context="html" enabled="true">&amp;Atilde;</template>
+  <template name="&amp;Auml" description="Auml" context="html" enabled="true">&amp;Auml;</template>
+  <template name="&amp;Aring" description="Aring" context="html" enabled="true">&amp;Aring;</template>
+  <template name="&amp;AElig" description="AElig" context="html" enabled="true">&amp;AElig;</template>
+  <template name="&amp;Ccedil" description="Ccedil" context="html" enabled="true">&amp;Ccedil;</template>
+  <template name="&amp;Egrave" description="Egrave" context="html" enabled="true">&amp;Egrave;</template>
+  <template name="&amp;Eacute" description="Eacute" context="html" enabled="true">&amp;Eacute;</template>
+  <template name="&amp;Ecirc" description="Ecirc" context="html" enabled="true">&amp;Ecirc;</template>
+  <template name="&amp;Euml" description="Euml" context="html" enabled="true">&amp;Euml;</template>
+  <template name="&amp;lgrave" description="lgrave" context="html" enabled="true">&amp;lgrave;</template>
+  <template name="&amp;lacute" description="lacute" context="html" enabled="true">&amp;lacute;</template>
+  <template name="&amp;lcirc" description="lcirc" context="html" enabled="true">&amp;lcirc;</template>
+  <template name="&amp;luml" description="luml" context="html" enabled="true">&amp;luml;</template>
+  <template name="&amp;ETH" description="ETH" context="html" enabled="true">&amp;ETH;</template>
+  <template name="&amp;Ntilde" description="Ntilde" context="html" enabled="true">&amp;Ntilde;</template>
+  <template name="&amp;Ograve" description="Ograve" context="html" enabled="true">&amp;Ograve;</template>
+  <template name="&amp;Oacute" description="Oacute" context="html" enabled="true">&amp;Oacute;</template>
+  <template name="&amp;Ocirc" description="Ocirc" context="html" enabled="true">&amp;Ocirc;</template>
+  <template name="&amp;Otilde" description="Otilde" context="html" enabled="true">&amp;Otilde;</template>
+  <template name="&amp;Ouml" description="Ouml" context="html" enabled="true">&amp;Ouml;</template>
+  <template name="&amp;times" description="times" context="html" enabled="true">&amp;times;</template>
+  <template name="&amp;Oslash" description="Oslash" context="html" enabled="true">&amp;Oslash;</template>
+  <template name="&amp;Ugrave" description="Ugrave" context="html" enabled="true">&amp;Ugrave;</template>
+  <template name="&amp;Uacute" description="Uacute" context="html" enabled="true">&amp;Uacute;</template>
+  <template name="&amp;Ucirc" description="Ucirc" context="html" enabled="true">&amp;Ucirc;</template>
+  <template name="&amp;Uuml" description="Uuml" context="html" enabled="true">&amp;Uuml;</template>
+  <template name="&amp;Yacute" description="Yacute" context="html" enabled="true">&amp;Yacute;</template>
+  <template name="&amp;THORN" description="THORN" context="html" enabled="true">&amp;THORN;</template>
+  <template name="&amp;szlig" description="szlig" context="html" enabled="true">&amp;szlig;</template>
+  <template name="&amp;agrave" description="agrave" context="html" enabled="true">&amp;agrave;</template>
+  <template name="&amp;aacute" description="aacute" context="html" enabled="true">&amp;aacute;</template>
+  <template name="&amp;acirc" description="acirc" context="html" enabled="true">&amp;acirc;</template>
+  <template name="&amp;atilde" description="atilde" context="html" enabled="true">&amp;atilde;</template>
+  <template name="&amp;auml" description="auml" context="html" enabled="true">&amp;auml;</template>
+  <template name="&amp;aring" description="aring" context="html" enabled="true">&amp;aring;</template>
+  <template name="&amp;aelig" description="aelig" context="html" enabled="true">&amp;aelig;</template>
+  <template name="&amp;ccedil" description="ccedil" context="html" enabled="true">&amp;ccedil;</template>
+  <template name="&amp;egrave" description="egrave" context="html" enabled="true">&amp;egrave;</template>
+  <template name="&amp;eacute" description="eacute" context="html" enabled="true">&amp;eacute;</template>
+  <template name="&amp;ecirc" description="ecirc" context="html" enabled="true">&amp;ecirc;</template>
+  <template name="&amp;euml" description="euml" context="html" enabled="true">&amp;euml;</template>
+  <template name="&amp;igrave" description="igrave" context="html" enabled="true">&amp;igrave;</template>
+  <template name="&amp;iacute" description="iacute" context="html" enabled="true">&amp;iacute;</template>
+  <template name="&amp;icirc" description="icirc" context="html" enabled="true">&amp;icirc;</template>
+  <template name="&amp;iuml" description="iuml" context="html" enabled="true">&amp;iuml;</template>
+  <template name="&amp;eth" description="eth" context="html" enabled="true">&amp;eth;</template>
+  <template name="&amp;ntilde" description="ntilde" context="html" enabled="true">&amp;ntilde;</template>
+  <template name="&amp;ograve" description="ograve" context="html" enabled="true">&amp;ograve;</template>
+  <template name="&amp;oacute" description="oacute" context="html" enabled="true">&amp;oacute;</template>
+  <template name="&amp;ocirc" description="ocirc" context="html" enabled="true">&amp;ocirc;</template>
+  <template name="&amp;otilde" description="otilde" context="html" enabled="true">&amp;otilde;</template>
+  <template name="&amp;ouml" description="ouml" context="html" enabled="true">&amp;ouml;</template>
+  <template name="&amp;divide" description="divide" context="html" enabled="true">&amp;divide;</template>
+  <template name="&amp;oslash" description="oslash" context="html" enabled="true">&amp;oslash;</template>
+  <template name="&amp;ugrave" description="ugrave" context="html" enabled="true">&amp;ugrave;</template>
+  <template name="&amp;uacute" description="uacute" context="html" enabled="true">&amp;uacute;</template>
+  <template name="&amp;ucirc" description="ucirc" context="html" enabled="true">&amp;ucirc;</template>
+  <template name="&amp;uuml" description="uuml" context="html" enabled="true">&amp;uuml;</template>
+  <template name="&amp;yacute" description="yacute" context="html" enabled="true">&amp;yacute;</template>
+  <template name="&amp;thorn" description="thorn" context="html" enabled="true">&amp;thorn;</template>
+  <template name="&amp;yuml" description="yuml" context="html" enabled="true">&amp;yuml;</template>
+
+
+  
+  <template name="#000000" description="Black (Color Code)" context="html" enabled="true">#000000</template>
+  <template name="#0000FF" description="Blue (Color Code)" context="html" enabled="true">#0000FF</template>
+  <template name="#A52A2A" description="Brown (Color Code)" context="html" enabled="true">#A52A2A</template>
+  <template name="#00FFFF" description="Cyan (Color Code)" context="html" enabled="true">#00FFFF</template>
+  <template name="#FFD700" description="Gold (Color Code)" context="html" enabled="true">#FFD700</template>
+  <template name="#808080" description="Grey (Color Code)" context="html" enabled="true">#808080</template>
+  <template name="#008000" description="Green (Color Code)" context="html" enabled="true">#008000</template>
+  <template name="#FF00FF" description="Magenta (Color Code)" context="html" enabled="true">#FF00FF</template>
+  <template name="#FFA500" description="Orange (Color Code)" context="html" enabled="true">#FFA500</template>
+  <template name="#FFC0CB" description="Pink (Color Code)" context="html" enabled="true">#FFC0CB</template>
+  <template name="#800080" description="Purple (Color Code)" context="html" enabled="true">#800080</template>
+  <template name="#FF0000" description="Red (Color Code)" context="html" enabled="true">#FF0000</template>
+  <template name="#C0C0C0" description="Silver (Color Code)" context="html" enabled="true">#C0C0C0</template>
+  <template name="#FFFFFF" description="White (Color Code)" context="html" enabled="true">#FFFFFF</template>
+  <template name="#FFFF00" description="Yellow (Color Code)" context="html" enabled="true">#FFFF00</template>
+
+  <template name="Black" description="Black (Color Code)" context="html" enabled="true">#000000</template>
+  <template name="Blue" description="Blue (Color Code)" context="html" enabled="true">#0000FF</template>
+  <template name="Brown" description="Brown (Color Code)" context="html" enabled="true">#A52A2A</template>
+  <template name="Cyan" description="Cyan (Color Code)" context="html" enabled="true">#00FFFF</template>
+  <template name="Gold" description="Gold (Color Code)" context="html" enabled="true">#FFD700</template>
+  <template name="Grey" description="Grey (Color Code)" context="html" enabled="true">#808080</template>
+  <template name="Green" description="Green (Color Code)" context="html" enabled="true">#008000</template>
+  <template name="Magenta" description="Magenta (Color Code)" context="html" enabled="true">#FF00FF</template>
+  <template name="Orange" description="Orange (Color Code)" context="html" enabled="true">#FFA500</template>
+  <template name="Pink" description="Pink (Color Code)" context="html" enabled="true">#FFC0CB</template>
+  <template name="Purple" description="Purple (Color Code)" context="html" enabled="true">#800080</template>
+  <template name="Red" description="Red (Color Code)" context="html" enabled="true">#FF0000</template>
+  <template name="Silver" description="Silver (Color Code)" context="html" enabled="true">#C0C0C0</template>
+  <template name="White" description="White (Color Code)" context="html" enabled="true">#FFFFFF</template>
+  <template name="Yelow" description="Yellow (Color Code)" context="html" enabled="true">#FFFF00</template>
+
+</templates>
\ No newline at end of file
index e459ce2..c9abf99 100644 (file)
@@ -21,7 +21,7 @@ public class HTMLUnitContext extends DocumentTemplateContext {
   /** The platform default line delimiter. */
   private static final String PLATFORM_LINE_DELIMITER = System.getProperty("line.separator"); //$NON-NLS-1$
 
-  private static final String specialChars = "$&<";
+  private static final String specialChars = "&<#";
   /** The compilation unit, may be <code>null</code>. */
   //   private final ICompilationUnit fCompilationUnit;
 
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/EditTemplateDialog.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/EditTemplateDialog.java
new file mode 100644 (file)
index 0000000..5a28e77
--- /dev/null
@@ -0,0 +1,545 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package net.sourceforge.phpdt.internal.ui.preferences;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+import net.sourceforge.phpdt.internal.corext.template.ContextTypeRegistry;
+import net.sourceforge.phpdt.internal.corext.template.Template;
+import net.sourceforge.phpdt.internal.corext.template.TemplateMessages;
+import net.sourceforge.phpdt.internal.corext.template.TemplateTranslator;
+import net.sourceforge.phpdt.internal.ui.dialog.StatusDialog;
+import net.sourceforge.phpdt.internal.ui.dialog.StatusInfo;
+import net.sourceforge.phpdt.internal.ui.text.template.TemplateVariableProcessor;
+import net.sourceforge.phpdt.internal.ui.util.SWTUtil;
+import net.sourceforge.phpeclipse.IPreferenceConstants;
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.phpeditor.PHPSourceViewerConfiguration;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.GroupMarker;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextListener;
+import org.eclipse.jface.text.ITextOperationTarget;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.ITextViewerExtension;
+import org.eclipse.jface.text.TextEvent;
+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.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.custom.VerifyKeyListener;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.texteditor.ITextEditorActionConstants;
+import org.eclipse.ui.texteditor.IUpdate;
+
+/**
+ * Dialog to edit a template.
+ */
+public class EditTemplateDialog extends StatusDialog {
+
+       private static class SimpleJavaSourceViewerConfiguration extends PHPSourceViewerConfiguration {
+
+               private final IContentAssistProcessor fProcessor;
+
+       //      SimpleJavaSourceViewerConfiguration(JavaTextTools tools, ITextEditor editor, IContentAssistProcessor processor) {
+               SimpleJavaSourceViewerConfiguration(IContentAssistProcessor processor) {        
+      super();
+                       fProcessor= processor;
+               }
+               
+               /*
+                * @see SourceViewerConfiguration#getContentAssistant(ISourceViewer)
+                */
+               public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
+
+                       IPreferenceStore store= PHPeclipsePlugin.getDefault().getPreferenceStore();
+
+                       ContentAssistant assistant= new ContentAssistant();
+                       assistant.setContentAssistProcessor(fProcessor, IDocument.DEFAULT_CONTENT_TYPE);
+                               // Register the same processor for strings and single line comments to get code completion at the start of those partitions.
+//                     assistant.setContentAssistProcessor(fProcessor, JavaPartitionScanner.JAVA_STRING);
+//                     assistant.setContentAssistProcessor(fProcessor, JavaPartitionScanner.JAVA_SINGLE_LINE_COMMENT);
+//                     
+//                     assistant.setContentAssistProcessor(fProcessor, JavaPartitionScanner.JAVA_DOC);
+
+//                     assistant.enableAutoInsert(store.getBoolean(ContentAssistPreference.AUTOINSERT));
+//                     assistant.enableAutoActivation(store.getBoolean(ContentAssistPreference.AUTOACTIVATION));
+//                     assistant.setAutoActivationDelay(store.getInt(ContentAssistPreference.AUTOACTIVATION_DELAY));
+                       assistant.setProposalPopupOrientation(assistant.PROPOSAL_OVERLAY);
+                       assistant.setContextInformationPopupOrientation(assistant.CONTEXT_INFO_ABOVE);
+//                     assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
+
+                       Display display= sourceViewer.getTextWidget().getDisplay();
+                       
+                       Color background= createColor(store, IPreferenceConstants.PROPOSALS_BACKGROUND, display);                       
+                       assistant.setContextInformationPopupBackground(background);
+                       assistant.setContextSelectorBackground(background);
+                       assistant.setProposalSelectorBackground(background);
+
+                       Color foreground= createColor(store, IPreferenceConstants.PROPOSALS_FOREGROUND, display);
+                       assistant.setContextInformationPopupForeground(foreground);
+                       assistant.setContextSelectorForeground(foreground);
+                       assistant.setProposalSelectorForeground(foreground);
+                       
+                       return assistant;
+               }       
+
+               /**
+                * Creates a color from the information stored in the given preference store.
+                * Returns <code>null</code> if there is no such information available.
+                */
+               private Color createColor(IPreferenceStore store, String key, Display display) {
+               
+                       RGB rgb= null;          
+                       
+                       if (store.contains(key)) {
+                               
+                               if (store.isDefault(key))
+                                       rgb= PreferenceConverter.getDefaultColor(store, key);
+                               else
+                                       rgb= PreferenceConverter.getColor(store, key);
+                       
+                               if (rgb != null)
+                                       return new Color(display, rgb);
+                       }
+                       
+                       return null;
+               }       
+       }
+
+       private static class TextViewerAction extends Action implements IUpdate {
+       
+               private int fOperationCode= -1;
+               private ITextOperationTarget fOperationTarget;
+       
+               public TextViewerAction(ITextViewer viewer, int operationCode) {
+                       fOperationCode= operationCode;
+                       fOperationTarget= viewer.getTextOperationTarget();
+                       update();
+               }
+       
+               /**
+                * Updates the enabled state of the action.
+                * Fires a property change if the enabled state changes.
+                * 
+                * @see Action#firePropertyChange(String, Object, Object)
+                */
+               public void update() {
+       
+                       boolean wasEnabled= isEnabled();
+                       boolean isEnabled= (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode));
+                       setEnabled(isEnabled);
+       
+                       if (wasEnabled != isEnabled) {
+                               firePropertyChange(ENABLED, wasEnabled ? Boolean.TRUE : Boolean.FALSE, isEnabled ? Boolean.TRUE : Boolean.FALSE);
+                       }
+               }
+               
+               /**
+                * @see Action#run()
+                */
+               public void run() {
+                       if (fOperationCode != -1 && fOperationTarget != null) {
+                               fOperationTarget.doOperation(fOperationCode);
+                       }
+               }
+       }       
+
+       private final Template fTemplate;
+       
+       private Text fNameText;
+       private Text fDescriptionText;
+       private Combo fContextCombo;
+       private SourceViewer fPatternEditor;    
+       private Button fInsertVariableButton;
+
+       private TemplateTranslator fTranslator= new TemplateTranslator();       
+       private boolean fSuppressError= true; // #4354  
+       private Map fGlobalActions= new HashMap(10);
+       private List fSelectionActions = new ArrayList(3);      
+       private Vector fContextTypes= new Vector();
+       
+       private final TemplateVariableProcessor fProcessor= new TemplateVariableProcessor();
+               
+       public EditTemplateDialog(Shell parent, Template template, boolean edit) {
+               super(parent);
+               
+               setShellStyle(getShellStyle() | SWT.MAX | SWT.RESIZE);
+               
+               String title= edit
+                       ? TemplateMessages.getString("EditTemplateDialog.title.edit") //$NON-NLS-1$
+                       : TemplateMessages.getString("EditTemplateDialog.title.new"); //$NON-NLS-1$
+               setTitle(title);
+
+               fTemplate= template;
+               
+               ContextTypeRegistry registry= ContextTypeRegistry.getInstance();
+               for (Iterator iterator= registry.iterator(); iterator.hasNext(); )
+                       fContextTypes.add(iterator.next());
+
+               if (fContextTypes.size() > 0)
+                       fProcessor.setContextType(ContextTypeRegistry.getInstance().getContextType((String) fContextTypes.get(0)));
+       }
+       
+       /*
+        * @see Dialog#createDialogArea(Composite)
+        */
+       protected Control createDialogArea(Composite ancestor) {
+               Composite parent= new Composite(ancestor, SWT.NONE);
+               GridLayout layout= new GridLayout();
+               layout.numColumns= 2;
+               parent.setLayout(layout);
+               parent.setLayoutData(new GridData(GridData.FILL_BOTH));
+               
+               createLabel(parent, TemplateMessages.getString("EditTemplateDialog.name")); //$NON-NLS-1$       
+               
+               Composite composite= new Composite(parent, SWT.NONE);
+               composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+               layout= new GridLayout();               
+               layout.numColumns= 3;
+               layout.marginWidth= 0;
+               layout.marginHeight= 0;
+               composite.setLayout(layout);
+
+               fNameText= createText(composite);
+               fNameText.addModifyListener(new ModifyListener() {
+                       public void modifyText(ModifyEvent e) {
+                               if (fSuppressError && (fNameText.getText().trim().length() != 0))
+                                       fSuppressError= false;
+
+                               updateButtons();
+                       }
+               });
+
+               createLabel(composite, TemplateMessages.getString("EditTemplateDialog.context")); //$NON-NLS-1$         
+               fContextCombo= new Combo(composite, SWT.READ_ONLY);
+
+               for (Iterator iterator= fContextTypes.iterator(); iterator.hasNext(); )
+                       fContextCombo.add((String) iterator.next());
+
+               fContextCombo.addModifyListener(new ModifyListener() {
+                       public void modifyText(ModifyEvent e) {
+                               String name= fContextCombo.getText();
+                               fProcessor.setContextType(ContextTypeRegistry.getInstance().getContextType(name));                              
+                       }
+               });
+               
+               createLabel(parent, TemplateMessages.getString("EditTemplateDialog.description")); //$NON-NLS-1$                
+               fDescriptionText= createText(parent);
+
+               Label patternLabel= createLabel(parent, TemplateMessages.getString("EditTemplateDialog.pattern")); //$NON-NLS-1$
+               patternLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
+               fPatternEditor= createEditor(parent);
+               
+               Label filler= new Label(parent, SWT.NONE);              
+               filler.setLayoutData(new GridData());
+               
+               composite= new Composite(parent, SWT.NONE);
+               layout= new GridLayout();               
+               layout.marginWidth= 0;
+               layout.marginHeight= 0;
+               composite.setLayout(layout);            
+               composite.setLayoutData(new GridData());
+               
+               fInsertVariableButton= new Button(composite, SWT.NONE);
+               fInsertVariableButton.setLayoutData(getButtonGridData(fInsertVariableButton));
+               fInsertVariableButton.setText(TemplateMessages.getString("EditTemplateDialog.insert.variable")); //$NON-NLS-1$
+               fInsertVariableButton.addSelectionListener(new SelectionListener() {
+                       public void widgetSelected(SelectionEvent e) {
+                               fPatternEditor.getTextWidget().setFocus();
+                               fPatternEditor.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);                      
+                       }
+
+                       public void widgetDefaultSelected(SelectionEvent e) {}
+               });
+
+               fNameText.setText(fTemplate.getName());
+               fDescriptionText.setText(fTemplate.getDescription());
+               fContextCombo.select(getIndex(fTemplate.getContextTypeName()));
+
+               initializeActions();
+
+               return composite;
+       }
+
+       private static GridData getButtonGridData(Button button) {
+               GridData data= new GridData(GridData.FILL_HORIZONTAL);
+               data.heightHint= SWTUtil.getButtonHeigthHint(button);
+       
+               return data;
+       }
+
+       private static Label createLabel(Composite parent, String name) {
+               Label label= new Label(parent, SWT.NULL);
+               label.setText(name);
+               label.setLayoutData(new GridData());
+
+               return label;
+       }
+
+       private static Text createText(Composite parent) {
+               Text text= new Text(parent, SWT.BORDER);
+               text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));             
+               
+               return text;
+       }
+
+       private SourceViewer createEditor(Composite parent) {
+               SourceViewer viewer= new SourceViewer(parent, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
+       //      JavaTextTools tools= JavaPlugin.getDefault().getJavaTextTools();
+               IDocument document= new Document(fTemplate.getPattern());
+       //      IDocumentPartitioner partitioner= tools.createDocumentPartitioner();
+       //      document.setDocumentPartitioner(partitioner);
+       //      partitioner.connect(document);          
+       //      viewer.configure(new SimpleJavaSourceViewerConfiguration(tools, null, fProcessor));
+               viewer.configure(new SimpleJavaSourceViewerConfiguration(fProcessor));
+    viewer.setEditable(true);
+               viewer.setDocument(document);
+               
+               Font font= JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT);
+               viewer.getTextWidget().setFont(font);
+               
+               Control control= viewer.getControl();
+               GridData data= new GridData(GridData.FILL_BOTH);
+               data.widthHint= convertWidthInCharsToPixels(60);
+               data.heightHint= convertHeightInCharsToPixels(5);
+               control.setLayoutData(data);
+               
+               viewer.addTextListener(new ITextListener() {
+                       public void textChanged(TextEvent event) {
+                           try {
+                                       fTranslator.translate(event.getDocumentEvent().getDocument().get());
+                           } catch (CoreException e) {
+                               PHPeclipsePlugin.log(e);
+                           }
+                               
+                               updateUndoAction();
+                               updateButtons();
+                       }
+               });
+
+               viewer.addSelectionChangedListener(new ISelectionChangedListener() {                    
+                       public void selectionChanged(SelectionChangedEvent event) {
+                               updateSelectionDependentActions();
+                       }
+               });
+
+               if (viewer instanceof ITextViewerExtension) {
+                        ((ITextViewerExtension) viewer).prependVerifyKeyListener(new VerifyKeyListener() {
+                               public void verifyKey(VerifyEvent event) {
+                                       handleVerifyKeyPressed(event);
+                               }
+                       });
+               } else {                        
+                       viewer.getTextWidget().addKeyListener(new KeyListener() {
+                               public void keyPressed(KeyEvent e) {
+                                       handleKeyPressed(e);
+                               }
+       
+                               public void keyReleased(KeyEvent e) {}
+                       });
+               }
+               
+               return viewer;
+       }
+
+       private void handleKeyPressed(KeyEvent event) {
+               if (event.stateMask != SWT.CTRL)
+                       return;
+                       
+               switch (event.character) {
+                       case ' ':
+                               fPatternEditor.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
+                               break;
+
+                       // CTRL-Z
+                       case (int) 'z' - (int) 'a' + 1:
+                               fPatternEditor.doOperation(ITextOperationTarget.UNDO);
+                               break;                          
+               }
+       }
+
+       private void handleVerifyKeyPressed(VerifyEvent event) {
+               if (!event.doit)
+                       return;
+
+               if (event.stateMask != SWT.CTRL)
+                       return;
+                       
+               switch (event.character) {
+                       case ' ':
+                               fPatternEditor.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
+                               event.doit= false;
+                               break;
+
+                       // CTRL-Z
+                       case (int) 'z' - (int) 'a' + 1:
+                               fPatternEditor.doOperation(ITextOperationTarget.UNDO);
+                               event.doit= false;
+                               break;                          
+               }
+       }
+
+       private void initializeActions() {
+               TextViewerAction action= new TextViewerAction(fPatternEditor, fPatternEditor.UNDO);
+               action.setText(TemplateMessages.getString("EditTemplateDialog.undo")); //$NON-NLS-1$
+               fGlobalActions.put(ITextEditorActionConstants.UNDO, action);
+
+               action= new TextViewerAction(fPatternEditor, fPatternEditor.CUT);
+               action.setText(TemplateMessages.getString("EditTemplateDialog.cut")); //$NON-NLS-1$
+               fGlobalActions.put(ITextEditorActionConstants.CUT, action);
+
+               action= new TextViewerAction(fPatternEditor, fPatternEditor.COPY);
+               action.setText(TemplateMessages.getString("EditTemplateDialog.copy")); //$NON-NLS-1$
+               fGlobalActions.put(ITextEditorActionConstants.COPY, action);
+
+               action= new TextViewerAction(fPatternEditor, fPatternEditor.PASTE);
+               action.setText(TemplateMessages.getString("EditTemplateDialog.paste")); //$NON-NLS-1$
+               fGlobalActions.put(ITextEditorActionConstants.PASTE, action);
+
+               action= new TextViewerAction(fPatternEditor, fPatternEditor.SELECT_ALL);
+               action.setText(TemplateMessages.getString("EditTemplateDialog.select.all")); //$NON-NLS-1$
+               fGlobalActions.put(ITextEditorActionConstants.SELECT_ALL, action);
+
+               action= new TextViewerAction(fPatternEditor, fPatternEditor.CONTENTASSIST_PROPOSALS);
+               action.setText(TemplateMessages.getString("EditTemplateDialog.content.assist")); //$NON-NLS-1$
+               fGlobalActions.put("ContentAssistProposal", action); //$NON-NLS-1$
+
+               fSelectionActions.add(ITextEditorActionConstants.CUT);
+               fSelectionActions.add(ITextEditorActionConstants.COPY);
+               fSelectionActions.add(ITextEditorActionConstants.PASTE);
+               
+               // create context menu
+               MenuManager manager= new MenuManager(null, null);
+               manager.setRemoveAllWhenShown(true);
+               manager.addMenuListener(new IMenuListener() {
+                       public void menuAboutToShow(IMenuManager mgr) {
+                               fillContextMenu(mgr);
+                       }
+               });
+
+               StyledText text= fPatternEditor.getTextWidget();                
+               Menu menu= manager.createContextMenu(text);
+               text.setMenu(menu);
+       }
+
+       private void fillContextMenu(IMenuManager menu) {
+               menu.add(new GroupMarker(ITextEditorActionConstants.GROUP_UNDO));
+               menu.appendToGroup(ITextEditorActionConstants.GROUP_UNDO, (IAction) fGlobalActions.get(ITextEditorActionConstants.UNDO));
+               
+               menu.add(new Separator(ITextEditorActionConstants.GROUP_EDIT));         
+               menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, (IAction) fGlobalActions.get(ITextEditorActionConstants.CUT));
+               menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, (IAction) fGlobalActions.get(ITextEditorActionConstants.COPY));
+               menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, (IAction) fGlobalActions.get(ITextEditorActionConstants.PASTE));
+               menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, (IAction) fGlobalActions.get(ITextEditorActionConstants.SELECT_ALL));
+
+       //      menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
+       //      menu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, (IAction) fGlobalActions.get("ContentAssistProposal")); //$NON-NLS-1$
+       }
+
+       protected void updateSelectionDependentActions() {
+               Iterator iterator= fSelectionActions.iterator();
+               while (iterator.hasNext())
+                       updateAction((String)iterator.next());          
+       }
+
+       protected void updateUndoAction() {
+               IAction action= (IAction) fGlobalActions.get(ITextEditorActionConstants.UNDO);
+               if (action instanceof IUpdate)
+                       ((IUpdate) action).update();
+       }
+
+       protected void updateAction(String actionId) {
+               IAction action= (IAction) fGlobalActions.get(actionId);
+               if (action instanceof IUpdate)
+                       ((IUpdate) action).update();
+       }
+
+       private int getIndex(String context) {
+               ContextTypeRegistry registry= ContextTypeRegistry.getInstance();
+               registry.getContextType(context);
+               
+               if (context == null)
+                       return -1;
+                       
+               return fContextTypes.indexOf(context);
+       }
+       
+       protected void okPressed() {
+               fTemplate.setName(fNameText.getText());
+               fTemplate.setDescription(fDescriptionText.getText());
+               fTemplate.setContext(fContextCombo.getText());
+               fTemplate.setPattern(fPatternEditor.getTextWidget().getText());
+               
+               super.okPressed();
+       }
+       
+       private void updateButtons() {          
+               boolean valid= fNameText.getText().trim().length() != 0;
+
+               StatusInfo status= new StatusInfo();
+               
+               if (!valid) {
+                       if (fSuppressError)
+                               status.setError(""); //$NON-NLS-1$                                                      
+                       else
+                               status.setError(TemplateMessages.getString("EditTemplateDialog.error.noname")); //$NON-NLS-1$
+               } else if (fTranslator.getErrorMessage() != null) {
+                       status.setError(fTranslator.getErrorMessage()); 
+               }
+
+               updateStatus(status);
+       }
+
+       /*
+        * @see org.eclipse.jface.window.Window#configureShell(Shell)
+        */
+       protected void configureShell(Shell newShell) {
+               super.configureShell(newShell);
+//             WorkbenchHelp.setHelp(newShell, IJavaHelpContextIds.EDIT_TEMPLATE_DIALOG);
+       }
+
+
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/TemplatePreferencePage.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/TemplatePreferencePage.java
new file mode 100644 (file)
index 0000000..1424d1f
--- /dev/null
@@ -0,0 +1,626 @@
+package net.sourceforge.phpdt.internal.ui.preferences;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import net.sourceforge.phpdt.internal.corext.template.ContextType;
+import net.sourceforge.phpdt.internal.corext.template.ContextTypeRegistry;
+import net.sourceforge.phpdt.internal.corext.template.Template;
+import net.sourceforge.phpdt.internal.corext.template.TemplateMessages;
+import net.sourceforge.phpdt.internal.corext.template.TemplateSet;
+import net.sourceforge.phpdt.internal.corext.template.Templates;
+import net.sourceforge.phpdt.internal.ui.text.template.TemplateContentProvider;
+import net.sourceforge.phpdt.internal.ui.text.template.TemplateLabelProvider;
+import net.sourceforge.phpdt.internal.ui.util.SWTUtil;
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.phpeditor.PHPSourceViewerConfiguration;
+import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ControlAdapter;
+import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+public class TemplatePreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+
+       // preference store keys
+       private static final String PREF_FORMAT_TEMPLATES= PHPeclipsePlugin.PLUGIN_ID + ".template.format"; //$NON-NLS-1$
+
+       private Templates fTemplates;
+
+       private CheckboxTableViewer fTableViewer;
+       private Button fAddButton;
+       private Button fEditButton;
+       private Button fImportButton;
+       private Button fExportButton;
+       private Button fExportAllButton;
+       private Button fRemoveButton;
+       private Button fEnableAllButton;
+       private Button fDisableAllButton;
+
+       private SourceViewer fPatternViewer;
+//     private Button fFormatButton;
+       
+       public TemplatePreferencePage() {
+               super();
+               
+               setPreferenceStore(PHPeclipsePlugin.getDefault().getPreferenceStore());
+               setDescription(TemplateMessages.getString("TemplatePreferencePage.message")); //$NON-NLS-1$
+
+               fTemplates= Templates.getInstance();
+       }
+
+       /*
+        * @see PreferencePage#createContents(Composite)
+        */
+       protected Control createContents(Composite ancestor) {  
+               Composite parent= new Composite(ancestor, SWT.NONE);
+               GridLayout layout= new GridLayout();
+               layout.numColumns= 2;
+               layout.marginHeight= 0;
+               layout.marginWidth= 0;
+               parent.setLayout(layout);                               
+
+        Composite innerParent= new Composite(parent, SWT.NONE);
+        GridLayout innerLayout= new GridLayout();
+        innerLayout.numColumns= 2;
+        innerLayout.marginHeight= 0;
+        innerLayout.marginWidth= 0;
+        innerParent.setLayout(innerLayout);
+        GridData gd= new GridData(GridData.FILL_BOTH);
+        gd.horizontalSpan= 2;
+        innerParent.setLayoutData(gd);
+
+               Table table= new Table(innerParent, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
+               
+               GridData data= new GridData(GridData.FILL_BOTH);
+               data.widthHint= convertWidthInCharsToPixels(3);
+               data.heightHint= convertHeightInCharsToPixels(10);
+               table.setLayoutData(data);
+                               
+               table.setHeaderVisible(true);
+               table.setLinesVisible(true);            
+
+               TableLayout tableLayout= new TableLayout();
+               table.setLayout(tableLayout);
+
+               TableColumn column1= new TableColumn(table, SWT.NONE);          
+               column1.setText(TemplateMessages.getString("TemplatePreferencePage.column.name")); //$NON-NLS-1$
+
+               TableColumn column2= new TableColumn(table, SWT.NONE);
+               column2.setText(TemplateMessages.getString("TemplatePreferencePage.column.context")); //$NON-NLS-1$
+       
+               TableColumn column3= new TableColumn(table, SWT.NONE);
+               column3.setText(TemplateMessages.getString("TemplatePreferencePage.column.description")); //$NON-NLS-1$
+               
+               fTableViewer= new CheckboxTableViewer(table);           
+               fTableViewer.setLabelProvider(new TemplateLabelProvider());
+               fTableViewer.setContentProvider(new TemplateContentProvider());
+
+               fTableViewer.setSorter(new ViewerSorter() {
+                       public int compare(Viewer viewer, Object object1, Object object2) {
+                               if ((object1 instanceof Template) && (object2 instanceof Template)) {
+                                       Template left= (Template) object1;
+                                       Template right= (Template) object2;
+                                       int result= left.getName().compareToIgnoreCase(right.getName());
+                                       if (result != 0)
+                                               return result;
+                                       return left.getDescription().compareToIgnoreCase(right.getDescription());
+                               }
+                               return super.compare(viewer, object1, object2);
+                       }
+                       
+                       public boolean isSorterProperty(Object element, String property) {
+                               return true;
+                       }
+               });
+               
+               fTableViewer.addDoubleClickListener(new IDoubleClickListener() {
+                       public void doubleClick(DoubleClickEvent e) {
+                               edit();
+                       }
+               });
+               
+               fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+                       public void selectionChanged(SelectionChangedEvent e) {
+                               selectionChanged1();
+                       }
+               });
+
+               fTableViewer.addCheckStateListener(new ICheckStateListener() {
+                       public void checkStateChanged(CheckStateChangedEvent event) {
+                               Template template= (Template) event.getElement();
+                               template.setEnabled(event.getChecked());
+                       }
+               });
+
+               Composite buttons= new Composite(innerParent, SWT.NONE);
+               buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
+               layout= new GridLayout();
+               layout.marginHeight= 0;
+               layout.marginWidth= 0;
+               buttons.setLayout(layout);
+               
+               fAddButton= new Button(buttons, SWT.PUSH);
+               fAddButton.setText(TemplateMessages.getString("TemplatePreferencePage.new")); //$NON-NLS-1$
+               fAddButton.setLayoutData(getButtonGridData(fAddButton));
+               fAddButton.addListener(SWT.Selection, new Listener() {
+                       public void handleEvent(Event e) {
+                               add();
+                       }
+               });
+
+               fEditButton= new Button(buttons, SWT.PUSH);
+               fEditButton.setText(TemplateMessages.getString("TemplatePreferencePage.edit")); //$NON-NLS-1$
+               fEditButton.setLayoutData(getButtonGridData(fEditButton));
+               fEditButton.addListener(SWT.Selection, new Listener() {
+                       public void handleEvent(Event e) {
+                               edit();
+                       }
+               });
+
+               fRemoveButton= new Button(buttons, SWT.PUSH);
+               fRemoveButton.setText(TemplateMessages.getString("TemplatePreferencePage.remove")); //$NON-NLS-1$
+               fRemoveButton.setLayoutData(getButtonGridData(fRemoveButton));
+               fRemoveButton.addListener(SWT.Selection, new Listener() {
+                       public void handleEvent(Event e) {
+                               remove();
+                       }
+               });
+                               
+               fImportButton= new Button(buttons, SWT.PUSH);
+               fImportButton.setText(TemplateMessages.getString("TemplatePreferencePage.import")); //$NON-NLS-1$
+               fImportButton.setLayoutData(getButtonGridData(fImportButton));
+               fImportButton.addListener(SWT.Selection, new Listener() {
+                       public void handleEvent(Event e) {
+                               import_();
+                       }
+               });
+
+               fExportButton= new Button(buttons, SWT.PUSH);
+               fExportButton.setText(TemplateMessages.getString("TemplatePreferencePage.export")); //$NON-NLS-1$
+               fExportButton.setLayoutData(getButtonGridData(fExportButton));
+               fExportButton.addListener(SWT.Selection, new Listener() {
+                       public void handleEvent(Event e) {
+                               export();
+                       }
+               });
+
+               fExportAllButton= new Button(buttons, SWT.PUSH);
+               fExportAllButton.setText(TemplateMessages.getString("TemplatePreferencePage.export.all")); //$NON-NLS-1$
+               fExportAllButton.setLayoutData(getButtonGridData(fExportAllButton));
+               fExportAllButton.addListener(SWT.Selection, new Listener() {
+                       public void handleEvent(Event e) {
+                               exportAll();
+                       }
+               });             
+
+               fEnableAllButton= new Button(buttons, SWT.PUSH);
+               fEnableAllButton.setText(TemplateMessages.getString("TemplatePreferencePage.enable.all")); //$NON-NLS-1$
+               fEnableAllButton.setLayoutData(getButtonGridData(fEnableAllButton));
+               fEnableAllButton.addListener(SWT.Selection, new Listener() {
+                       public void handleEvent(Event e) {
+                               enableAll(true);
+                       }
+               });
+
+               fDisableAllButton= new Button(buttons, SWT.PUSH);
+               fDisableAllButton.setText(TemplateMessages.getString("TemplatePreferencePage.disable.all")); //$NON-NLS-1$
+               fDisableAllButton.setLayoutData(getButtonGridData(fDisableAllButton));
+               fDisableAllButton.addListener(SWT.Selection, new Listener() {
+                       public void handleEvent(Event e) {
+                               enableAll(false);
+                       }
+               });
+
+               fPatternViewer= createViewer(parent);
+               
+//             fFormatButton= new Button(parent, SWT.CHECK);
+//             fFormatButton.setText(TemplateMessages.getString("TemplatePreferencePage.use.code.formatter")); //$NON-NLS-1$
+//        GridData gd1= new GridData();
+//        gd1.horizontalSpan= 2;
+//        fFormatButton.setLayoutData(gd1);
+
+               fTableViewer.setInput(fTemplates);              
+               fTableViewer.setAllChecked(false);
+               fTableViewer.setCheckedElements(getEnabledTemplates());         
+
+               IPreferenceStore prefs= PHPeclipsePlugin.getDefault().getPreferenceStore();
+       //      fFormatButton.setSelection(prefs.getBoolean(PREF_FORMAT_TEMPLATES));
+
+               updateButtons();
+        configureTableResizing(innerParent, buttons, table, column1, column2, column3);
+
+               // WorkbenchHelp.setHelp(parent, IJavaHelpContextIds.TEMPLATE_PREFERENCE_PAGE);
+               
+               return parent;
+       }
+    
+     /**
+     * Correctly resizes the table so no phantom columns appear
+     */
+    private static void configureTableResizing(final Composite parent, final Composite buttons, final Table table, final TableColumn column1, final TableColumn column2, final TableColumn column3) {
+        parent.addControlListener(new ControlAdapter() {
+            public void controlResized(ControlEvent e) {
+                Rectangle area = parent.getClientArea();
+                Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+                int width = area.width - 2 * table.getBorderWidth();
+                if (preferredSize.y > area.height) {
+                    // Subtract the scrollbar width from the total column width
+                    // if a vertical scrollbar will be required
+                    Point vBarSize = table.getVerticalBar().getSize();
+                    width -= vBarSize.x;
+                }
+                width-= buttons.getSize().x;
+                Point oldSize = table.getSize();
+                if (oldSize.x > width) {
+                    // table is getting smaller so make the columns
+                    // smaller first and then resize the table to
+                    // match the client area width
+                    column1.setWidth(width/4);
+                    column2.setWidth(width/4);
+                    column3.setWidth(width - (column1.getWidth() + column2.getWidth()));
+                    table.setSize(width, area.height);
+                } else {
+                    // table is getting bigger so make the table
+                    // bigger first and then make the columns wider
+                    // to match the client area width
+                    table.setSize(width, area.height);
+                    column1.setWidth(width/4);
+                    column2.setWidth(width/4);
+                    column3.setWidth(width - (column1.getWidth() + column2.getWidth()));
+                 }
+            }
+        });
+    }
+    
+       
+       private Template[] getEnabledTemplates() {
+               Template[] templates= fTemplates.getTemplates();
+               
+               List list= new ArrayList(templates.length);
+               
+               for (int i= 0; i != templates.length; i++)
+                       if (templates[i].isEnabled())
+                               list.add(templates[i]);
+                               
+               return (Template[]) list.toArray(new Template[list.size()]);
+       }
+       
+       private SourceViewer createViewer(Composite parent) {
+               Label label= new Label(parent, SWT.NONE);
+               label.setText(TemplateMessages.getString("TemplatePreferencePage.preview")); //$NON-NLS-1$
+               GridData data= new GridData();
+               data.horizontalSpan= 2;
+               label.setLayoutData(data);
+               
+               SourceViewer viewer= new SourceViewer(parent, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
+//             JavaTextTools tools= PHPeclipsePlugin.getDefault().getJavaTextTools();
+               IDocument document= new Document();
+//             IDocumentPartitioner partitioner= new PHPPartitionScanner(); //tools.createDocumentPartitioner();
+//             document.setDocumentPartitioner(partitioner);
+//             partitioner.connect(document);          
+               viewer.configure(new PHPSourceViewerConfiguration()); // (tools, null));
+               viewer.setEditable(false);
+               viewer.setDocument(document);
+               viewer.getTextWidget().setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+       
+               Font font= JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT);
+               viewer.getTextWidget().setFont(font);
+               
+               Control control= viewer.getControl();
+               data= new GridData(GridData.FILL_BOTH);
+        data.horizontalSpan= 2;
+               data.heightHint= convertHeightInCharsToPixels(5);
+               control.setLayoutData(data);
+               
+               return viewer;
+       }
+       
+       private static GridData getButtonGridData(Button button) {
+               GridData data= new GridData(GridData.FILL_HORIZONTAL);
+               data.widthHint= SWTUtil.getButtonWidthHint(button);
+               data.heightHint= SWTUtil.getButtonHeigthHint(button);
+       
+               return data;
+       }
+       
+       private void selectionChanged1() {              
+               IStructuredSelection selection= (IStructuredSelection) fTableViewer.getSelection();
+
+               if (selection.size() == 1) {
+                       Template template= (Template) selection.getFirstElement();
+                       fPatternViewer.getTextWidget().setText(template.getPattern());
+               } else {                
+                       fPatternViewer.getTextWidget().setText(""); //$NON-NLS-1$
+               }
+               
+               updateButtons();
+       }
+       
+       private void updateButtons() {
+               int selectionCount= ((IStructuredSelection) fTableViewer.getSelection()).size();
+               int itemCount= fTableViewer.getTable().getItemCount();
+               
+               fEditButton.setEnabled(selectionCount == 1);
+               fExportButton.setEnabled(selectionCount > 0);
+               fRemoveButton.setEnabled(selectionCount > 0 && selectionCount <= itemCount);
+               fEnableAllButton.setEnabled(itemCount > 0);
+               fDisableAllButton.setEnabled(itemCount > 0);
+       }
+       
+       private void add() {            
+               
+               Template template= new Template();
+
+               ContextTypeRegistry registry=ContextTypeRegistry.getInstance();
+               ContextType type= registry.getContextType("php"); //$NON-NLS-1$
+               
+               String contextTypeName;
+               if (type != null)
+                       contextTypeName= type.getName();
+               else {
+                       Iterator iterator= registry.iterator();
+                       contextTypeName= (String) iterator.next();
+               }
+               template.setContext(contextTypeName); //$NON-NLS-1$
+               
+               EditTemplateDialog dialog= new EditTemplateDialog(getShell(), template, false);
+               if (dialog.open() == dialog.OK) {
+                       fTemplates.add(template);
+                       fTableViewer.refresh();
+                       fTableViewer.setChecked(template, template.isEnabled());
+                       fTableViewer.setSelection(new StructuredSelection(template));                   
+               }
+       }
+
+       private void edit() {
+               IStructuredSelection selection= (IStructuredSelection) fTableViewer.getSelection();
+
+               Object[] objects= selection.toArray();          
+               if ((objects == null) || (objects.length != 1))
+                       return;
+               
+               Template template= (Template) selection.getFirstElement();
+               edit(template);
+       }
+
+       private void edit(Template template) {
+               Template newTemplate= new Template(template);
+               EditTemplateDialog dialog= new EditTemplateDialog(getShell(), newTemplate, true);
+               if (dialog.open() == dialog.OK) {
+
+                       if (!newTemplate.getName().equals(template.getName()) &&
+                               MessageDialog.openQuestion(getShell(),
+                               TemplateMessages.getString("TemplatePreferencePage.question.create.new.title"), //$NON-NLS-1$
+                               TemplateMessages.getString("TemplatePreferencePage.question.create.new.message"))) //$NON-NLS-1$
+                       {
+                               template= newTemplate;
+                               fTemplates.add(template);
+                               fTableViewer.refresh();
+                       } else {
+                               template.setName(newTemplate.getName());
+                               template.setDescription(newTemplate.getDescription());
+                               template.setContext(newTemplate.getContextTypeName());
+                               template.setPattern(newTemplate.getPattern());
+                               fTableViewer.refresh(template);
+                       }
+                       fTableViewer.setChecked(template, template.isEnabled());
+                       fTableViewer.setSelection(new StructuredSelection(template));                   
+               }
+       }
+               
+       private void import_() {
+               FileDialog dialog= new FileDialog(getShell());
+               dialog.setText(TemplateMessages.getString("TemplatePreferencePage.import.title")); //$NON-NLS-1$
+               dialog.setFilterExtensions(new String[] {TemplateMessages.getString("TemplatePreferencePage.import.extension")}); //$NON-NLS-1$
+               String path= dialog.open();
+               
+               if (path == null)
+                       return;
+               
+               try {
+                       fTemplates.addFromFile(new File(path));
+                       
+                       fTableViewer.refresh();
+                       fTableViewer.setAllChecked(false);
+                       fTableViewer.setCheckedElements(getEnabledTemplates());
+
+               } catch (CoreException e) {                     
+                       openReadErrorDialog(e);
+               }
+       }
+       
+       private void exportAll() {
+               export(fTemplates);     
+       }
+
+       private void export() {
+               IStructuredSelection selection= (IStructuredSelection) fTableViewer.getSelection();
+               Object[] templates= selection.toArray();
+               
+               TemplateSet templateSet= new TemplateSet();
+               for (int i= 0; i != templates.length; i++)
+                       templateSet.add((Template) templates[i]);
+               
+               export(templateSet);
+       }
+       
+       private void export(TemplateSet templateSet) {
+               FileDialog dialog= new FileDialog(getShell(), SWT.SAVE);
+               dialog.setText(TemplateMessages.getFormattedString("TemplatePreferencePage.export.title", new Integer(templateSet.getTemplates().length))); //$NON-NLS-1$
+               dialog.setFilterExtensions(new String[] {TemplateMessages.getString("TemplatePreferencePage.export.extension")}); //$NON-NLS-1$
+               dialog.setFileName(TemplateMessages.getString("TemplatePreferencePage.export.filename")); //$NON-NLS-1$
+               String path= dialog.open();
+               
+               if (path == null)
+                       return;
+               
+               File file= new File(path);              
+
+               if (!file.exists() || confirmOverwrite(file)) {
+                       try {
+                               templateSet.saveToFile(file);                   
+                       } catch (CoreException e) {                     
+                               PHPeclipsePlugin.log(e);
+                               openWriteErrorDialog(e);
+                       }               
+               }
+       }
+
+       private boolean confirmOverwrite(File file) {
+               return MessageDialog.openQuestion(getShell(),
+                       TemplateMessages.getString("TemplatePreferencePage.export.exists.title"), //$NON-NLS-1$
+                       TemplateMessages.getFormattedString("TemplatePreferencePage.export.exists.message", file.getAbsolutePath())); //$NON-NLS-1$
+       }
+       
+       private void remove() {
+               IStructuredSelection selection= (IStructuredSelection) fTableViewer.getSelection();
+
+               Iterator elements= selection.iterator();
+               while (elements.hasNext()) {
+                       Template template= (Template) elements.next();
+                       fTemplates.remove(template);
+               }
+
+               fTableViewer.refresh();
+       }
+       
+       private void enableAll(boolean enable) {
+               Template[] templates= fTemplates.getTemplates();
+               for (int i= 0; i != templates.length; i++)
+                       templates[i].setEnabled(enable);                
+                       
+               fTableViewer.setAllChecked(enable);
+       }
+       
+       /*
+        * @see IWorkbenchPreferencePage#init(IWorkbench)
+        */
+       public void init(IWorkbench workbench) {}
+
+       /*
+        * @see Control#setVisible(boolean)
+        */
+       public void setVisible(boolean visible) {
+               super.setVisible(visible);
+               if (visible)
+                       setTitle(TemplateMessages.getString("TemplatePreferencePage.title")); //$NON-NLS-1$
+       }
+       
+       /*
+        * @see PreferencePage#performDefaults()
+        */
+       protected void performDefaults() {
+               IPreferenceStore prefs= PHPeclipsePlugin.getDefault().getPreferenceStore();
+       //      fFormatButton.setSelection(prefs.getDefaultBoolean(PREF_FORMAT_TEMPLATES));
+
+               try {
+                       fTemplates.restoreDefaults();
+               } catch (CoreException e) {
+                       PHPeclipsePlugin.log(e);
+                       openReadErrorDialog(e);
+               }
+               
+               // refresh
+               fTableViewer.refresh();
+               fTableViewer.setAllChecked(false);
+               fTableViewer.setCheckedElements(getEnabledTemplates());         
+       }
+
+       /*
+        * @see PreferencePage#performOk()
+        */     
+       public boolean performOk() {
+               IPreferenceStore prefs= PHPeclipsePlugin.getDefault().getPreferenceStore();
+       //      prefs.setValue(PREF_FORMAT_TEMPLATES, fFormatButton.getSelection());
+
+               try {
+                       fTemplates.save();
+               } catch (CoreException e) {
+                       PHPeclipsePlugin.log(e);
+                       openWriteErrorDialog(e);
+               }
+               
+               PHPeclipsePlugin.getDefault().savePluginPreferences();
+               return super.performOk();
+       }       
+       
+       /*
+        * @see PreferencePage#performCancel()
+        */
+       public boolean performCancel() {
+               try {
+                       fTemplates.reset();                     
+               } catch (CoreException e) {
+                       PHPeclipsePlugin.log(e);
+                       openReadErrorDialog(e);
+               }
+
+               return super.performCancel();
+       }
+       
+       /**
+        * Initializes the default values of this page in the preference bundle.
+        * Will be called on startup of the PHPeclipsePlugin
+        */
+       public static void initDefaults(IPreferenceStore prefs) {
+               prefs.setDefault(PREF_FORMAT_TEMPLATES, true);
+       }
+
+//     public static boolean useCodeFormatter() {
+//             IPreferenceStore prefs= PHPeclipsePlugin.getDefault().getPreferenceStore();
+//             return prefs.getBoolean(PREF_FORMAT_TEMPLATES);
+//     }
+
+       private void openReadErrorDialog(CoreException e) {
+               ErrorDialog.openError(getShell(),
+                       TemplateMessages.getString("TemplatePreferencePage.error.read.title"), //$NON-NLS-1$
+                       null, e.getStatus());
+       }
+       
+       private void openWriteErrorDialog(CoreException e) {
+               ErrorDialog.openError(getShell(),
+                       TemplateMessages.getString("TemplatePreferencePage.error.write.title"), //$NON-NLS-1$
+                       null, e.getStatus());           
+       }
+               
+}
index db03c5f..6a4051e 100644 (file)
@@ -68,4 +68,9 @@ public interface IPreferenceConstants {
   
   public final static String PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT = "_defaultBackgroundColor"; //$NON-NLS-1$
   public final static String PREFERENCE_COLOR_BACKGROUND = "backgroundColor"; //$NON-NLS-1$
+  
+  /** Preference key for content assist proposal color */
+  public final static String PROPOSALS_FOREGROUND=  "content_assist_proposals_foreground"; //$NON-NLS-1$
+  /** Preference key for content assist proposal color */
+  public final static String PROPOSALS_BACKGROUND=  "content_assist_proposals_background"; //$NON-NLS-1$
 }
\ No newline at end of file
index 926ece6..feb1c44 100644 (file)
@@ -14,6 +14,7 @@ package net.sourceforge.phpeclipse;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 
+import net.sourceforge.phpdt.internal.ui.preferences.TemplatePreferencePage;
 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
@@ -297,6 +298,8 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon
 
     store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
     PreferenceConverter.setDefault(store, PREFERENCE_COLOR_BACKGROUND, PHPColorProvider.BACKGROUND_COLOR);
+  
+    TemplatePreferencePage.initDefaults(store); 
   }
   
     public void startup() throws CoreException {
index 7e9ede4..9ccac8e 100644 (file)
@@ -363,7 +363,6 @@ public class PHPParser extends PHPKeywords {
           if (openString) {
             throwSyntaxError("Open string character \"`\" at end of file.", startRow);
           }
-          setMarker("Other string delimiters prefered (found \"`\").", rowCount, PHPParser.INFO);
           token = TT_STRING_CONSTANT;
           return;
         }