Skip to content

Commit b316d5c

Browse files
angelozerrmickaelistria
authored andcommitted
[XML] Formatting preference page
Fixes #859 Signed-off-by: azerr <[email protected]>
1 parent 8999a87 commit b316d5c

File tree

7 files changed

+192
-8
lines changed

7 files changed

+192
-8
lines changed

org.eclipse.wildwebdeveloper.xml/plugin.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ XMLCatalogPreferencePage.name=Catalogs
1717
XMLCatalogPreferencePage.preferenceKeywords.xmlcatalog=xml catalog entries
1818
XMLCodeLensPreferencePage.name=CodeLens
1919
XMLCodeLensPreferencePage.preferenceKeywords.xmlcodelens=xml codelens
20+
XMLFormattingPreferencePage.name=Formatting
21+
XMLFormattingPreferencePage.preferenceKeywords.xmlformatting=xml formatting
2022
XMLValidationPreferencePage.name=Validation & Resolution
2123
XMLValidationPreferencePage.preferenceKeywords.xmlvalidation=xml validation resolution

org.eclipse.wildwebdeveloper.xml/plugin.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,14 @@
148148
id="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLCodeLensPreferencePage"
149149
name="%XMLCodeLensPreferencePage.name">
150150
<keywordReference id="org.eclipse.wildwebdeveloper.xml.ui.xmlcodelens"/>
151-
</page>
151+
</page>
152+
<page
153+
category="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferencePage"
154+
class="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLFormattingPreferencePage"
155+
id="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLLFormattingPreferencePage"
156+
name="%XMLFormattingPreferencePage.name">
157+
<keywordReference id="org.eclipse.wildwebdeveloper.xml.ui.xmlformatting"/>
158+
</page>
152159
<page
153160
category="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferencePage"
154161
class="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLValidationPreferencePage"
@@ -165,7 +172,10 @@
165172
id="org.eclipse.wildwebdeveloper.xml.ui.xmlcatalogs"/>
166173
<keyword
167174
label="%XMLCodeLensPreferencesPage.preferenceKeywords.xmlcodelens"
168-
id="org.eclipse.wildwebdeveloper.xml.ui.xmlcodelens"/>
175+
id="org.eclipse.wildwebdeveloper.xml.ui.xmlcodelens"/>
176+
<keyword
177+
label="%XMLCodeLensPreferencesPage.preferenceKeywords.xmlformatting"
178+
id="org.eclipse.wildwebdeveloper.xml.ui.xmlformatting"/>
169179
<keyword
170180
label="%XMLValidationPreferencesPage.preferenceKeywords.xmlvalidation"
171181
id="org.eclipse.wildwebdeveloper.xml.ui.xmlvalidation"/>

org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/Messages.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ public class Messages extends NLS {
2929

3030
public static String XMLCodelensPreferencePage_codelens_enabled;
3131

32+
// --------- XML Formatting preference page
33+
34+
public static String XMLFormattingPreferencePage_format_emptyElements;
35+
public static String XMLFormattingPreferencePage_format_emptyElements_collapse;
36+
public static String XMLFormattingPreferencePage_format_emptyElements_expand;
37+
public static String XMLFormattingPreferencePage_format_spaceBeforeEmptyCloseTag;
38+
public static String XMLFormattingPreferencePage_format_splitAttributes;
39+
public static String XMLFormattingPreferencePage_format_splitAttributesIndentSize;
40+
public static String XMLFormattingPreferencePage_format_preserveAttributeLineBreaks;
41+
public static String XMLFormattingPreferencePage_format_closingBracketNewLine;
42+
public static String XMLFormattingPreferencePage_format_xsiSchemaLocationSplit;
43+
public static String XMLFormattingPreferencePage_format_xsiSchemaLocationSplit_onElement;
44+
public static String XMLFormattingPreferencePage_format_xsiSchemaLocationSplit_onPair;
45+
public static String XMLFormattingPreferencePage_format_xsiSchemaLocationSplit_none;
46+
public static String XMLFormattingPreferencePage_format_joinCommentLines;
47+
3248
// --------- XML Validation preference page
3349

3450
public static String XMLValidationPreferencePage_validation_enabled;

org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/messages.properties

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ XMLCatalogPreferencePage_OpenInEditorApplyAndEdit=Apply and Edit
2323
# XML CodeLens preference page
2424
XMLCodelensPreferencePage_codelens_enabled=Enable XML &CodeLens
2525

26+
# XML Formatting preference page
27+
XMLFormattingPreferencePage_format_emptyElements=Expand/collapse &empty elements
28+
XMLFormattingPreferencePage_format_emptyElements_collapse=Collapse
29+
XMLFormattingPreferencePage_format_emptyElements_expand=Expand
30+
XMLFormattingPreferencePage_format_spaceBeforeEmptyCloseTag=Insert space before end of self closing &tag
31+
XMLFormattingPreferencePage_format_splitAttributes=&Split multiple attributes each onto a new line
32+
XMLFormattingPreferencePage_format_splitAttributesIndentSize=Indentation &level for attributes
33+
XMLFormattingPreferencePage_format_closingBracketNewLine=Place closing &brackets on new lines
34+
XMLFormattingPreferencePage_format_preserveAttributeLineBreaks=&Preserve line breaks around attributes
35+
XMLFormattingPreferencePage_format_xsiSchemaLocationSplit=Split `&xsi:schemaLocation` content
36+
XMLFormattingPreferencePage_format_xsiSchemaLocationSplit_onElement=On element
37+
XMLFormattingPreferencePage_format_xsiSchemaLocationSplit_onPair=On pair
38+
XMLFormattingPreferencePage_format_xsiSchemaLocationSplit_none=None
39+
XMLFormattingPreferencePage_format_joinCommentLines=Join &comment content on format
40+
2641
# XML Validation preference page
2742
XMLValidationPreferencePage_validation_enabled=Enable &validation
2843
XMLValidationPreferencePage_validation_namespaces_enabled=Enable &namespaces validation
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2022 Red Hat Inc. and others.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Angelo ZERR (Red Hat Inc.) - initial implementation
12+
*******************************************************************************/
13+
package org.eclipse.wildwebdeveloper.xml.internal.ui.preferences;
14+
15+
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceConstants.XML_PREFERENCES_FORMAT_CLOSING_BRACKET_NEW_LINE;
16+
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceConstants.XML_PREFERENCES_FORMAT_EMPTY_ELEMENTS;
17+
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceConstants.XML_PREFERENCES_FORMAT_JOIN_COMMENTLINES;
18+
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceConstants.XML_PREFERENCES_FORMAT_PRESERVE_ATTRIBUTE_LINE_BREAKS;
19+
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceConstants.XML_PREFERENCES_FORMAT_SPACE_BEFORE_EMPTY_CLOSE_TAG;
20+
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceConstants.XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES;
21+
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceConstants.XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES_INDENT_SIZE;
22+
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceConstants.XML_PREFERENCES_FORMAT_XSI_SCHEMA_LOCATION_SPLIT;
23+
24+
import org.eclipse.jface.action.Action;
25+
import org.eclipse.jface.dialogs.IDialogConstants;
26+
import org.eclipse.jface.preference.BooleanFieldEditor;
27+
import org.eclipse.jface.preference.ComboFieldEditor;
28+
import org.eclipse.jface.preference.FieldEditorPreferencePage;
29+
import org.eclipse.jface.preference.IntegerFieldEditor;
30+
import org.eclipse.ui.IWorkbench;
31+
import org.eclipse.ui.IWorkbenchPreferencePage;
32+
import org.eclipse.wildwebdeveloper.xml.internal.Activator;
33+
import org.eclipse.wildwebdeveloper.xml.internal.ui.Messages;
34+
35+
/**
36+
* XML formatting preference page.
37+
*
38+
*/
39+
public class XMLFormattingPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
40+
41+
public XMLFormattingPreferencePage() {
42+
super(GRID);
43+
}
44+
45+
@Override
46+
public void createFieldEditors() {
47+
// Settings for tag elements
48+
addField(new ComboFieldEditor(XML_PREFERENCES_FORMAT_EMPTY_ELEMENTS.preferenceId,
49+
Messages.XMLFormattingPreferencePage_format_emptyElements,
50+
new String[][] { { Action.removeMnemonics(IDialogConstants.IGNORE_LABEL), "ignore" },
51+
{ Messages.XMLFormattingPreferencePage_format_emptyElements_collapse, "collapse" },
52+
{ Messages.XMLFormattingPreferencePage_format_emptyElements_expand, "expand" } },
53+
getFieldEditorParent()));
54+
addField(new BooleanFieldEditor(XML_PREFERENCES_FORMAT_SPACE_BEFORE_EMPTY_CLOSE_TAG.preferenceId,
55+
Messages.XMLFormattingPreferencePage_format_spaceBeforeEmptyCloseTag, getFieldEditorParent()));
56+
57+
// Settings for attributes
58+
addField(new BooleanFieldEditor(XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES.preferenceId,
59+
Messages.XMLFormattingPreferencePage_format_splitAttributes, getFieldEditorParent()));
60+
addField(new IntegerFieldEditor(XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES_INDENT_SIZE.preferenceId,
61+
Messages.XMLFormattingPreferencePage_format_splitAttributesIndentSize, getFieldEditorParent()));
62+
addField(new BooleanFieldEditor(XML_PREFERENCES_FORMAT_CLOSING_BRACKET_NEW_LINE.preferenceId,
63+
Messages.XMLFormattingPreferencePage_format_closingBracketNewLine, getFieldEditorParent()));
64+
addField(new BooleanFieldEditor(XML_PREFERENCES_FORMAT_PRESERVE_ATTRIBUTE_LINE_BREAKS.preferenceId,
65+
Messages.XMLFormattingPreferencePage_format_preserveAttributeLineBreaks, getFieldEditorParent()));
66+
addField(new ComboFieldEditor(XML_PREFERENCES_FORMAT_XSI_SCHEMA_LOCATION_SPLIT.preferenceId,
67+
Messages.XMLFormattingPreferencePage_format_xsiSchemaLocationSplit,
68+
new String[][] {
69+
{ Messages.XMLFormattingPreferencePage_format_xsiSchemaLocationSplit_onElement, "onElement" },
70+
{ Messages.XMLFormattingPreferencePage_format_xsiSchemaLocationSplit_onPair, "onPair" },
71+
{ Messages.XMLFormattingPreferencePage_format_xsiSchemaLocationSplit_none, "none" } },
72+
getFieldEditorParent()));
73+
74+
// Settings for comments
75+
addField(new BooleanFieldEditor(XML_PREFERENCES_FORMAT_JOIN_COMMENTLINES.preferenceId,
76+
Messages.XMLFormattingPreferencePage_format_joinCommentLines, getFieldEditorParent()));
77+
}
78+
79+
@Override
80+
public void init(IWorkbench workbench) {
81+
setPreferenceStore(Activator.getDefault().getPreferenceStore());
82+
}
83+
}

org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/XMLPreferenceConstants.java

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,51 @@ public void storeToLemminxOptions(Object value, Map<String, Object> options) {
6161
}
6262
}
6363

64+
// Catalog settings
6465
public static final LemminxPreference XML_PREFERENCES_CATAGLOGS = new LemminxPreference("catalogs");
66+
67+
// CodeLens settings
6568
public static final LemminxPreference XML_PREFERENCES_CODELENS_ENABLED = new LemminxPreference("codeLens/enabled");
69+
70+
// Folding settings
71+
public static final LemminxPreference XML_PREFERENCES_FOLDING_INCLUDE_CLOSING_TAG_IN_FOLD = new LemminxPreference("foldings/includeClosingTagInFold");
72+
73+
// Format settings
74+
public static final LemminxPreference XML_PREFERENCES_FORMAT_EMPTY_ELEMENTS = new LemminxPreference("format/emptyElements");
75+
public static final LemminxPreference XML_PREFERENCES_FORMAT_SPACE_BEFORE_EMPTY_CLOSE_TAG = new LemminxPreference("format/spaceBeforeEmptyCloseTag");
76+
public static final LemminxPreference XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES = new LemminxPreference("format/splitAttributes");
77+
public static final LemminxPreference XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES_INDENT_SIZE = new LemminxPreference("format/splitAttributesIndentSize");
78+
public static final LemminxPreference XML_PREFERENCES_FORMAT_PRESERVE_ATTRIBUTE_LINE_BREAKS = new LemminxPreference("format/preserveAttributeLineBreaks");
79+
public static final LemminxPreference XML_PREFERENCES_FORMAT_CLOSING_BRACKET_NEW_LINE = new LemminxPreference("format/closingBracketNewLine");
80+
public static final LemminxPreference XML_PREFERENCES_FORMAT_XSI_SCHEMA_LOCATION_SPLIT = new LemminxPreference("format/xsiSchemaLocationSplit");
81+
public static final LemminxPreference XML_PREFERENCES_FORMAT_JOIN_COMMENTLINES = new LemminxPreference("format/joinCommentLines");
82+
83+
// Validation settings
6684
public static final LemminxPreference XML_PREFERENCES_VALIDATION_ENABLED = new LemminxPreference("validation/enabled");
6785
public static final LemminxPreference XML_PREFERENCES_VALIDATION_NAMESPACES_ENABLED = new LemminxPreference("validation/namespaces/enabled");
6886
public static final LemminxPreference XML_PREFERENCES_VALIDATION_SCHEMA_ENABLED = new LemminxPreference("validation/schema/enabled");
6987
public static final LemminxPreference XML_PREFERENCES_VALIDATION_DISALLOW_DOCTYPE_DECL = new LemminxPreference("validation/disallowDocTypeDecl");
7088
public static final LemminxPreference XML_PREFERENCES_VALIDATION_RESOLVE_EXTERNAL_ENTITIES = new LemminxPreference("validation/resolveExternalEntities");
7189
public static final LemminxPreference XML_PREFERENCES_VALIDATION_NO_GRAMMAR = new LemminxPreference("validation/noGrammar");
72-
public static final LemminxPreference XML_PREFERENCES_FOLDING_INCLUDE_CLOSING_TAG_IN_FOLD = new LemminxPreference("foldings/includeClosingTagInFold");
7390

7491
private static final LemminxPreference[] ALL_LEMMINX_PREFERENCES = {
7592
XML_PREFERENCES_CATAGLOGS,
7693
XML_PREFERENCES_CODELENS_ENABLED,
94+
XML_PREFERENCES_FOLDING_INCLUDE_CLOSING_TAG_IN_FOLD,
95+
XML_PREFERENCES_FORMAT_EMPTY_ELEMENTS,
96+
XML_PREFERENCES_FORMAT_SPACE_BEFORE_EMPTY_CLOSE_TAG,
97+
XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES,
98+
XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES_INDENT_SIZE,
99+
XML_PREFERENCES_FORMAT_PRESERVE_ATTRIBUTE_LINE_BREAKS,
100+
XML_PREFERENCES_FORMAT_CLOSING_BRACKET_NEW_LINE,
101+
XML_PREFERENCES_FORMAT_XSI_SCHEMA_LOCATION_SPLIT,
102+
XML_PREFERENCES_FORMAT_JOIN_COMMENTLINES,
77103
XML_PREFERENCES_VALIDATION_ENABLED,
78104
XML_PREFERENCES_VALIDATION_NAMESPACES_ENABLED,
79105
XML_PREFERENCES_VALIDATION_SCHEMA_ENABLED,
80106
XML_PREFERENCES_VALIDATION_DISALLOW_DOCTYPE_DECL,
81107
XML_PREFERENCES_VALIDATION_RESOLVE_EXTERNAL_ENTITIES,
82-
XML_PREFERENCES_VALIDATION_NO_GRAMMAR,
83-
XML_PREFERENCES_FOLDING_INCLUDE_CLOSING_TAG_IN_FOLD
108+
XML_PREFERENCES_VALIDATION_NO_GRAMMAR
84109
};
85110

86111
public static Optional<LemminxPreference> getLemminxPreference(PropertyChangeEvent event) {
@@ -92,10 +117,28 @@ private XMLPreferenceConstants() {
92117
}
93118

94119
public static void storePreferencesToLemminxOptions(IPreferenceStore store, Map<String, Object> xmlOpts) {
120+
// Catalo settings
95121
XML_PREFERENCES_CATAGLOGS.storeToLemminxOptions(
96122
XMLCatalogs.getAllCatalogs(store).stream().map(File::getAbsolutePath).toArray(String[]::new),
97123
xmlOpts);
124+
125+
// CodeLens settings
98126
XML_PREFERENCES_CODELENS_ENABLED.storeToLemminxOptions(store.getBoolean(XML_PREFERENCES_CODELENS_ENABLED.preferenceId), xmlOpts);
127+
128+
// Folding settings
129+
XML_PREFERENCES_FOLDING_INCLUDE_CLOSING_TAG_IN_FOLD.storeToLemminxOptions(store.getBoolean(XML_PREFERENCES_FOLDING_INCLUDE_CLOSING_TAG_IN_FOLD.preferenceId), xmlOpts);
130+
131+
// Format settings
132+
XML_PREFERENCES_FORMAT_EMPTY_ELEMENTS.storeToLemminxOptions(store.getString(XML_PREFERENCES_FORMAT_EMPTY_ELEMENTS.preferenceId), xmlOpts);
133+
XML_PREFERENCES_FORMAT_SPACE_BEFORE_EMPTY_CLOSE_TAG.storeToLemminxOptions(store.getBoolean(XML_PREFERENCES_FORMAT_SPACE_BEFORE_EMPTY_CLOSE_TAG.preferenceId), xmlOpts);
134+
XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES.storeToLemminxOptions(store.getBoolean(XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES.preferenceId), xmlOpts);
135+
XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES_INDENT_SIZE.storeToLemminxOptions(store.getInt(XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES_INDENT_SIZE.preferenceId), xmlOpts);
136+
XML_PREFERENCES_FORMAT_PRESERVE_ATTRIBUTE_LINE_BREAKS.storeToLemminxOptions(store.getBoolean(XML_PREFERENCES_FORMAT_PRESERVE_ATTRIBUTE_LINE_BREAKS.preferenceId), xmlOpts);
137+
XML_PREFERENCES_FORMAT_CLOSING_BRACKET_NEW_LINE.storeToLemminxOptions(store.getBoolean(XML_PREFERENCES_FORMAT_CLOSING_BRACKET_NEW_LINE.preferenceId), xmlOpts);
138+
XML_PREFERENCES_FORMAT_XSI_SCHEMA_LOCATION_SPLIT.storeToLemminxOptions(store.getString(XML_PREFERENCES_FORMAT_XSI_SCHEMA_LOCATION_SPLIT.preferenceId), xmlOpts);
139+
XML_PREFERENCES_FORMAT_JOIN_COMMENTLINES.storeToLemminxOptions(store.getBoolean(XML_PREFERENCES_FORMAT_JOIN_COMMENTLINES.preferenceId), xmlOpts);
140+
141+
// Validation settings
99142
XML_PREFERENCES_VALIDATION_ENABLED.storeToLemminxOptions(store.getBoolean(XML_PREFERENCES_VALIDATION_ENABLED.preferenceId), xmlOpts);
100143
XML_PREFERENCES_VALIDATION_NAMESPACES_ENABLED.storeToLemminxOptions(store.getString(XML_PREFERENCES_VALIDATION_NAMESPACES_ENABLED.preferenceId), xmlOpts);
101144
XML_PREFERENCES_VALIDATION_SCHEMA_ENABLED.storeToLemminxOptions(store.getString(XML_PREFERENCES_VALIDATION_SCHEMA_ENABLED.preferenceId),
@@ -105,7 +148,6 @@ public static void storePreferencesToLemminxOptions(IPreferenceStore store, Map<
105148
XML_PREFERENCES_VALIDATION_RESOLVE_EXTERNAL_ENTITIES.storeToLemminxOptions(
106149
store.getBoolean(XML_PREFERENCES_VALIDATION_RESOLVE_EXTERNAL_ENTITIES.preferenceId), xmlOpts);
107150
XML_PREFERENCES_VALIDATION_NO_GRAMMAR.storeToLemminxOptions(store.getString(XML_PREFERENCES_VALIDATION_NO_GRAMMAR.preferenceId),
108-
xmlOpts);
109-
XML_PREFERENCES_FOLDING_INCLUDE_CLOSING_TAG_IN_FOLD.storeToLemminxOptions(store.getBoolean(XML_PREFERENCES_FOLDING_INCLUDE_CLOSING_TAG_IN_FOLD.preferenceId), xmlOpts);
151+
xmlOpts);
110152
}
111153
}

0 commit comments

Comments
 (0)