Skip to content

Commit

Permalink
Merge pull request #4589 from kwvanderlinde/bugfix/4585-clear-drawabl…
Browse files Browse the repository at this point in the history
…es-unsupported-operation

Better encapsulated version of Zone.clearDrawables()
  • Loading branch information
cwisniew authored Dec 30, 2023
2 parents 736655e + 89140ba commit 942ee09
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -966,9 +966,8 @@ private void handle(ClearAllDrawingsMsg clearAllDrawingsMsg) {
() -> {
var zoneGUID = GUID.valueOf(clearAllDrawingsMsg.getZoneGuid());
var layer = Zone.Layer.valueOf(clearAllDrawingsMsg.getLayer());

var zone = MapTool.getCampaign().getZone(zoneGUID);
zone.clearDrawables(zone.getDrawnElements(layer));
zone.clearDrawables(layer);
MapTool.getFrame().refresh();
});
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/net/rptools/maptool/model/Zone.java
Original file line number Diff line number Diff line change
Expand Up @@ -1492,12 +1492,15 @@ private void removeDrawable(List<DrawnElement> drawableList, GUID drawableId) {
}
}

public void clearDrawables(List<DrawnElement> drawableList) {
for (DrawnElement drawable : drawableList) {
public void clearDrawables(Layer layer) {
final var original = drawablesByLayer.get(layer);
final var copy = new ArrayList<>(original);
original.clear();
undo.clear(); // clears the *entire* undo queue, but finer grained control isn't available

for (final var drawable : copy) {
new MapToolEventBus().getMainEventBus().post(new DrawableRemoved(this, drawable));
}
drawableList.clear();
undo.clear(); // clears the *entire* undo queue, but finer grained control isn't available
}

public void addDrawable(Pen pen, Drawable drawable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,7 @@ private void handle(ClearAllDrawingsMsg clearAllDrawingsMsg) {
var zoneGUID = GUID.valueOf(clearAllDrawingsMsg.getZoneGuid());
var layer = Zone.Layer.valueOf(clearAllDrawingsMsg.getLayer());
Zone zone = server.getCampaign().getZone(zoneGUID);
List<DrawnElement> list = zone.getDrawnElements(layer);
zone.clearDrawables(list); // FJE Empties the DrawableUndoManager and empties the list
zone.clearDrawables(layer);
});
}

Expand Down

0 comments on commit 942ee09

Please sign in to comment.