Add saving & clearing of changes of the sidebar tab ordering

This commit is contained in:
Oliver 2026-02-26 23:02:00 -07:00
parent a682048852
commit 8c8d16e315
5 changed files with 99 additions and 9 deletions

View file

@ -1,7 +1,9 @@
import { __ID__, filePath } from "../consts.mjs";
import { performArraySort } from "../utils/performArraySort.mjs";
import { key as rearrangeSidebarTabsKey } from "../tweaks/rearrangeSidebarTabs.mjs";
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
const { SettingsConfig } = foundry.applications.settings;
const { DragDrop } = foundry.applications.ux;
const { getDocumentClass } = foundry.utils;
@ -23,6 +25,7 @@ export class SidebarTabRearranger extends HandlebarsApplicationMixin(Application
submitOnChange: false,
},
actions: {
unsetSetting: this.#unsetSetting,
},
};
@ -37,10 +40,16 @@ export class SidebarTabRearranger extends HandlebarsApplicationMixin(Application
constructor(...args) {
super(...args);
// TODO: define this using the game settings
this.#order = Object.keys(ui.sidebar.constructor.TABS);
};
get worldSave() {
return game.settings.get(__ID__, `${rearrangeSidebarTabsKey}World`);
};
get userSave() {
return game.settings.get(__ID__, `${rearrangeSidebarTabsKey}User`);
};
// #endregion Instance Data
// #region Lifecycle
@ -61,7 +70,21 @@ export class SidebarTabRearranger extends HandlebarsApplicationMixin(Application
};
/** @this {SidebarTabRearranger} */
static async #onSubmit() {};
static async #onSubmit(event) {
const { scope } = event.submitter.dataset;
if (!scope || ![`User`, `World`].includes(scope)) { return };
if (scope === `World` && this.userSave != null) {
return;
}
game.settings.set(
__ID__,
`${rearrangeSidebarTabsKey}${scope}`,
this.#order,
);
SettingsConfig.reloadConfirm({ world: scope === `World` });
};
// #endregion Lifecycle
// #region Data Prep
@ -69,7 +92,9 @@ export class SidebarTabRearranger extends HandlebarsApplicationMixin(Application
const ctx = {
meta: {
idp: this.id,
isGM: game.user.isGM,
},
showUserOverrideWarning: game.user.isGM && this.userSave != null,
};
const tabs = ui.sidebar.constructor.TABS;
@ -100,6 +125,14 @@ export class SidebarTabRearranger extends HandlebarsApplicationMixin(Application
// #endregion Data Prep
// #region Actions
/** @this {SidebarTabRearranger} */
static async #unsetSetting(event, target) {
const { scope } = target.dataset;
if (!scope || ![`User`, `World`].includes(scope)) { return };
await game.settings.set(__ID__, `${rearrangeSidebarTabsKey}${scope}`, null);
SettingsConfig.reloadConfirm({ world: scope === `World` });
};
// #endregion Actions
// #region Drag & Drop