Skip to content

Commit 5b52f88

Browse files
author
stoecker
committed
fix #21922 - patch by Bjoeni - GPX file marked as modified when saving session
git-svn-id: https://josm.openstreetmap.de/svn/trunk@18399 0c6e7542-c601-0410-84e7-c038aed88b3b
1 parent ff2c2a3 commit 5b52f88

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

src/org/openstreetmap/josm/data/gpx/GpxData.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,10 +1092,29 @@ public synchronized boolean equals(Object obj) {
10921092
return true;
10931093
}
10941094

1095+
/**
1096+
* Put a key / value pair as a new attribute. Overrides key / value pair with the same key (if present).
1097+
*
1098+
* @param key the key
1099+
* @param value the value
1100+
*/
10951101
@Override
10961102
public void put(String key, Object value) {
1103+
put(key, value, true);
1104+
}
1105+
1106+
/**
1107+
* Put a key / value pair as a new attribute. Overrides key / value pair with the same key (if present).
1108+
* Only sets the modified state when setModified is true.
1109+
*
1110+
* @param key the key
1111+
* @param value the value
1112+
* @param setModified whether to change the modified state
1113+
* @since 18399
1114+
*/
1115+
public void put(String key, Object value, boolean setModified) {
10971116
super.put(key, value);
1098-
invalidate();
1117+
fireInvalidate(setModified);
10991118
}
11001119

11011120
/**
@@ -1132,12 +1151,12 @@ public void invalidate() {
11321151
}
11331152

11341153
private void fireInvalidate(boolean setModified) {
1154+
if (setModified) {
1155+
setModified(true);
1156+
}
11351157
if (updating || initializing) {
11361158
suppressedInvalidate = true;
11371159
} else {
1138-
if (setModified) {
1139-
setModified(true);
1140-
}
11411160
if (listeners.hasListeners()) {
11421161
GpxDataChangeEvent e = new GpxDataChangeEvent(this);
11431162
listeners.fireEvent(l -> l.gpxDataChanged(e));
@@ -1158,10 +1177,9 @@ public void beginUpdate() {
11581177
* @since 15496
11591178
*/
11601179
public void endUpdate() {
1161-
boolean setModified = updating;
11621180
updating = initializing = false;
11631181
if (suppressedInvalidate) {
1164-
fireInvalidate(setModified);
1182+
fireInvalidate(false);
11651183
suppressedInvalidate = false;
11661184
}
11671185
}

src/org/openstreetmap/josm/data/gpx/GpxTrack.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,21 @@ private Bounds calculateBounds() {
8282

8383
@Override
8484
public void setColor(Color color) {
85-
setColorExtension(color);
85+
setColorExtensionGPXD(color, true);
8686
colorCache = color;
8787
}
8888

89-
private void setColorExtension(Color color) {
89+
private void setColorExtensionGPXD(Color color, boolean invalidate) {
9090
getExtensions().findAndRemove("gpxx", "DisplayColor");
9191
if (color == null) {
9292
getExtensions().findAndRemove("gpxd", "color");
9393
} else {
9494
getExtensions().addOrUpdate("gpxd", "color", String.format("#%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue()));
9595
}
96-
fireInvalidate();
96+
colorFormat = ColorFormat.GPXD;
97+
if (invalidate) {
98+
fireInvalidate();
99+
}
97100
}
98101

99102
@Override
@@ -167,7 +170,7 @@ public void convertColor(ColorFormat cFormat) {
167170
closestGarminColorCache.put(c, colorString);
168171
getExtensions().addIfNotPresent("gpxx", "TrackExtension").getExtensions().addOrUpdate("gpxx", "DisplayColor", colorString);
169172
} else if (cFormat == ColorFormat.GPXD) {
170-
setColor(c);
173+
setColorExtensionGPXD(c, false);
171174
}
172175
colorFormat = cFormat;
173176
}

src/org/openstreetmap/josm/io/GpxWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void write(GpxData data, ColorFormat colorFormat, boolean savePrefs) {
123123
e.put("value", entry.getValue());
124124
});
125125
}
126-
data.put(META_TIME, (metaTime != null ? metaTime : Instant.now()).toString());
126+
data.put(META_TIME, (metaTime != null ? metaTime : Instant.now()).toString(), false);
127127
data.endUpdate();
128128

129129
Collection<IWithAttributes> all = new ArrayList<>();

0 commit comments

Comments
 (0)