null
if the project
+ * does not have a C nature.
*/
- private Preferences getPreferences() {
+ private IEclipsePreferences getPreferences() {
if (!(isCProject())) {
return null;
}
- Preferences preferences = new Preferences();
- Iterator iter = CModelManager.OptionNames.iterator();
-
- while (iter.hasNext()) {
- String qualifiedName = (String) iter.next();
- String dequalifiedName = qualifiedName.substring(CCorePlugin.PLUGIN_ID.length() + 1);
- String value = null;
-
- try {
- value = resource.getPersistentProperty(new QualifiedName(CCorePlugin.PLUGIN_ID, dequalifiedName));
- } catch (CoreException e) {
- }
-
- if (value != null)
- preferences.setValue(qualifiedName, value);
- }
-
+ IScopeContext context= new ProjectScope(getProject());
+ final IEclipsePreferences preferences= context.getNode(CCorePlugin.PLUGIN_ID);
return preferences;
}
diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index f4db8b8f54d..02a421b9bbf 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -1931,7 +1931,20 @@
+
+ + * This preference store is read-only i.e. write access + * throws an {@link java.lang.UnsupportedOperationException}. + *
+ */ +class EclipsePreferencesAdapter implements IPreferenceStore { + + /** + * Preference change listener. Listens for events preferences + * fires a {@link org.eclipse.jface.util.PropertyChangeEvent} + * on this adapter with arguments from the received event. + */ + private class PreferenceChangeListener implements IEclipsePreferences.IPreferenceChangeListener { + + /** + * {@inheritDoc} + */ + public void preferenceChange(final IEclipsePreferences.PreferenceChangeEvent event) { + if (Display.getCurrent() == null) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + firePropertyChangeEvent(event.getKey(), event.getOldValue(), event.getNewValue()); + } + }); + } else { + firePropertyChangeEvent(event.getKey(), event.getOldValue(), event.getNewValue()); + } + } + } + + /** Listeners on on this adapter */ + private ListenerList fListeners= new ListenerList(ListenerList.IDENTITY); + + /** Listener on the node */ + private IEclipsePreferences.IPreferenceChangeListener fListener= new PreferenceChangeListener(); + + /** wrapped node */ + private final IScopeContext fContext; + private final String fQualifier; + + /** + * Initialize with the node to wrap + * + * @param context the context to access + * @param qualifier the qualifier + */ + public EclipsePreferencesAdapter(IScopeContext context, String qualifier) { + fContext= context; + fQualifier= qualifier; + } + + private IEclipsePreferences getNode() { + return fContext.getNode(fQualifier); + } + + /** + * {@inheritDoc} + */ + public void addPropertyChangeListener(IPropertyChangeListener listener) { + if (fListeners.size() == 0) + getNode().addPreferenceChangeListener(fListener); + fListeners.add(listener); + } + + /** + * {@inheritDoc} + */ + public void removePropertyChangeListener(IPropertyChangeListener listener) { + fListeners.remove(listener); + if (fListeners.size() == 0) { + getNode().removePreferenceChangeListener(fListener); + } + } + + /** + * {@inheritDoc} + */ + public boolean contains(String name) { + return getNode().get(name, null) != null; + } + + /** + * {@inheritDoc} + */ + public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) { + PropertyChangeEvent event= new PropertyChangeEvent(this, name, oldValue, newValue); + Object[] listeners= fListeners.getListeners(); + for (int i= 0; i < listeners.length; i++) + ((IPropertyChangeListener) listeners[i]).propertyChange(event); + } + + /** + * {@inheritDoc} + */ + public boolean getBoolean(String name) { + return getNode().getBoolean(name, BOOLEAN_DEFAULT_DEFAULT); + } + + /** + * {@inheritDoc} + */ + public boolean getDefaultBoolean(String name) { + return BOOLEAN_DEFAULT_DEFAULT; + } + + /** + * {@inheritDoc} + */ + public double getDefaultDouble(String name) { + return DOUBLE_DEFAULT_DEFAULT; + } + + /** + * {@inheritDoc} + */ + public float getDefaultFloat(String name) { + return FLOAT_DEFAULT_DEFAULT; + } + + /** + * {@inheritDoc} + */ + public int getDefaultInt(String name) { + return INT_DEFAULT_DEFAULT; + } + + /** + * {@inheritDoc} + */ + public long getDefaultLong(String name) { + return LONG_DEFAULT_DEFAULT; + } + + /** + * {@inheritDoc} + */ + public String getDefaultString(String name) { + return STRING_DEFAULT_DEFAULT; + } + + /** + * {@inheritDoc} + */ + public double getDouble(String name) { + return getNode().getDouble(name, DOUBLE_DEFAULT_DEFAULT); + } + + /** + * {@inheritDoc} + */ + public float getFloat(String name) { + return getNode().getFloat(name, FLOAT_DEFAULT_DEFAULT); + } + + /** + * {@inheritDoc} + */ + public int getInt(String name) { + return getNode().getInt(name, INT_DEFAULT_DEFAULT); + } + + /** + * {@inheritDoc} + */ + public long getLong(String name) { + return getNode().getLong(name, LONG_DEFAULT_DEFAULT); + } + + /** + * {@inheritDoc} + */ + public String getString(String name) { + return getNode().get(name, STRING_DEFAULT_DEFAULT); + } + + /** + * {@inheritDoc} + */ + public boolean isDefault(String name) { + return false; + } + + /** + * {@inheritDoc} + */ + public boolean needsSaving() { + try { + return getNode().keys().length > 0; + } catch (BackingStoreException e) { + // ignore + } + return true; + } + + /** + * {@inheritDoc} + */ + public void putValue(String name, String value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setDefault(String name, double value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setDefault(String name, float value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setDefault(String name, int value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setDefault(String name, long value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setDefault(String name, String defaultObject) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setDefault(String name, boolean value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setToDefault(String name) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setValue(String name, double value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setValue(String name, float value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setValue(String name, int value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setValue(String name, long value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setValue(String name, String value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setValue(String name, boolean value) { + throw new UnsupportedOperationException(); + } + +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CodeFormatterPreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CodeFormatterPreferencePage.java index 959da136de9..43cc5d0dc25 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CodeFormatterPreferencePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CodeFormatterPreferencePage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 QNX Software Systems and others. + * Copyright (c) 2000, 2008 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 @@ -8,20 +8,17 @@ * Contributors: * QNX Software Systems - Initial API and implementation * Sergey Prigogin, Google + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.ui.preferences; -import org.eclipse.core.runtime.IAdaptable; - import org.eclipse.core.resources.IProject; - +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.preference.IPreferencePageContainer; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; - -import org.eclipse.jface.preference.IPreferencePageContainer; - import org.eclipse.ui.PlatformUI; import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; import org.eclipse.ui.preferences.IWorkingCopyManager; @@ -47,7 +44,7 @@ public class CodeFormatterPreferencePage extends PropertyAndPreferencePage { setTitle(PreferencesMessages.CodeFormatterPreferencePage_title); } - /* (non-Javadoc) + /* * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) */ public void createControl(Composite parent) { @@ -65,21 +62,21 @@ public class CodeFormatterPreferencePage extends PropertyAndPreferencePage { PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), ICHelpContextIds.CODEFORMATTER_PREFERENCE_PAGE); } - /* (non-Javadoc) + /* * @see org.eclipse.cdt.internal.ui.preferences.PropertyAndPreferencePage#createPreferenceContent(org.eclipse.swt.widgets.Composite) */ protected Control createPreferenceContent(Composite composite) { return fConfigurationBlock.createContents(composite); } - /* (non-Javadoc) + /* * @see org.eclipse.cdt.internal.ui.preferences.PropertyAndPreferencePage#hasProjectSpecificOptions(org.eclipse.core.resources.IProject) */ protected boolean hasProjectSpecificOptions(IProject project) { return fConfigurationBlock.hasProjectSpecificOptions(project); } - /* (non-Javadoc) + /* * @see org.eclipse.cdt.internal.ui.preferences.PropertyAndPreferencePage#enableProjectSpecificSettings(boolean) */ protected void enableProjectSpecificSettings(boolean useProjectSpecificSettings) { @@ -89,23 +86,21 @@ public class CodeFormatterPreferencePage extends PropertyAndPreferencePage { } } - /* (non-Javadoc) + /* * @see org.eclipse.cdt.internal.ui.preferences.PropertyAndPreferencePage#getPreferencePageID() */ protected String getPreferencePageID() { return PREF_ID; } - /* (non-Javadoc) + /* * @see org.eclipse.cdt.internal.ui.preferences.PropertyAndPreferencePage#getPropertyPageID() */ protected String getPropertyPageID() { - return null; - // project specific settings unsupported for now -// return PROP_ID; + return PROP_ID; } - /* (non-Javadoc) + /* * @see org.eclipse.jface.dialogs.DialogPage#dispose() */ public void dispose() { @@ -115,7 +110,7 @@ public class CodeFormatterPreferencePage extends PropertyAndPreferencePage { super.dispose(); } - /* (non-Javadoc) + /* * @see org.eclipse.jface.preference.IPreferencePage#performDefaults() */ protected void performDefaults() { @@ -125,7 +120,7 @@ public class CodeFormatterPreferencePage extends PropertyAndPreferencePage { super.performDefaults(); } - /* (non-Javadoc) + /* * @see org.eclipse.jface.preference.IPreferencePage#performOk() */ public boolean performOk() { @@ -135,7 +130,7 @@ public class CodeFormatterPreferencePage extends PropertyAndPreferencePage { return super.performOk(); } - /* (non-Javadoc) + /* * @see org.eclipse.jface.preference.IPreferencePage#performOk() */ public void performApply() { @@ -145,7 +140,7 @@ public class CodeFormatterPreferencePage extends PropertyAndPreferencePage { super.performApply(); } - /* (non-Javadoc) + /* * @see org.eclipse.cdt.internal.ui.preferences.PropertyAndPreferencePage#setElement(org.eclipse.core.runtime.IAdaptable) */ public void setElement(IAdaptable element) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/CodeFormatterConfigurationBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/CodeFormatterConfigurationBlock.java index 8e180e00f30..73611ba0cea 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/CodeFormatterConfigurationBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/CodeFormatterConfigurationBlock.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2008 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 @@ -98,10 +98,7 @@ public class CodeFormatterConfigurationBlock extends ProfileConfigurationBlock { */ public CodeFormatterConfigurationBlock(IProject project, PreferencesAccess access) { super(project, access, DIALOGSTORE_LASTSAVELOADPATH); - if (project == null) { - //TLETODO formatter customizable on project level? - fCustomCodeFormatterBlock= new CustomCodeFormatterBlock(access); - } + fCustomCodeFormatterBlock= new CustomCodeFormatterBlock(project, access); } protected IProfileVersioner createProfileVersioner() { @@ -116,12 +113,9 @@ public class CodeFormatterConfigurationBlock extends ProfileConfigurationBlock { return new FormatterProfileManager(profiles, context, access, profileVersioner); } - protected void configurePreview(Composite composite, int numColumns, ProfileManager profileManager) { - if (fCustomCodeFormatterBlock != null) { - fCustomCodeFormatterBlock.createContents(composite); - } - + fCustomCodeFormatterBlock.createContents(composite); + createLabel(composite, FormatterMessages.CodingStyleConfigurationBlock_preview_label_text, numColumns); TranslationUnitPreview result= new TranslationUnitPreview(profileManager.getSelected().getSettings(), composite); result.setFormatterId(fCustomCodeFormatterBlock.getFormatterId()); @@ -138,7 +132,6 @@ public class CodeFormatterConfigurationBlock extends ProfileConfigurationBlock { new PreviewController(profileManager); } - protected ModifyDialog createModifyDialog(Shell shell, Profile profile, ProfileManager profileManager, ProfileStore profileStore, boolean newProfile) { return new FormatterModifyDialog(shell, profile, profileManager, profileStore, newProfile, FORMATTER_DIALOG_PREFERENCE_KEY, DIALOGSTORE_LASTSAVELOADPATH); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/CustomCodeFormatterBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/CustomCodeFormatterBlock.java index 21224d9eba0..a55a5749250 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/CustomCodeFormatterBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/CustomCodeFormatterBlock.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 QNX Software Systems and others. + * Copyright (c) 2000, 2008 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 @@ -18,11 +18,13 @@ import java.util.Iterator; import java.util.Map; import java.util.Observable; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IScopeContext; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; @@ -47,7 +49,7 @@ import org.eclipse.cdt.internal.ui.preferences.PreferencesAccess; */ public class CustomCodeFormatterBlock extends Observable { - private HashMap idMap = new HashMap(); + private HashMapnull
if no corresponding
+ * C project exists.
+ *
+ * @param input the editor input
+ * @return the corresponding C project
+ *
+ * @since 5.0
+ */
+ public static ICProject getCProject(IEditorInput input) {
+ ICProject cProject= null;
+ if (input instanceof IFileEditorInput) {
+ IProject project= ((IFileEditorInput)input).getFile().getProject();
+ if (project != null) {
+ cProject= CoreModel.getDefault().create(project);
+ if (!cProject.exists())
+ cProject= null;
+ }
+ } else if (input instanceof ITranslationUnitEditorInput) {
+ cProject= ((ITranslationUnitEditorInput)input).getTranslationUnit().getCProject();
+ }
+ return cProject;
+ }
}