mirror of
https://github.com/huderlem/porymap.git
synced 2026-03-21 17:45:44 -05:00
Automatically save selected tabs
Some checks failed
Build Porymap / build-linux (, 5.14.2) (push) Has been cancelled
Build Porymap / build-linux (, 6.8.*) (push) Has been cancelled
Build Porymap / build-linux (minimal, 5.14.2) (push) Has been cancelled
Build Porymap / build-macos (macos-15-intel) (push) Has been cancelled
Build Porymap / build-macos (macos-latest) (push) Has been cancelled
Build Porymap / build-static-windows (push) Has been cancelled
Some checks failed
Build Porymap / build-linux (, 5.14.2) (push) Has been cancelled
Build Porymap / build-linux (, 6.8.*) (push) Has been cancelled
Build Porymap / build-linux (minimal, 5.14.2) (push) Has been cancelled
Build Porymap / build-macos (macos-15-intel) (push) Has been cancelled
Build Porymap / build-macos (macos-latest) (push) Has been cancelled
Build Porymap / build-static-windows (push) Has been cancelled
This commit is contained in:
parent
386b608504
commit
dffa2f6e1f
|
|
@ -45,7 +45,6 @@ public:
|
|||
|
||||
bool reopenOnLaunch = true;
|
||||
bool projectManuallyClosed = false;
|
||||
int mapListTab = 0;
|
||||
bool mapListEditGroupsEnabled = false;
|
||||
OrderedSet<int> mapListTabsHidingEmptyFolders;
|
||||
bool mapListLayoutsSorted = true;
|
||||
|
|
@ -80,7 +79,6 @@ public:
|
|||
QString textEditorOpenFolder;
|
||||
QString textEditorGotoLine;
|
||||
int paletteEditorBitDepth = 24;
|
||||
int projectSettingsTab = 0;
|
||||
ScriptAutocompleteMode scriptAutocompleteMode = ScriptAutocompleteMode::MapOnly;
|
||||
bool warpBehaviorWarningDisabled = false;
|
||||
bool eventDeleteWarningDisabled = false;
|
||||
|
|
@ -113,7 +111,6 @@ public:
|
|||
m_fm = std::make_shared<FieldManager>();
|
||||
m_fm->addField(&this->reopenOnLaunch, "reopen_on_launch");
|
||||
m_fm->addField(&this->projectManuallyClosed, "project_manually_closed");
|
||||
m_fm->addField(&this->mapListTab, "map_list_tab", 0, 2);
|
||||
m_fm->addField(&this->mapListEditGroupsEnabled, "map_list_edit_groups_enabled");
|
||||
m_fm->addField(&this->mapListTabsHidingEmptyFolders, "map_list_tabs_hiding_empty_folders");
|
||||
m_fm->addField(&this->mapListLayoutsSorted, "map_list_layouts_sorted");
|
||||
|
|
@ -148,7 +145,6 @@ public:
|
|||
m_fm->addField(&this->textEditorOpenFolder, "text_editor_open_folder");
|
||||
m_fm->addField(&this->textEditorGotoLine, "text_editor_goto_line");
|
||||
m_fm->addField(&this->paletteEditorBitDepth, "palette_editor_bit_depth", {24,15});
|
||||
m_fm->addField(&this->projectSettingsTab, "project_settings_tab");
|
||||
m_fm->addField(&this->scriptAutocompleteMode, "script_autocomplete_mode");
|
||||
m_fm->addField(&this->warpBehaviorWarningDisabled, "warp_behavior_warning_disabled");
|
||||
m_fm->addField(&this->eventDeleteWarningDisabled, "event_delete_warning_disabled");
|
||||
|
|
@ -179,6 +175,11 @@ protected:
|
|||
virtual QJsonObject getDefaultJson() const override;
|
||||
|
||||
private:
|
||||
static QList<QWidget*> findChildrenWithStates(const QWidget* widget);
|
||||
static QByteArray getWidgetState(const QWidget* widget);
|
||||
static void restoreWidgetState(QWidget* widget, const QByteArray& state);
|
||||
|
||||
|
||||
std::shared_ptr<FieldManager> m_fm = nullptr;
|
||||
QStringList recentProjects;
|
||||
QMap<QString, QByteArray> savedGeometryMap;
|
||||
|
|
|
|||
|
|
@ -302,7 +302,6 @@ private slots:
|
|||
void on_actionOpen_Manual_triggered();
|
||||
void on_actionCheck_for_Updates_triggered();
|
||||
void togglePreferenceSpecificUi();
|
||||
void on_actionProject_Settings_triggered();
|
||||
void on_actionPlugins_triggered();
|
||||
void reloadScriptEngine();
|
||||
void on_actionShow_Grid_triggered();
|
||||
|
|
@ -420,7 +419,7 @@ private:
|
|||
void setMapListSorted(MapTree *list, bool sort);
|
||||
void updateMapList();
|
||||
void openMapListItem(const QModelIndex &index);
|
||||
void onMapListTabChanged(int index);
|
||||
void setMapListTab(int index);
|
||||
QString getActiveItemName();
|
||||
void recordMapNavigation(const QString &itemName);
|
||||
void resetMapNavigation();
|
||||
|
|
@ -456,7 +455,7 @@ private:
|
|||
void initShortcutsEditor();
|
||||
void initPluginEditor();
|
||||
void connectSubEditorsToShortcutsEditor();
|
||||
void openProjectSettingsEditor(int tab);
|
||||
void openProjectSettingsEditor(int tab = -1);
|
||||
bool isProjectOpen();
|
||||
void showExportMapImageWindow(ImageExporterMode mode);
|
||||
double getMetatilesZoomScale();
|
||||
|
|
|
|||
|
|
@ -81,7 +81,6 @@ private slots:
|
|||
void updateAttributeLimits(const QString &attrSize);
|
||||
void updatePokemonIconPath(const QString &species);
|
||||
void markEdited();
|
||||
void on_mainTabs_tabBarClicked(int index);
|
||||
void updateBlockMaskOverlapWarning();
|
||||
void updateAttributeMaskOverlapWarning();
|
||||
void updateWarpBehaviorsList(bool adding);
|
||||
|
|
|
|||
|
|
@ -89,8 +89,6 @@ bool PorymapConfig::parseLegacyKeyValue(const QString &key, const QString &value
|
|||
this->reopenOnLaunch = toBool(value);
|
||||
} else if (key == "pretty_cursors") {
|
||||
this->prettyCursors = toBool(value);
|
||||
} else if (key == "map_list_tab") {
|
||||
this->mapListTab = toInt(value, 0, 2, 0);
|
||||
} else if (key == "map_list_edit_groups_enabled") {
|
||||
this->mapListEditGroupsEnabled = toBool(value);
|
||||
} else if (key.startsWith("map_list_hide_empty_enabled/")) {
|
||||
|
|
@ -161,8 +159,6 @@ bool PorymapConfig::parseLegacyKeyValue(const QString &key, const QString &value
|
|||
if (bitDepth == 15 || bitDepth == 24){
|
||||
this->paletteEditorBitDepth = bitDepth;
|
||||
}
|
||||
} else if (key == "project_settings_tab") {
|
||||
this->projectSettingsTab = toInt(value, 0);
|
||||
} else if (key == "load_all_event_scripts") { // Old setting replaced by script_autocomplete_mode
|
||||
this->scriptAutocompleteMode = toBool(value) ? ScriptAutocompleteMode::All : ScriptAutocompleteMode::MapOnly;
|
||||
} else if (key == "script_autocomplete_mode") {
|
||||
|
|
|
|||
|
|
@ -58,49 +58,82 @@ const QStringList& PorymapConfig::getRecentProjects() const {
|
|||
return this->recentProjects;
|
||||
}
|
||||
|
||||
QList<QWidget*> PorymapConfig::findChildrenWithStates(const QWidget* widget) {
|
||||
QList<QWidget*> children;
|
||||
for (const auto& c : widget->findChildren<QSplitter*>()) children.append(qobject_cast<QWidget*>(c));
|
||||
for (const auto& c : widget->findChildren<QTabWidget*>()) children.append(qobject_cast<QWidget*>(c));
|
||||
return children;
|
||||
}
|
||||
|
||||
void PorymapConfig::saveGeometry(const QWidget* widget, const QString& keyPrefix, bool recursive) {
|
||||
if (!widget || widget->objectName().isEmpty()) return;
|
||||
|
||||
const QString key = keyPrefix + widget->objectName();
|
||||
this->savedGeometryMap.insert(key, widget->saveGeometry());
|
||||
if (!widget->parentWidget()) { // Only save geometry for top-level widgets;
|
||||
this->savedGeometryMap.insert(key, widget->saveGeometry());
|
||||
}
|
||||
|
||||
// In addition to geometry, some widgets have other states that can be saved/restored.
|
||||
const QString stateKey = key + QStringLiteral("/State");
|
||||
auto mainWindow = qobject_cast<const QMainWindow*>(widget);
|
||||
if (mainWindow) this->savedGeometryMap.insert(stateKey, mainWindow->saveState());
|
||||
else {
|
||||
auto splitter = qobject_cast<const QSplitter*>(widget);
|
||||
if (splitter) this->savedGeometryMap.insert(stateKey, splitter->saveState());
|
||||
const QByteArray state = getWidgetState(widget);
|
||||
if (!state.isEmpty()) {
|
||||
this->savedGeometryMap.insert(key + QStringLiteral("/State"), state);
|
||||
}
|
||||
|
||||
if (recursive) {
|
||||
for (const auto& splitter : widget->findChildren<QSplitter*>()) {
|
||||
saveGeometry(splitter, key + "_", false);
|
||||
for (const auto& child : findChildrenWithStates(widget)) {
|
||||
saveGeometry(child, key + "_", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray PorymapConfig::getWidgetState(const QWidget* widget) {
|
||||
auto mainWindow = qobject_cast<const QMainWindow*>(widget);
|
||||
if (mainWindow) return mainWindow->saveState();
|
||||
|
||||
auto splitter = qobject_cast<const QSplitter*>(widget);
|
||||
if (splitter) return splitter->saveState();
|
||||
|
||||
auto tabWidget = qobject_cast<const QTabWidget*>(widget);
|
||||
if (tabWidget) return QString::number(tabWidget->currentIndex()).toUtf8();
|
||||
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
bool PorymapConfig::restoreGeometry(QWidget* widget, const QString& keyPrefix, bool recursive) const {
|
||||
if (!widget || widget->objectName().isEmpty()) return false;
|
||||
|
||||
const QString key = keyPrefix + widget->objectName();
|
||||
auto it = this->savedGeometryMap.constFind(key);
|
||||
if (it == this->savedGeometryMap.constEnd()) return false;
|
||||
widget->restoreGeometry(it.value());
|
||||
if (it != this->savedGeometryMap.constEnd()) {
|
||||
widget->restoreGeometry(it.value());
|
||||
}
|
||||
|
||||
// In addition to geometry, some widgets have other states that can be saved/restored.
|
||||
it = this->savedGeometryMap.constFind(key + QStringLiteral("/State"));
|
||||
if (it != this->savedGeometryMap.constEnd()) {
|
||||
auto mainWindow = qobject_cast<QMainWindow*>(widget);
|
||||
if (mainWindow) mainWindow->restoreState(it.value());
|
||||
else {
|
||||
auto splitter = qobject_cast<QSplitter*>(widget);
|
||||
if (splitter) splitter->restoreState(it.value());
|
||||
}
|
||||
}
|
||||
if (it != this->savedGeometryMap.constEnd()) restoreWidgetState(widget, it.value());
|
||||
|
||||
if (recursive) {
|
||||
for (const auto& splitter : widget->findChildren<QSplitter*>()) {
|
||||
restoreGeometry(splitter, key + "_", false);
|
||||
for (const auto& child : findChildrenWithStates(widget)) {
|
||||
restoreGeometry(child, key + "_", false);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void PorymapConfig::restoreWidgetState(QWidget* widget, const QByteArray& state) {
|
||||
auto mainWindow = qobject_cast<QMainWindow*>(widget);
|
||||
if (mainWindow) {
|
||||
mainWindow->restoreState(state);
|
||||
return;
|
||||
}
|
||||
auto splitter = qobject_cast<QSplitter*>(widget);
|
||||
if (splitter) {
|
||||
splitter->restoreState(state);
|
||||
return;
|
||||
}
|
||||
auto tabWidget = qobject_cast<QTabWidget*>(widget);
|
||||
if (tabWidget) {
|
||||
tabWidget->setCurrentIndex(QString::fromUtf8(state).toInt());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -398,6 +398,7 @@ void MainWindow::initExtraSignals() {
|
|||
connect(ui->actionDuplicate_Current_Layout, &QAction::triggered, [this] {
|
||||
if (this->editor->layout) openDuplicateLayoutDialog(this->editor->layout->id);
|
||||
});
|
||||
connect(ui->actionProject_Settings, &QAction::triggered, this, &MainWindow::openProjectSettingsEditor);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionCheck_for_Updates_triggered() {
|
||||
|
|
@ -501,8 +502,6 @@ void MainWindow::initMiscHeapObjects() {
|
|||
}
|
||||
|
||||
void MainWindow::initMapList() {
|
||||
ui->mapListContainer->setCurrentIndex(porymapConfig.mapListTab);
|
||||
|
||||
auto noScrollFilter = new NoScrollFilter(this, false);
|
||||
ui->mainTabBar->installEventFilter(noScrollFilter);
|
||||
ui->mapListContainer->tabBar()->installEventFilter(noScrollFilter);
|
||||
|
|
@ -624,7 +623,7 @@ void MainWindow::initMapList() {
|
|||
connect(ui->mapListToolBar_Locations, &MapListToolBar::addFolderClicked, this, &MainWindow::openNewLocationDialog);
|
||||
connect(ui->mapListToolBar_Layouts, &MapListToolBar::addFolderClicked, this, &MainWindow::openNewLayoutDialog);
|
||||
|
||||
connect(ui->mapListContainer, &QTabWidget::currentChanged, this, &MainWindow::onMapListTabChanged);
|
||||
connect(ui->mapListContainer, &QTabWidget::tabBarClicked, this, &MainWindow::setMapListTab);
|
||||
}
|
||||
|
||||
void MainWindow::updateWindowTitle() {
|
||||
|
|
@ -1241,7 +1240,7 @@ bool MainWindow::userSetLayout(const QString &layoutId) {
|
|||
recordMapNavigation(prevItem);
|
||||
|
||||
// Only the Layouts tab of the map list shows Layouts, so if we're not already on that tab we'll open it now.
|
||||
ui->mapListContainer->setCurrentIndex(MapListTab::Layouts);
|
||||
setMapListTab(MapListTab::Layouts);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1897,16 +1896,14 @@ void MainWindow::currentMetatilesSelectionChanged() {
|
|||
scrollMetatileSelectorToSelection();
|
||||
}
|
||||
|
||||
void MainWindow::onMapListTabChanged(int index) {
|
||||
void MainWindow::setMapListTab(int index) {
|
||||
auto newToolbar = getMapListToolBar(index);
|
||||
auto oldToolbar = getMapListToolBar(porymapConfig.mapListTab);
|
||||
auto oldToolbar = getMapListToolBar(ui->mapListContainer->currentIndex());
|
||||
ui->mapListContainer->setCurrentIndex(index);
|
||||
if (newToolbar && oldToolbar && newToolbar != oldToolbar) {
|
||||
newToolbar->applyFilter(oldToolbar->filterText());
|
||||
}
|
||||
|
||||
// Save current tab for future sessions.
|
||||
porymapConfig.mapListTab = index;
|
||||
|
||||
// After changing a map list tab the old tab's search widget can keep focus, which isn't helpful
|
||||
// (and might be a little confusing to the user, because they don't know that each search bar is secretly a separate object).
|
||||
// When we change tabs we'll automatically focus in on the search bar. This should also make finding maps a little quicker.
|
||||
|
|
@ -3072,14 +3069,10 @@ void MainWindow::openProjectSettingsEditor(int tab) {
|
|||
connect(this->projectSettingsEditor, &ProjectSettingsEditor::reloadProject,
|
||||
this, &MainWindow::on_action_Reload_Project_triggered);
|
||||
}
|
||||
this->projectSettingsEditor->setTab(tab);
|
||||
if (tab >= 0) this->projectSettingsEditor->setTab(tab);
|
||||
Util::show(this->projectSettingsEditor);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionProject_Settings_triggered() {
|
||||
this->openProjectSettingsEditor(porymapConfig.projectSettingsTab);
|
||||
}
|
||||
|
||||
void MainWindow::onWarpBehaviorWarningClicked() {
|
||||
static const QString informative = QStringLiteral(
|
||||
"<html><head/><body><p>"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "ui_preferenceeditor.h"
|
||||
#include "message.h"
|
||||
#include "tile.h"
|
||||
#include "eventfilters.h"
|
||||
|
||||
#include <QAbstractButton>
|
||||
#include <QRegularExpression>
|
||||
|
|
@ -36,6 +37,7 @@ PreferenceEditor::PreferenceEditor(QWidget *parent) :
|
|||
|
||||
initFields();
|
||||
updateFields();
|
||||
installEventFilter(new GeometrySaver(this));
|
||||
}
|
||||
|
||||
PreferenceEditor::~PreferenceEditor()
|
||||
|
|
|
|||
|
|
@ -211,14 +211,8 @@ BaseGame::Version ProjectSettingsEditor::getBaseGameVersion() const {
|
|||
return static_cast<BaseGame::Version>(ui->comboBox_BaseGameVersion->currentData().toInt());
|
||||
}
|
||||
|
||||
// Remember the current settings tab for future sessions
|
||||
void ProjectSettingsEditor::on_mainTabs_tabBarClicked(int index) {
|
||||
porymapConfig.projectSettingsTab = index;
|
||||
}
|
||||
|
||||
void ProjectSettingsEditor::setTab(int index) {
|
||||
ui->mainTabs->setCurrentIndex(index);
|
||||
porymapConfig.projectSettingsTab = index;
|
||||
}
|
||||
|
||||
void ProjectSettingsEditor::setBorderMetatilesUi(bool customSize) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user