Skip to content

Commit

Permalink
fix #21922 - patch by Bjoeni - GPX file marked as modified when savin…
Browse files Browse the repository at this point in the history
…g session

git-svn-id: https://josm.openstreetmap.de/svn/trunk@18399 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
stoecker committed Mar 13, 2022
1 parent ff2c2a3 commit 5b52f88
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
30 changes: 24 additions & 6 deletions src/org/openstreetmap/josm/data/gpx/GpxData.java
Original file line number Diff line number Diff line change
Expand Up @@ -1092,10 +1092,29 @@ public synchronized boolean equals(Object obj) {
return true;
}

/**
* Put a key / value pair as a new attribute. Overrides key / value pair with the same key (if present).
*
* @param key the key
* @param value the value
*/
@Override
public void put(String key, Object value) {
put(key, value, true);
}

/**
* Put a key / value pair as a new attribute. Overrides key / value pair with the same key (if present).
* Only sets the modified state when setModified is true.
*
* @param key the key
* @param value the value
* @param setModified whether to change the modified state
* @since 18399
*/
public void put(String key, Object value, boolean setModified) {
super.put(key, value);
invalidate();
fireInvalidate(setModified);
}

/**
Expand Down Expand Up @@ -1132,12 +1151,12 @@ public void invalidate() {
}

private void fireInvalidate(boolean setModified) {
if (setModified) {
setModified(true);
}
if (updating || initializing) {
suppressedInvalidate = true;
} else {
if (setModified) {
setModified(true);
}
if (listeners.hasListeners()) {
GpxDataChangeEvent e = new GpxDataChangeEvent(this);
listeners.fireEvent(l -> l.gpxDataChanged(e));
Expand All @@ -1158,10 +1177,9 @@ public void beginUpdate() {
* @since 15496
*/
public void endUpdate() {
boolean setModified = updating;
updating = initializing = false;
if (suppressedInvalidate) {
fireInvalidate(setModified);
fireInvalidate(false);
suppressedInvalidate = false;
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/org/openstreetmap/josm/data/gpx/GpxTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,21 @@ private Bounds calculateBounds() {

@Override
public void setColor(Color color) {
setColorExtension(color);
setColorExtensionGPXD(color, true);
colorCache = color;
}

private void setColorExtension(Color color) {
private void setColorExtensionGPXD(Color color, boolean invalidate) {
getExtensions().findAndRemove("gpxx", "DisplayColor");
if (color == null) {
getExtensions().findAndRemove("gpxd", "color");
} else {
getExtensions().addOrUpdate("gpxd", "color", String.format("#%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue()));
}
fireInvalidate();
colorFormat = ColorFormat.GPXD;
if (invalidate) {
fireInvalidate();
}
}

@Override
Expand Down Expand Up @@ -167,7 +170,7 @@ public void convertColor(ColorFormat cFormat) {
closestGarminColorCache.put(c, colorString);
getExtensions().addIfNotPresent("gpxx", "TrackExtension").getExtensions().addOrUpdate("gpxx", "DisplayColor", colorString);
} else if (cFormat == ColorFormat.GPXD) {
setColor(c);
setColorExtensionGPXD(c, false);
}
colorFormat = cFormat;
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/openstreetmap/josm/io/GpxWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void write(GpxData data, ColorFormat colorFormat, boolean savePrefs) {
e.put("value", entry.getValue());
});
}
data.put(META_TIME, (metaTime != null ? metaTime : Instant.now()).toString());
data.put(META_TIME, (metaTime != null ? metaTime : Instant.now()).toString(), false);
data.endUpdate();

Collection<IWithAttributes> all = new ArrayList<>();
Expand Down

0 comments on commit 5b52f88

Please sign in to comment.