Modify

Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#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)

19056.patch (2.3 KB ) - added by taylor.smock 5 years ago.
19056.1.patch (2.2 KB ) - added by taylor.smock 4 years ago.
createSimplifiedSequenceCommand -> wrapIfNeeded

Download all attachments as: .zip

Change History (7)

by taylor.smock, 5 years ago

Attachment: 19056.patch added

comment:1 by simon04, 4 years ago

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?

comment:2 by taylor.smock, 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.

by taylor.smock, 4 years ago

Attachment: 19056.1.patch added

createSimplifiedSequenceCommand -> wrapIfNeeded

comment:3 by simon04, 4 years ago

Resolution: fixed
Status: newclosed

In 16573/josm:

fix #19056 - Add SequenceCommand.wrapIfNeeded (patch by taylor.smock)

comment:4 by simon04, 4 years ago

In 16574/josm:

see #19056 - Add SequenceCommandTest.testWrapIfNeeded

comment:5 by simon04, 4 years ago

Milestone: 20.06

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.