Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions org.eclipse.wildwebdeveloper.xml/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ XMLCatalogPreferencePage.name=Catalogs
XMLCatalogPreferencePage.preferenceKeywords.xmlcatalog=xml catalog entries
XMLCodeLensPreferencePage.name=CodeLens
XMLCodeLensPreferencePage.preferenceKeywords.xmlcodelens=xml codelens
XMLFormattingPreferencePage.name=Formatting
XMLFormattingPreferencePage.preferenceKeywords.xmlformatting=xml formatting
XMLValidationPreferencePage.name=Validation & Resolution
XMLValidationPreferencePage.preferenceKeywords.xmlvalidation=xml validation resolution
14 changes: 12 additions & 2 deletions org.eclipse.wildwebdeveloper.xml/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,14 @@
id="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLCodeLensPreferencePage"
name="%XMLCodeLensPreferencePage.name">
<keywordReference id="org.eclipse.wildwebdeveloper.xml.ui.xmlcodelens"/>
</page>
</page>
<page
category="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferencePage"
class="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLFormattingPreferencePage"
id="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLLFormattingPreferencePage"
name="%XMLFormattingPreferencePage.name">
<keywordReference id="org.eclipse.wildwebdeveloper.xml.ui.xmlformatting"/>
</page>
<page
category="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferencePage"
class="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLValidationPreferencePage"
Expand All @@ -165,7 +172,10 @@
id="org.eclipse.wildwebdeveloper.xml.ui.xmlcatalogs"/>
<keyword
label="%XMLCodeLensPreferencesPage.preferenceKeywords.xmlcodelens"
id="org.eclipse.wildwebdeveloper.xml.ui.xmlcodelens"/>
id="org.eclipse.wildwebdeveloper.xml.ui.xmlcodelens"/>
<keyword
label="%XMLCodeLensPreferencesPage.preferenceKeywords.xmlformatting"
id="org.eclipse.wildwebdeveloper.xml.ui.xmlformatting"/>
<keyword
label="%XMLValidationPreferencesPage.preferenceKeywords.xmlvalidation"
id="org.eclipse.wildwebdeveloper.xml.ui.xmlvalidation"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ public class Messages extends NLS {

public static String XMLCodelensPreferencePage_codelens_enabled;

// --------- XML Formatting preference page

public static String XMLFormattingPreferencePage_format_emptyElements;
public static String XMLFormattingPreferencePage_format_emptyElements_collapse;
public static String XMLFormattingPreferencePage_format_emptyElements_expand;
public static String XMLFormattingPreferencePage_format_spaceBeforeEmptyCloseTag;
public static String XMLFormattingPreferencePage_format_splitAttributes;
public static String XMLFormattingPreferencePage_format_splitAttributesIndentSize;
public static String XMLFormattingPreferencePage_format_preserveAttributeLineBreaks;
public static String XMLFormattingPreferencePage_format_closingBracketNewLine;
public static String XMLFormattingPreferencePage_format_xsiSchemaLocationSplit;
public static String XMLFormattingPreferencePage_format_xsiSchemaLocationSplit_onElement;
public static String XMLFormattingPreferencePage_format_xsiSchemaLocationSplit_onPair;
public static String XMLFormattingPreferencePage_format_xsiSchemaLocationSplit_none;
public static String XMLFormattingPreferencePage_format_joinCommentLines;

// --------- XML Validation preference page

public static String XMLValidationPreferencePage_validation_enabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ XMLCatalogPreferencePage_OpenInEditorApplyAndEdit=Apply and Edit
# XML CodeLens preference page
XMLCodelensPreferencePage_codelens_enabled=Enable XML &CodeLens

# XML Formatting preference page
XMLFormattingPreferencePage_format_emptyElements=Expand/collapse &empty elements
XMLFormattingPreferencePage_format_emptyElements_collapse=Collapse
XMLFormattingPreferencePage_format_emptyElements_expand=Expand
XMLFormattingPreferencePage_format_spaceBeforeEmptyCloseTag=Insert space before end of self closing &tag
XMLFormattingPreferencePage_format_splitAttributes=&Split multiple attributes each onto a new line
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split is probably not the right term. I suggest Place attributes on separate lines

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
XMLFormattingPreferencePage_format_splitAttributes=&Split multiple attributes each onto a new line
XMLFormattingPreferencePage_format_splitAttributes=&Place attributes on separate lines

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep this label since we use it too in vscode-xml and WTP uses too this label:

image

XMLFormattingPreferencePage_format_splitAttributesIndentSize=Indentation &level for attributes
XMLFormattingPreferencePage_format_closingBracketNewLine=Place closing &brackets on new lines
XMLFormattingPreferencePage_format_preserveAttributeLineBreaks=&Preserve line breaks around attributes
XMLFormattingPreferencePage_format_xsiSchemaLocationSplit=Split `&xsi:schemaLocation` content
XMLFormattingPreferencePage_format_xsiSchemaLocationSplit_onElement=On element
XMLFormattingPreferencePage_format_xsiSchemaLocationSplit_onPair=On pair
XMLFormattingPreferencePage_format_xsiSchemaLocationSplit_none=None
XMLFormattingPreferencePage_format_joinCommentLines=Join &comment content on format

# XML Validation preference page
XMLValidationPreferencePage_validation_enabled=Enable &validation
XMLValidationPreferencePage_validation_namespaces_enabled=Enable &namespaces validation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*******************************************************************************
* Copyright (c) 2022 Red Hat Inc. and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Angelo ZERR (Red Hat Inc.) - initial implementation
*******************************************************************************/
package org.eclipse.wildwebdeveloper.xml.internal.ui.preferences;

import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceConstants.XML_PREFERENCES_FORMAT_CLOSING_BRACKET_NEW_LINE;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceConstants.XML_PREFERENCES_FORMAT_EMPTY_ELEMENTS;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceConstants.XML_PREFERENCES_FORMAT_JOIN_COMMENTLINES;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceConstants.XML_PREFERENCES_FORMAT_PRESERVE_ATTRIBUTE_LINE_BREAKS;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceConstants.XML_PREFERENCES_FORMAT_SPACE_BEFORE_EMPTY_CLOSE_TAG;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceConstants.XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceConstants.XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES_INDENT_SIZE;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceConstants.XML_PREFERENCES_FORMAT_XSI_SCHEMA_LOCATION_SPLIT;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.ComboFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.wildwebdeveloper.xml.internal.Activator;
import org.eclipse.wildwebdeveloper.xml.internal.ui.Messages;

/**
* XML formatting preference page.
*
*/
public class XMLFormattingPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {

public XMLFormattingPreferencePage() {
super(GRID);
}

@Override
public void createFieldEditors() {
// Settings for tag elements
addField(new ComboFieldEditor(XML_PREFERENCES_FORMAT_EMPTY_ELEMENTS.preferenceId,
Messages.XMLFormattingPreferencePage_format_emptyElements,
new String[][] { { Action.removeMnemonics(IDialogConstants.IGNORE_LABEL), "ignore" },
{ Messages.XMLFormattingPreferencePage_format_emptyElements_collapse, "collapse" },
{ Messages.XMLFormattingPreferencePage_format_emptyElements_expand, "expand" } },
getFieldEditorParent()));
addField(new BooleanFieldEditor(XML_PREFERENCES_FORMAT_SPACE_BEFORE_EMPTY_CLOSE_TAG.preferenceId,
Messages.XMLFormattingPreferencePage_format_spaceBeforeEmptyCloseTag, getFieldEditorParent()));

// Settings for attributes
addField(new BooleanFieldEditor(XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES.preferenceId,
Messages.XMLFormattingPreferencePage_format_splitAttributes, getFieldEditorParent()));
addField(new IntegerFieldEditor(XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES_INDENT_SIZE.preferenceId,
Messages.XMLFormattingPreferencePage_format_splitAttributesIndentSize, getFieldEditorParent()));
addField(new BooleanFieldEditor(XML_PREFERENCES_FORMAT_CLOSING_BRACKET_NEW_LINE.preferenceId,
Messages.XMLFormattingPreferencePage_format_closingBracketNewLine, getFieldEditorParent()));
addField(new BooleanFieldEditor(XML_PREFERENCES_FORMAT_PRESERVE_ATTRIBUTE_LINE_BREAKS.preferenceId,
Messages.XMLFormattingPreferencePage_format_preserveAttributeLineBreaks, getFieldEditorParent()));
addField(new ComboFieldEditor(XML_PREFERENCES_FORMAT_XSI_SCHEMA_LOCATION_SPLIT.preferenceId,
Messages.XMLFormattingPreferencePage_format_xsiSchemaLocationSplit,
new String[][] {
{ Messages.XMLFormattingPreferencePage_format_xsiSchemaLocationSplit_onElement, "onElement" },
{ Messages.XMLFormattingPreferencePage_format_xsiSchemaLocationSplit_onPair, "onPair" },
{ Messages.XMLFormattingPreferencePage_format_xsiSchemaLocationSplit_none, "none" } },
getFieldEditorParent()));

// Settings for comments
addField(new BooleanFieldEditor(XML_PREFERENCES_FORMAT_JOIN_COMMENTLINES.preferenceId,
Messages.XMLFormattingPreferencePage_format_joinCommentLines, getFieldEditorParent()));
}

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,51 @@ public void storeToLemminxOptions(Object value, Map<String, Object> options) {
}
}

// Catalog settings
public static final LemminxPreference XML_PREFERENCES_CATAGLOGS = new LemminxPreference("catalogs");

// CodeLens settings
public static final LemminxPreference XML_PREFERENCES_CODELENS_ENABLED = new LemminxPreference("codeLens/enabled");

// Folding settings
public static final LemminxPreference XML_PREFERENCES_FOLDING_INCLUDE_CLOSING_TAG_IN_FOLD = new LemminxPreference("foldings/includeClosingTagInFold");

// Format settings
public static final LemminxPreference XML_PREFERENCES_FORMAT_EMPTY_ELEMENTS = new LemminxPreference("format/emptyElements");
public static final LemminxPreference XML_PREFERENCES_FORMAT_SPACE_BEFORE_EMPTY_CLOSE_TAG = new LemminxPreference("format/spaceBeforeEmptyCloseTag");
public static final LemminxPreference XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES = new LemminxPreference("format/splitAttributes");
public static final LemminxPreference XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES_INDENT_SIZE = new LemminxPreference("format/splitAttributesIndentSize");
public static final LemminxPreference XML_PREFERENCES_FORMAT_PRESERVE_ATTRIBUTE_LINE_BREAKS = new LemminxPreference("format/preserveAttributeLineBreaks");
public static final LemminxPreference XML_PREFERENCES_FORMAT_CLOSING_BRACKET_NEW_LINE = new LemminxPreference("format/closingBracketNewLine");
public static final LemminxPreference XML_PREFERENCES_FORMAT_XSI_SCHEMA_LOCATION_SPLIT = new LemminxPreference("format/xsiSchemaLocationSplit");
public static final LemminxPreference XML_PREFERENCES_FORMAT_JOIN_COMMENTLINES = new LemminxPreference("format/joinCommentLines");

// Validation settings
public static final LemminxPreference XML_PREFERENCES_VALIDATION_ENABLED = new LemminxPreference("validation/enabled");
public static final LemminxPreference XML_PREFERENCES_VALIDATION_NAMESPACES_ENABLED = new LemminxPreference("validation/namespaces/enabled");
public static final LemminxPreference XML_PREFERENCES_VALIDATION_SCHEMA_ENABLED = new LemminxPreference("validation/schema/enabled");
public static final LemminxPreference XML_PREFERENCES_VALIDATION_DISALLOW_DOCTYPE_DECL = new LemminxPreference("validation/disallowDocTypeDecl");
public static final LemminxPreference XML_PREFERENCES_VALIDATION_RESOLVE_EXTERNAL_ENTITIES = new LemminxPreference("validation/resolveExternalEntities");
public static final LemminxPreference XML_PREFERENCES_VALIDATION_NO_GRAMMAR = new LemminxPreference("validation/noGrammar");
public static final LemminxPreference XML_PREFERENCES_FOLDING_INCLUDE_CLOSING_TAG_IN_FOLD = new LemminxPreference("foldings/includeClosingTagInFold");

private static final LemminxPreference[] ALL_LEMMINX_PREFERENCES = {
XML_PREFERENCES_CATAGLOGS,
XML_PREFERENCES_CODELENS_ENABLED,
XML_PREFERENCES_FOLDING_INCLUDE_CLOSING_TAG_IN_FOLD,
XML_PREFERENCES_FORMAT_EMPTY_ELEMENTS,
XML_PREFERENCES_FORMAT_SPACE_BEFORE_EMPTY_CLOSE_TAG,
XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES,
XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES_INDENT_SIZE,
XML_PREFERENCES_FORMAT_PRESERVE_ATTRIBUTE_LINE_BREAKS,
XML_PREFERENCES_FORMAT_CLOSING_BRACKET_NEW_LINE,
XML_PREFERENCES_FORMAT_XSI_SCHEMA_LOCATION_SPLIT,
XML_PREFERENCES_FORMAT_JOIN_COMMENTLINES,
XML_PREFERENCES_VALIDATION_ENABLED,
XML_PREFERENCES_VALIDATION_NAMESPACES_ENABLED,
XML_PREFERENCES_VALIDATION_SCHEMA_ENABLED,
XML_PREFERENCES_VALIDATION_DISALLOW_DOCTYPE_DECL,
XML_PREFERENCES_VALIDATION_RESOLVE_EXTERNAL_ENTITIES,
XML_PREFERENCES_VALIDATION_NO_GRAMMAR,
XML_PREFERENCES_FOLDING_INCLUDE_CLOSING_TAG_IN_FOLD
XML_PREFERENCES_VALIDATION_NO_GRAMMAR
};

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

public static void storePreferencesToLemminxOptions(IPreferenceStore store, Map<String, Object> xmlOpts) {
// Catalo settings
XML_PREFERENCES_CATAGLOGS.storeToLemminxOptions(
XMLCatalogs.getAllCatalogs(store).stream().map(File::getAbsolutePath).toArray(String[]::new),
xmlOpts);

// CodeLens settings
XML_PREFERENCES_CODELENS_ENABLED.storeToLemminxOptions(store.getBoolean(XML_PREFERENCES_CODELENS_ENABLED.preferenceId), xmlOpts);

// Folding settings
XML_PREFERENCES_FOLDING_INCLUDE_CLOSING_TAG_IN_FOLD.storeToLemminxOptions(store.getBoolean(XML_PREFERENCES_FOLDING_INCLUDE_CLOSING_TAG_IN_FOLD.preferenceId), xmlOpts);

// Format settings
XML_PREFERENCES_FORMAT_EMPTY_ELEMENTS.storeToLemminxOptions(store.getString(XML_PREFERENCES_FORMAT_EMPTY_ELEMENTS.preferenceId), xmlOpts);
XML_PREFERENCES_FORMAT_SPACE_BEFORE_EMPTY_CLOSE_TAG.storeToLemminxOptions(store.getBoolean(XML_PREFERENCES_FORMAT_SPACE_BEFORE_EMPTY_CLOSE_TAG.preferenceId), xmlOpts);
XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES.storeToLemminxOptions(store.getBoolean(XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES.preferenceId), xmlOpts);
XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES_INDENT_SIZE.storeToLemminxOptions(store.getInt(XML_PREFERENCES_FORMAT_SPLIT_ATTRIBUTES_INDENT_SIZE.preferenceId), xmlOpts);
XML_PREFERENCES_FORMAT_PRESERVE_ATTRIBUTE_LINE_BREAKS.storeToLemminxOptions(store.getBoolean(XML_PREFERENCES_FORMAT_PRESERVE_ATTRIBUTE_LINE_BREAKS.preferenceId), xmlOpts);
XML_PREFERENCES_FORMAT_CLOSING_BRACKET_NEW_LINE.storeToLemminxOptions(store.getBoolean(XML_PREFERENCES_FORMAT_CLOSING_BRACKET_NEW_LINE.preferenceId), xmlOpts);
XML_PREFERENCES_FORMAT_XSI_SCHEMA_LOCATION_SPLIT.storeToLemminxOptions(store.getString(XML_PREFERENCES_FORMAT_XSI_SCHEMA_LOCATION_SPLIT.preferenceId), xmlOpts);
XML_PREFERENCES_FORMAT_JOIN_COMMENTLINES.storeToLemminxOptions(store.getBoolean(XML_PREFERENCES_FORMAT_JOIN_COMMENTLINES.preferenceId), xmlOpts);

// Validation settings
XML_PREFERENCES_VALIDATION_ENABLED.storeToLemminxOptions(store.getBoolean(XML_PREFERENCES_VALIDATION_ENABLED.preferenceId), xmlOpts);
XML_PREFERENCES_VALIDATION_NAMESPACES_ENABLED.storeToLemminxOptions(store.getString(XML_PREFERENCES_VALIDATION_NAMESPACES_ENABLED.preferenceId), xmlOpts);
XML_PREFERENCES_VALIDATION_SCHEMA_ENABLED.storeToLemminxOptions(store.getString(XML_PREFERENCES_VALIDATION_SCHEMA_ENABLED.preferenceId),
Expand All @@ -105,7 +148,6 @@ public static void storePreferencesToLemminxOptions(IPreferenceStore store, Map<
XML_PREFERENCES_VALIDATION_RESOLVE_EXTERNAL_ENTITIES.storeToLemminxOptions(
store.getBoolean(XML_PREFERENCES_VALIDATION_RESOLVE_EXTERNAL_ENTITIES.preferenceId), xmlOpts);
XML_PREFERENCES_VALIDATION_NO_GRAMMAR.storeToLemminxOptions(store.getString(XML_PREFERENCES_VALIDATION_NO_GRAMMAR.preferenceId),
xmlOpts);
XML_PREFERENCES_FOLDING_INCLUDE_CLOSING_TAG_IN_FOLD.storeToLemminxOptions(store.getBoolean(XML_PREFERENCES_FOLDING_INCLUDE_CLOSING_TAG_IN_FOLD.preferenceId), xmlOpts);
xmlOpts);
}
}
Loading