Skip to content

Commit

Permalink
Add potential issues to TODO list, if the TODO plugin is installed
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <[email protected]>
  • Loading branch information
tsmock committed Nov 6, 2024
1 parent b9a2772 commit f710db6
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@
import org.openstreetmap.josm.data.osm.OsmPrimitive;
import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.data.osm.WaySegment;
import org.openstreetmap.josm.data.osm.search.SearchCompiler;
import org.openstreetmap.josm.data.osm.search.SearchParseError;
import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.util.GuiHelper;
import org.openstreetmap.josm.tools.Geometry;
import org.openstreetmap.josm.tools.JosmRuntimeException;
import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.SubclassFilteredCollection;

/**
* The actual class for modifying ways
Expand Down Expand Up @@ -127,7 +131,7 @@ public void run() {
newWays = DownloadAdditionalWays.getAdditionalWays(wayChangingName, originalName);
}
}
newWays = newWays.thenApplyAsync(ignored -> {
newWays.thenApplyAsync(ignored -> {
for (OsmPrimitive osm : wayChangingName) {
if (originalName != null) {
doRealRun(osm, originalName);
Expand All @@ -140,17 +144,25 @@ public void run() {
}
}
return ignored;
});
if (Boolean.TRUE.equals(this.recursive)) {
newWays.thenApplyAsync(primitives -> {
List<OsmPrimitive> toChange = primitives.stream().filter(p -> p.hasTag("name", this.originalName))
.collect(Collectors.toList());
}).thenApplyAsync(primitives -> {
List<OsmPrimitive> toChange = primitives.stream().filter(p -> p.hasTag("name", this.originalName))
.collect(Collectors.toList());
if (Boolean.TRUE.equals(this.recursive) && !toChange.isEmpty()) {
final ChangePropertyCommand changePropertyCommand = new ChangePropertyCommand(toChange, "name",
wayChangingName.iterator().next().get("name"));
GuiHelper.runInEDT(() -> UndoRedoHandler.getInstance().add(changePropertyCommand));
return primitives;
});
}
} else if (toChange.isEmpty() || !Boolean.TRUE.equals(this.recursive)) {
try {
final DataSet ds = this.wayChangingName.iterator().next().getDataSet();
ds.setSelected(SubclassFilteredCollection.filter(ds.allPrimitives(),
SearchCompiler.compile(this.originalName)));
TodoHelper.addTodoItems();
} catch (SearchParseError searchParseError) {
throw new JosmRuntimeException(searchParseError);
}
}
return primitives;
});
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
Logging.error(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.highwaynamemodification;

import java.lang.reflect.Field;

import javax.swing.AbstractListModel;

import org.openstreetmap.josm.actions.JosmAction;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
import org.openstreetmap.josm.plugins.PluginException;
import org.openstreetmap.josm.plugins.PluginInformation;
import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.ReflectionUtils;

/**
* Helper for the TODO plugin (so we don't <i>have</i> to depend upon it)
*/
public final class TodoHelper {
private static final Class<? extends ToggleDialog> CLASS;
private static final Field ACT_ADD;
private static final Field MODEL;
static {
Class<? extends ToggleDialog> clazz = null;
Field actAdd = null;
Field model = null;
try {
final PluginInformation info = PluginInformation.findPlugin("todo");
if (info != null) {
clazz = (Class<? extends ToggleDialog>) Class.forName("org.openstreetmap.josm.plugins.todo.TodoDialog",
false, info.getClass().getClassLoader());
actAdd = clazz.getDeclaredField("actAdd");
model = clazz.getDeclaredField("model");
ReflectionUtils.setObjectsAccessible(actAdd, model);
}
} catch (ClassNotFoundException | PluginException | NoSuchFieldException classNotFoundException) {
Logging.trace(classNotFoundException);
}
ACT_ADD = actAdd;
MODEL = model;
CLASS = clazz;
}

public static void addTodoItems() {
if (CLASS == null || MODEL == null || ACT_ADD == null) {
return;
}
final ToggleDialog todoDialog = MainApplication.getMap().getToggleDialog(CLASS);
try {
AbstractListModel<?> m = (AbstractListModel<?>) MODEL.get(todoDialog);
if (m.getSize() == 0) {
JosmAction a = (JosmAction) ACT_ADD.get(todoDialog);
a.actionPerformed(null);
}
} catch (ReflectiveOperationException e) {
Logging.error(e);
}
}
}

0 comments on commit f710db6

Please sign in to comment.