Add reopen on launch config option

This commit is contained in:
GriffinR 2022-07-04 15:47:03 -04:00 committed by Marcus Huderle
parent 4a41858e5b
commit a407fa9e17
3 changed files with 19 additions and 0 deletions

View file

@ -39,6 +39,7 @@ public:
}
virtual void reset() override {
this->recentProject = "";
this->reopenOnLaunch = true;
this->mapSortOrder = MapSortOrder::Group;
this->prettyCursors = true;
this->collisionOpacity = 50;
@ -54,6 +55,7 @@ public:
this->textEditorGotoLine = "";
}
void setRecentProject(QString project);
void setReopenOnLaunch(bool enabled);
void setMapSortOrder(MapSortOrder order);
void setPrettyCursors(bool enabled);
void setMainGeometry(QByteArray, QByteArray, QByteArray, QByteArray);
@ -72,6 +74,7 @@ public:
void setTextEditorOpenFolder(const QString &command);
void setTextEditorGotoLine(const QString &command);
QString getRecentProject();
bool getReopenOnLaunch();
MapSortOrder getMapSortOrder();
bool getPrettyCursors();
QMap<QString, QByteArray> getMainGeometry();
@ -97,6 +100,7 @@ protected:
virtual void setUnreadKeys() override {};
private:
QString recentProject;
bool reopenOnLaunch;
QString stringFromByteArray(QByteArray);
QByteArray bytesFromString(QString);
MapSortOrder mapSortOrder;

View file

@ -116,6 +116,8 @@ QString PorymapConfig::getConfigFilepath() {
void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
if (key == "recent_project") {
this->recentProject = value;
} else if (key == "reopen_on_launch") {
setConfigBool(key, &this->reopenOnLaunch, value);
} else if (key == "pretty_cursors") {
setConfigBool(key, &this->prettyCursors, value);
} else if (key == "map_sort_order") {
@ -195,6 +197,7 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
QMap<QString, QString> PorymapConfig::getKeyValueMap() {
QMap<QString, QString> map;
map.insert("recent_project", this->recentProject);
map.insert("reopen_on_launch", this->reopenOnLaunch ? "1" : "0");
map.insert("pretty_cursors", this->prettyCursors ? "1" : "0");
map.insert("map_sort_order", mapSortOrderMap.value(this->mapSortOrder));
map.insert("main_window_geometry", stringFromByteArray(this->mainWindowGeometry));
@ -244,6 +247,11 @@ void PorymapConfig::setRecentProject(QString project) {
this->save();
}
void PorymapConfig::setReopenOnLaunch(bool enabled) {
this->reopenOnLaunch = enabled;
this->save();
}
void PorymapConfig::setMapSortOrder(MapSortOrder order) {
this->mapSortOrder = order;
this->save();
@ -338,6 +346,10 @@ QString PorymapConfig::getRecentProject() {
return this->recentProject;
}
bool PorymapConfig::getReopenOnLaunch() {
return this->reopenOnLaunch;
}
MapSortOrder PorymapConfig::getMapSortOrder() {
return this->mapSortOrder;
}

View file

@ -485,6 +485,9 @@ void MainWindow::setTheme(QString theme) {
}
bool MainWindow::openRecentProject() {
if (!porymapConfig.getReopenOnLaunch())
return false;
QString default_dir = porymapConfig.getRecentProject();
if (!default_dir.isNull() && default_dir.length() > 0) {
logInfo(QString("Opening recent project: '%1'").arg(default_dir));