1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 45203. Beginning of preference UI.

This commit is contained in:
Sergey Prigogin 2013-01-24 20:33:56 -08:00
parent 72201542c7
commit 64a3b12f94
14 changed files with 1068 additions and 8 deletions

View file

@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2003, 2012 IBM Corporation, QNX Software Systems, and others.
# Copyright (c) 2003, 2013 IBM Corporation, 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
@ -196,6 +196,7 @@ CPluginFileTypesPreferencePage.name=File Types
CodeStylePreferencePage.name=Code Style
codeTemplatePreferencePage.name=Code Templates
codeFormatterPreferencePage.name=Formatter
includeStylePreferencePage.name=Includes
nameStylePreferencePage.name=Name Style
CodeAssistPreferencePage.name=Content Assist
CodeAssistAdvancedPreferencePage.name=Advanced
@ -566,7 +567,8 @@ preferenceKeywords.common=c cpp cplusplus cdt
preferenceKeywords.codeformatter=profile codestyle project specific comment indentation brace white space blank line new control statement wrapping tab parenthesis bracket
preferenceKeywords.codestyle=class member visibility order ordering
preferenceKeywords.codetemplates=comment code constructor method file type content
preferenceKeywords.namestyle=name file getter setter field variable
preferenceKeywords.includestyle=include includes style header file system
preferenceKeywords.namestyle=name style file getter setter field variable
preferenceKeywords.todo=case sensitive task tag todo xxx fix fixme project comments
preferenceKeywords.indexer=index skip references type macro search build configuration cache memory performance

View file

@ -1223,6 +1223,14 @@
<keywordReference id="org.eclipse.cdt.ui.codestyle"/>
<keywordReference id="org.eclipse.cdt.ui.common"/>
</page>
<page
name="%includeStylePreferencePage.name"
category="org.eclipse.cdt.ui.preferences.CodeStylePreferencePage"
class="org.eclipse.cdt.internal.ui.preferences.IncludeStylePreferencePage"
id="org.eclipse.cdt.ui.preferences.IncludeStylePreferencePage">
<keywordReference id="org.eclipse.cdt.ui.includestyle"/>
<keywordReference id="org.eclipse.cdt.ui.common"/>
</page>
<page
name="%nameStylePreferencePage.name"
category="org.eclipse.cdt.ui.preferences.CodeStylePreferencePage"
@ -1281,6 +1289,9 @@
<keyword
label="%preferenceKeywords.codetemplates"
id="org.eclipse.cdt.ui.codetemplates"/>
<keyword
label="%preferenceKeywords.includestyle"
id="org.eclipse.cdt.ui.includestyle"/>
<keyword
label="%preferenceKeywords.namestyle"
id="org.eclipse.cdt.ui.namestyle"/>

View file

@ -87,6 +87,7 @@ public interface ICHelpContextIds {
public static final String SPELLING_CONFIGURATION_BLOCK= PREFIX + "spelling_configuration_block_context"; //$NON-NLS-1$
public static final String CODE_STYLE_PREFERENCE_PAGE = PREFIX + "code_style_preference_context"; //$NON-NLS-1$
public static final String CODE_TEMPLATES_PREFERENCE_PAGE = PREFIX + "code_templates_preference_context"; //$NON-NLS-1$
public static final String INCLUDE_STYLE_PREFERENCE_PAGE = PREFIX + "include_style_preference_context"; //$NON-NLS-1$
public static final String NAME_STYLE_PREFERENCE_PAGE = PREFIX + "name_style_preference_context"; //$NON-NLS-1$
// Console view

View file

@ -0,0 +1,370 @@
/*******************************************************************************
* Copyright (c) 2013 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 java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.layout.PixelConverter;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener;
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.cdt.internal.ui.refactoring.includes.IncludeGroupStyle;
import org.eclipse.cdt.internal.ui.refactoring.includes.IncludeGroupStyle.IncludeKind;
import org.eclipse.cdt.internal.ui.refactoring.includes.IncludePreferences;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.TreeListDialogField;
/**
* The preference block for configuring styles of different categories of include statements.
*/
public class IncludeCategoriesBlock extends OptionsConfigurationBlock {
private static final Key KEY_STYLE_GROUP_RELATED = getCDTUIKey(IncludePreferences.INCLUDE_STYLE_GROUP_RELATED);
private static final Key KEY_STYLE_PARTNER = getCDTUIKey(IncludePreferences.INCLUDE_STYLE_PARTNER);
private static final Key KEY_STYLE_GROUP_PARTNER = getCDTUIKey(IncludePreferences.INCLUDE_STYLE_GROUP_PARTNER);
private static final Key KEY_STYLE_SAME_FOLDER = getCDTUIKey(IncludePreferences.INCLUDE_STYLE_SAME_FOLDER);
private static final Key KEY_STYLE_GROUP_SAME_FOLDER = getCDTUIKey(IncludePreferences.INCLUDE_STYLE_GROUP_SAME_FOLDER);
private static final Key KEY_STYLE_SUBFOLDER = getCDTUIKey(IncludePreferences.INCLUDE_STYLE_SUBFOLDER);
private static final Key KEY_STYLE_GROUP_SUBFOLDER = getCDTUIKey(IncludePreferences.INCLUDE_STYLE_GROUP_SUBFOLDER);
private static final Key KEY_STYLE_GROUP_SYSTEM = getCDTUIKey(IncludePreferences.INCLUDE_STYLE_GROUP_SYSTEM);
private static Key[] getAllKeys() {
return new Key[] {
KEY_STYLE_GROUP_RELATED,
KEY_STYLE_PARTNER,
KEY_STYLE_GROUP_PARTNER,
KEY_STYLE_SAME_FOLDER,
KEY_STYLE_GROUP_SAME_FOLDER,
KEY_STYLE_SUBFOLDER,
KEY_STYLE_GROUP_SUBFOLDER,
KEY_STYLE_GROUP_SYSTEM,
};
}
private final Category[] rootCategories;
private TreeListDialogField<Category> categoryTree;
private PixelConverter pixelConverter;
private StackLayout editorAreaStack;
private Category selectedCategory;
public IncludeCategoriesBlock(IStatusChangeListener context, IProject project,
IWorkbenchPreferenceContainer container) {
super(context, project, getAllKeys(), container);
rootCategories = createCategories();
}
private static Category[] createCategories() {
Category related = new Category(PreferencesMessages.IncludeCategoriesBlock_related_headers_node,
PreferencesMessages.IncludeCategoriesBlock_related_headers_node_description)
.setGroupingKey(KEY_STYLE_GROUP_RELATED);
new Category(PreferencesMessages.IncludeCategoriesBlock_partner_header_node,
PreferencesMessages.IncludeCategoriesBlock_partner_header_node_description, related)
.setIncludeKind(IncludeKind.PARTNER)
.setGroupingKey(KEY_STYLE_GROUP_PARTNER)
.setStyleKey(KEY_STYLE_PARTNER);
new Category(PreferencesMessages.IncludeCategoriesBlock_same_folder_header_node,
PreferencesMessages.IncludeCategoriesBlock_same_folder_header_node_description, related)
.setIncludeKind(IncludeKind.IN_SAME_FOLDER)
.setGroupingKey(KEY_STYLE_GROUP_SAME_FOLDER)
.setStyleKey(KEY_STYLE_SAME_FOLDER);
new Category(PreferencesMessages.IncludeCategoriesBlock_subfolder_header_node,
PreferencesMessages.IncludeCategoriesBlock_subfolder_header_node_description, related)
.setIncludeKind(IncludeKind.IN_SUBFOLDERS)
.setGroupingKey(KEY_STYLE_GROUP_SUBFOLDER)
.setStyleKey(KEY_STYLE_SUBFOLDER);
Category system = new Category(PreferencesMessages.IncludeCategoriesBlock_system_headers_node,
PreferencesMessages.IncludeCategoriesBlock_system_headers_node_description)
.setGroupingKey(KEY_STYLE_GROUP_SYSTEM);
return new Category[] { related, system };
}
public void postSetSelection(Object element) {
categoryTree.postSetSelection(new StructuredSelection(element));
}
@Override
protected Control createContents(Composite parent) {
pixelConverter = new PixelConverter(parent);
setShell(parent.getShell());
Composite composite = new Composite(parent, SWT.NONE);
composite.setFont(parent.getFont());
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
IncludeStyleAdapter adapter = new IncludeStyleAdapter();
categoryTree = new TreeListDialogField<Category>(adapter, null, new IncludeStyleLabelProvider());
categoryTree.setDialogFieldListener(adapter);
categoryTree.setLabelText(PreferencesMessages.NameStyleBlock_categories_label);
categoryTree.setViewerComparator(adapter);
createCategories();
for (Category category : rootCategories) {
categoryTree.addElement(category);
}
Label label = categoryTree.getLabelControl(composite);
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.verticalAlignment = GridData.BEGINNING;
label.setLayoutData(gd);
Control tree = categoryTree.getTreeControl(composite);
gd = new GridData();
gd.horizontalAlignment = GridData.FILL;
gd.grabExcessHorizontalSpace = true;
gd.verticalAlignment = GridData.FILL;
gd.grabExcessVerticalSpace = false;
gd.widthHint = pixelConverter.convertWidthInCharsToPixels(50);
gd.heightHint = pixelConverter.convertHeightInCharsToPixels(12);
tree.setLayoutData(gd);
createCategoryEditorArea(composite);
categoryTree.setTreeExpansionLevel(2);
categoryTree.selectFirstElement();
updateControls();
return composite;
}
private void createCategoryEditorArea(Composite parent) {
Composite editorArea = new Composite(parent, SWT.NONE);
editorArea.setLayoutData(new GridData(GridData.FILL_BOTH));
editorArea.setFont(parent.getFont());
editorAreaStack = new StackLayout();
editorArea.setLayout(editorAreaStack);
for (Category category : rootCategories) {
createCategoryEditor(editorArea, category);
}
}
private void createCategoryEditor(Composite parent, Category category) {
IncludeGroupStyle style = null;
Key styleKey = category.getStyleKey();
if (styleKey != null) {
IncludeKind includeKind = category.getIncludeKind();
String str = getValue(styleKey);
if (str != null)
style = IncludeGroupStyle.fromString(str, includeKind);
if (style == null)
style = new IncludeGroupStyle(includeKind);
}
IncludeGroupStyleBlock block = new IncludeGroupStyleBlock(fContext, fProject, fContainer,
category.getDescription(), category.getGroupingKey(), style);
Control composite = block.createContents(parent);
category.setEditorArea(composite);
for (Category child : category.getChildren()) {
createCategoryEditor(parent, child);
}
}
@Override
protected void updateControls() {
super.updateControls();
// XXX Implement
}
private void updateConfigurationBlock(List<Object> selection) {
if (selection.size() == 0)
return;
selectedCategory = (Category) selection.get(0);
editorAreaStack.topControl = selectedCategory.getEditorArea();
editorAreaStack.topControl.getParent().layout();
}
@Override
public void performDefaults() {
super.performDefaults();
// Refresh
categoryTree.refresh();
updateConfigurationBlock(categoryTree.getSelectedElements());
}
@Override
public boolean performOk() {
return super.performOk();
}
@Override
protected void validateSettings(Key changedKey, String oldValue, String newValue) {
StatusInfo status = new StatusInfo();
fContext.statusChanged(status);
}
/**
* Represents a category of settings.
*/
private final static class Category {
public final String name;
public final String description;
public final Category parent;
public final int index; // Index in the siblings list
private final List<Category> children;
private IncludeKind includeKind;
private Key styleKey;
private Key groupingKey;
private Control editorArea;
Category(String name, String description, Category parent) {
this.name = name;
this.description = description;
this.parent = parent;
children = new ArrayList<Category>();
index = parent != null ? parent.addChild(this) : 0;
}
/**
* @param name Category name
*/
Category(String name, String description) {
this(name, description, null);
}
private int addChild(Category category) {
children.add(category);
return children.size() - 1;
}
Category[] getChildren() {
return children.toArray(new Category[children.size()]);
}
boolean hasChildren() {
return !children.isEmpty();
}
@Override
public String toString() {
return name;
}
IncludeKind getIncludeKind() {
return includeKind;
}
Category setIncludeKind(IncludeKind includeKind) {
this.includeKind = includeKind;
return this;
}
Key getStyleKey() {
return styleKey;
}
Category setStyleKey(Key key) {
this.styleKey = key;
return this;
}
Key getGroupingKey() {
return groupingKey;
}
Category setGroupingKey(Key key) {
this.groupingKey = key;
return this;
}
Control getEditorArea() {
return editorArea;
}
Category setEditorArea(Control editorArea) {
this.editorArea = editorArea;
return this;
}
public String getDescription() {
return description;
}
}
private class IncludeStyleAdapter extends ViewerComparator
implements ITreeListAdapter<Category>, IDialogFieldListener {
@Override
public void selectionChanged(TreeListDialogField<Category> field) {
updateConfigurationBlock(field.getSelectedElements());
}
@Override
public void customButtonPressed(TreeListDialogField<Category> field, int index) {
}
@Override
public void doubleClicked(TreeListDialogField<Category> field) {
}
@Override
public Category[] getChildren(TreeListDialogField<Category> field, Object element) {
return ((Category) element).getChildren();
}
@Override
public Category getParent(TreeListDialogField<Category> field, Object element) {
return ((Category) element).parent;
}
@Override
public boolean hasChildren(TreeListDialogField<Category> field, Object element) {
return ((Category) element).hasChildren();
}
@Override
public void dialogFieldChanged(DialogField field) {
}
@Override
public void keyPressed(TreeListDialogField<Category> field, KeyEvent event) {
}
@Override
public int category(Object element) {
return ((Category) element).index;
}
}
private static class IncludeStyleLabelProvider extends LabelProvider {
@Override
public Image getImage(Object element) {
return null;
}
@Override
public String getText(Object element) {
return ((Category) element).name;
}
}
}

View file

@ -0,0 +1,166 @@
/*******************************************************************************
* Copyright (c) 2013 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 java.util.ArrayList;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.layout.PixelConverter;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener;
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.cdt.internal.ui.refactoring.includes.IncludeGroupStyle;
/**
* The preference block for configuring styles of different categories of include statements.
*/
public class IncludeGroupStyleBlock extends OptionsConfigurationBlock {
private final String description;
private final Key groupingKey;
private final IncludeGroupStyle style;
@SuppressWarnings("hiding")
private final ArrayList<Button> fCheckBoxes = new ArrayList<Button>();
@SuppressWarnings("hiding")
private final ArrayList<Text> fTextBoxes = new ArrayList<Text>();
private PixelConverter pixelConverter;
public IncludeGroupStyleBlock(IStatusChangeListener context, IProject project,
IWorkbenchPreferenceContainer container, String description, Key groupingKey,
IncludeGroupStyle style) {
super(context, project, new Key[] { groupingKey }, container);
this.description = description;
this.groupingKey = groupingKey;
this.style = style;
}
@Override
protected Control createContents(Composite parent) {
pixelConverter = new PixelConverter(parent);
setShell(parent.getShell());
Composite composite = new Composite(parent, SWT.NONE);
composite.setFont(parent.getFont());
GridLayout layout = new GridLayout();
layout.marginHeight = pixelConverter.convertHeightInCharsToPixels(1);
layout.marginWidth = 0;
composite.setLayout(layout);
composite.setFont(parent.getFont());
Group group = ControlFactory.createGroup(composite, description, 1);
group.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite envelope = new Composite(group, SWT.NONE);
layout = new GridLayout(4, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
envelope.setLayout(layout);
addCheckBox(envelope, PreferencesMessages.IncludeGroupStyleBlock_keep_includes_together,
groupingKey, TRUE_FALSE, 0);
if (style != null) {
addCheckBox(envelope, PreferencesMessages.IncludeGroupStyleBlock_use_relative_path,
new BooleanDataSource() {
@Override
public boolean get() {
return style.isRelativePath();
}
@Override
public void set(boolean value) {
style.setRelativePath(value);
}
});
addCheckBox(envelope, PreferencesMessages.IncludeGroupStyleBlock_use_angle_brackets,
new BooleanDataSource() {
@Override
public boolean get() {
return style.isAngleBrackets();
}
@Override
public void set(boolean value) {
style.setAngleBrackets(value);
}
});
}
updateControls();
return composite;
}
private Button addCheckBox(Composite parent, String label, BooleanDataSource dataSource) {
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan= 3;
Button checkBox= new Button(parent, SWT.CHECK);
checkBox.setFont(JFaceResources.getDialogFont());
checkBox.setText(label);
checkBox.setData(dataSource);
checkBox.setLayoutData(gd);
checkBox.addSelectionListener(getSelectionListener());
makeScrollableCompositeAware(checkBox);
checkBox.setSelection(dataSource.get());
fCheckBoxes.add(checkBox);
return checkBox;
}
@Override
protected void updateControls() {
super.updateControls();
// XXX Implement
}
@Override
public void performDefaults() {
super.performDefaults();
// XXX Implement
}
@Override
public boolean performOk() {
return super.performOk();
// XXX Implement
}
@Override
protected void validateSettings(Key changedKey, String oldValue, String newValue) {
StatusInfo status = new StatusInfo();
fContext.statusChanged(status);
}
private interface BooleanDataSource {
boolean get();
void set(boolean value);
}
private interface StringDataSource {
String get();
void set(String value);
}
}

View file

@ -0,0 +1,71 @@
/*******************************************************************************
* Copyright (c) 2013 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.jface.layout.PixelConverter;
import org.eclipse.swt.SWT;
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.internal.ui.dialogs.IStatusChangeListener;
/**
* The preference block for configuring relative order of include statements.
*/
public class IncludeOrderBlock extends OptionsConfigurationBlock {
private static Key[] getAllKeys() {
return new Key[] {
};
}
private PixelConverter pixelConverter;
public IncludeOrderBlock(IStatusChangeListener context, IProject project,
IWorkbenchPreferenceContainer container) {
super(context, project, getAllKeys(), container);
}
public void postSetSelection(Object element) {
}
@Override
protected Control createContents(Composite parent) {
pixelConverter = new PixelConverter(parent);
setShell(parent.getShell());
Composite composite = new Composite(parent, SWT.NONE);
composite.setFont(parent.getFont());
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
updateControls();
return composite;
}
@Override
public void performDefaults() {
super.performDefaults();
// TODO Implement
}
@Override
protected void validateSettings(Key changedKey, String oldValue, String newValue) {
// TODO Implement
}
}

View file

@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2013 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.ui.preferences.IWorkbenchPreferenceContainer;
import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener;
/**
* The preference block for configuring style of include statements.
*/
public class IncludeStyleBlock extends TabConfigurationBlock {
public IncludeStyleBlock(IStatusChangeListener context, IProject project,
IWorkbenchPreferenceContainer container) {
super(context, project, getTabs(context, project, container), getTabLabels(), container);
}
private static OptionsConfigurationBlock[] getTabs(IStatusChangeListener context,
IProject project, IWorkbenchPreferenceContainer container) {
return new OptionsConfigurationBlock[] {
new IncludeCategoriesBlock(context, project, container),
new IncludeOrderBlock(context, project, container),
};
}
private static String[] getTabLabels() {
return new String[] {
PreferencesMessages.IncludeStyleBlock_categories_tab,
PreferencesMessages.IncludeStyleBlock_order_tab,
};
}
}

View file

@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright (c) 2013 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 preference page for configuring styles of include statements.
*/
public class IncludeStylePreferencePage extends ConfigurationBlockPropertyAndPreferencePage {
public static final String PREF_ID= "org.eclipse.cdt.ui.preferences.IncludeStylePreferencePage"; //$NON-NLS-1$
public static final String PROP_ID= "org.eclipse.cdt.ui.propertyPages.IncludeStylePreferencePage"; //$NON-NLS-1$
public IncludeStylePreferencePage() {
setPreferenceStore(CUIPlugin.getDefault().getPreferenceStore());
// Only used when the page is shown programmatically.
setTitle(PreferencesMessages.IncludeStylePreferencePage_title);
}
@Override
protected OptionsConfigurationBlock createConfigurationBlock(IWorkbenchPreferenceContainer container) {
return new IncludeStyleBlock(getNewStatusChangedListener(), getProject(), container);
}
@Override
protected String getHelpId() {
return ICHelpContextIds.INCLUDE_STYLE_PREFERENCE_PAGE;
}
@Override
protected String getPreferencePageId() {
return PREF_ID;
}
@Override
protected String getPropertyPageId() {
return null;
// TODO(sprigogin): Project specific settings
// return PROP_ID;
}
}

View file

@ -176,7 +176,7 @@ public abstract class OptionsConfigurationBlock {
private Shell fShell;
private final IWorkingCopyManager fManager;
private final IWorkbenchPreferenceContainer fContainer;
protected final IWorkbenchPreferenceContainer fContainer;
private Map<Key, String> fDisabledProjectSettings; // null when project specific settings are turned off
@ -536,7 +536,7 @@ public abstract class OptionsConfigurationBlock {
return null;
}
private void makeScrollableCompositeAware(Control control) {
protected void makeScrollableCompositeAware(Control control) {
ScrolledPageContent parentScrolledComposite= getParentScrolledComposite(control);
if (parentScrolledComposite != null) {
parentScrolledComposite.adaptChild(control);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2011 IBM Corporation and others.
* Copyright (c) 2000, 2013 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
@ -364,6 +364,37 @@ public final class PreferencesMessages extends NLS {
public static String CodeTemplateBlock_export_error_hidden;
public static String CodeTemplateBlock_export_error_canNotWrite;
public static String IncludeStylePreferencePage_title;
public static String IncludeStyleBlock_categories_tab;
public static String IncludeStyleBlock_order_tab;
public static String IncludeCategoriesBlock_external_headers_node;
public static String IncludeCategoriesBlock_external_headers_node_description;
public static String IncludeCategoriesBlock_other_headers_node;
public static String IncludeCategoriesBlock_other_headers_node_description;
public static String IncludeCategoriesBlock_other_project_headers_node;
public static String IncludeCategoriesBlock_other_project_headers_node_description;
public static String IncludeCategoriesBlock_partner_header_node;
public static String IncludeCategoriesBlock_partner_header_node_description;
public static String IncludeCategoriesBlock_same_project_headers_node;
public static String IncludeCategoriesBlock_same_project_headers_node_description;
public static String IncludeCategoriesBlock_related_headers_node;
public static String IncludeCategoriesBlock_related_headers_node_description;
public static String IncludeCategoriesBlock_same_folder_header_node;
public static String IncludeCategoriesBlock_same_folder_header_node_description;
public static String IncludeCategoriesBlock_subfolder_header_node;
public static String IncludeCategoriesBlock_subfolder_header_node_description;
public static String IncludeCategoriesBlock_system_headers_node;
public static String IncludeCategoriesBlock_system_headers_node_description;
public static String IncludeCategoriesBlock_system_headers_with_extension_node;
public static String IncludeCategoriesBlock_system_headers_with_extension_node_description;
public static String IncludeCategoriesBlock_system_headers_without_extension_node;
public static String IncludeCategoriesBlock_system_headers_without_extension_node_description;
public static String IncludeCategoriesBlock_user_defined_categories_node;
public static String IncludeCategoriesBlock_user_defined_categories_node_description;
public static String IncludeGroupStyleBlock_keep_includes_together;
public static String IncludeGroupStyleBlock_use_relative_path;
public static String IncludeGroupStyleBlock_use_angle_brackets;
public static String NameStylePreferencePage_title;
public static String NameStyleBlock_code_node;
public static String NameStyleBlock_files_node;

View file

@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2000, 2011 IBM Corporation and others.
# Copyright (c) 2000, 2013 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
@ -38,7 +38,7 @@ CEditorPreferencePage_ContentAssistPage_autoActivationDelay=Dela&y (ms)
CEditorPreferencePage_ContentAssistPage_proposalFilterSelect=Completion Proposal Filter:
CEditorPreferencePage_ContentAssistPage_completionProposalBackgroundColor=Completion proposal background
CEditorPreferencePage_ContentAssistPage_completionProposalForegroundColor=Completion proposal foreground
CEditorPreferencePage_ContentAssistPage_completionProposalTimeoutErrMsg=Time must be >= 0 milli seconds
CEditorPreferencePage_ContentAssistPage_completionProposalTimeoutErrMsg=Timeout must be a positive number
CEditorPreferencePage_ContentAssistPage_completionProposalTimeout=Timeout for each proposal kind (ms):
CEditorPreferencePage_ContentAssistPage_completionProposalTimeoutToolTip=If a proposal kind has consumed more time for computation than defined here\nit is assumed that the computer is faulty.\nIn this case a dialog is showing up telling an appropriate message to the user.
CEditorPreferencePage_ContentAssistPage_parameterBackgroundColor=Parameter hint background
@ -419,6 +419,38 @@ CodeTemplateBlock_export_error_title= Export Templates
CodeTemplateBlock_export_error_hidden= Export failed.\n{0} is a hidden file.
CodeTemplateBlock_export_error_canNotWrite= Export failed.\n{0} cannot be modified.
IncludeStylePreferencePage_title= Includes
IncludeStyleBlock_categories_tab= Categories
IncludeStyleBlock_order_tab= Order
IncludeCategoriesBlock_external_headers_node= External Headers
IncludeCategoriesBlock_external_headers_node_description= Header files outside workspace
IncludeCategoriesBlock_other_headers_node= Other Headers
IncludeCategoriesBlock_other_headers_node_description= Header files in the workspace and outside it
IncludeCategoriesBlock_other_project_headers_node= Headers in Other Projects
IncludeCategoriesBlock_other_project_headers_node_description= Header files in projects this project depends upon
IncludeCategoriesBlock_partner_header_node= Partner Header
IncludeCategoriesBlock_partner_header_node_description= Header file with the same name
IncludeCategoriesBlock_same_project_headers_node= Headers in Same Project
IncludeCategoriesBlock_same_project_headers_node_description= Header files in the same project
IncludeCategoriesBlock_related_headers_node= Related Headers
IncludeCategoriesBlock_related_headers_node_description= Related header files
IncludeCategoriesBlock_same_folder_header_node= Headers in Same Folder
IncludeCategoriesBlock_same_folder_header_node_description= Header files in the same folder
IncludeCategoriesBlock_subfolder_header_node= Headers in Subfolders
IncludeCategoriesBlock_subfolder_header_node_description= Header files in subfolders
IncludeCategoriesBlock_system_headers_node= System Headers
IncludeCategoriesBlock_system_headers_node_description= System header files
IncludeCategoriesBlock_system_headers_with_extension_node= System Headers with Extension
IncludeCategoriesBlock_system_headers_with_extension_node_description= System header files with extension, e.g. stdio.h
IncludeCategoriesBlock_system_headers_without_extension_node= System Headers without Extension
IncludeCategoriesBlock_system_headers_without_extension_node_description= System headers without extension, e.g. vector
IncludeCategoriesBlock_user_defined_categories_node= User-defined Categories
IncludeCategoriesBlock_user_defined_categories_node_description= Categories of header files defined by the user
IncludeGroupStyleBlock_keep_includes_together= &Keep include statements together
IncludeGroupStyleBlock_use_relative_path= Use path &relative to including file
IncludeGroupStyleBlock_use_angle_brackets= Use &angle brackets
NameStylePreferencePage_title=Name Style
NameStyleBlock_code_node=Code
NameStyleBlock_files_node=Files

View file

@ -0,0 +1,106 @@
/*******************************************************************************
* Copyright (c) 2013 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 java.util.ArrayList;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.layout.PixelConverter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.utils.ui.controls.TabFolderLayout;
import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener;
/**
* The preference block for configuring styles of names.
*/
public class TabConfigurationBlock extends OptionsConfigurationBlock {
private final OptionsConfigurationBlock[] fTabs;
private final String[] fTabLabels;
private IStatus fStatus = Status.OK_STATUS;
public TabConfigurationBlock(IStatusChangeListener context, IProject project,
OptionsConfigurationBlock[] tabs, String[] tabLabels,
IWorkbenchPreferenceContainer container) {
super(context, project, getAllKeys(tabs), container);
if (tabLabels.length != tabs.length) {
throw new IllegalArgumentException("Number of labels doesn't match the number of tabs"); //$NON-NLS-1$
}
fTabs = tabs;
fTabLabels = tabLabels;
IStatusChangeListener statusMerger = new IStatusChangeListener() {
@Override
public void statusChanged(IStatus status) {
if (status.getSeverity() > fStatus.getSeverity())
fStatus = status;
}
};
for (OptionsConfigurationBlock tab : tabs) {
tab.fContext = statusMerger;
}
}
private static Key[] getAllKeys(OptionsConfigurationBlock[] tabs) {
ArrayList<Key> keys = new ArrayList<Key>();
for (OptionsConfigurationBlock tab : tabs) {
ArrayUtil.addAll(keys, tab.fAllKeys);
}
return keys.toArray(new Key[keys.size()]);
}
@Override
protected Control createContents(Composite parent) {
PixelConverter pixelConverter = new PixelConverter(parent);
final TabFolder folder = new TabFolder(parent, SWT.NONE);
folder.setLayout(new TabFolderLayout());
folder.setLayoutData(new GridData(GridData.FILL_BOTH));
for (int i = 0; i < fTabs.length; i++) {
TabItem item = new TabItem(folder, SWT.NONE);
item.setText(fTabLabels[i]);
Composite composite = new Composite(folder, SWT.NONE);
FillLayout layout = new FillLayout();
layout.marginHeight = pixelConverter.convertHorizontalDLUsToPixels(4);
layout.marginWidth = pixelConverter.convertVerticalDLUsToPixels(4);
composite.setLayout(layout);
item.setControl(composite);
item.setData(fTabs[i]);
fTabs[i].createContents(composite);
}
Dialog.applyDialogFont(folder);
return folder;
}
@Override
protected void validateSettings(Key changedKey, String oldValue, String newValue) {
fStatus = Status.OK_STATUS;
for (OptionsConfigurationBlock tab : fTabs) {
tab.validateSettings(changedKey, oldValue, newValue);
if (fStatus.getSeverity() >= IStatus.ERROR)
break;
}
fContext.statusChanged(fStatus);
}
}

View file

@ -0,0 +1,165 @@
/*******************************************************************************
* Copyright (c) 2013 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.refactoring.includes;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.regex.Pattern;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.WorkbenchException;
import org.eclipse.ui.XMLMemento;
import org.eclipse.cdt.ui.CUIPlugin;
/**
* Style preferences for a category of include statements.
*/
public class IncludeGroupStyle {
public enum IncludeKind {
PARTNER,
IN_SAME_FOLDER,
IN_SUBFOLDERS,
SYSTEM_WITH_EXTENSION,
SYSTEM_WITHOUT_EXTENSION,
IN_WORKSPACE,
EXTERNAL,
MATCHING_PATTERN,
}
private static final String TAG_STYLE = "style"; //$NON-NLS-1$
private static final String TAG_NAME = "name"; //$NON-NLS-1$
private static final String TAG_PATTERN = "pattern"; //$NON-NLS-1$
private static final String TAG_DISABLED = "disabled"; //$NON-NLS-1$
private static final String TAG_RELATIVE_PATH = "relative_path"; //$NON-NLS-1$
private static final String TAG_ANGLE_BRACKETS = "angle_brackets"; //$NON-NLS-1$
private final IncludeKind includeKind;
private boolean disabled;
private boolean relativePath;
private boolean angleBrackets;
private Pattern headerNamePattern;
private String name;
public IncludeGroupStyle(IncludeKind includeKind) {
if (includeKind == null || includeKind == IncludeKind.MATCHING_PATTERN)
throw new IllegalArgumentException();
this.includeKind = includeKind;
}
public IncludeGroupStyle(String name, Pattern headerNamePattern) {
if (name == null)
throw new IllegalArgumentException();
if (headerNamePattern == null)
throw new IllegalArgumentException();
this.includeKind = IncludeKind.MATCHING_PATTERN;
this.name = name;
this.headerNamePattern = headerNamePattern;
}
public boolean isDisabled() {
return disabled;
}
public void setDisabled(boolean disabled) {
this.disabled = disabled;
}
public boolean isRelativePath() {
return relativePath;
}
public void setRelativePath(boolean relativePath) {
this.relativePath = relativePath;
}
public boolean isAngleBrackets() {
return angleBrackets;
}
public void setAngleBrackets(boolean angleBrackets) {
this.angleBrackets = angleBrackets;
}
public Pattern getHeaderNamePattern() {
return headerNamePattern;
}
public void setHeaderNamePattern(Pattern headerNamePattern) {
this.headerNamePattern = headerNamePattern;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public IncludeKind getIncludeKind() {
return includeKind;
}
public static IncludeGroupStyle fromMemento(IMemento memento, IncludeKind includeKind) {
IncludeGroupStyle style;
if (includeKind == IncludeKind.MATCHING_PATTERN) {
String name = nullToEmpty(memento.getString(TAG_NAME));
String pattern = nullToEmpty(memento.getString(TAG_PATTERN));
style = new IncludeGroupStyle(name, Pattern.compile(pattern));
} else {
style = new IncludeGroupStyle(includeKind);
}
style.setDisabled(memento.getBoolean(TAG_DISABLED));
style.setRelativePath(memento.getBoolean(TAG_RELATIVE_PATH));
style.setAngleBrackets(memento.getBoolean(TAG_ANGLE_BRACKETS));
return style;
}
private static String nullToEmpty(String string) {
return string != null ? string : ""; //$NON-NLS-1$
}
public void saveToMemento(IMemento memento) {
if (includeKind == IncludeKind.MATCHING_PATTERN) {
memento.putString(TAG_NAME, name);
memento.putString(TAG_PATTERN, headerNamePattern.toString());
}
memento.putBoolean(TAG_DISABLED, disabled);
memento.putBoolean(TAG_RELATIVE_PATH, relativePath);
memento.putBoolean(TAG_ANGLE_BRACKETS, angleBrackets);
}
@Override
public String toString() {
XMLMemento memento = XMLMemento.createWriteRoot(TAG_STYLE);
saveToMemento(memento);
StringWriter writer = new StringWriter();
try {
memento.save(writer);
} catch (IOException e) {
CUIPlugin.log(e);
}
return writer.toString();
}
public static IncludeGroupStyle fromString(String str, IncludeKind includeKind) {
StringReader reader = new StringReader(str);
XMLMemento memento;
try {
memento = XMLMemento.createReadRoot(reader);
} catch (WorkbenchException e) {
return null;
}
return fromMemento(memento, includeKind);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012 Google, Inc and others.
* Copyright (c) 2012, 2013 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
@ -280,6 +280,16 @@ public class IncludePreferences {
public static final String PREF_COMMENT_OUT_UNUSED_INCLUDES = "comment_out_unused_includes"; //$NON-NLS-1$
public static final String INCLUDE_STYLE_GROUP_RELATED = "allow_to_reorder_includes"; //$NON-NLS-1$
public static final String INCLUDE_STYLE_PARTNER = "include_style_partner"; //$NON-NLS-1$
public static final String INCLUDE_STYLE_GROUP_PARTNER = "include_style_group_partner"; //$NON-NLS-1$
public static final String INCLUDE_STYLE_SAME_FOLDER = "include_style_same_folder"; //$NON-NLS-1$
public static final String INCLUDE_STYLE_GROUP_SAME_FOLDER = "include_style_group_same_folder"; //$NON-NLS-1$
public static final String INCLUDE_STYLE_SUBFOLDER = "include_style_subfolder"; //$NON-NLS-1$
public static final String INCLUDE_STYLE_GROUP_SUBFOLDER = "include_style_group_subfolder"; //$NON-NLS-1$
public static final String INCLUDE_STYLE_GROUP_SYSTEM = "include_style_group_system"; //$NON-NLS-1$
/**
* Initializes the given preference store with the default values.
*