1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

Added editing of include guard style preference.

This commit is contained in:
Sergey Prigogin 2014-06-17 10:40:46 -07:00
parent d962e2eee7
commit 246d2eb69b
7 changed files with 91 additions and 36 deletions

View file

@ -581,7 +581,7 @@ 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 style file getter setter field variable
preferenceKeywords.namestyle=name style file getter setter field variable include guard
preferenceKeywords.includestyle=include includes style partner system header file system
preferenceKeywords.includepragmas=include includes pragma pragmas IWYU export begin_exports end_exports
preferenceKeywords.headersubstitution=header file substitution map IWYU

View file

@ -38,8 +38,8 @@ import org.eclipse.cdt.internal.ui.refactoring.includes.IncludeGroupStyle;
public class IncludeGroupStyleBlock extends OptionsConfigurationBlock {
private final String description;
private IncludeGroupStyle style;
private final ArrayList<Button> checkBoxes = new ArrayList<Button>();
private final ArrayList<Text> textBoxes = new ArrayList<Text>();
private final ArrayList<Button> checkBoxes = new ArrayList<>();
private final ArrayList<Text> textBoxes = new ArrayList<>();
private PixelConverter pixelConverter;
private Button checkBoxBlankLine;
private static final Key[] EMPTY_KEY_ARRAY = {};

View file

@ -108,6 +108,7 @@ public class NameStyleBlock extends OptionsConfigurationBlock {
private static final Key KEY_CPP_TEST_WORD_DELIMITER = getCDTUIKey(PreferenceConstants.NAME_STYLE_CPP_TEST_WORD_DELIMITER);
private static final Key KEY_CPP_TEST_PREFIX = getCDTUIKey(PreferenceConstants.NAME_STYLE_CPP_TEST_PREFIX);
private static final Key KEY_CPP_TEST_SUFFIX = getCDTUIKey(PreferenceConstants.NAME_STYLE_CPP_TEST_SUFFIX);
private static final Key KEY_INCLUDE_GUARD_SCHEME = getCDTUIKey(PreferenceConstants.CODE_TEMPLATES_INCLUDE_GUARD_SCHEME);
private static final IdentifierValidator IDENTIFIER_VALIDATOR = new IdentifierValidator();
private static final FilenameValidator FILENAME_VALIDATOR = new FilenameValidator();
@ -151,6 +152,7 @@ public class NameStyleBlock extends OptionsConfigurationBlock {
KEY_CPP_TEST_WORD_DELIMITER,
KEY_CPP_TEST_PREFIX,
KEY_CPP_TEST_SUFFIX,
KEY_INCLUDE_GUARD_SCHEME,
};
}
@ -166,7 +168,7 @@ public class NameStyleBlock extends OptionsConfigurationBlock {
rootCategories = createCategories();
}
private static Category[] createCategories() {
private Category[] createCategories() {
Category codeCategory = new Category(PreferencesMessages.NameStyleBlock_code_node);
new Category(PreferencesMessages.NameStyleBlock_constant_node,
PreferencesMessages.NameStyleBlock_constant_node_description, EXAMPLE_CONSTANT_NAME,
@ -221,6 +223,7 @@ public class NameStyleBlock extends OptionsConfigurationBlock {
.setSeedNameGenerator(fieldCategory)
.setNameValidator(IDENTIFIER_VALIDATOR)
.setTrimFieldName(true);
new IncludeGuardCategory(codeCategory);
Category fileCategory = new Category(PreferencesMessages.NameStyleBlock_files_node);
new Category(PreferencesMessages.NameStyleBlock_cpp_header_node,
PreferencesMessages.NameStyleBlock_cpp_header_node_description, EXAMPLE_CLASS_NAME,
@ -273,8 +276,6 @@ public class NameStyleBlock extends OptionsConfigurationBlock {
categoryTree.setLabelText(PreferencesMessages.NameStyleBlock_categories_label);
categoryTree.setViewerComparator(adapter);
createCategories();
for (Category category : rootCategories) {
categoryTree.addElement(category);
}
@ -331,6 +332,22 @@ public class NameStyleBlock extends OptionsConfigurationBlock {
layout.marginWidth = 0;
envelope.setLayout(layout);
if (category instanceof IncludeGuardCategory) {
envelope.setLayoutData(new GridData(GridData.FILL_BOTH));
addRadioButton(envelope, PreferencesMessages.NameStyleBlock_file_path_relative_to_source_folder,
KEY_INCLUDE_GUARD_SCHEME,
new String[] { String.valueOf(PreferenceConstants.CODE_TEMPLATES_INCLUDE_GUARD_SCHEME_FILE_PATH), null },
0);
addRadioButton(envelope, PreferencesMessages.NameStyleBlock_file_name,
KEY_INCLUDE_GUARD_SCHEME,
new String[] { String.valueOf(PreferenceConstants.CODE_TEMPLATES_INCLUDE_GUARD_SCHEME_FILE_NAME), null },
0);
addRadioButton(envelope, PreferencesMessages.NameStyleBlock_unique_identifier,
KEY_INCLUDE_GUARD_SCHEME,
new String[] { String.valueOf(PreferenceConstants.CODE_TEMPLATES_INCLUDE_GUARD_SCHEME_UUID), null },
0);
} else {
envelope.setLayoutData(new GridData(GridData.FILL_VERTICAL));
Control control = addComboBox(envelope, PreferencesMessages.NameStyleBlock_capitalization_label,
category.getCapitalizationKey(), CAPITALIZATION_VALUES,
CAPITALIZATION_LABELS, 0);
@ -356,6 +373,7 @@ public class NameStyleBlock extends OptionsConfigurationBlock {
category.getSuffixKey(), 0, pixelConverter.convertWidthInCharsToPixels(10));
LayoutUtil.setHorizontalSpan(control, 3);
LayoutUtil.setHorizontalAlignment(control, SWT.BEGINNING);
}
ControlFactory.insertSpace(envelope, 4, pixelConverter.convertHeightInCharsToPixels(1));
ControlFactory.createLabel(envelope, PreferencesMessages.NameStyleBlock_preview_label);
@ -431,7 +449,7 @@ public class NameStyleBlock extends OptionsConfigurationBlock {
/**
* Represents a category of settings.
*/
private final static class Category {
private static class Category {
public final String name;
public final String description;
public final Category parent;
@ -448,14 +466,14 @@ public class NameStyleBlock extends OptionsConfigurationBlock {
private Text previewText;
private Composite editorArea;
private boolean trimFieldName = false;
private boolean trimFieldName;
Category(String name, String description, String seedName, Category parent) {
this.name = name;
this.description = description;
this.seedName = seedName;
this.parent = parent;
children = new ArrayList<Category>();
children = new ArrayList<>();
index = parent != null ? parent.addChild(this) : 0;
}
@ -584,6 +602,33 @@ public class NameStyleBlock extends OptionsConfigurationBlock {
}
}
private static class IncludeGuardCategory extends Category {
IncludeGuardCategory(Category parent) {
super(PreferencesMessages.NameStyleBlock_include_guard_node,
PreferencesMessages.NameStyleBlock_include_guard_node_description, null, parent);
}
@Override
String composeExampleName(NameStyleBlock settings) {
int scheme = Integer.parseInt(settings.getValue(KEY_INCLUDE_GUARD_SCHEME));
switch (scheme) {
case PreferenceConstants.CODE_TEMPLATES_INCLUDE_GUARD_SCHEME_FILE_PATH:
return "DIR1_DIR2_FILENAME_H_"; //$NON-NLS-1$
case PreferenceConstants.CODE_TEMPLATES_INCLUDE_GUARD_SCHEME_FILE_NAME:
return "FILENAME_H_"; //$NON-NLS-1$
case PreferenceConstants.CODE_TEMPLATES_INCLUDE_GUARD_SCHEME_UUID:
return "H5C9C6A49_D213_49BD_99A7_9BBA0FA998BF"; //$NON-NLS-1$
default:
return ""; //$NON-NLS-1$
}
}
@Override
boolean isConcrete() {
return true;
}
}
private abstract static class NameValidator {
boolean isValidStart(String prefix) {
for (int i = 0; i < prefix.length(); i++) {

View file

@ -385,8 +385,8 @@ public abstract class OptionsConfigurationBlock {
ControlData data= new ControlData(key, values);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan= 3;
gd.horizontalIndent= indent;
gd.horizontalSpan= 4;
// gd.horizontalIndent= indent;
Button radioButton= new Button(parent, SWT.RADIO);
radioButton.setFont(JFaceResources.getDialogFont());
@ -395,7 +395,7 @@ public abstract class OptionsConfigurationBlock {
radioButton.setLayoutData(gd);
radioButton.addSelectionListener(getSelectionListener());
makeScrollableCompositeAware(radioButton);
// makeScrollableCompositeAware(radioButton);
String currValue= getValue(key);
radioButton.setSelection(data.getSelection(currValue) == 0);

View file

@ -476,6 +476,8 @@ public final class PreferencesMessages extends NLS {
public static String NameStyleBlock_getter_node_description;
public static String NameStyleBlock_setter_node;
public static String NameStyleBlock_setter_node_description;
public static String NameStyleBlock_include_guard_node;
public static String NameStyleBlock_include_guard_node_description;
public static String NameStyleBlock_cpp_source_node;
public static String NameStyleBlock_cpp_source_node_description;
public static String NameStyleBlock_cpp_header_node;
@ -494,6 +496,9 @@ public final class PreferencesMessages extends NLS {
public static String NameStyleBlock_prefix_for_boolean_label;
public static String NameStyleBlock_suffix_label;
public static String NameStyleBlock_preview_label;
public static String NameStyleBlock_file_path_relative_to_source_folder;
public static String NameStyleBlock_file_name;
public static String NameStyleBlock_unique_identifier;
public static String NameStyleBlock_select_concrete_category;
public static String NameStyleBlock_invalid_prefix;
public static String NameStyleBlock_invalid_word_delimiter;

View file

@ -534,6 +534,8 @@ NameStyleBlock_getter_node=Getter Method
NameStyleBlock_getter_node_description=Getter name based on the field name
NameStyleBlock_setter_node=Setter Method
NameStyleBlock_setter_node_description=Setter name based on the field name
NameStyleBlock_include_guard_node=Include Guard
NameStyleBlock_include_guard_node_description=Include guard macro name
NameStyleBlock_cpp_source_node=C++ Source File
NameStyleBlock_cpp_source_node_description=C++ source file name based on the class name
NameStyleBlock_cpp_header_node=C++ Header File
@ -552,6 +554,9 @@ NameStyleBlock_prefix_label=&Prefix:
NameStyleBlock_prefix_for_boolean_label=For &Boolean:
NameStyleBlock_suffix_label=&Suffix:
NameStyleBlock_preview_label=Pre&view:
NameStyleBlock_file_path_relative_to_source_folder=File &path relative to source folder
NameStyleBlock_file_name=File &name
NameStyleBlock_unique_identifier=&Unique identifier
NameStyleBlock_select_concrete_category=Select a specific name category
NameStyleBlock_invalid_prefix=Invalid prefix
NameStyleBlock_invalid_word_delimiter=Invalid word delimiter

View file

@ -213,7 +213,7 @@ public class ControlFactory {
Label label = new Label(parent, style);
label.setFont(parent.getFont());
label.setText(text);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan = 1;
gd.widthHint = widthHint;
gd.heightHint = heightHint;