diff --git a/src/tiled/changemapobject.cpp b/src/tiled/changemapobject.cpp index 4ea3a389da3..950b680bd64 100644 --- a/src/tiled/changemapobject.cpp +++ b/src/tiled/changemapobject.cpp @@ -115,6 +115,18 @@ ChangeMapObjectsTile::ChangeMapObjectsTile(MapDocument *mapDocument, } } +void ChangeMapObjectsTile::undo() +{ + restoreTiles(); + QUndoCommand::undo(); // undo child commands +} + +void ChangeMapObjectsTile::redo() +{ + QUndoCommand::redo(); // redo child commands + changeTiles(); +} + static void setObjectCell(MapObject *object, const Cell &cell, const bool updateSize) diff --git a/src/tiled/changemapobject.h b/src/tiled/changemapobject.h index 5f9308b0484..08009f6c669 100644 --- a/src/tiled/changemapobject.h +++ b/src/tiled/changemapobject.h @@ -96,8 +96,8 @@ class ChangeMapObjectsTile : public QUndoCommand const QList &mapObjects, Tile *tile); - void undo() override { restoreTiles(); } - void redo() override { changeTiles(); } + void undo() override; + void redo() override; private: void changeTiles(); diff --git a/src/tiled/tilesetdock.cpp b/src/tiled/tilesetdock.cpp index f55e8a5ade9..ecd3ac26d0c 100644 --- a/src/tiled/tilesetdock.cpp +++ b/src/tiled/tilesetdock.cpp @@ -993,6 +993,15 @@ void TilesetDock::changeSelectedMapObjectsTile(Tile *tile) if (tileObjects.isEmpty()) return; - QUndoStack *undoStack = mMapDocument->undoStack(); - undoStack->push(new ChangeMapObjectsTile(mMapDocument, tileObjects, tile)); + auto changeMapObjectCommand = new ChangeMapObjectsTile(mMapDocument, tileObjects, tile); + + if (Tileset *tileset = tile->tileset()) { + SharedTileset sharedTileset = tileset->sharedPointer(); + + // Make sure this tileset is part of the map + if (!mMapDocument->map()->tilesets().contains(sharedTileset)) + new AddTileset(mMapDocument, sharedTileset, changeMapObjectCommand); + } + + mMapDocument->undoStack()->push(changeMapObjectCommand); }