#19056 closed enhancement (fixed)
[PATCH] Add method for simpler SequenceCommands
Reported by: | taylor.smock | Owned by: | team |
---|---|---|---|
Priority: | normal | Milestone: | 20.06 |
Component: | Core | Version: | |
Keywords: | command | Cc: |
Description
Use case:
You build a series of commands, each of which may have a series of subcommands. It would be nice if, instead of creating a SequenceCommand for a single command, if there was a way to just get the original command.
In the MapWithAI plugin, I've added logic that is essentially if (commands.size() == 1) return commands.get(0); else return new SequenceCommand(desc, commands);
.
The attached patch adds two new static methods to SequenceCommand
, both of which take the same arguments as a new
object would. They return the singular command, or a sequence command.
It also makes a modification to the DeleteCommand.delete
method so that if no ChangeCommand
is created, it just returns a DeleteCommand
.
Attachments (2)
Change History (7)
by , 5 years ago
Attachment: | 19056.patch added |
---|
comment:1 by , 4 years ago
comment:2 by , 4 years ago
Possibly. I think I just modified one command in core where it made sense (to me). I do like wrapIfNeeded
over createSimplifiedSequenceCommand
. It is shorter and clearer.
In one of my plugins, I have a bunch of if (list.size() == 1) return list.get(0); else if (!list.isEmpty()) return new SequenceCommand(list, message); else return null;
. This is mostly so I don't have trees of SequenceCommands
when debugging. I kind of figured that other people might find it useful in core/other plugins.
comment:5 by , 4 years ago
Milestone: | → 20.06 |
---|
Sometimes, wrapping even just one command is intended for a more descriptive command name, e.g.,
org.openstreetmap.josm.actions.CombineWayAction
.I'm unsure whether having just one occurrence in JOSM core justifies this addition… Maybe
wrapIfNeeded
would be a more precise function name?