diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CodeStyleBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CodeStyleBlock.java new file mode 100644 index 00000000000..fcd29643ff2 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CodeStyleBlock.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2012 Google, Inc 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: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.preferences; + +import org.eclipse.core.resources.IProject; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; + +import org.eclipse.cdt.ui.PreferenceConstants; + +import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; + +/** + * Configures C Editor typing preferences. + */ +class CodeStyleBlock extends OptionsConfigurationBlock { + private static final Key CLASS_MEMBER_ASCENDING_VISIBILITY_ORDER = getCDTUIKey(PreferenceConstants.CLASS_MEMBER_ASCENDING_VISIBILITY_ORDER); + + private static Key[] getAllKeys() { + return new Key[] { + CLASS_MEMBER_ASCENDING_VISIBILITY_ORDER, + }; + } + + public CodeStyleBlock(IStatusChangeListener context, IProject project, + IWorkbenchPreferenceContainer container) { + super(context, project, getAllKeys(), container); + } + + @Override + public Control createContents(Composite parent) { + ScrolledPageContent scrolled= new ScrolledPageContent(parent, SWT.H_SCROLL | SWT.V_SCROLL); + scrolled.setExpandHorizontal(true); + scrolled.setExpandVertical(true); + + Composite control= new Composite(scrolled, SWT.NONE); + GridLayout layout= new GridLayout(); + control.setLayout(layout); + + Composite composite = addSubsection(control, PreferencesMessages.CodeStyleBlock_class_member_order); + fillClassMemberOrderSection(composite); + + scrolled.setContent(control); + final Point size= control.computeSize(SWT.DEFAULT, SWT.DEFAULT); + scrolled.setMinSize(size.x, size.y); + return scrolled; + } + + private void fillClassMemberOrderSection(Composite composite) { + GridLayout layout= new GridLayout(); + layout.numColumns= 3; + composite.setLayout(layout); + + addRadioButton(composite, PreferencesMessages.CodeStyleBlock_public_private, + CLASS_MEMBER_ASCENDING_VISIBILITY_ORDER, FALSE_TRUE, 0); + addRadioButton(composite, PreferencesMessages.CodeStyleBlock_private_public, + CLASS_MEMBER_ASCENDING_VISIBILITY_ORDER, TRUE_FALSE, 0); + } + + @Override + protected void validateSettings(Key changedKey, String oldValue, String newValue) { + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CodeStylePreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CodeStylePreferencePage.java new file mode 100644 index 00000000000..27a47f5947f --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CodeStylePreferencePage.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2012 Google, Inc 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: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.preferences; + +import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; + +import org.eclipse.cdt.ui.CUIPlugin; + +import org.eclipse.cdt.internal.ui.ICHelpContextIds; + +/** + * The page for setting various code style preferences. + */ +public class CodeStylePreferencePage extends ConfigurationBlockPropertyAndPreferencePage { + public static final String PREF_ID= "org.eclipse.cdt.ui.preferences.CodeStylePreferencePage"; //$NON-NLS-1$ + public static final String PROP_ID= "org.eclipse.cdt.ui.propertyPages.CodeStylePreferencePage"; //$NON-NLS-1$ + + public CodeStylePreferencePage() { + setPreferenceStore(CUIPlugin.getDefault().getPreferenceStore()); + // Only used when the page is shown programmatically. + setTitle(PreferencesMessages.CodeStylePreferencePage_title); + } + + @Override + protected String getHelpId() { + return ICHelpContextIds.CODE_STYLE_PREFERENCE_PAGE; + } + + @Override + protected OptionsConfigurationBlock createConfigurationBlock(IWorkbenchPreferenceContainer container) { + return new CodeStyleBlock(getNewStatusChangedListener(), getProject(), container); + } + + @Override + protected String getPreferencePageID() { + return PREF_ID; + } + + @Override + protected String getPropertyPageID() { + return null; + // TODO(sprigogin): Project specific settings +// return PROP_ID; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/ConfigurationBlockPropertyAndPreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/ConfigurationBlockPropertyAndPreferencePage.java new file mode 100644 index 00000000000..d203c83075a --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/ConfigurationBlockPropertyAndPreferencePage.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2012 Google, Inc 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: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.preferences; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; + +import org.eclipse.cdt.internal.ui.dialogs.StatusUtil; + +public abstract class ConfigurationBlockPropertyAndPreferencePage extends PropertyAndPreferencePage { + private OptionsConfigurationBlock fConfigurationBlock; + + public ConfigurationBlockPropertyAndPreferencePage() { + super(); + } + + protected abstract OptionsConfigurationBlock createConfigurationBlock(IWorkbenchPreferenceContainer container); + + protected abstract String getHelpId(); + + @Override + public void createControl(Composite parent) { + IWorkbenchPreferenceContainer container= (IWorkbenchPreferenceContainer) getContainer(); + fConfigurationBlock= createConfigurationBlock(container); + super.createControl(parent); + PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), getHelpId()); + } + + @Override + protected Control createPreferenceContent(Composite composite) { + return fConfigurationBlock.createContents(composite); + } + + @Override + protected void enableProjectSpecificSettings(boolean useProjectSpecificSettings) { + super.enableProjectSpecificSettings(useProjectSpecificSettings); + if (fConfigurationBlock != null) { + fConfigurationBlock.useProjectSpecificSettings(useProjectSpecificSettings); + } + } + + @Override + public boolean performOk() { + if (fConfigurationBlock != null) { + return fConfigurationBlock.performOk(); + } + return true; + } + + @Override + protected void performDefaults() { + super.performDefaults(); + if (fConfigurationBlock != null) { + fConfigurationBlock.performDefaults(); + } + } + + @Override + public void dispose() { + if (fConfigurationBlock != null) { + fConfigurationBlock.dispose(); + } + super.dispose(); + } + + public void statusChanged(IStatus status) { + setValid(!status.matches(IStatus.ERROR)); + StatusUtil.applyToStatusLine(this, status); + } + + @Override + public void performApply() { + if (fConfigurationBlock != null) { + fConfigurationBlock.performApply(); + } + } + + @Override + protected boolean hasProjectSpecificOptions(IProject project) { + return fConfigurationBlock.hasProjectSpecificOptions(project); + } +}