do not call initWindow() on failed load
This commit is contained in:
parent
1b3bd9314d
commit
d1af93f3b5
3 changed files with 34 additions and 27 deletions
|
@ -51,7 +51,8 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef ORDERED_JSON_H
|
||||
#define ORDERED_JSON_H
|
||||
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
|
@ -240,3 +241,4 @@ protected:
|
|||
|
||||
} // namespace poryjson
|
||||
|
||||
#endif // ORDERED_JSON_H
|
||||
|
|
|
@ -262,6 +262,7 @@ private:
|
|||
|
||||
bool isProgrammaticEventTabChange;
|
||||
bool projectHasUnsavedChanges;
|
||||
bool projectOpenFailure = false;
|
||||
|
||||
MapSortOrder mapSortOrder;
|
||||
|
||||
|
|
|
@ -58,10 +58,11 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
|
||||
this->initWindow();
|
||||
if (!this->openRecentProject()) {
|
||||
// Re-initialize everything to a blank slate if opening the recent project failed.
|
||||
this->initWindow();
|
||||
setWindowDisabled(true);
|
||||
} else {
|
||||
setWindowDisabled(false);
|
||||
on_toolButton_Paint_clicked();
|
||||
}
|
||||
on_toolButton_Paint_clicked();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
@ -118,6 +119,7 @@ void MainWindow::initExtraShortcuts() {
|
|||
|
||||
void MainWindow::initCustomUI() {
|
||||
// Set up the tab bar
|
||||
while (ui->mainTabBar->count()) ui->mainTabBar->removeTab(0);
|
||||
ui->mainTabBar->addTab("Map");
|
||||
ui->mainTabBar->setTabIcon(0, QIcon(QStringLiteral(":/icons/map.ico")));
|
||||
ui->mainTabBar->addTab("Events");
|
||||
|
@ -125,12 +127,19 @@ void MainWindow::initCustomUI() {
|
|||
ui->mainTabBar->addTab("Connections");
|
||||
ui->mainTabBar->addTab("Wild Pokemon");
|
||||
ui->mainTabBar->setTabIcon(4, QIcon(QStringLiteral(":/icons/tall_grass.ico")));
|
||||
}
|
||||
|
||||
void MainWindow::initExtraSignals() {
|
||||
// Right-clicking on items in the map list tree view brings up a context menu.
|
||||
ui->mapList->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui->mapList, SIGNAL(customContextMenuRequested(const QPoint &)),
|
||||
this, SLOT(onOpenMapListContextMenu(const QPoint &)));
|
||||
|
||||
// other signals
|
||||
connect(ui->newEventToolButton, SIGNAL(newEventAdded(QString)), this, SLOT(addNewEvent(QString)));
|
||||
connect(ui->tabWidget_EventType, &QTabWidget::currentChanged, this, &MainWindow::eventTabChanged);
|
||||
|
||||
// Change pages on wild encounter groups
|
||||
QStackedWidget *stack = ui->stackedWidget_WildMons;
|
||||
QComboBox *labelCombo = ui->comboBox_EncounterGroupLabel;
|
||||
connect(labelCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index){
|
||||
|
@ -151,11 +160,6 @@ void MainWindow::initCustomUI() {
|
|||
ui->frame_mapTools->setLayout(flowLayout);
|
||||
}
|
||||
|
||||
void MainWindow::initExtraSignals() {
|
||||
connect(ui->newEventToolButton, SIGNAL(newEventAdded(QString)), this, SLOT(addNewEvent(QString)));
|
||||
connect(ui->tabWidget_EventType, &QTabWidget::currentChanged, this, &MainWindow::eventTabChanged);
|
||||
}
|
||||
|
||||
void MainWindow::initEditor() {
|
||||
this->editor = new Editor(ui);
|
||||
connect(this->editor, SIGNAL(objectsChanged()), this, SLOT(updateObjects()));
|
||||
|
@ -394,6 +398,7 @@ bool MainWindow::openRecentProject() {
|
|||
|
||||
bool MainWindow::openProject(QString dir) {
|
||||
if (dir.isNull()) {
|
||||
projectOpenFailure = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -450,13 +455,12 @@ bool MainWindow::openProject(QString dir) {
|
|||
Scripting::cb_ProjectOpened(dir);
|
||||
}
|
||||
|
||||
setWindowDisabled(false);
|
||||
|
||||
projectOpenFailure = !success;
|
||||
return success;
|
||||
}
|
||||
|
||||
bool MainWindow::isProjectOpen() {
|
||||
return editor != nullptr && editor->project != nullptr;
|
||||
return !projectOpenFailure && editor && editor->project;
|
||||
}
|
||||
|
||||
QString MainWindow::getDefaultMap() {
|
||||
|
@ -500,9 +504,7 @@ void MainWindow::on_action_Open_Project_triggered()
|
|||
this->ui->graphicsView_Map->overlay.clearItems();
|
||||
}
|
||||
porymapConfig.setRecentProject(dir);
|
||||
if (!openProject(dir)) {
|
||||
this->initWindow();
|
||||
}
|
||||
setWindowDisabled(!openProject(dir));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2666,19 +2668,22 @@ void MainWindow::closeSupplementaryWindows() {
|
|||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event) {
|
||||
if (projectHasUnsavedChanges || (editor->map && editor->map->hasUnsavedChanges())) {
|
||||
QMessageBox::StandardButton result = QMessageBox::question(
|
||||
this, "porymap", "The project has been modified, save changes?",
|
||||
QMessageBox::No | QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes);
|
||||
if (isProjectOpen()) {
|
||||
if (projectHasUnsavedChanges || (editor->map && editor->map->hasUnsavedChanges())) {
|
||||
QMessageBox::StandardButton result = QMessageBox::question(
|
||||
this, "porymap", "The project has been modified, save changes?",
|
||||
QMessageBox::No | QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes);
|
||||
|
||||
if (result == QMessageBox::Yes) {
|
||||
editor->saveProject();
|
||||
} else if (result == QMessageBox::No) {
|
||||
logWarn("Closing porymap with unsaved changes.");
|
||||
} else if (result == QMessageBox::Cancel) {
|
||||
event->ignore();
|
||||
return;
|
||||
if (result == QMessageBox::Yes) {
|
||||
editor->saveProject();
|
||||
} else if (result == QMessageBox::No) {
|
||||
logWarn("Closing porymap with unsaved changes.");
|
||||
} else if (result == QMessageBox::Cancel) {
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
}
|
||||
projectConfig.save();
|
||||
}
|
||||
|
||||
porymapConfig.setMainGeometry(
|
||||
|
@ -2688,7 +2693,6 @@ void MainWindow::closeEvent(QCloseEvent *event) {
|
|||
this->ui->splitter_main->saveState()
|
||||
);
|
||||
porymapConfig.save();
|
||||
projectConfig.save();
|
||||
|
||||
QMainWindow::closeEvent(event);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue