<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">
*/</template>
<template name="echo" description="echo a string" context="php" enabled="true">echo "${string}";
${cursor}</template>
-
-
- <template name="&nbsp" description="no-break space " context="html" enabled="true">&nbsp
- </template>
<template name="<html" description="html page with head,title,body" context="html" enabled="true">
<html>
<template name="<blockquote" description="blockquoted text" context="html" enabled="true">
<blockquote>${cursor}</blockquote>
</template>
- </templates>
\ No newline at end of file
+
+ <template name="&quot" description="quot" context="html" enabled="true">&quot;</template>
+ <template name="&amp" description="ampersand" context="html" enabled="true">&amp;</template>
+ <template name="&lt" description="less than" context="html" enabled="true">&lt;</template>
+ <template name="&gt" description="greater than" context="html" enabled="true">&gt;</template>
+
+ <template name="&nbsp" description="no-break space" context="html" enabled="true">&nbsp;</template>
+ <template name="&iexcl" description="iexcl" context="html" enabled="true">&iexcl;</template>
+ <template name="&cent" description="cent" context="html" enabled="true">&cent;</template>
+ <template name="&pound" description="pound" context="html" enabled="true">&pound;</template>
+ <template name="&curren" description="curren" context="html" enabled="true">&curren;</template>
+ <template name="&yen" description="yen" context="html" enabled="true">&yen;</template>
+ <template name="&brvbar" description="brvbar" context="html" enabled="true">&brvbar;</template>
+ <template name="&brkbar" description="brkbar" context="html" enabled="true">&brkbar;</template>
+ <template name="&sect" description="sect" context="html" enabled="true">&sect;</template>
+ <template name="&uml" description="uml" context="html" enabled="true">&uml;</template>
+ <template name="&die" description="die" context="html" enabled="true">&die;</template>
+ <template name="&copy" description="copy" context="html" enabled="true">&copy;</template>
+ <template name="&ordf" description="ordf" context="html" enabled="true">&ordf;</template>
+ <template name="&laquo" description="laquo" context="html" enabled="true">&laquo;</template>
+ <template name="&not" description="not" context="html" enabled="true">&not;</template>
+ <template name="&shy" description="shy" context="html" enabled="true">&shy;</template>
+ <template name="&reg" description="reg" context="html" enabled="true">&reg;</template>
+ <template name="&macr" description="macr" context="html" enabled="true">&macr;</template>
+ <template name="&hibar" description="hibar" context="html" enabled="true">&hibar;</template>
+ <template name="&deg" description="deg" context="html" enabled="true">&deg;</template>
+ <template name="&plusmn" description="plusmn" context="html" enabled="true">&plusmn;</template>
+ <template name="&sup2" description="sup2" context="html" enabled="true">&sup2;</template>
+ <template name="&sup3" description="sup3" context="html" enabled="true">&sup3;</template>
+ <template name="&acute" description="acute" context="html" enabled="true">&acute;</template>
+ <template name="&micro" description="micro" context="html" enabled="true">&micro;</template>
+ <template name="&para" description="para" context="html" enabled="true">&para;</template>
+ <template name="&middot" description="middot" context="html" enabled="true">&middot;</template>
+ <template name="&cedil" description="cedil" context="html" enabled="true">&cedil;</template>
+ <template name="&sup1" description="sup1" context="html" enabled="true">&sup1;</template>
+ <template name="&ordm" description="ordm" context="html" enabled="true">&ordm;</template>
+ <template name="&raquo" description="raquo" context="html" enabled="true">&raquo;</template>
+ <template name="&frac14" description="frac14" context="html" enabled="true">&frac14;</template>
+ <template name="&frac12" description="frac12" context="html" enabled="true">&frac12;</template>
+ <template name="&frac34" description="frac34" context="html" enabled="true">&frac34;</template>
+ <template name="&iquest" description="iquest" context="html" enabled="true">&iquest;</template>
+ <template name="&Agrave" description="Agrave" context="html" enabled="true">&Agrave;</template>
+ <template name="&Aacute" description="Aacute" context="html" enabled="true">&Aacute;</template>
+ <template name="&Acirc" description="Acirc" context="html" enabled="true">&Acirc;</template>
+ <template name="&Atilde" description="Atilde" context="html" enabled="true">&Atilde;</template>
+ <template name="&Auml" description="Auml" context="html" enabled="true">&Auml;</template>
+ <template name="&Aring" description="Aring" context="html" enabled="true">&Aring;</template>
+ <template name="&AElig" description="AElig" context="html" enabled="true">&AElig;</template>
+ <template name="&Ccedil" description="Ccedil" context="html" enabled="true">&Ccedil;</template>
+ <template name="&Egrave" description="Egrave" context="html" enabled="true">&Egrave;</template>
+ <template name="&Eacute" description="Eacute" context="html" enabled="true">&Eacute;</template>
+ <template name="&Ecirc" description="Ecirc" context="html" enabled="true">&Ecirc;</template>
+ <template name="&Euml" description="Euml" context="html" enabled="true">&Euml;</template>
+ <template name="&lgrave" description="lgrave" context="html" enabled="true">&lgrave;</template>
+ <template name="&lacute" description="lacute" context="html" enabled="true">&lacute;</template>
+ <template name="&lcirc" description="lcirc" context="html" enabled="true">&lcirc;</template>
+ <template name="&luml" description="luml" context="html" enabled="true">&luml;</template>
+ <template name="&ETH" description="ETH" context="html" enabled="true">&ETH;</template>
+ <template name="&Ntilde" description="Ntilde" context="html" enabled="true">&Ntilde;</template>
+ <template name="&Ograve" description="Ograve" context="html" enabled="true">&Ograve;</template>
+ <template name="&Oacute" description="Oacute" context="html" enabled="true">&Oacute;</template>
+ <template name="&Ocirc" description="Ocirc" context="html" enabled="true">&Ocirc;</template>
+ <template name="&Otilde" description="Otilde" context="html" enabled="true">&Otilde;</template>
+ <template name="&Ouml" description="Ouml" context="html" enabled="true">&Ouml;</template>
+ <template name="&times" description="times" context="html" enabled="true">&times;</template>
+ <template name="&Oslash" description="Oslash" context="html" enabled="true">&Oslash;</template>
+ <template name="&Ugrave" description="Ugrave" context="html" enabled="true">&Ugrave;</template>
+ <template name="&Uacute" description="Uacute" context="html" enabled="true">&Uacute;</template>
+ <template name="&Ucirc" description="Ucirc" context="html" enabled="true">&Ucirc;</template>
+ <template name="&Uuml" description="Uuml" context="html" enabled="true">&Uuml;</template>
+ <template name="&Yacute" description="Yacute" context="html" enabled="true">&Yacute;</template>
+ <template name="&THORN" description="THORN" context="html" enabled="true">&THORN;</template>
+ <template name="&szlig" description="szlig" context="html" enabled="true">&szlig;</template>
+ <template name="&agrave" description="agrave" context="html" enabled="true">&agrave;</template>
+ <template name="&aacute" description="aacute" context="html" enabled="true">&aacute;</template>
+ <template name="&acirc" description="acirc" context="html" enabled="true">&acirc;</template>
+ <template name="&atilde" description="atilde" context="html" enabled="true">&atilde;</template>
+ <template name="&auml" description="auml" context="html" enabled="true">&auml;</template>
+ <template name="&aring" description="aring" context="html" enabled="true">&aring;</template>
+ <template name="&aelig" description="aelig" context="html" enabled="true">&aelig;</template>
+ <template name="&ccedil" description="ccedil" context="html" enabled="true">&ccedil;</template>
+ <template name="&egrave" description="egrave" context="html" enabled="true">&egrave;</template>
+ <template name="&eacute" description="eacute" context="html" enabled="true">&eacute;</template>
+ <template name="&ecirc" description="ecirc" context="html" enabled="true">&ecirc;</template>
+ <template name="&euml" description="euml" context="html" enabled="true">&euml;</template>
+ <template name="&igrave" description="igrave" context="html" enabled="true">&igrave;</template>
+ <template name="&iacute" description="iacute" context="html" enabled="true">&iacute;</template>
+ <template name="&icirc" description="icirc" context="html" enabled="true">&icirc;</template>
+ <template name="&iuml" description="iuml" context="html" enabled="true">&iuml;</template>
+ <template name="&eth" description="eth" context="html" enabled="true">&eth;</template>
+ <template name="&ntilde" description="ntilde" context="html" enabled="true">&ntilde;</template>
+ <template name="&ograve" description="ograve" context="html" enabled="true">&ograve;</template>
+ <template name="&oacute" description="oacute" context="html" enabled="true">&oacute;</template>
+ <template name="&ocirc" description="ocirc" context="html" enabled="true">&ocirc;</template>
+ <template name="&otilde" description="otilde" context="html" enabled="true">&otilde;</template>
+ <template name="&ouml" description="ouml" context="html" enabled="true">&ouml;</template>
+ <template name="&divide" description="divide" context="html" enabled="true">&divide;</template>
+ <template name="&oslash" description="oslash" context="html" enabled="true">&oslash;</template>
+ <template name="&ugrave" description="ugrave" context="html" enabled="true">&ugrave;</template>
+ <template name="&uacute" description="uacute" context="html" enabled="true">&uacute;</template>
+ <template name="&ucirc" description="ucirc" context="html" enabled="true">&ucirc;</template>
+ <template name="&uuml" description="uuml" context="html" enabled="true">&uuml;</template>
+ <template name="&yacute" description="yacute" context="html" enabled="true">&yacute;</template>
+ <template name="&thorn" description="thorn" context="html" enabled="true">&thorn;</template>
+ <template name="&yuml" description="yuml" context="html" enabled="true">&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
/** 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;
--- /dev/null
+/*
+ * (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
--- /dev/null
+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());
+ }
+
+}
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
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;
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 {
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;
}