diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui
index d92666d5..8c0c1b40 100644
--- a/forms/mainwindow.ui
+++ b/forms/mainwindow.ui
@@ -561,7 +561,7 @@
0
0
- 545
+ 542
628
@@ -767,7 +767,7 @@
8
0
- 221
+ 224
324
@@ -1118,7 +1118,7 @@
0
0
- 231
+ 234
83
@@ -2886,6 +2886,7 @@
File
+
@@ -3172,6 +3173,11 @@
Themes...
+
+
+ Reload Project
+
+
diff --git a/include/mainwindow.h b/include/mainwindow.h
index 02f12cfa..fd5ecef8 100644
--- a/include/mainwindow.h
+++ b/include/mainwindow.h
@@ -42,6 +42,7 @@ public slots:
private slots:
void on_action_Open_Project_triggered();
+ void on_action_Reload_Project_triggered();
void on_mapList_activated(const QModelIndex &index);
void on_action_Save_Project_triggered();
void openWarpMap(QString map_name, QString warp_num);
diff --git a/include/project.h b/include/project.h
index 5fec4a1b..431d94df 100644
--- a/include/project.h
+++ b/include/project.h
@@ -64,6 +64,9 @@ public:
void set_root(QString);
+ void clearMapCache();
+ void clearTilesetCache();
+
struct DataQualifiers
{
bool isStatic;
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 40b8b364..d304ada9 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -306,7 +306,10 @@ bool MainWindow::openProject(QString dir) {
&& populateMapList()
&& setMap(getDefaultMap(), true);
} else {
- success = loadDataStructures() && populateMapList() && setMap(editor->map->name, true);
+ QString open_map = editor->map->name;
+ editor->project->clearMapCache();
+ editor->project->clearTilesetCache();
+ success = loadDataStructures() && populateMapList() && setMap(open_map, true);
}
if (success) {
@@ -373,6 +376,19 @@ void MainWindow::on_action_Open_Project_triggered()
}
}
+void MainWindow::on_action_Reload_Project_triggered() {
+ // TODO: when undo history is complete show only if has unsaved changes
+ QMessageBox warning(this);
+ warning.setText("WARNING");
+ warning.setInformativeText("Reloading this project will discard any unsaved changes.");
+ warning.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
+ warning.setIcon(QMessageBox::Warning);
+
+ if (warning.exec() == QMessageBox::Ok) {
+ openProject(editor->project->root);
+ }
+}
+
bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
logInfo(QString("Setting map to '%1'").arg(map_name));
if (map_name.isEmpty()) {
diff --git a/src/project.cpp b/src/project.cpp
index f04f3870..533221b7 100644
--- a/src/project.cpp
+++ b/src/project.cpp
@@ -77,7 +77,9 @@ Project::~Project()
delete this->mapConstantsToMapNames;
delete this->mapNamesToMapConstants;
+ clearMapCache();
delete this->mapCache;
+ clearTilesetCache();
delete this->tilesetCache;
}
@@ -94,6 +96,20 @@ QString Project::getProjectTitle() {
}
}
+void Project::clearMapCache() {
+ for (QString mapName : mapCache->keys()) {
+ Map *map = mapCache->take(mapName);
+ if (map) delete map;
+ }
+}
+
+void Project::clearTilesetCache() {
+ for (QString tilesetName : tilesetCache->keys()) {
+ Tileset *tileset = tilesetCache->take(tilesetName);
+ if (tileset) delete tileset;
+ }
+}
+
Map* Project::loadMap(QString map_name) {
Map *map;
if (mapCache->contains(map_name)) {