From 8c8d16e315e0c69ed82034c7ce5ca9d0976de649 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 26 Feb 2026 23:02:00 -0700 Subject: [PATCH] Add saving & clearing of changes of the sidebar tab ordering --- langs/en-ca.json | 7 +++- module/apps/SidebarTabRearranger.mjs | 39 +++++++++++++++++++-- styles/apps/SidebarTabRearranger.css | 15 ++++++++ templates/SidebarTabRearranger/footer.hbs | 42 ++++++++++++++++++++--- templates/SidebarTabRearranger/list.hbs | 5 +++ 5 files changed, 99 insertions(+), 9 deletions(-) diff --git a/langs/en-ca.json b/langs/en-ca.json index 8bd6b3f..ec50645 100644 --- a/langs/en-ca.json +++ b/langs/en-ca.json @@ -102,7 +102,12 @@ "SidebarTabRearranger": { "title": "Rearrange Sidebar Tabs", "top": "Top", - "bottom": "Bottom" + "bottom": "Bottom", + "save-user": "Save Changes for User", + "remove-user": "Remove User Order", + "save-world": "Save Changes for World", + "remove-world": "Remove World Order", + "user-override-warning": "You have a User-level tab order, saving any changes to the World-level tab order will not show up for you." } }, "notifs": { diff --git a/module/apps/SidebarTabRearranger.mjs b/module/apps/SidebarTabRearranger.mjs index 53ee0fa..b5a4d97 100644 --- a/module/apps/SidebarTabRearranger.mjs +++ b/module/apps/SidebarTabRearranger.mjs @@ -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 diff --git a/styles/apps/SidebarTabRearranger.css b/styles/apps/SidebarTabRearranger.css index efd1f19..e51f1f1 100644 --- a/styles/apps/SidebarTabRearranger.css +++ b/styles/apps/SidebarTabRearranger.css @@ -3,10 +3,18 @@ gap: 16px; } + main { + width: min-content; + } + footer { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; + + .wide { + grid-column: span 2; + } } .drop-zone { @@ -66,4 +74,11 @@ .bottom-label { text-align: right; } + + .warning { + border: 1px solid var(--color-level-warning-border); + border-radius: 4px; + padding: 4px 6px; + font-weight: 600; + } } diff --git a/templates/SidebarTabRearranger/footer.hbs b/templates/SidebarTabRearranger/footer.hbs index f159af4..5f53dc2 100644 --- a/templates/SidebarTabRearranger/footer.hbs +++ b/templates/SidebarTabRearranger/footer.hbs @@ -1,14 +1,46 @@ diff --git a/templates/SidebarTabRearranger/list.hbs b/templates/SidebarTabRearranger/list.hbs index 63dd785..6de3416 100644 --- a/templates/SidebarTabRearranger/list.hbs +++ b/templates/SidebarTabRearranger/list.hbs @@ -1,4 +1,9 @@
+ {{#if showUserOverrideWarning}} +

+ {{ localize "OFT.apps.SidebarTabRearranger.user-override-warning" }} +

+ {{/if}}
{{ localize "OFT.apps.SidebarTabRearranger.top" }}