Rename HTML editor to Smarty editor
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / preferences / EditTemplateDialog.java
index cf895cd..cbd80ba 100644 (file)
@@ -1,7 +1,13 @@
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials 
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ * 
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
 package net.sourceforge.phpdt.internal.ui.preferences;
 
 import java.util.ArrayList;
@@ -9,22 +15,19 @@ 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.IJavaHelpContextIds;
+import net.sourceforge.phpdt.internal.ui.dialogs.StatusDialog;
+import net.sourceforge.phpdt.internal.ui.dialogs.StatusInfo;
+import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
+import net.sourceforge.phpdt.internal.ui.text.template.preferences.TemplateVariableProcessor;
 import net.sourceforge.phpdt.internal.ui.util.SWTUtil;
+import net.sourceforge.phpdt.ui.IContextMenuConstants;
+import net.sourceforge.phpdt.ui.PreferenceConstants;
 import net.sourceforge.phpdt.ui.text.JavaTextTools;
-import net.sourceforge.phpeclipse.IPreferenceConstants;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
-import net.sourceforge.phpeclipse.phpeditor.PHPSourceViewerConfiguration;
+import net.sourceforge.phpeclipse.phpeditor.JavaSourceViewer;
 
-import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.GroupMarker;
 import org.eclipse.jface.action.IAction;
@@ -33,47 +36,44 @@ 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.IDocumentPartitioner;
 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.text.templates.ContextTypeRegistry;
+import org.eclipse.jface.text.templates.Template;
+import org.eclipse.jface.text.templates.TemplateContextType;
+import org.eclipse.jface.text.templates.TemplateException;
 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.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
 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.swt.widgets.Widget;
+import org.eclipse.ui.help.WorkbenchHelp;
 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
 import org.eclipse.ui.texteditor.IUpdate;
 
@@ -82,81 +82,17 @@ import org.eclipse.ui.texteditor.IUpdate;
  */
 public class EditTemplateDialog extends StatusDialog {
 
-       private static class SimpleJavaSourceViewerConfiguration extends PHPSourceViewerConfiguration {
-
-               private final IContentAssistProcessor fProcessor;
-
-       //      SimpleJavaSourceViewerConfiguration(JavaTextTools tools, ITextEditor editor, IContentAssistProcessor processor) {
-               SimpleJavaSourceViewerConfiguration(JavaTextTools tools, IContentAssistProcessor processor) {   
-      super(tools, null);
-                       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.PHP_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(IContentAssistant.PROPOSAL_OVERLAY);
-                       assistant.setContextInformationPopupOrientation(IContentAssistant.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;
        
+               /** 
+                * Creates a new action.
+                * 
+                * @param viewer the viewer
+                * @param operationCode the opcode
+                */
                public TextViewerAction(ITextViewer viewer, int operationCode) {
                        fOperationCode= operationCode;
                        fOperationTarget= viewer.getTextOperationTarget();
@@ -197,33 +133,73 @@ public class EditTemplateDialog extends StatusDialog {
        private Combo fContextCombo;
        private SourceViewer fPatternEditor;    
        private Button fInsertVariableButton;
+       private boolean fIsNameModifiable;
 
-       private TemplateTranslator fTranslator= new TemplateTranslator();       
+       private StatusInfo fValidationStatus;
        private boolean fSuppressError= true; // #4354  
        private Map fGlobalActions= new HashMap(10);
        private List fSelectionActions = new ArrayList(3);      
-       private Vector fContextTypes= new Vector();
+       private String[][] fContextTypes;
        
-       private final TemplateVariableProcessor fProcessor= new TemplateVariableProcessor();
+       private ContextTypeRegistry fContextTypeRegistry; 
+       
+       private final TemplateVariableProcessor fTemplateProcessor= new TemplateVariableProcessor();
                
-       public EditTemplateDialog(Shell parent, Template template, boolean edit) {
+       /**
+        * Creates a new dialog.
+        * 
+        * @param parent the shell parent of the dialog
+        * @param template the template to edit
+        * @param edit whether this is a new template or an existing being edited
+        * @param isNameModifiable whether the name of the template may be modified
+        * @param registry the context type registry to use
+        */
+       public EditTemplateDialog(Shell parent, Template template, boolean edit, boolean isNameModifiable, ContextTypeRegistry registry) {
                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$
+                       ? PreferencesMessages.getString("EditTemplateDialog.title.edit") //$NON-NLS-1$
+                       : PreferencesMessages.getString("EditTemplateDialog.title.new"); //$NON-NLS-1$
                setTitle(title);
 
                fTemplate= template;
+               fIsNameModifiable= isNameModifiable;
                
-               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)));
+               // XXX workaround for bug 63313 - disabling prefix until fixed.
+//             String delim= new Document().getLegalLineDelimiters()[0];
+               
+               List contexts= new ArrayList();
+               for (Iterator it= registry.contextTypes(); it.hasNext();) {
+                       TemplateContextType type= (TemplateContextType) it.next();
+//                     if (type.getId().equals("javadoc")) //$NON-NLS-1$
+//                             contexts.add(new String[] { type.getId(), type.getName(), "/**" + delim }); //$NON-NLS-1$
+//                     else
+                               contexts.add(new String[] { type.getId(), type.getName(), "" }); //$NON-NLS-1$
+               }
+               fContextTypes= (String[][]) contexts.toArray(new String[contexts.size()][]);
+                               
+               fValidationStatus= new StatusInfo();
+               
+               fContextTypeRegistry= registry;
+               
+               TemplateContextType type= fContextTypeRegistry.getContextType(template.getContextTypeId());
+               fTemplateProcessor.setContextType(type);
+       }
+       
+       /*
+        * @see net.sourceforge.phpdt.internal.ui.dialogs.StatusDialog#create()
+        */
+       public void create() {
+               super.create();
+               // update initial ok button to be disabled for new templates 
+               boolean valid= fNameText == null || fNameText.getText().trim().length() != 0;
+               if (!valid) {
+                       StatusInfo status = new StatusInfo();
+                       status.setError(PreferencesMessages.getString("EditTemplateDialog.error.noname")); //$NON-NLS-1$
+                       updateButtonsEnableState(status);
+               }
        }
        
        /*
@@ -236,50 +212,63 @@ public class EditTemplateDialog extends StatusDialog {
                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() {
+               ModifyListener listener= new ModifyListener() {
                        public void modifyText(ModifyEvent e) {
-                               if (fSuppressError && (fNameText.getText().trim().length() != 0))
-                                       fSuppressError= false;
-
-                               updateButtons();
+                               doTextWidgetChanged(e.widget);
                        }
-               });
-
-               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));                              
+               };
+               
+               if (fIsNameModifiable) {
+                       createLabel(parent, PreferencesMessages.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.addFocusListener(new FocusListener() {
+                               
+                               public void focusGained(FocusEvent e) {
+                               }
+                               
+                               public void focusLost(FocusEvent e) {
+                                       if (fSuppressError) {
+                                               fSuppressError= false;
+                                               updateButtons();
+                                       }
+                               }
+                       });
+                       
+                       createLabel(composite, PreferencesMessages.getString("EditTemplateDialog.context")); //$NON-NLS-1$              
+                       fContextCombo= new Combo(composite, SWT.READ_ONLY);
+       
+                       for (int i= 0; i < fContextTypes.length; i++) {
+                               fContextCombo.add(fContextTypes[i][1]);
                        }
-               });
+       
+                       fContextCombo.addModifyListener(listener);
+               }
+               
+               createLabel(parent, PreferencesMessages.getString("EditTemplateDialog.description")); //$NON-NLS-1$             
+               
+               int descFlags= fIsNameModifiable ? SWT.BORDER : SWT.BORDER | SWT.READ_ONLY;
+               fDescriptionText= new Text(parent, descFlags );
+               fDescriptionText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 
                
-               createLabel(parent, TemplateMessages.getString("EditTemplateDialog.description")); //$NON-NLS-1$                
-               fDescriptionText= createText(parent);
+               fDescriptionText.addModifyListener(listener);
 
-               Label patternLabel= createLabel(parent, TemplateMessages.getString("EditTemplateDialog.pattern")); //$NON-NLS-1$
+               Label patternLabel= createLabel(parent, PreferencesMessages.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);
+               Composite composite= new Composite(parent, SWT.NONE);
                layout= new GridLayout();               
                layout.marginWidth= 0;
                layout.marginHeight= 0;
@@ -288,7 +277,7 @@ public class EditTemplateDialog extends StatusDialog {
                
                fInsertVariableButton= new Button(composite, SWT.NONE);
                fInsertVariableButton.setLayoutData(getButtonGridData(fInsertVariableButton));
-               fInsertVariableButton.setText(TemplateMessages.getString("EditTemplateDialog.insert.variable")); //$NON-NLS-1$
+               fInsertVariableButton.setText(PreferencesMessages.getString("EditTemplateDialog.insert.variable")); //$NON-NLS-1$
                fInsertVariableButton.addSelectionListener(new SelectionListener() {
                        public void widgetSelected(SelectionEvent e) {
                                fPatternEditor.getTextWidget().setFocus();
@@ -298,18 +287,70 @@ public class EditTemplateDialog extends StatusDialog {
                        public void widgetDefaultSelected(SelectionEvent e) {}
                });
 
-               fNameText.setText(fTemplate.getName());
                fDescriptionText.setText(fTemplate.getDescription());
-               fContextCombo.select(getIndex(fTemplate.getContextTypeName()));
-
+               if (fIsNameModifiable) {
+                       fNameText.setText(fTemplate.getName());
+                       fNameText.addModifyListener(listener);
+                       fContextCombo.select(getIndex(fTemplate.getContextTypeId()));
+               } else {
+                       fPatternEditor.getControl().setFocus();
+               }
                initializeActions();
 
+               applyDialogFont(parent);
                return composite;
        }
+       
+       protected void doTextWidgetChanged(Widget w) {
+               if (w == fNameText) {
+                       fSuppressError= false;
+                       String name= fNameText.getText();
+                       fTemplate.setName(name);
+                       updateButtons();                        
+               } else if (w == fContextCombo) {
+                       String name= fContextCombo.getText();
+                       String contextId= getContextId(name);
+                       fTemplate.setContextTypeId(contextId);
+                       fTemplateProcessor.setContextType(fContextTypeRegistry.getContextType(contextId));
+               } else if (w == fDescriptionText) {
+                       String desc= fDescriptionText.getText();
+                       fTemplate.setDescription(desc);
+               }       
+       }
+       
+       private String getContextId(String name) {
+               if (name == null)
+                       return name;
+               
+               for (int i= 0; i < fContextTypes.length; i++) {
+                       if (name.equals(fContextTypes[i][1])) {
+                               return fContextTypes[i][0];     
+                       }
+               }
+               return name;
+       }
+
+       protected void doSourceChanged(IDocument document) {
+               String text= document.get();
+               String prefix= getPrefix();
+               fTemplate.setPattern(text.substring(prefix.length(), text.length()));
+               fValidationStatus.setOK();
+               TemplateContextType contextType= fContextTypeRegistry.getContextType(fTemplate.getContextTypeId());
+               if (contextType != null) {
+                       try {
+                               contextType.validate(text);
+                       } catch (TemplateException e) {
+                               fValidationStatus.setError(e.getLocalizedMessage());
+                       }
+               }
+
+               updateUndoAction();
+               updateButtons();
+       }       
 
        private static GridData getButtonGridData(Button button) {
                GridData data= new GridData(GridData.FILL_HORIZONTAL);
-               data.heightHint= SWTUtil.getButtonHeigthHint(button);
+               data.heightHint= SWTUtil.getButtonHeightHint(button);
        
                return data;
        }
@@ -330,36 +371,40 @@ public class EditTemplateDialog extends StatusDialog {
        }
 
        private SourceViewer createEditor(Composite parent) {
-               SourceViewer viewer= new SourceViewer(parent, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
-         JavaTextTools tools= PHPeclipsePlugin.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(tools, fProcessor));
-    viewer.setEditable(true);
+               String prefix= getPrefix();
+               IDocument document= new Document(prefix + fTemplate.getPattern());
+               JavaTextTools tools= PHPeclipsePlugin.getDefault().getJavaTextTools();
+               tools.setupJavaDocumentPartitioner(document, IPHPPartitions.PHP_PARTITIONING);
+               IPreferenceStore store= PHPeclipsePlugin.getDefault().getCombinedPreferenceStore();
+               SourceViewer viewer= new JavaSourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, store);
+               TemplateEditorSourceViewerConfiguration configuration= new TemplateEditorSourceViewerConfiguration(tools.getColorManager(), store, null, fTemplateProcessor);
+               viewer.configure(configuration);
+               viewer.setEditable(true);
+               // XXX workaround for bug 63313 - disabling prefix until fixed.
+//             viewer.setDocument(document, prefix.length(), document.getLength() - prefix.length());
                viewer.setDocument(document);
                
-               Font font= JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT);
+               Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
                viewer.getTextWidget().setFont(font);
+               new JavaSourcePreviewerUpdater(viewer, configuration, store);
                
+               int nLines= document.getNumberOfLines();
+               if (nLines < 5) {
+                       nLines= 5;
+               } else if (nLines > 12) {
+                       nLines= 12;     
+               }
+                               
                Control control= viewer.getControl();
                GridData data= new GridData(GridData.FILL_BOTH);
-               data.widthHint= convertWidthInCharsToPixels(60);
-               data.heightHint= convertHeightInCharsToPixels(5);
+               data.widthHint= convertWidthInCharsToPixels(80);
+               data.heightHint= convertHeightInCharsToPixels(nLines);
                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();
+                               if (event .getDocumentEvent() != null)
+                                       doSourceChanged(event.getDocumentEvent().getDocument());
                        }
                });
 
@@ -369,46 +414,31 @@ public class EditTemplateDialog extends StatusDialog {
                        }
                });
 
-               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) {}
-                       });
-               }
+               viewer.prependVerifyKeyListener(new VerifyKeyListener() {
+                       public void verifyKey(VerifyEvent event) {
+                               handleVerifyKeyPressed(event);
+                       }
+               });
                
                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 String getPrefix() {
+               String prefix;
+               int idx= getIndex(fTemplate.getContextTypeId());
+               if (idx != -1)
+                       prefix= fContextTypes[idx][2];
+               else
+                       prefix= ""; //$NON-NLS-1$
+
+               return prefix;
        }
 
        private void handleVerifyKeyPressed(VerifyEvent event) {
                if (!event.doit)
                        return;
 
-               if (event.stateMask != SWT.CTRL)
+               if (event.stateMask != SWT.MOD1)
                        return;
                        
                switch (event.character) {
@@ -418,7 +448,7 @@ public class EditTemplateDialog extends StatusDialog {
                                break;
 
                        // CTRL-Z
-                       case (int) 'z' - (int) 'a' + 1:
+                       case 'z' - 'a' + 1:
                                fPatternEditor.doOperation(ITextOperationTarget.UNDO);
                                event.doit= false;
                                break;                          
@@ -427,27 +457,27 @@ public class EditTemplateDialog extends StatusDialog {
 
        private void initializeActions() {
                TextViewerAction action= new TextViewerAction(fPatternEditor, SourceViewer.UNDO);
-               action.setText(TemplateMessages.getString("EditTemplateDialog.undo")); //$NON-NLS-1$
+               action.setText(PreferencesMessages.getString("EditTemplateDialog.undo")); //$NON-NLS-1$
                fGlobalActions.put(ITextEditorActionConstants.UNDO, action);
 
                action= new TextViewerAction(fPatternEditor, SourceViewer.CUT);
-               action.setText(TemplateMessages.getString("EditTemplateDialog.cut")); //$NON-NLS-1$
+               action.setText(PreferencesMessages.getString("EditTemplateDialog.cut")); //$NON-NLS-1$
                fGlobalActions.put(ITextEditorActionConstants.CUT, action);
 
                action= new TextViewerAction(fPatternEditor, SourceViewer.COPY);
-               action.setText(TemplateMessages.getString("EditTemplateDialog.copy")); //$NON-NLS-1$
+               action.setText(PreferencesMessages.getString("EditTemplateDialog.copy")); //$NON-NLS-1$
                fGlobalActions.put(ITextEditorActionConstants.COPY, action);
 
                action= new TextViewerAction(fPatternEditor, SourceViewer.PASTE);
-               action.setText(TemplateMessages.getString("EditTemplateDialog.paste")); //$NON-NLS-1$
+               action.setText(PreferencesMessages.getString("EditTemplateDialog.paste")); //$NON-NLS-1$
                fGlobalActions.put(ITextEditorActionConstants.PASTE, action);
 
                action= new TextViewerAction(fPatternEditor, SourceViewer.SELECT_ALL);
-               action.setText(TemplateMessages.getString("EditTemplateDialog.select.all")); //$NON-NLS-1$
+               action.setText(PreferencesMessages.getString("EditTemplateDialog.select.all")); //$NON-NLS-1$
                fGlobalActions.put(ITextEditorActionConstants.SELECT_ALL, action);
 
                action= new TextViewerAction(fPatternEditor, SourceViewer.CONTENTASSIST_PROPOSALS);
-               action.setText(TemplateMessages.getString("EditTemplateDialog.content.assist")); //$NON-NLS-1$
+               action.setText(PreferencesMessages.getString("EditTemplateDialog.content.assist")); //$NON-NLS-1$
                fGlobalActions.put("ContentAssistProposal", action); //$NON-NLS-1$
 
                fSelectionActions.add(ITextEditorActionConstants.CUT);
@@ -478,8 +508,8 @@ public class EditTemplateDialog extends StatusDialog {
                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$
+               menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
+               menu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, (IAction) fGlobalActions.get("ContentAssistProposal")); //$NON-NLS-1$
        }
 
        protected void updateSelectionDependentActions() {
@@ -500,39 +530,35 @@ public class EditTemplateDialog extends StatusDialog {
                        ((IUpdate) action).update();
        }
 
-       private int getIndex(String context) {
-               ContextTypeRegistry registry= ContextTypeRegistry.getInstance();
-               registry.getContextType(context);
+       private int getIndex(String contextid) {
                
-               if (context == null)
+               if (contextid == null)
                        return -1;
-                       
-               return fContextTypes.indexOf(context);
+               
+               for (int i= 0; i < fContextTypes.length; i++) {
+                       if (contextid.equals(fContextTypes[i][0])) {
+                               return i;       
+                       }
+               }
+               return -1;
        }
        
        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;
 
-               StatusInfo status= new StatusInfo();
-               
+               boolean valid= fNameText == null || fNameText.getText().trim().length() != 0;
                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()); 
-               }
-
+                       status = new StatusInfo();
+                       if (!fSuppressError) {
+                               status.setError(PreferencesMessages.getString("EditTemplateDialog.error.noname")); //$NON-NLS-1$
+                       }
+               } else {
+                       status= fValidationStatus; 
+               }
                updateStatus(status);
        }
 
@@ -541,8 +567,8 @@ public class EditTemplateDialog extends StatusDialog {
         */
        protected void configureShell(Shell newShell) {
                super.configureShell(newShell);
-//             WorkbenchHelp.setHelp(newShell, IJavaHelpContextIds.EDIT_TEMPLATE_DIALOG);
+               WorkbenchHelp.setHelp(newShell, IJavaHelpContextIds.EDIT_TEMPLATE_DIALOG);
        }
 
 
-}
\ No newline at end of file
+}