From: khartlage Date: Mon, 7 Apr 2003 20:35:06 +0000 (+0000) Subject: New Autoactivation for PHP ("$") and PHPDoc ("@") added X-Git-Url: http://secure.phpeclipse.com?hp=7955fa611f2b4720075f68f6fc8a372b3f2f78d4 New Autoactivation for PHP ("$") and PHPDoc ("@") added --- diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/ContextTypeRegistry.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/ContextTypeRegistry.java index cca4fd6..db8650a 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/ContextTypeRegistry.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/ContextTypeRegistry.java @@ -10,6 +10,7 @@ import java.util.Map; import net.sourceforge.phpdt.internal.corext.template.php.HTMLContextType; import net.sourceforge.phpdt.internal.corext.template.php.PHPContextType; +import net.sourceforge.phpdt.internal.corext.template.php.PHPDocContextType; @@ -65,6 +66,7 @@ public class ContextTypeRegistry { // XXX bootstrap with java and javadoc context types private ContextTypeRegistry() { add(new PHPContextType()); + add(new PHPDocContextType()); add(new HTMLContextType()); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/ContentAssistPreference.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/ContentAssistPreference.java new file mode 100644 index 0000000..aaec612 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/ContentAssistPreference.java @@ -0,0 +1,250 @@ +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ +package net.sourceforge.phpdt.internal.ui.text; + +import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCompletionProcessor; +import net.sourceforge.phpdt.ui.PreferenceConstants; +import net.sourceforge.phpdt.ui.text.IColorManager; +import net.sourceforge.phpdt.ui.text.JavaTextTools; +import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import net.sourceforge.phpeclipse.phpeditor.php.IPHPPartitionScannerConstants; +import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.contentassist.ContentAssistant; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; + + +public class ContentAssistPreference { + + /** Preference key for content assist auto activation */ + private final static String AUTOACTIVATION= PreferenceConstants.CODEASSIST_AUTOACTIVATION; + /** Preference key for content assist auto activation delay */ + private final static String AUTOACTIVATION_DELAY= PreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY; + /** Preference key for content assist proposal color */ + private final static String PROPOSALS_FOREGROUND= PreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND; + /** Preference key for content assist proposal color */ + private final static String PROPOSALS_BACKGROUND= PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND; + /** Preference key for content assist parameters color */ + private final static String PARAMETERS_FOREGROUND= PreferenceConstants.CODEASSIST_PARAMETERS_FOREGROUND; + /** Preference key for content assist parameters color */ + private final static String PARAMETERS_BACKGROUND= PreferenceConstants.CODEASSIST_PARAMETERS_BACKGROUND; + /** Preference key for content assist completion replacement color */ + private final static String COMPLETION_REPLACEMENT_FOREGROUND= PreferenceConstants.CODEASSIST_REPLACEMENT_FOREGROUND; + /** Preference key for content assist completion replacement color */ + private final static String COMPLETION_REPLACEMENT_BACKGROUND= PreferenceConstants.CODEASSIST_REPLACEMENT_BACKGROUND; + /** Preference key for content assist auto insert */ + private final static String AUTOINSERT= PreferenceConstants.CODEASSIST_AUTOINSERT; + + /** Preference key for php content assist auto activation triggers */ + private final static String AUTOACTIVATION_TRIGGERS_JAVA= PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA; + /** Preference key for phpdoc content assist auto activation triggers */ + private final static String AUTOACTIVATION_TRIGGERS_JAVADOC= PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVADOC; + + /** Preference key for visibility of proposals */ + private final static String SHOW_VISIBLE_PROPOSALS= PreferenceConstants.CODEASSIST_SHOW_VISIBLE_PROPOSALS; + /** Preference key for alphabetic ordering of proposals */ + private final static String ORDER_PROPOSALS= PreferenceConstants.CODEASSIST_ORDER_PROPOSALS; + /** Preference key for case sensitivity of propsals */ + private final static String CASE_SENSITIVITY= PreferenceConstants.CODEASSIST_CASE_SENSITIVITY; + /** Preference key for adding imports on code assist */ + private final static String ADD_IMPORT= PreferenceConstants.CODEASSIST_ADDIMPORT; + /** Preference key for inserting content assist */ + private static final String INSERT_COMPLETION= PreferenceConstants.CODEASSIST_INSERT_COMPLETION; + /** Preference key for filling argument names on method completion */ + private static final String FILL_METHOD_ARGUMENTS= PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES; + /** Preference key for guessing argument names on method completion */ + private static final String GUESS_METHOD_ARGUMENTS= PreferenceConstants.CODEASSIST_GUESS_METHOD_ARGUMENTS; + + + private static Color getColor(IPreferenceStore store, String key, IColorManager manager) { + RGB rgb= PreferenceConverter.getColor(store, key); + return manager.getColor(rgb); + } + + private static Color getColor(IPreferenceStore store, String key) { + JavaTextTools textTools= PHPeclipsePlugin.getDefault().getJavaTextTools(); + return getColor(store, key, textTools.getColorManager()); + } + + private static PHPCompletionProcessor getJavaProcessor(ContentAssistant assistant) { + IContentAssistProcessor p= assistant.getContentAssistProcessor(IPHPPartitionScannerConstants.PHP); + if (p instanceof PHPCompletionProcessor) + return (PHPCompletionProcessor) p; + return null; + } + + private static PHPDocCompletionProcessor getJavaDocProcessor(ContentAssistant assistant) { + IContentAssistProcessor p= assistant.getContentAssistProcessor(IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); + if (p instanceof PHPDocCompletionProcessor) + return (PHPDocCompletionProcessor) p; + return null; + } + + private static void configureJavaProcessor(ContentAssistant assistant, IPreferenceStore store) { + PHPCompletionProcessor jcp= getJavaProcessor(assistant); + if (jcp == null) + return; + + String triggers= store.getString(AUTOACTIVATION_TRIGGERS_JAVA); + if (triggers != null) + jcp.setCompletionProposalAutoActivationCharacters(triggers.toCharArray()); + +// boolean enabled= store.getBoolean(SHOW_VISIBLE_PROPOSALS); +// jcp.restrictProposalsToVisibility(enabled); +// +// enabled= store.getBoolean(CASE_SENSITIVITY); +// jcp.restrictProposalsToMatchingCases(enabled); +// +// enabled= store.getBoolean(ORDER_PROPOSALS); +// jcp.orderProposalsAlphabetically(enabled); +// +// enabled= store.getBoolean(ADD_IMPORT); +// jcp.allowAddingImports(enabled); + } + + private static void configureJavaDocProcessor(ContentAssistant assistant, IPreferenceStore store) { + PHPDocCompletionProcessor jdcp= getJavaDocProcessor(assistant); + if (jdcp == null) + return; + + String triggers= store.getString(AUTOACTIVATION_TRIGGERS_JAVADOC); + if (triggers != null) + jdcp.setCompletionProposalAutoActivationCharacters(triggers.toCharArray()); + + boolean enabled= store.getBoolean(CASE_SENSITIVITY); + jdcp.restrictProposalsToMatchingCases(enabled); + + enabled= store.getBoolean(ORDER_PROPOSALS); + jdcp.orderProposalsAlphabetically(enabled); + } + + /** + * Configure the given content assistant from the given store. + */ + public static void configure(ContentAssistant assistant, IPreferenceStore store) { + + JavaTextTools textTools= PHPeclipsePlugin.getDefault().getJavaTextTools(); + IColorManager manager= textTools.getColorManager(); + + + boolean enabled= store.getBoolean(AUTOACTIVATION); + assistant.enableAutoActivation(enabled); + + int delay= store.getInt(AUTOACTIVATION_DELAY); + assistant.setAutoActivationDelay(delay); + + Color c= getColor(store, PROPOSALS_FOREGROUND, manager); + assistant.setProposalSelectorForeground(c); + + c= getColor(store, PROPOSALS_BACKGROUND, manager); + assistant.setProposalSelectorBackground(c); + + c= getColor(store, PARAMETERS_FOREGROUND, manager); + assistant.setContextInformationPopupForeground(c); + assistant.setContextSelectorForeground(c); + + c= getColor(store, PARAMETERS_BACKGROUND, manager); + assistant.setContextInformationPopupBackground(c); + assistant.setContextSelectorBackground(c); + + enabled= store.getBoolean(AUTOINSERT); + assistant.enableAutoInsert(enabled); + + configureJavaProcessor(assistant, store); + configureJavaDocProcessor(assistant, store); + } + + + private static void changeJavaProcessor(ContentAssistant assistant, IPreferenceStore store, String key) { + PHPCompletionProcessor jcp= getJavaProcessor(assistant); + if (jcp == null) + return; + + if (AUTOACTIVATION_TRIGGERS_JAVA.equals(key)) { + String triggers= store.getString(AUTOACTIVATION_TRIGGERS_JAVA); + if (triggers != null) + jcp.setCompletionProposalAutoActivationCharacters(triggers.toCharArray()); + } +// else if (SHOW_VISIBLE_PROPOSALS.equals(key)) { +// boolean enabled= store.getBoolean(SHOW_VISIBLE_PROPOSALS); +// jcp.restrictProposalsToVisibility(enabled); +// } else if (CASE_SENSITIVITY.equals(key)) { +// boolean enabled= store.getBoolean(CASE_SENSITIVITY); +// jcp.restrictProposalsToMatchingCases(enabled); +// } else if (ORDER_PROPOSALS.equals(key)) { +// boolean enable= store.getBoolean(ORDER_PROPOSALS); +// jcp.orderProposalsAlphabetically(enable); +// } else if (ADD_IMPORT.equals(key)) { +// boolean enabled= store.getBoolean(ADD_IMPORT); +// jcp.allowAddingImports(enabled); +// } + } + + private static void changeJavaDocProcessor(ContentAssistant assistant, IPreferenceStore store, String key) { + PHPDocCompletionProcessor jdcp= getJavaDocProcessor(assistant); + if (jdcp == null) + return; + + if (AUTOACTIVATION_TRIGGERS_JAVADOC.equals(key)) { + String triggers= store.getString(AUTOACTIVATION_TRIGGERS_JAVADOC); + if (triggers != null) + jdcp.setCompletionProposalAutoActivationCharacters(triggers.toCharArray()); + } else if (CASE_SENSITIVITY.equals(key)) { + boolean enabled= store.getBoolean(CASE_SENSITIVITY); + jdcp.restrictProposalsToMatchingCases(enabled); + } else if (ORDER_PROPOSALS.equals(key)) { + boolean enable= store.getBoolean(ORDER_PROPOSALS); + jdcp.orderProposalsAlphabetically(enable); + } + } + + /** + * Changes the configuration of the given content assistant according to the given property + * change event and the given preference store. + */ + public static void changeConfiguration(ContentAssistant assistant, IPreferenceStore store, PropertyChangeEvent event) { + + String p= event.getProperty(); + + if (AUTOACTIVATION.equals(p)) { + boolean enabled= store.getBoolean(AUTOACTIVATION); + assistant.enableAutoActivation(enabled); + } else if (AUTOACTIVATION_DELAY.equals(p)) { + int delay= store.getInt(AUTOACTIVATION_DELAY); + assistant.setAutoActivationDelay(delay); + } else if (PROPOSALS_FOREGROUND.equals(p)) { + Color c= getColor(store, PROPOSALS_FOREGROUND); + assistant.setProposalSelectorForeground(c); + } else if (PROPOSALS_BACKGROUND.equals(p)) { + Color c= getColor(store, PROPOSALS_BACKGROUND); + assistant.setProposalSelectorBackground(c); + } else if (PARAMETERS_FOREGROUND.equals(p)) { + Color c= getColor(store, PARAMETERS_FOREGROUND); + assistant.setContextInformationPopupForeground(c); + assistant.setContextSelectorForeground(c); + } else if (PARAMETERS_BACKGROUND.equals(p)) { + Color c= getColor(store, PARAMETERS_BACKGROUND); + assistant.setContextInformationPopupBackground(c); + assistant.setContextSelectorBackground(c); + } else if (AUTOINSERT.equals(p)) { + boolean enabled= store.getBoolean(AUTOINSERT); + assistant.enableAutoInsert(enabled); + } + + changeJavaProcessor(assistant, store, p); + changeJavaDocProcessor(assistant, store, p); + } + + public static boolean fillArgumentsOnMethodCompletion(IPreferenceStore store) { + return store.getBoolean(FILL_METHOD_ARGUMENTS); + } +} + diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/phpdoc/PHPDocCompletionProcessor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/phpdoc/PHPDocCompletionProcessor.java index bca81e5..4a782fd 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/phpdoc/PHPDocCompletionProcessor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/phpdoc/PHPDocCompletionProcessor.java @@ -27,7 +27,7 @@ import org.eclipse.ui.IEditorPart; */ public class PHPDocCompletionProcessor implements IContentAssistProcessor { - private static class JavaDocCompletionProposalComparator implements Comparator { + private static class PHPDocCompletionProposalComparator implements Comparator { public int compare(Object o1, Object o2) { ICompletionProposal c1= (ICompletionProposal) o1; ICompletionProposal c2= (ICompletionProposal) o2; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java index e5c035f..0afea31 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java @@ -1768,7 +1768,7 @@ public class PreferenceConstants { PreferenceConverter.setDefault(store, PreferenceConstants.CODEASSIST_PARAMETERS_FOREGROUND, new RGB(0, 0, 0)); PreferenceConverter.setDefault(store, PreferenceConstants.CODEASSIST_REPLACEMENT_BACKGROUND, new RGB(255, 255, 0)); PreferenceConverter.setDefault(store, PreferenceConstants.CODEASSIST_REPLACEMENT_FOREGROUND, new RGB(255, 0, 0)); - store.setDefault(PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA, "."); //$NON-NLS-1$ + store.setDefault(PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA, "$"); //$NON-NLS-1$ store.setDefault(PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVADOC, "@"); //$NON-NLS-1$ store.setDefault(PreferenceConstants.CODEASSIST_SHOW_VISIBLE_PROPOSALS, true); store.setDefault(PreferenceConstants.CODEASSIST_CASE_SENSITIVITY, false); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java index b2396d4..481b7d5 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java @@ -86,8 +86,8 @@ public interface IPreferenceConstants { public static final String RESOURCE_BUNDLE_ES = "net.sourceforge.phpeclipse.newPHPPreferencesMessages_es_ES"; public static final String RESOURCE_BUNDLE_EN_GB = "net.sourceforge.phpeclipse.newPHPPreferencesMessages_en_GB"; - public static final String FORMATTER_TAB_SIZE = "_formatter_tab_size"; - public static final String SPACES_FOR_TABS = "_formatter_tab_size"; + //public static final String FORMATTER_TAB_SIZE = "_formatter_tab_size"; + //public static final String SPACES_FOR_TABS = "_formatter_tab_size"; public static final String EDITOR_BOLD_SUFFIX = "_editor_bold_suffix"; /** Preference key for showing the line number ruler */ diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java index 99c2a80..6dad304 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java @@ -326,7 +326,7 @@ public class PHPeclipsePlugin // show line numbers: // store.setDefault(LINE_NUMBER_RULER, "false"); - store.setDefault(FORMATTER_TAB_SIZE, "4"); +// store.setDefault(FORMATTER_TAB_SIZE, "4"); // php syntax highlighting store.setDefault(PHP_USERDEF_XMLFILE, ""); //assume there is none chooA diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java index 9fbe169..45ee036 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java @@ -13,10 +13,13 @@ package net.sourceforge.phpeclipse.phpeditor; import java.util.Vector; +import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference; import net.sourceforge.phpdt.internal.ui.text.JavaColorManager; import net.sourceforge.phpdt.internal.ui.text.java.JavaFormattingStrategy; import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCompletionProcessor; +import net.sourceforge.phpdt.ui.PreferenceConstants; import net.sourceforge.phpdt.ui.text.JavaTextTools; +import net.sourceforge.phpeclipse.PHPCore; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.phpeditor.html.HTMLFormattingStrategy; import net.sourceforge.phpeclipse.phpeditor.php.HTMLCompletionProcessor; @@ -26,6 +29,7 @@ import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor; import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector; import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider; +import org.eclipse.core.runtime.Preferences; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.DefaultAutoIndentStrategy; import org.eclipse.jface.text.IAutoIndentStrategy; @@ -34,6 +38,7 @@ import org.eclipse.jface.text.ITextDoubleClickStrategy; import org.eclipse.jface.text.ITextHover; import org.eclipse.jface.text.TextAttribute; import org.eclipse.jface.text.contentassist.ContentAssistant; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; import org.eclipse.jface.text.contentassist.IContentAssistant; import org.eclipse.jface.text.formatter.ContentFormatter; import org.eclipse.jface.text.formatter.IContentFormatter; @@ -47,14 +52,28 @@ import org.eclipse.jface.text.rules.Token; import org.eclipse.jface.text.source.IAnnotationHover; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.SourceViewerConfiguration; -import org.eclipse.swt.graphics.RGB; /** * Configuration for an SourceViewer which shows PHP code. */ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { - public static final String HTML_DEFAULT = IPHPPartitionScannerConstants.HTML; + + /** + * Preference key used to look up display tab width. + * + * @since 2.0 + */ + public final static String PREFERENCE_TAB_WIDTH= PreferenceConstants.EDITOR_TAB_WIDTH; + /** + * Preference key for inserting spaces rather than tabs. + * + * @since 2.0 + */ + public final static String SPACES_FOR_TABS= PreferenceConstants.EDITOR_SPACES_FOR_TABS; + + +// public static final String HTML_DEFAULT = IPHPPartitionScannerConstants.HTML; //IDocument.DEFAULT_CONTENT_TYPE; private JavaTextTools fJavaTextTools; @@ -97,12 +116,9 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { fFormatter = new ContentFormatter(); IFormattingStrategy strategy = new JavaFormattingStrategy(sourceViewer); - fFormatter.setFormattingStrategy( - strategy, - IDocument.DEFAULT_CONTENT_TYPE); + fFormatter.setFormattingStrategy(strategy, IDocument.DEFAULT_CONTENT_TYPE); fFormatter.enablePartitionAwareFormatting(false); - fFormatter.setPartitionManagingPositionCategories( - getPartitionManagingPositionCategories()); + fFormatter.setPartitionManagingPositionCategories(getPartitionManagingPositionCategories()); } return fFormatter; } @@ -136,6 +152,18 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { return fEditor; } + /** + * Returns the preference store used by this configuration to initialize + * the individual bits and pieces. + * + * @return the preference store used to initialize this configuration + * + * @since 2.0 + */ + protected IPreferenceStore getPreferenceStore() { + return PHPeclipsePlugin.getDefault().getPreferenceStore(); + } + /* (non-Javadoc) * Method declared on SourceViewerConfiguration */ @@ -146,13 +174,8 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { /* (non-Javadoc) * Method declared on SourceViewerConfiguration */ - public IAutoIndentStrategy getAutoIndentStrategy( - ISourceViewer sourceViewer, - String contentType) { - return ( - IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) - ? new PHPAutoIndentStrategy() - : new DefaultAutoIndentStrategy()); + public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) { + return (IPHPPartitionScannerConstants.PHP.equals(contentType) ? new PHPAutoIndentStrategy() : new DefaultAutoIndentStrategy()); } /* (non-Javadoc) @@ -160,15 +183,15 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { */ public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { return new String[] { - IDocument.DEFAULT_CONTENT_TYPE, - IPHPPartitionScannerConstants.PHP, - IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT, + // IDocument.DEFAULT_CONTENT_TYPE, IPHPPartitionScannerConstants.HTML, - IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT, - IPHPPartitionScannerConstants.CSS, - IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT, - IPHPPartitionScannerConstants.JAVASCRIPT, - IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT }; + IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT, + IPHPPartitionScannerConstants.PHP, + IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT, + IPHPPartitionScannerConstants.CSS, + IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT, + IPHPPartitionScannerConstants.JAVASCRIPT, + IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT }; } /* (non-Javadoc) @@ -177,24 +200,32 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { ContentAssistant assistant = new ContentAssistant(); - assistant.setContentAssistProcessor( - new HTMLCompletionProcessor(), - IDocument.DEFAULT_CONTENT_TYPE); - assistant.setContentAssistProcessor( - new PHPCompletionProcessor(), - IPHPPartitionScannerConstants.PHP); - assistant.setContentAssistProcessor( - new PHPDocCompletionProcessor(), - IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); - - assistant.enableAutoActivation(true); - assistant.setAutoActivationDelay(500); - assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY); - assistant.setContextInformationPopupOrientation( - ContentAssistant.CONTEXT_INFO_ABOVE); - assistant.setContextInformationPopupBackground( - PHPEditorEnvironment.getPHPColorProvider().getColor( - new RGB(150, 150, 0))); + IContentAssistProcessor processor = new HTMLCompletionProcessor(); + assistant.setContentAssistProcessor(processor, IPHPPartitionScannerConstants.HTML); + assistant.setContentAssistProcessor(processor, IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT); + assistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE); + assistant.setContentAssistProcessor(processor, IPHPPartitionScannerConstants.CSS); + assistant.setContentAssistProcessor(processor, IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT); + assistant.setContentAssistProcessor(processor, IPHPPartitionScannerConstants.JAVASCRIPT); + assistant.setContentAssistProcessor(processor, IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT); + + assistant.setContentAssistProcessor(new PHPCompletionProcessor(), IPHPPartitionScannerConstants.PHP); + + assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(), IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); + + // assistant.enableAutoActivation(true); + // assistant.setAutoActivationDelay(500); + // assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY); + // ContentAssistPreference.configure(assistant, getPreferenceStore()); + // assistant.setContextInformationPopupOrientation( + // ContentAssistant.CONTEXT_INFO_ABOVE); + // assistant.setContextInformationPopupBackground( + // PHPEditorEnvironment.getPHPColorProvider().getColor( + // new RGB(150, 150, 0))); + ContentAssistPreference.configure(assistant, getPreferenceStore()); + + assistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE); + assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer)); return assistant; } @@ -211,45 +242,30 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { * @see SourceViewerConfiguration#getDefaultPrefix(ISourceViewer, String) * @since 2.0 */ - public String[] getDefaultPrefixes( - ISourceViewer sourceViewer, - String contentType) { + public String[] getDefaultPrefixes(ISourceViewer sourceViewer, String contentType) { return new String[] { "//", "" }; //$NON-NLS-1$ //$NON-NLS-2$ } /* (non-Javadoc) * Method declared on SourceViewerConfiguration */ - public ITextDoubleClickStrategy getDoubleClickStrategy( - ISourceViewer sourceViewer, - String contentType) { + public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) { return new PHPDoubleClickSelector(); } - /* (non-Javadoc) - * Method declared on SourceViewerConfiguration - */ - // public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) { - // return new String[] { "\t", " " }; //$NON-NLS-1$ //$NON-NLS-2$ - // } - /* * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String) */ - public String[] getIndentPrefixes( - ISourceViewer sourceViewer, - String contentType) { + public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) { Vector vector = new Vector(); // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces - final IPreferenceStore store = - PHPeclipsePlugin.getDefault().getPreferenceStore(); - - int tabWidth = store.getInt(PHPeclipsePlugin.FORMATTER_TAB_SIZE); - boolean useSpaces = store.getBoolean(PHPeclipsePlugin.SPACES_FOR_TABS); - + final IPreferenceStore preferences= PHPeclipsePlugin.getDefault().getPreferenceStore(); + int tabWidth= preferences.getInt(PHPCore.FORMATTER_TAB_SIZE); + boolean useSpaces= getPreferenceStore().getBoolean(SPACES_FOR_TABS); + for (int i = 0; i <= tabWidth; i++) { StringBuffer prefix = new StringBuffer(); @@ -278,48 +294,41 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { * Method declared on SourceViewerConfiguration */ public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { - - // PHPColorProvider provider = PHPEditorEnvironment.getPHPColorProvider(); + // PHPColorProvider provider = PHPEditorEnvironment.getPHPColorProvider(); JavaColorManager provider = PHPEditorEnvironment.getPHPColorProvider(); PresentationReconciler reconciler = new PresentationReconciler(); - DefaultDamagerRepairer dr = - new DefaultDamagerRepairer(PHPEditorEnvironment.getHTMLCodeScanner()); + DefaultDamagerRepairer dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getHTMLCodeScanner()); reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); - // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(provider.HTML_DEFAULT)))); - // reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); - // reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); + dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getHTMLCodeScanner()); + reconciler.setDamager(dr, IPHPPartitionScannerConstants.HTML); + reconciler.setRepairer(dr, IPHPPartitionScannerConstants.HTML); + dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getHTMLCodeScanner()); + reconciler.setDamager(dr, IPHPPartitionScannerConstants.CSS); + reconciler.setRepairer(dr, IPHPPartitionScannerConstants.CSS); + dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getHTMLCodeScanner()); + reconciler.setDamager(dr, IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT); + reconciler.setRepairer(dr, IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT); + dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getHTMLCodeScanner()); + reconciler.setDamager(dr, IPHPPartitionScannerConstants.JAVASCRIPT); + reconciler.setRepairer(dr, IPHPPartitionScannerConstants.JAVASCRIPT); + dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getHTMLCodeScanner()); + reconciler.setDamager(dr, IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT); + reconciler.setRepairer(dr, IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT); + dr = + new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(PHPColorProvider.MULTI_LINE_COMMENT)))); + reconciler.setDamager(dr, IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT); + reconciler.setRepairer(dr, IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT); dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getPHPCodeScanner()); reconciler.setDamager(dr, IPHPPartitionScannerConstants.PHP); reconciler.setRepairer(dr, IPHPPartitionScannerConstants.PHP); - dr = - new DefaultDamagerRepairer(PHPEditorEnvironment.getPHPDocCodeScanner()); - reconciler.setDamager( - dr, - IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); - reconciler.setRepairer( - dr, - IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); - - dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getHTMLCodeScanner()); - reconciler.setDamager(dr, IPHPPartitionScannerConstants.HTML); - reconciler.setRepairer(dr, IPHPPartitionScannerConstants.HTML); - - dr = - new DefaultDamagerRepairer( - new SingleTokenScanner( - new TextAttribute( - provider.getColor(PHPColorProvider.MULTI_LINE_COMMENT)))); - reconciler.setDamager( - dr, - IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT); - reconciler.setRepairer( - dr, - IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT); + dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getPHPDocCodeScanner()); + reconciler.setDamager(dr, IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); + reconciler.setRepairer(dr, IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); return reconciler; } @@ -328,15 +337,13 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { * Method declared on SourceViewerConfiguration */ public int getTabWidth(ISourceViewer sourceViewer) { - return 4; + return getPreferenceStore().getInt(PREFERENCE_TAB_WIDTH); } /* (non-Javadoc) * Method declared on SourceViewerConfiguration */ - public ITextHover getTextHover( - ISourceViewer sourceViewer, - String contentType) { + public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) { return new PHPTextHover(); } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java index 8c567f9..01a0a96 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference; import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher; import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager; import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI; @@ -30,6 +31,7 @@ import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.ITextViewerExtension; import org.eclipse.jface.text.ITypedRegion; import org.eclipse.jface.text.IWidgetTokenKeeper; +import org.eclipse.jface.text.contentassist.ContentAssistant; import org.eclipse.jface.text.contentassist.IContentAssistant; import org.eclipse.jface.text.source.IAnnotationModel; import org.eclipse.jface.text.source.ISourceViewer; @@ -1311,9 +1313,9 @@ public class PHPUnitEditor extends PHPEditor { } } -// IContentAssistant c= asv.getContentAssistant(); -// if (c instanceof ContentAssistant) -// ContentAssistPreference.changeConfiguration((ContentAssistant) c, getPreferenceStore(), event); + IContentAssistant c= asv.getContentAssistant(); + if (c instanceof ContentAssistant) + ContentAssistPreference.changeConfiguration((ContentAssistant) c, getPreferenceStore(), event); } } finally { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCompletionProcessor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCompletionProcessor.java index 6f5c592..893e0c1 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCompletionProcessor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCompletionProcessor.java @@ -235,6 +235,7 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { protected final static String[] fgProposals = PHPFunctionNames.FUNCTION_NAMES; + private char[] fProposalAutoActivationSet; protected IContextInformationValidator fValidator = new Validator(); private TemplateEngine fTemplateEngine; private PHPCompletionProposalComparator fComparator; @@ -248,6 +249,16 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { fComparator = new PHPCompletionProposalComparator(); } + + /** + * Sets this processor's set of characters triggering the activation of the + * completion proposal computation. + * + * @param activationSet the activation set + */ + public void setCompletionProposalAutoActivationCharacters(char[] activationSet) { + fProposalAutoActivationSet= activationSet; + } /* (non-Javadoc) * Method declared on IContentAssistProcessor */ @@ -442,7 +453,8 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { * Method declared on IContentAssistProcessor */ public char[] getCompletionProposalAutoActivationCharacters() { - return null; // new char[] { '$' }; + return fProposalAutoActivationSet; +// return null; // new char[] { '$' }; } /* (non-Javadoc)