Fix crash when file watcher message triggers
This commit is contained in:
parent
2ce5c3fcc5
commit
785ac958a5
4 changed files with 44 additions and 50 deletions
|
@ -366,6 +366,7 @@ private:
|
||||||
void scrollMapListToCurrentMap(MapTree *list);
|
void scrollMapListToCurrentMap(MapTree *list);
|
||||||
void scrollMapListToCurrentLayout(MapTree *list);
|
void scrollMapListToCurrentLayout(MapTree *list);
|
||||||
void resetMapListFilters();
|
void resetMapListFilters();
|
||||||
|
void showFileWatcherWarning(QString filepath);
|
||||||
QString getExistingDirectory(QString);
|
QString getExistingDirectory(QString);
|
||||||
bool openProject(QString dir, bool initial = false);
|
bool openProject(QString dir, bool initial = false);
|
||||||
bool closeProject();
|
bool closeProject();
|
||||||
|
|
|
@ -88,8 +88,6 @@ public:
|
||||||
|
|
||||||
void set_root(QString);
|
void set_root(QString);
|
||||||
|
|
||||||
void initSignals();
|
|
||||||
|
|
||||||
void clearMapCache();
|
void clearMapCache();
|
||||||
void clearTilesetCache();
|
void clearTilesetCache();
|
||||||
void clearMapLayouts();
|
void clearMapLayouts();
|
||||||
|
@ -267,8 +265,7 @@ private:
|
||||||
static int max_object_events;
|
static int max_object_events;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void reloadProject();
|
void fileChanged(QString filepath);
|
||||||
void uncheckMonitorFilesAction();
|
|
||||||
void mapLoaded(Map *map);
|
void mapLoaded(Map *map);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -602,13 +602,8 @@ bool MainWindow::openProject(QString dir, bool initial) {
|
||||||
// Create the project
|
// Create the project
|
||||||
auto project = new Project(editor);
|
auto project = new Project(editor);
|
||||||
project->set_root(dir);
|
project->set_root(dir);
|
||||||
QObject::connect(project, &Project::reloadProject, this, &MainWindow::on_action_Reload_Project_triggered);
|
QObject::connect(project, &Project::fileChanged, this, &MainWindow::showFileWatcherWarning);
|
||||||
QObject::connect(project, &Project::mapLoaded, this, &MainWindow::onMapLoaded);
|
QObject::connect(project, &Project::mapLoaded, this, &MainWindow::onMapLoaded);
|
||||||
QObject::connect(project, &Project::uncheckMonitorFilesAction, [this]() {
|
|
||||||
porymapConfig.monitorFiles = false;
|
|
||||||
if (this->preferenceEditor)
|
|
||||||
this->preferenceEditor->updateFields();
|
|
||||||
});
|
|
||||||
this->editor->setProject(project);
|
this->editor->setProject(project);
|
||||||
|
|
||||||
// Make sure project looks reasonable before attempting to load it
|
// Make sure project looks reasonable before attempting to load it
|
||||||
|
@ -761,6 +756,46 @@ void MainWindow::openSubWindow(QWidget * window) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::showFileWatcherWarning(QString filepath) {
|
||||||
|
if (!porymapConfig.monitorFiles || !isProjectOpen())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Project *project = this->editor->project;
|
||||||
|
if (project->modifiedFileTimestamps.contains(filepath)) {
|
||||||
|
if (QDateTime::currentMSecsSinceEpoch() < project->modifiedFileTimestamps[filepath]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
project->modifiedFileTimestamps.remove(filepath);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool showing = false;
|
||||||
|
if (showing) return;
|
||||||
|
|
||||||
|
QMessageBox notice(this);
|
||||||
|
notice.setText("File Changed");
|
||||||
|
notice.setInformativeText(QString("The file %1 has changed on disk. Would you like to reload the project?")
|
||||||
|
.arg(filepath.remove(project->root + "/")));
|
||||||
|
notice.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
|
||||||
|
notice.setDefaultButton(QMessageBox::No);
|
||||||
|
notice.setIcon(QMessageBox::Question);
|
||||||
|
|
||||||
|
QCheckBox showAgainCheck("Do not ask again.");
|
||||||
|
notice.setCheckBox(&showAgainCheck);
|
||||||
|
|
||||||
|
showing = true;
|
||||||
|
int choice = notice.exec();
|
||||||
|
if (choice == QMessageBox::Yes) {
|
||||||
|
on_action_Reload_Project_triggered();
|
||||||
|
} else if (choice == QMessageBox::No) {
|
||||||
|
if (showAgainCheck.isChecked()) {
|
||||||
|
porymapConfig.monitorFiles = false;
|
||||||
|
if (this->preferenceEditor)
|
||||||
|
this->preferenceEditor->updateFields();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
showing = false;
|
||||||
|
}
|
||||||
|
|
||||||
QString MainWindow::getExistingDirectory(QString dir) {
|
QString MainWindow::getExistingDirectory(QString dir) {
|
||||||
return FileDialog::getExistingDirectory(this, "Open Directory", dir, QFileDialog::ShowDirsOnly);
|
return FileDialog::getExistingDirectory(this, "Open Directory", dir, QFileDialog::ShowDirsOnly);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ int Project::max_object_events = 64;
|
||||||
Project::Project(QObject *parent) :
|
Project::Project(QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
initSignals();
|
QObject::connect(&this->fileWatcher, &QFileSystemWatcher::fileChanged, this, &Project::fileChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
Project::~Project()
|
Project::~Project()
|
||||||
|
@ -49,45 +49,6 @@ Project::~Project()
|
||||||
clearEventGraphics();
|
clearEventGraphics();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::initSignals() {
|
|
||||||
// detect changes to specific filepaths being monitored
|
|
||||||
QObject::connect(&fileWatcher, &QFileSystemWatcher::fileChanged, [this](QString changed){
|
|
||||||
if (!porymapConfig.monitorFiles) return;
|
|
||||||
if (modifiedFileTimestamps.contains(changed)) {
|
|
||||||
if (QDateTime::currentMSecsSinceEpoch() < modifiedFileTimestamps[changed]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
modifiedFileTimestamps.remove(changed);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool showing = false;
|
|
||||||
if (showing) return;
|
|
||||||
|
|
||||||
QMessageBox notice(this->parentWidget());
|
|
||||||
notice.setText("File Changed");
|
|
||||||
notice.setInformativeText(QString("The file %1 has changed on disk. Would you like to reload the project?")
|
|
||||||
.arg(changed.remove(this->root + "/")));
|
|
||||||
notice.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
|
|
||||||
notice.setDefaultButton(QMessageBox::No);
|
|
||||||
notice.setIcon(QMessageBox::Question);
|
|
||||||
|
|
||||||
QCheckBox showAgainCheck("Do not ask again.");
|
|
||||||
notice.setCheckBox(&showAgainCheck);
|
|
||||||
|
|
||||||
showing = true;
|
|
||||||
int choice = notice.exec();
|
|
||||||
if (choice == QMessageBox::Yes) {
|
|
||||||
emit reloadProject();
|
|
||||||
} else if (choice == QMessageBox::No) {
|
|
||||||
if (showAgainCheck.isChecked()) {
|
|
||||||
porymapConfig.monitorFiles = false;
|
|
||||||
emit uncheckMonitorFilesAction();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
showing = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void Project::set_root(QString dir) {
|
void Project::set_root(QString dir) {
|
||||||
this->root = dir;
|
this->root = dir;
|
||||||
FileDialog::setDirectory(dir);
|
FileDialog::setDirectory(dir);
|
||||||
|
|
Loading…
Reference in a new issue