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.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.codestyle=class member visibility order ordering
preferenceKeywords.codetemplates=comment code constructor method file type content 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.includestyle=include includes style partner system header file system
preferenceKeywords.includepragmas=include includes pragma pragmas IWYU export begin_exports end_exports preferenceKeywords.includepragmas=include includes pragma pragmas IWYU export begin_exports end_exports
preferenceKeywords.headersubstitution=header file substitution map IWYU 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 { public class IncludeGroupStyleBlock extends OptionsConfigurationBlock {
private final String description; private final String description;
private IncludeGroupStyle style; private IncludeGroupStyle style;
private final ArrayList<Button> checkBoxes = new ArrayList<Button>(); private final ArrayList<Button> checkBoxes = new ArrayList<>();
private final ArrayList<Text> textBoxes = new ArrayList<Text>(); private final ArrayList<Text> textBoxes = new ArrayList<>();
private PixelConverter pixelConverter; private PixelConverter pixelConverter;
private Button checkBoxBlankLine; private Button checkBoxBlankLine;
private static final Key[] EMPTY_KEY_ARRAY = {}; 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_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_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_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 IdentifierValidator IDENTIFIER_VALIDATOR = new IdentifierValidator();
private static final FilenameValidator FILENAME_VALIDATOR = new FilenameValidator(); 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_WORD_DELIMITER,
KEY_CPP_TEST_PREFIX, KEY_CPP_TEST_PREFIX,
KEY_CPP_TEST_SUFFIX, KEY_CPP_TEST_SUFFIX,
KEY_INCLUDE_GUARD_SCHEME,
}; };
} }
@ -166,7 +168,7 @@ public class NameStyleBlock extends OptionsConfigurationBlock {
rootCategories = createCategories(); rootCategories = createCategories();
} }
private static Category[] createCategories() { private Category[] createCategories() {
Category codeCategory = new Category(PreferencesMessages.NameStyleBlock_code_node); Category codeCategory = new Category(PreferencesMessages.NameStyleBlock_code_node);
new Category(PreferencesMessages.NameStyleBlock_constant_node, new Category(PreferencesMessages.NameStyleBlock_constant_node,
PreferencesMessages.NameStyleBlock_constant_node_description, EXAMPLE_CONSTANT_NAME, PreferencesMessages.NameStyleBlock_constant_node_description, EXAMPLE_CONSTANT_NAME,
@ -221,6 +223,7 @@ public class NameStyleBlock extends OptionsConfigurationBlock {
.setSeedNameGenerator(fieldCategory) .setSeedNameGenerator(fieldCategory)
.setNameValidator(IDENTIFIER_VALIDATOR) .setNameValidator(IDENTIFIER_VALIDATOR)
.setTrimFieldName(true); .setTrimFieldName(true);
new IncludeGuardCategory(codeCategory);
Category fileCategory = new Category(PreferencesMessages.NameStyleBlock_files_node); Category fileCategory = new Category(PreferencesMessages.NameStyleBlock_files_node);
new Category(PreferencesMessages.NameStyleBlock_cpp_header_node, new Category(PreferencesMessages.NameStyleBlock_cpp_header_node,
PreferencesMessages.NameStyleBlock_cpp_header_node_description, EXAMPLE_CLASS_NAME, 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.setLabelText(PreferencesMessages.NameStyleBlock_categories_label);
categoryTree.setViewerComparator(adapter); categoryTree.setViewerComparator(adapter);
createCategories();
for (Category category : rootCategories) { for (Category category : rootCategories) {
categoryTree.addElement(category); categoryTree.addElement(category);
} }
@ -331,31 +332,48 @@ public class NameStyleBlock extends OptionsConfigurationBlock {
layout.marginWidth = 0; layout.marginWidth = 0;
envelope.setLayout(layout); envelope.setLayout(layout);
Control control = addComboBox(envelope, PreferencesMessages.NameStyleBlock_capitalization_label, if (category instanceof IncludeGuardCategory) {
category.getCapitalizationKey(), CAPITALIZATION_VALUES, envelope.setLayoutData(new GridData(GridData.FILL_BOTH));
CAPITALIZATION_LABELS, 0); addRadioButton(envelope, PreferencesMessages.NameStyleBlock_file_path_relative_to_source_folder,
LayoutUtil.setHorizontalSpan(getLabel(control), 1); KEY_INCLUDE_GUARD_SCHEME,
LayoutUtil.setHorizontalSpan(control, 3); new String[] { String.valueOf(PreferenceConstants.CODE_TEMPLATES_INCLUDE_GUARD_SCHEME_FILE_PATH), null },
control = addTextField(envelope, PreferencesMessages.NameStyleBlock_word_delimiter_label, 0);
category.getWordDelimiterKey(), 0, pixelConverter.convertWidthInCharsToPixels(10)); addRadioButton(envelope, PreferencesMessages.NameStyleBlock_file_name,
LayoutUtil.setHorizontalSpan(control, 3); KEY_INCLUDE_GUARD_SCHEME,
LayoutUtil.setHorizontalAlignment(control, SWT.BEGINNING); new String[] { String.valueOf(PreferenceConstants.CODE_TEMPLATES_INCLUDE_GUARD_SCHEME_FILE_NAME), null },
control = addTextField(envelope, PreferencesMessages.NameStyleBlock_prefix_label, 0);
category.getPrefixKey(), 0, pixelConverter.convertWidthInCharsToPixels(10)); addRadioButton(envelope, PreferencesMessages.NameStyleBlock_unique_identifier,
boolean getter = PreferencesMessages.NameStyleBlock_getter_node.equals(category.name); KEY_INCLUDE_GUARD_SCHEME,
LayoutUtil.setHorizontalSpan(control, getter ? 1 : 3); new String[] { String.valueOf(PreferenceConstants.CODE_TEMPLATES_INCLUDE_GUARD_SCHEME_UUID), null },
LayoutUtil.setHorizontalAlignment(control, SWT.BEGINNING); 0);
if (getter) { } else {
control = addTextField(envelope, PreferencesMessages.NameStyleBlock_prefix_for_boolean_label, envelope.setLayoutData(new GridData(GridData.FILL_VERTICAL));
category.getAlternativePrefixKey(), pixelConverter.convertWidthInCharsToPixels(2), Control control = addComboBox(envelope, PreferencesMessages.NameStyleBlock_capitalization_label,
pixelConverter.convertWidthInCharsToPixels(10)); category.getCapitalizationKey(), CAPITALIZATION_VALUES,
LayoutUtil.setHorizontalSpan(control, 1); CAPITALIZATION_LABELS, 0);
LayoutUtil.setHorizontalSpan(getLabel(control), 1);
LayoutUtil.setHorizontalSpan(control, 3);
control = addTextField(envelope, PreferencesMessages.NameStyleBlock_word_delimiter_label,
category.getWordDelimiterKey(), 0, pixelConverter.convertWidthInCharsToPixels(10));
LayoutUtil.setHorizontalSpan(control, 3);
LayoutUtil.setHorizontalAlignment(control, SWT.BEGINNING);
control = addTextField(envelope, PreferencesMessages.NameStyleBlock_prefix_label,
category.getPrefixKey(), 0, pixelConverter.convertWidthInCharsToPixels(10));
boolean getter = PreferencesMessages.NameStyleBlock_getter_node.equals(category.name);
LayoutUtil.setHorizontalSpan(control, getter ? 1 : 3);
LayoutUtil.setHorizontalAlignment(control, SWT.BEGINNING);
if (getter) {
control = addTextField(envelope, PreferencesMessages.NameStyleBlock_prefix_for_boolean_label,
category.getAlternativePrefixKey(), pixelConverter.convertWidthInCharsToPixels(2),
pixelConverter.convertWidthInCharsToPixels(10));
LayoutUtil.setHorizontalSpan(control, 1);
LayoutUtil.setHorizontalAlignment(control, SWT.BEGINNING);
}
control = addTextField(envelope, PreferencesMessages.NameStyleBlock_suffix_label,
category.getSuffixKey(), 0, pixelConverter.convertWidthInCharsToPixels(10));
LayoutUtil.setHorizontalSpan(control, 3);
LayoutUtil.setHorizontalAlignment(control, SWT.BEGINNING); LayoutUtil.setHorizontalAlignment(control, SWT.BEGINNING);
} }
control = addTextField(envelope, PreferencesMessages.NameStyleBlock_suffix_label,
category.getSuffixKey(), 0, pixelConverter.convertWidthInCharsToPixels(10));
LayoutUtil.setHorizontalSpan(control, 3);
LayoutUtil.setHorizontalAlignment(control, SWT.BEGINNING);
ControlFactory.insertSpace(envelope, 4, pixelConverter.convertHeightInCharsToPixels(1)); ControlFactory.insertSpace(envelope, 4, pixelConverter.convertHeightInCharsToPixels(1));
ControlFactory.createLabel(envelope, PreferencesMessages.NameStyleBlock_preview_label); ControlFactory.createLabel(envelope, PreferencesMessages.NameStyleBlock_preview_label);
@ -431,7 +449,7 @@ public class NameStyleBlock extends OptionsConfigurationBlock {
/** /**
* Represents a category of settings. * Represents a category of settings.
*/ */
private final static class Category { private static class Category {
public final String name; public final String name;
public final String description; public final String description;
public final Category parent; public final Category parent;
@ -448,14 +466,14 @@ public class NameStyleBlock extends OptionsConfigurationBlock {
private Text previewText; private Text previewText;
private Composite editorArea; private Composite editorArea;
private boolean trimFieldName = false; private boolean trimFieldName;
Category(String name, String description, String seedName, Category parent) { Category(String name, String description, String seedName, Category parent) {
this.name = name; this.name = name;
this.description = description; this.description = description;
this.seedName = seedName; this.seedName = seedName;
this.parent = parent; this.parent = parent;
children = new ArrayList<Category>(); children = new ArrayList<>();
index = parent != null ? parent.addChild(this) : 0; 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 { private abstract static class NameValidator {
boolean isValidStart(String prefix) { boolean isValidStart(String prefix) {
for (int i = 0; i < prefix.length(); i++) { for (int i = 0; i < prefix.length(); i++) {

View file

@ -385,8 +385,8 @@ public abstract class OptionsConfigurationBlock {
ControlData data= new ControlData(key, values); ControlData data= new ControlData(key, values);
GridData gd = new GridData(GridData.FILL_HORIZONTAL); GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan= 3; gd.horizontalSpan= 4;
gd.horizontalIndent= indent; // gd.horizontalIndent= indent;
Button radioButton= new Button(parent, SWT.RADIO); Button radioButton= new Button(parent, SWT.RADIO);
radioButton.setFont(JFaceResources.getDialogFont()); radioButton.setFont(JFaceResources.getDialogFont());
@ -395,7 +395,7 @@ public abstract class OptionsConfigurationBlock {
radioButton.setLayoutData(gd); radioButton.setLayoutData(gd);
radioButton.addSelectionListener(getSelectionListener()); radioButton.addSelectionListener(getSelectionListener());
makeScrollableCompositeAware(radioButton); // makeScrollableCompositeAware(radioButton);
String currValue= getValue(key); String currValue= getValue(key);
radioButton.setSelection(data.getSelection(currValue) == 0); 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_getter_node_description;
public static String NameStyleBlock_setter_node; public static String NameStyleBlock_setter_node;
public static String NameStyleBlock_setter_node_description; 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;
public static String NameStyleBlock_cpp_source_node_description; public static String NameStyleBlock_cpp_source_node_description;
public static String NameStyleBlock_cpp_header_node; 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_prefix_for_boolean_label;
public static String NameStyleBlock_suffix_label; public static String NameStyleBlock_suffix_label;
public static String NameStyleBlock_preview_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_select_concrete_category;
public static String NameStyleBlock_invalid_prefix; public static String NameStyleBlock_invalid_prefix;
public static String NameStyleBlock_invalid_word_delimiter; 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_getter_node_description=Getter name based on the field name
NameStyleBlock_setter_node=Setter Method NameStyleBlock_setter_node=Setter Method
NameStyleBlock_setter_node_description=Setter name based on the field name 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=C++ Source File
NameStyleBlock_cpp_source_node_description=C++ source file name based on the class name NameStyleBlock_cpp_source_node_description=C++ source file name based on the class name
NameStyleBlock_cpp_header_node=C++ Header File NameStyleBlock_cpp_header_node=C++ Header File
@ -552,6 +554,9 @@ NameStyleBlock_prefix_label=&Prefix:
NameStyleBlock_prefix_for_boolean_label=For &Boolean: NameStyleBlock_prefix_for_boolean_label=For &Boolean:
NameStyleBlock_suffix_label=&Suffix: NameStyleBlock_suffix_label=&Suffix:
NameStyleBlock_preview_label=Pre&view: 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_select_concrete_category=Select a specific name category
NameStyleBlock_invalid_prefix=Invalid prefix NameStyleBlock_invalid_prefix=Invalid prefix
NameStyleBlock_invalid_word_delimiter=Invalid word delimiter NameStyleBlock_invalid_word_delimiter=Invalid word delimiter

View file

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