diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 29e08e22e4..29da0372b3 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -196,6 +196,8 @@ MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags)
mUi->mapView->zoomable(), SLOT(resetZoom()));
connect(mUi->actionNewTileset, SIGNAL(triggered()), SLOT(newTileset()));
+ connect(mUi->actionAddExternalTileset, SIGNAL(triggered()),
+ SLOT(addExternalTileset()));
connect(mUi->actionResizeMap, SIGNAL(triggered()), SLOT(resizeMap()));
connect(mUi->actionOffsetMap, SIGNAL(triggered()), SLOT(offsetMap()));
connect(mUi->actionMapProperties, SIGNAL(triggered()),
@@ -626,6 +628,28 @@ void MainWindow::newTileset()
mMapDocument->undoStack()->push(new AddTileset(mMapDocument, tileset));
}
+void MainWindow::addExternalTileset()
+{
+ if (!mMapDocument)
+ return;
+
+ const QString start = fileDialogStartLocation();
+ const QString fileName =
+ QFileDialog::getOpenFileName(this, tr("Add External Tileset"),
+ start,
+ tr("Tiled tileset files (*.tsx)"));
+ if (fileName.isEmpty())
+ return;
+
+ TmxMapReader reader;
+ if (Tileset *tileset = reader.readTileset(fileName)) {
+ mMapDocument->undoStack()->push(new AddTileset(mMapDocument, tileset));
+ } else {
+ QMessageBox::critical(this, tr("Error Reading Tileset"),
+ reader.errorString());
+ }
+}
+
void MainWindow::resizeMap()
{
if (!mMapDocument)
diff --git a/src/mainwindow.h b/src/mainwindow.h
index bbe34bea41..5bb803ffcc 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -102,6 +102,7 @@ private slots:
void openPreferences();
void newTileset();
+ void addExternalTileset();
void resizeMap();
void offsetMap();
void editMapProperties();
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index 03b7baeae1..a40576f494 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -99,6 +99,7 @@
&Map
+
@@ -354,6 +355,11 @@
&Export As...
+
+
+ &Add External Tileset...
+
+
diff --git a/src/tmxmapreader.cpp b/src/tmxmapreader.cpp
index e0d7ce5a4b..9063a29564 100644
--- a/src/tmxmapreader.cpp
+++ b/src/tmxmapreader.cpp
@@ -789,3 +789,15 @@ Map *TmxMapReader::fromString(const QString &string)
return map;
}
+
+Tileset *TmxMapReader::readTileset(const QString &fileName)
+{
+ mError.clear();
+
+ TmxReader reader;
+ Tileset *tileset = reader.readTileset(fileName);
+ if (!tileset)
+ mError = reader.errorString();
+
+ return tileset;
+}
diff --git a/src/tmxmapreader.h b/src/tmxmapreader.h
index c4283ae293..ce2dae69d5 100644
--- a/src/tmxmapreader.h
+++ b/src/tmxmapreader.h
@@ -27,6 +27,9 @@
#include
namespace Tiled {
+
+class Tileset;
+
namespace Internal {
/**
@@ -47,6 +50,8 @@ class TmxMapReader : public MapReaderInterface
*/
Map *fromString(const QString &string);
+ Tileset *readTileset(const QString &fileName);
+
QString nameFilter() const { return tr("Tiled map files (*.tmx)"); }
QString errorString() const { return mError; }