Add script action warning

This commit is contained in:
GriffinR 2023-02-09 13:15:02 -05:00
parent 7dacfeb52b
commit 880dabade3
3 changed files with 31 additions and 2 deletions

View file

@ -62,6 +62,7 @@ public:
this->textEditorOpenFolder = "";
this->textEditorGotoLine = "";
this->warnScriptLoad = true;
this->warnScriptAction = true;
}
void setRecentProject(QString project);
void setReopenOnLaunch(bool enabled);
@ -80,6 +81,7 @@ public:
void setMonitorFiles(bool monitor);
void setTilesetCheckerboardFill(bool checkerboard);
void setWarnScriptLoad(bool enabled);
void setWarnScriptAction(bool enabled);
void setTheme(QString theme);
void setTextEditorOpenFolder(const QString &command);
void setTextEditorGotoLine(const QString &command);
@ -100,6 +102,7 @@ public:
bool getMonitorFiles();
bool getTilesetCheckerboardFill();
bool getWarnScriptLoad();
bool getWarnScriptAction();
QString getTheme();
QString getTextEditorOpenFolder();
QString getTextEditorGotoLine();
@ -136,6 +139,7 @@ private:
bool monitorFiles;
bool tilesetCheckerboardFill;
bool warnScriptLoad;
bool warnScriptAction;
QString theme;
QString textEditorOpenFolder;
QString textEditorGotoLine;

View file

@ -242,6 +242,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
this->tilesetCheckerboardFill = getConfigBool(key, value);
} else if (key == "warn_script_load") {
this->warnScriptLoad = getConfigBool(key, value);
} else if (key == "warn_script_action") {
this->warnScriptAction = getConfigBool(key, value);
} else if (key == "theme") {
this->theme = value;
} else if (key == "text_editor_open_directory") {
@ -278,6 +280,7 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
map.insert("monitor_files", this->monitorFiles ? "1" : "0");
map.insert("tileset_checkerboard_fill", this->tilesetCheckerboardFill ? "1" : "0");
map.insert("warn_script_load", this->warnScriptLoad ? "1" : "0");
map.insert("warn_script_action", this->warnScriptAction ? "1" : "0");
map.insert("theme", this->theme);
map.insert("text_editor_open_directory", this->textEditorOpenFolder);
map.insert("text_editor_goto_line", this->textEditorGotoLine);
@ -337,6 +340,11 @@ void PorymapConfig::setWarnScriptLoad(bool enabled) {
this->save();
}
void PorymapConfig::setWarnScriptAction(bool enabled) {
this->warnScriptAction = enabled;
this->save();
}
void PorymapConfig::setMainGeometry(QByteArray mainWindowGeometry_, QByteArray mainWindowState_,
QByteArray mapSplitterState_, QByteArray mainSplitterState_) {
this->mainWindowGeometry = mainWindowGeometry_;
@ -498,6 +506,10 @@ bool PorymapConfig::getWarnScriptLoad() {
return this->warnScriptLoad;
}
bool PorymapConfig::getWarnScriptAction() {
return this->warnScriptAction;
}
QString PorymapConfig::getTheme() {
return this->theme;
}

View file

@ -57,7 +57,6 @@ void Scripting::loadModules(QStringList moduleFiles) {
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) {
@ -159,8 +158,22 @@ void Scripting::invokeAction(QString actionName) {
QJSValue result = callbackFunction.call(QJSValueList());
if (tryErrorJS(result)) continue;
}
if (!foundFunction)
if (!foundFunction) {
logError(QString("Unknown custom script function '%1'").arg(functionName));
if (porymapConfig.getWarnScriptAction()) {
QMessageBox messageBox(instance->mainWindow);
messageBox.setText("Failed to run custom action");
messageBox.setInformativeText(getMostRecentError());
messageBox.setIcon(QMessageBox::Warning);
messageBox.addButton(QMessageBox::Ok);
QCheckBox * checkbox = new QCheckBox("Don't show this warning again");
messageBox.setCheckBox(checkbox);
QObject::connect(checkbox, &QCheckBox::stateChanged, [](int state) {
porymapConfig.setWarnScriptAction(static_cast<Qt::CheckState>(state) != Qt::CheckState::Checked);
});
messageBox.exec();
}
}
}
void Scripting::cb_ProjectOpened(QString projectPath) {