Add script load warning
This commit is contained in:
parent
e710567400
commit
7dacfeb52b
4 changed files with 36 additions and 1 deletions
|
@ -61,6 +61,7 @@ public:
|
||||||
this->theme = "default";
|
this->theme = "default";
|
||||||
this->textEditorOpenFolder = "";
|
this->textEditorOpenFolder = "";
|
||||||
this->textEditorGotoLine = "";
|
this->textEditorGotoLine = "";
|
||||||
|
this->warnScriptLoad = true;
|
||||||
}
|
}
|
||||||
void setRecentProject(QString project);
|
void setRecentProject(QString project);
|
||||||
void setReopenOnLaunch(bool enabled);
|
void setReopenOnLaunch(bool enabled);
|
||||||
|
@ -78,6 +79,7 @@ public:
|
||||||
void setShowGrid(bool enabled);
|
void setShowGrid(bool enabled);
|
||||||
void setMonitorFiles(bool monitor);
|
void setMonitorFiles(bool monitor);
|
||||||
void setTilesetCheckerboardFill(bool checkerboard);
|
void setTilesetCheckerboardFill(bool checkerboard);
|
||||||
|
void setWarnScriptLoad(bool enabled);
|
||||||
void setTheme(QString theme);
|
void setTheme(QString theme);
|
||||||
void setTextEditorOpenFolder(const QString &command);
|
void setTextEditorOpenFolder(const QString &command);
|
||||||
void setTextEditorGotoLine(const QString &command);
|
void setTextEditorGotoLine(const QString &command);
|
||||||
|
@ -97,6 +99,7 @@ public:
|
||||||
bool getShowGrid();
|
bool getShowGrid();
|
||||||
bool getMonitorFiles();
|
bool getMonitorFiles();
|
||||||
bool getTilesetCheckerboardFill();
|
bool getTilesetCheckerboardFill();
|
||||||
|
bool getWarnScriptLoad();
|
||||||
QString getTheme();
|
QString getTheme();
|
||||||
QString getTextEditorOpenFolder();
|
QString getTextEditorOpenFolder();
|
||||||
QString getTextEditorGotoLine();
|
QString getTextEditorGotoLine();
|
||||||
|
@ -132,6 +135,7 @@ private:
|
||||||
bool showGrid;
|
bool showGrid;
|
||||||
bool monitorFiles;
|
bool monitorFiles;
|
||||||
bool tilesetCheckerboardFill;
|
bool tilesetCheckerboardFill;
|
||||||
|
bool warnScriptLoad;
|
||||||
QString theme;
|
QString theme;
|
||||||
QString textEditorOpenFolder;
|
QString textEditorOpenFolder;
|
||||||
QString textEditorGotoLine;
|
QString textEditorGotoLine;
|
||||||
|
|
|
@ -61,6 +61,7 @@ public:
|
||||||
static QJSValue dialogInput(QJSValue input, bool selectedOk);
|
static QJSValue dialogInput(QJSValue input, bool selectedOk);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
MainWindow *mainWindow;
|
||||||
QJSEngine *engine;
|
QJSEngine *engine;
|
||||||
QStringList filepaths;
|
QStringList filepaths;
|
||||||
QList<QJSValue> modules;
|
QList<QJSValue> modules;
|
||||||
|
|
|
@ -240,6 +240,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
|
||||||
this->monitorFiles = getConfigBool(key, value);
|
this->monitorFiles = getConfigBool(key, value);
|
||||||
} else if (key == "tileset_checkerboard_fill") {
|
} else if (key == "tileset_checkerboard_fill") {
|
||||||
this->tilesetCheckerboardFill = getConfigBool(key, value);
|
this->tilesetCheckerboardFill = getConfigBool(key, value);
|
||||||
|
} else if (key == "warn_script_load") {
|
||||||
|
this->warnScriptLoad = getConfigBool(key, value);
|
||||||
} else if (key == "theme") {
|
} else if (key == "theme") {
|
||||||
this->theme = value;
|
this->theme = value;
|
||||||
} else if (key == "text_editor_open_directory") {
|
} else if (key == "text_editor_open_directory") {
|
||||||
|
@ -275,6 +277,7 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
|
||||||
map.insert("show_grid", this->showGrid ? "1" : "0");
|
map.insert("show_grid", this->showGrid ? "1" : "0");
|
||||||
map.insert("monitor_files", this->monitorFiles ? "1" : "0");
|
map.insert("monitor_files", this->monitorFiles ? "1" : "0");
|
||||||
map.insert("tileset_checkerboard_fill", this->tilesetCheckerboardFill ? "1" : "0");
|
map.insert("tileset_checkerboard_fill", this->tilesetCheckerboardFill ? "1" : "0");
|
||||||
|
map.insert("warn_script_load", this->warnScriptLoad ? "1" : "0");
|
||||||
map.insert("theme", this->theme);
|
map.insert("theme", this->theme);
|
||||||
map.insert("text_editor_open_directory", this->textEditorOpenFolder);
|
map.insert("text_editor_open_directory", this->textEditorOpenFolder);
|
||||||
map.insert("text_editor_goto_line", this->textEditorGotoLine);
|
map.insert("text_editor_goto_line", this->textEditorGotoLine);
|
||||||
|
@ -329,6 +332,11 @@ void PorymapConfig::setTilesetCheckerboardFill(bool checkerboard) {
|
||||||
this->save();
|
this->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PorymapConfig::setWarnScriptLoad(bool enabled) {
|
||||||
|
this->warnScriptLoad = enabled;
|
||||||
|
this->save();
|
||||||
|
}
|
||||||
|
|
||||||
void PorymapConfig::setMainGeometry(QByteArray mainWindowGeometry_, QByteArray mainWindowState_,
|
void PorymapConfig::setMainGeometry(QByteArray mainWindowGeometry_, QByteArray mainWindowState_,
|
||||||
QByteArray mapSplitterState_, QByteArray mainSplitterState_) {
|
QByteArray mapSplitterState_, QByteArray mainSplitterState_) {
|
||||||
this->mainWindowGeometry = mainWindowGeometry_;
|
this->mainWindowGeometry = mainWindowGeometry_;
|
||||||
|
@ -486,6 +494,10 @@ bool PorymapConfig::getTilesetCheckerboardFill() {
|
||||||
return this->tilesetCheckerboardFill;
|
return this->tilesetCheckerboardFill;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PorymapConfig::getWarnScriptLoad() {
|
||||||
|
return this->warnScriptLoad;
|
||||||
|
}
|
||||||
|
|
||||||
QString PorymapConfig::getTheme() {
|
QString PorymapConfig::getTheme() {
|
||||||
return this->theme;
|
return this->theme;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ void Scripting::init(MainWindow *mainWindow) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Scripting::Scripting(MainWindow *mainWindow) {
|
Scripting::Scripting(MainWindow *mainWindow) {
|
||||||
|
this->mainWindow = mainWindow;
|
||||||
this->engine = new QJSEngine(mainWindow);
|
this->engine = new QJSEngine(mainWindow);
|
||||||
this->engine->installExtensions(QJSEngine::ConsoleExtension);
|
this->engine->installExtensions(QJSEngine::ConsoleExtension);
|
||||||
for (QString script : userConfig.getCustomScripts()) {
|
for (QString script : userConfig.getCustomScripts()) {
|
||||||
|
@ -48,7 +49,24 @@ void Scripting::loadModules(QStringList moduleFiles) {
|
||||||
if (module.isError()) {
|
if (module.isError()) {
|
||||||
QString relativePath = QDir::cleanPath(userConfig.getProjectDir() + QDir::separator() + filepath);
|
QString relativePath = QDir::cleanPath(userConfig.getProjectDir() + QDir::separator() + filepath);
|
||||||
module = this->engine->importModule(relativePath);
|
module = this->engine->importModule(relativePath);
|
||||||
if (tryErrorJS(module)) continue;
|
if (tryErrorJS(module)) {
|
||||||
|
if (porymapConfig.getWarnScriptLoad()) {
|
||||||
|
QMessageBox messageBox(this->mainWindow);
|
||||||
|
messageBox.setText("Failed to load script");
|
||||||
|
messageBox.setInformativeText(QString("An error occurred while loading custom script file '%1'").arg(filepath));
|
||||||
|
messageBox.setDetailedText(getMostRecentError());
|
||||||
|
messageBox.setIcon(QMessageBox::Warning);
|
||||||
|
messageBox.addButton(QMessageBox::Ok);
|
||||||
|
messageBox.setDefaultButton(QMessageBox::Ok);
|
||||||
|
QCheckBox * checkbox = new QCheckBox("Don't show this warning again");
|
||||||
|
messageBox.setCheckBox(checkbox);
|
||||||
|
QObject::connect(checkbox, &QCheckBox::stateChanged, [](int state) {
|
||||||
|
porymapConfig.setWarnScriptLoad(static_cast<Qt::CheckState>(state) != Qt::CheckState::Checked);
|
||||||
|
});
|
||||||
|
messageBox.exec();
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logInfo(QString("Successfully loaded custom script file '%1'").arg(filepath));
|
logInfo(QString("Successfully loaded custom script file '%1'").arg(filepath));
|
||||||
|
|
Loading…
Reference in a new issue