1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Bug 173458: Make camel-case content assist a UI preference, by Jens Elmenthaler.

This commit is contained in:
Markus Schorn 2011-05-02 09:24:05 +00:00
parent f915813d3e
commit 63eebc5290
26 changed files with 234 additions and 114 deletions

View file

@ -14,22 +14,18 @@ package org.eclipse.cdt.core.parser.tests;
import junit.framework.TestCase;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CCorePreferenceConstants;
import org.eclipse.cdt.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.core.parser.util.IContentAssistMatcher;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
public class ContentAssistMatcherFactoryTest extends TestCase {
@Override
protected void tearDown() throws Exception {
InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID).remove(
CCorePreferenceConstants.SHOW_CAMEL_CASE_MATCHES);
ContentAssistMatcherFactory.getInstance().setShowCamelCaseMatches(true);
super.tearDown();
}
public void testCamelCasePreference() {
public void testConfiguration() {
// Default is show camel case matches on
assertTrue(match("foo", "fooBar"));
assertTrue(match("fB", "fooBar"));
@ -64,8 +60,7 @@ public class ContentAssistMatcherFactoryTest extends TestCase {
}
private void setShowCamelCaseMatches(boolean enabled) {
InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID).putBoolean(
CCorePreferenceConstants.SHOW_CAMEL_CASE_MATCHES, enabled);
ContentAssistMatcherFactory.getInstance().setShowCamelCaseMatches(enabled);
}
private boolean match(String pattern, String name) {

View file

@ -67,7 +67,7 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.internal.core.parser.problem;x-internal:=true,
org.eclipse.cdt.internal.core.parser.scanner;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.parser.token;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.parser.util;x-internal:=true,
org.eclipse.cdt.internal.core.parser.util;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.pdom;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.pdom.db;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.pdom.dom;x-friends:="org.eclipse.cdt.ui",

View file

@ -329,14 +329,7 @@ public interface IIndex {
public IIndexBinding[] findBindingsForPrefix(char[] prefix, boolean fileScopeOnly, IndexFilter filter, IProgressMonitor monitor) throws CoreException;
/**
* Searches for all bindings that are valid completions to the given prefix.
* @param prefix the text to be completed.
* @param fileScopeOnly if true, only bindings at file scope are returned
* @param filter a filter that allows for skipping parts of the index
* @param monitor a monitor for progress reporting and cancellation, may be <code>null</code>
* @return an array of bindings that complete the given text
* @throws CoreException
* @since 5.3
* @noreference This method is not intended to be referenced by clients.
*/
public IIndexBinding[] findBindingsForContentAssist(char[] prefix, boolean fileScopeOnly, IndexFilter filter, IProgressMonitor monitor) throws CoreException;

View file

@ -230,7 +230,7 @@ public class SegmentMatcher {
* name survived a binary search using the prefix returned by
* @{@link #getPrefixForBinarySearch()} as key.
*/
boolean matchRequiredAfterBinarySearch() {
public boolean matchRequiredAfterBinarySearch() {
return !singleSegment;
}
}

View file

@ -57,13 +57,13 @@ import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.core.parser.util.IContentAssistMatcher;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousParameterDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousSimpleDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;

View file

@ -90,7 +90,6 @@ import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArraySet;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.core.parser.util.IContentAssistMatcher;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
@ -99,6 +98,7 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
/**
* Collection of methods to find information in an AST.

View file

@ -42,11 +42,11 @@ import org.eclipse.cdt.core.model.IEnumeration;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.internal.core.dom.parser.IASTInternalNameOwner;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.core.runtime.Assert;
/**

View file

@ -55,13 +55,13 @@ import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
/**
* Base implementation for c++ scopes.

View file

@ -46,13 +46,13 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.core.parser.util.IContentAssistMatcher;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.core.runtime.PlatformObject;
/**

View file

@ -38,7 +38,6 @@ import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.core.parser.util.IContentAssistMatcher;
import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
@ -46,6 +45,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.LookupData;
import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;

View file

@ -7,18 +7,13 @@
*
* Contributors:
* Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion)
* IBM Corporation
*******************************************************************************/
package org.eclipse.cdt.core.parser.util;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CCorePreferenceConstants;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.core.runtime.preferences.InstanceScope;
package org.eclipse.cdt.internal.core.parser.util;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.IContentAssistMatcher;
import org.eclipse.cdt.core.parser.util.SegmentMatcher;
/**
* The facade to the pattern matching algorithms of content assist.
@ -32,18 +27,8 @@ public class ContentAssistMatcherFactory {
private static ContentAssistMatcherFactory instance = null;
private boolean showCamelCaseMatches;
private final IPreferenceChangeListener preferencesListener = new IPreferenceChangeListener() {
private boolean showCamelCaseMatches = true;
public void preferenceChange(PreferenceChangeEvent event) {
String prop = event.getKey();
if (prop.equals(CCorePreferenceConstants.SHOW_CAMEL_CASE_MATCHES)) {
updateOnPreferences();
}
}
};
private static class CamelCaseMatcher implements IContentAssistMatcher {
private final SegmentMatcher matcher;
@ -88,9 +73,7 @@ public class ContentAssistMatcherFactory {
}
private ContentAssistMatcherFactory() {
getPreferences().addPreferenceChangeListener(
preferencesListener);
updateOnPreferences();
}
public static synchronized ContentAssistMatcherFactory getInstance() {
@ -101,28 +84,22 @@ public class ContentAssistMatcherFactory {
return instance;
}
private void shutdownInternal() {
getPreferences().removePreferenceChangeListener(
preferencesListener);
/**
* This function is not supposed to be called from any functions except
* for ContentAssistMatcherPreference.updateOnPreferences.
*
* @param showCamelCaseMatches
*/
public synchronized void setShowCamelCaseMatches(boolean showCamelCaseMatches) {
this.showCamelCaseMatches = showCamelCaseMatches;
}
/**
* @noreference This method is not intended to be referenced by clients.
*
* @return <code>true</code> if showCamelCaseMatches is set from the content assist preference page.
*/
public static synchronized void shutdown() {
if (instance != null) {
instance.shutdownInternal();
}
}
private static IEclipsePreferences getPreferences() {
return InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID);
}
private synchronized void updateOnPreferences() {
IPreferencesService prefs = Platform.getPreferencesService();
showCamelCaseMatches = prefs.getBoolean(CCorePlugin.PLUGIN_ID,
CCorePreferenceConstants.SHOW_CAMEL_CASE_MATCHES, true, null);
public boolean getShowCamelCaseMatches() {
return showCamelCaseMatches;
}
/**

View file

@ -14,8 +14,8 @@ package org.eclipse.cdt.internal.core.pdom.dom;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.core.parser.util.IContentAssistMatcher;
import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
import org.eclipse.cdt.internal.core.pdom.db.IString;
import org.eclipse.core.runtime.CoreException;

View file

@ -16,8 +16,8 @@ import java.util.List;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.core.parser.util.IContentAssistMatcher;
import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
import org.eclipse.cdt.internal.core.pdom.db.IString;
import org.eclipse.core.runtime.CoreException;

View file

@ -42,12 +42,12 @@ import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.parser.util.CharArrayMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.cdt.internal.core.index.DeclaredBindingsFilter;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.BindingCollector;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;

View file

@ -29,10 +29,10 @@ import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.parser.util.CharArrayMap;
import org.eclipse.cdt.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.core.parser.util.IContentAssistMatcher;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.core.runtime.CoreException;

View file

@ -34,7 +34,6 @@ import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.cdt.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.core.resources.IPathEntryVariableManager;
import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference;
@ -324,9 +323,7 @@ public class CCorePlugin extends Plugin {
fNewCProjectDescriptionManager.shutdown();
ResourceLookup.shutdown();
ContentAssistMatcherFactory.shutdown();
savePluginPreferences();
savePluginPreferences();
} finally {
super.stop(context);
}

View file

@ -165,10 +165,5 @@ public class CCorePreferenceConstants {
*/
public static final String PREF_BUILD_CONFIGS_RESOURCE_CHANGES = "build.proj.ref.configs.enabled"; //$NON-NLS-1$
/**
* Key for boolean preference telling whether camel case/underscore matches are to be shown by content assist features or not.
*
* @since 5.3
*/
public static final String SHOW_CAMEL_CASE_MATCHES = "contentAssist.showCamelCaseMatches"; //$NON-NLS-1$
}

View file

@ -70,7 +70,6 @@ public class CCorePreferenceInitializer extends AbstractPreferenceInitializer {
// indexer defaults
IndexerPreferences.initializeDefaultPreferences(defaultPreferences);
// content assist defaults
defaultPreferences.putBoolean(CCorePreferenceConstants.SHOW_CAMEL_CASE_MATCHES, true);
}
}

View file

@ -71,5 +71,7 @@ public class ContentAssist2TestSuite extends TestSuite {
addTest(CompletionTests.suite());
addTest(CompletionTests_PlainC.suite());
addTest(ParameterHintTests.suite());
addTest(ShowCamelCasePreferenceTest.suite());
}
}

View file

@ -0,0 +1,113 @@
/*******************************************************************************
* Copyright (c) 2011 Jens Elmenthaler and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
import junit.framework.Test;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
/**
* Test the correct response to the value of {@link ContentAssistPreference#SHOW_CAMEL_CASE_MATCHES}.
*/
public class ShowCamelCasePreferenceTest extends AbstractContentAssistTest {
private static final String SOURCE_FILE_NAME = "ContentAssistPreferenceTest.cpp";
private static final String CURSOR_LOCATION_TAG = "/*cursor*/";
protected int fCursorOffset;
private IProject fProject;
public ShowCamelCasePreferenceTest(String name) {
super(name, true);
}
public static Test suite() {
return BaseTestCase.suite(ShowCamelCasePreferenceTest.class, "_");
}
@Override
protected IFile setUpProjectContent(IProject project) throws Exception {
fProject= project;
StringBuffer sourceContent= getContentsForTest(1)[0];
fCursorOffset= sourceContent.indexOf(CURSOR_LOCATION_TAG);
assertTrue("No cursor location specified", fCursorOffset >= 0);
sourceContent.delete(fCursorOffset, fCursorOffset+CURSOR_LOCATION_TAG.length());
return createFile(project, SOURCE_FILE_NAME, sourceContent.toString());
}
@Override
protected void setUp() throws Exception {
InstanceScope.INSTANCE.getNode(CUIPlugin.PLUGIN_ID).remove(
ContentAssistPreference.SHOW_CAMEL_CASE_MATCHES);
super.setUp();
}
@Override
protected void tearDown() throws Exception {
InstanceScope.INSTANCE.getNode(CUIPlugin.PLUGIN_ID).remove(
ContentAssistPreference.SHOW_CAMEL_CASE_MATCHES);
super.tearDown();
}
protected void assertCompletionResults(int offset, String[] expected, int compareType) throws Exception {
assertContentAssistResults(offset, expected, true, compareType);
}
protected void assertCompletionResults(String[] expected) throws Exception {
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
}
private void setShowCamelCaseMatches(boolean enabled) {
InstanceScope.INSTANCE.getNode(CUIPlugin.PLUGIN_ID).putBoolean(
ContentAssistPreference.SHOW_CAMEL_CASE_MATCHES, enabled);
}
// int fbar;
// int fooBar;
// void something() {
// fB/*cursor*/
// }
public void testDefault() throws Exception {
final String[] expected= { "fbar", "fooBar" };
assertCompletionResults(expected);
}
// int fbar;
// int fooBar;
// void something() {
// fB/*cursor*/
// }
public void testCamelCaseOff() throws Exception {
setShowCamelCaseMatches(false);
final String[] expected= { "fbar" };
assertCompletionResults(expected);
}
// int fbar;
// int fooBar;
// void something() {
// fB/*cursor*/
// }
public void testCamelCaseOn() throws Exception {
setShowCamelCaseMatches(true);
final String[] expected= { "fbar", "fooBar" };
assertCompletionResults(expected);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2002, 2010 QNX Software Systems and others.
* Copyright (c) 2002, 2011 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -26,7 +26,6 @@ import org.eclipse.swt.widgets.Group;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.cdt.core.CCorePreferenceConstants;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.internal.ui.preferences.OverlayPreferenceStore.OverlayKey;
@ -35,7 +34,7 @@ import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
/**
* CodeAssistPreferencePage
*/
public class CodeAssistPreferencePage extends AbstractMixedPreferencePage {
public class CodeAssistPreferencePage extends AbstractPreferencePage {
/**
*
@ -59,6 +58,7 @@ public class CodeAssistPreferencePage extends AbstractMixedPreferencePage {
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_REPLACE_DOT_WITH_ARROW));
// overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.SHOW_DOCUMENTED_PROPOSALS));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.ORDER_PROPOSALS));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.SHOW_CAMEL_CASE_MATCHES));
// overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.ADD_INCLUDE));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.CURRENT_FILE_SEARCH_SCOPE));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.PROJECT_SEARCH_SCOPE));
@ -69,18 +69,7 @@ public class CodeAssistPreferencePage extends AbstractMixedPreferencePage {
return keys;
}
@Override
protected OverlayPreferenceStore.OverlayKey[] createCorePrefsOverlayStoreKeys() {
ArrayList<OverlayKey> overlayKeys = new ArrayList<OverlayKey>();
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, CCorePreferenceConstants.SHOW_CAMEL_CASE_MATCHES));
OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
overlayKeys.toArray(keys);
return keys;
}
/*
* @see PreferencePage#createControl(Composite)
*/
@ -97,9 +86,7 @@ public class CodeAssistPreferencePage extends AbstractMixedPreferencePage {
protected Control createContents(Composite parent) {
fOverlayStore.load();
fOverlayStore.start();
corePrefsOverlayStore.load();
corePrefsOverlayStore.start();
Composite contentAssistComposite = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
@ -140,7 +127,7 @@ public class CodeAssistPreferencePage extends AbstractMixedPreferencePage {
addComboBox(sortingGroup, label, ContentAssistPreference.PROPOSALS_FILTER, NO_TEXT_LIMIT, 0);
label= PreferencesMessages.CEditorPreferencePage_ContentAssistPage_showCamelCaseMatches;
addCorePrefsCheckBox(sortingGroup, label, CCorePreferenceConstants.SHOW_CAMEL_CASE_MATCHES, 0);
addCheckBox(sortingGroup, label, ContentAssistPreference.SHOW_CAMEL_CASE_MATCHES, 0);
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// The following items are grouped for Auto Activation
@ -189,7 +176,8 @@ public class CodeAssistPreferencePage extends AbstractMixedPreferencePage {
store.setDefault(ContentAssistPreference.PREFIX_COMPLETION, true);
store.setDefault(ContentAssistPreference.ORDER_PROPOSALS, false);
store.setDefault(ContentAssistPreference.PROPOSALS_FILTER, ProposalFilterPreferencesUtil.getProposalFilternamesAsString()); // $NON_NLS 1$
store.setDefault(ContentAssistPreference.SHOW_CAMEL_CASE_MATCHES, true);
}
}

View file

@ -50,10 +50,11 @@ import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.ui.texteditor.link.EditorLinkedModeUI;
import org.eclipse.cdt.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.ICCompletionProposal;
import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.internal.ui.text.CTextTools;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -12,6 +12,13 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist;
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.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
@ -19,14 +26,9 @@ import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.IColorManager;
import org.eclipse.cdt.internal.ui.text.CTextTools;
import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
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.cdt.internal.ui.text.CTextTools;
@ -70,6 +72,9 @@ public class ContentAssistPreference {
public final static String PROJECT_SEARCH_SCOPE= "content_assist_project_search_scope"; //$NON-NLS-1$
/** Preference key for completion filtering */
public final static String PROPOSALS_FILTER= "content_assist_proposal_filter"; //$NON-NLS-1$
/** Key for boolean preference telling whether camel case/underscore matches are to be shown by content assist features or not*/
public static final String SHOW_CAMEL_CASE_MATCHES = "contentAssist.showCamelCaseMatches"; //$NON-NLS-1$
private static Color getColor(IPreferenceStore store, String key, IColorManager manager) {
RGB rgb= PreferenceConverter.getColor(store, key);
@ -259,4 +264,53 @@ public class ContentAssistPreference {
changeCProcessor(assistant, store, p);
}
private static ContentAssistPreference instance = null;
private final IPropertyChangeListener propertyListener = new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
String prop = event.getProperty();
if (prop.equals(ContentAssistPreference.SHOW_CAMEL_CASE_MATCHES)) {
updateOnPreferences();
}
}
};
private ContentAssistPreference() {
getPreferences().addPropertyChangeListener(
propertyListener);
updateOnPreferences();
}
public static synchronized ContentAssistPreference getInstance() {
if (instance == null) {
instance = new ContentAssistPreference();
}
return instance;
}
private static IPreferenceStore getPreferences() {
return CUIPlugin.getDefault().getPreferenceStore();
}
private synchronized void updateOnPreferences() {
boolean showCamelCaseMatches = getPreferences().getBoolean(ContentAssistPreference.SHOW_CAMEL_CASE_MATCHES);
ContentAssistMatcherFactory.getInstance().setShowCamelCaseMatches(showCamelCaseMatches);
}
private void shutdownInternal() {
getPreferences().removePropertyChangeListener(propertyListener);
}
/**
* @noreference This method is not intended to be referenced by clients.
*/
public static synchronized void shutdown() {
if (instance != null) {
instance.shutdownInternal();
}
}
}

View file

@ -65,7 +65,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.core.parser.util.IContentAssistMatcher;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.ICPartitions;
@ -80,6 +79,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitMethod;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitTypedef;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.AccessContext;
import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;

View file

@ -42,13 +42,14 @@ import org.eclipse.cdt.core.model.IInclude;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.IExtendedScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.core.parser.util.IContentAssistMatcher;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.contentassist.ContentAssistInvocationContext;
import org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer;
import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
/**

View file

@ -97,6 +97,7 @@ import org.eclipse.cdt.internal.ui.preferences.BuildConsolePreferencePage;
import org.eclipse.cdt.internal.ui.refactoring.CTextFileChangeFactory;
import org.eclipse.cdt.internal.ui.text.CTextTools;
import org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverDescriptor;
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
import org.eclipse.cdt.internal.ui.text.doctools.EditorReopener;
import org.eclipse.cdt.internal.ui.text.folding.CFoldingStructureProviderRegistry;
@ -557,6 +558,8 @@ public class CUIPlugin extends AbstractUIPlugin {
// A workaround for black console bug 320723.
BuildConsolePreferencePage.initDefaults(getPreferenceStore());
//initialize ContentAssistMatcherPreference
ContentAssistPreference.getInstance();
// start make-ui plugin, such that it can check for project conversions.
Job job= new Job(Messages.CUIPlugin_jobStartMakeUI) {
@ -623,6 +626,8 @@ public class CUIPlugin extends AbstractUIPlugin {
fDocumentProvider.shutdown();
fDocumentProvider= null;
}
ContentAssistPreference.shutdown();
// Do this last.
super.stop(context);