From b84283f50ae0e2d1db1bdea1be2dac12660768a5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Perrin?= Date: Sun, 30 Dec 2018 13:39:17 +0000 Subject: [PATCH] Duplicate point before converting it to waypoint --- src/tim/prune/function/edit/PointEditor.java | 13 +++++++++++ .../prune/function/edit/PointNameEditor.java | 22 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/tim/prune/function/edit/PointEditor.java b/src/tim/prune/function/edit/PointEditor.java index c66201b..546a65e 100644 --- a/src/tim/prune/function/edit/PointEditor.java +++ b/src/tim/prune/function/edit/PointEditor.java @@ -307,10 +307,23 @@ public class PointEditor if (_model.getChanged(i)) { Field field = fieldList.getField(i); + if (field == field.WAYPT_NAME) { + if (wasNameAdded(_model.getValue(i))) { + _app.createPoint(_point.clonePoint()); + } + } editList.addEdit(new FieldEdit(field, _model.getValue(i))); undoList.addEdit(new FieldEdit(field, _point.getFieldValue(field))); } } _app.completePointEdit(editList, undoList); } + + private boolean wasNameAdded(String newName) + { + String prevName = _point.getWaypointName(); + boolean prevNull = (prevName == null || prevName.equals("")); + boolean newNull = (newName == null || newName.equals("")); + return (prevNull && !newNull); + } } diff --git a/src/tim/prune/function/edit/PointNameEditor.java b/src/tim/prune/function/edit/PointNameEditor.java index 53e1f83..ca5771d 100644 --- a/src/tim/prune/function/edit/PointNameEditor.java +++ b/src/tim/prune/function/edit/PointNameEditor.java @@ -206,7 +206,14 @@ public class PointNameEditor extends GenericFunction // Check whether name has really changed if (hasNameChanged()) { - // Make lists for edit and undo, and add the changed field + // If a new name has been added, changing the point + // from trackpoint to waypoint, duplicate it + if (wasNameAdded()) + { + _app.createPoint(_point.clonePoint()); + } + + // make lists for edit and undo, and add the changed field FieldEditList editList = new FieldEditList(); FieldEditList undoList = new FieldEditList(); editList.addEdit(new FieldEdit(Field.WAYPT_NAME, _nameField.getText().trim())); @@ -231,4 +238,17 @@ public class PointNameEditor extends GenericFunction || (!prevNull && newNull) || (!prevNull && !newNull && !prevName.equals(newName)); } + + /** + * Check whether a new name has been added + * @return true if it has indeed + */ + private boolean wasNameAdded() + { + String prevName = _point.getWaypointName(); + String newName = _nameField.getText().trim(); + boolean prevNull = (prevName == null || prevName.equals("")); + boolean newNull = (newName == null || newName.equals("")); + return (prevNull && !newNull); + } } -- 2.43.0