Skip to content

Commit

Permalink
Merge branch 'support_label_text_in_optional'
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Aug 23, 2023
2 parents 990f773 + aef3f1a commit a27e29e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
6 changes: 3 additions & 3 deletions documentation/docs/tutorials/presets.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Vespucci Preset System
_Documentation for Vespucci 19.1_
_Documentation for Vespucci 19.2_

As explained in the [help documentation](../help/en/Presets.md) Vespucci uses JOSM compatible presets, currently any preset used in JOSM should simply work with Vespucci, however there can be differences. Particularly with the new preset driven tagging interface presets have become even more important and if you are writing presets yourself and want them to work well in Vespucci please keep on reading.

Expand Down Expand Up @@ -133,10 +133,10 @@ Note: this is loosely based on what [JOSM claims](https://josm.openstreetmap.de/
| | match | supported |
| | match_expression | ignored |
| | use_last_as_default | extension | "force" has the same effect as "true"
|__<label>__ | | ignored |
|__<label>__ | | supported |
|__<space/>__ | | ignored |
|__<optional>__ | | supported | contained fields are not displayed the in "Properties" tab when a preset is applied except if applying with optional fields is used, further matching ignores any optional fields
| | text | ignored | not displayed
| | text | supported |
|__<separator/>__ | | supported | starts a new row in the preset selection display
|__<item_separator/>__ | | ignored |
|__<link>__ | | supported | not legal inside <chunk> elements
Expand Down
32 changes: 25 additions & 7 deletions src/main/java/de/blau/android/presets/PresetParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ static void parseXML(@NonNull Preset preset, @NonNull InputStream input, boolean
private int checkGroupCounter = 0;
/** */
private String currentLabel = null;
private boolean addedLabel = false;

/**
* ${@inheritDoc}.
Expand Down Expand Up @@ -304,6 +305,7 @@ private void parseItem(@NonNull String name, @NonNull Attributes attr) throws SA
switch (name) {
case OPTIONAL:
inOptionalSection = true;
currentLabel = addLabelField(supportLabels, attr);
break;
case KEY_ATTR:
String key = attr.getValue(KEY_ATTR);
Expand Down Expand Up @@ -396,12 +398,7 @@ private void parseItem(@NonNull String name, @NonNull Attributes attr) throws SA
}
break;
case LABEL:
currentLabel = attr.getValue(TEXT);
if (supportLabels) {
PresetLabelField labelField = new PresetLabelField(currentLabel, attr.getValue(TEXT_CONTEXT));
currentItem.addField(labelField);
labelField.setOptional(inOptionalSection);
}
currentLabel = addLabelField(supportLabels, attr);
break;
case CHECKGROUP:
checkGroup = new PresetCheckGroupField(currentItem.getName() + PresetCheckGroupField.class.getSimpleName() + checkGroupCounter);
Expand Down Expand Up @@ -619,9 +616,30 @@ private void parseItem(@NonNull String name, @NonNull Attributes attr) throws SA
Log.w(DEBUG_TAG, "Unknown start tag in preset item " + name);
}
// always zap label after next element
if (!LABEL.equals(name)) {
if (!addedLabel) {
currentLabel = null;
} else {
addedLabel = false;
}
}

/**
* Extract the label text and add a field if supportLabels is true
*
* @param supportLabels flag
* @param attr XML attributes
* @return the label text or null
*/
@Nullable
private String addLabelField(boolean supportLabels, @NonNull Attributes attr) {
String labelText = attr.getValue(TEXT);
if (supportLabels && labelText != null) {
PresetLabelField labelField = new PresetLabelField(labelText, attr.getValue(TEXT_CONTEXT));
currentItem.addField(labelField);
labelField.setOptional(inOptionalSection);
addedLabel = true;
}
return labelText;
}

/**
Expand Down

0 comments on commit a27e29e

Please sign in to comment.