Add saving & clearing of changes of the sidebar tab ordering
This commit is contained in:
parent
a682048852
commit
8c8d16e315
5 changed files with 99 additions and 9 deletions
|
|
@ -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": {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,46 @@
|
|||
<footer>
|
||||
<button type="close">
|
||||
{{ localize "OFT.apps.discard-changes" }}
|
||||
</button>
|
||||
<button>
|
||||
<button data-scope="User">
|
||||
<oft-icon
|
||||
name="icons/save"
|
||||
aria-hidden="true"
|
||||
var:fill="currentColor"
|
||||
var:size="1rem"
|
||||
></oft-icon>
|
||||
{{ localize "Save Changes" }}
|
||||
{{ localize "OFT.apps.SidebarTabRearranger.save-user" }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
data-action="unsetSetting"
|
||||
data-scope="User"
|
||||
>
|
||||
{{ localize "OFT.apps.SidebarTabRearranger.remove-user" }}
|
||||
</button>
|
||||
|
||||
{{#if meta.isGM}}
|
||||
<button
|
||||
data-scope="World"
|
||||
>
|
||||
<oft-icon
|
||||
name="icons/save"
|
||||
aria-hidden="true"
|
||||
var:fill="currentColor"
|
||||
var:size="1rem"
|
||||
></oft-icon>
|
||||
{{ localize "OFT.apps.SidebarTabRearranger.save-world" }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
data-action="unsetSetting"
|
||||
data-scope="World"
|
||||
>
|
||||
{{ localize "OFT.apps.SidebarTabRearranger.remove-world" }}
|
||||
</button>
|
||||
{{/if}}
|
||||
|
||||
<button
|
||||
class="wide"
|
||||
type="close"
|
||||
>
|
||||
{{ localize "OFT.apps.discard-changes" }}
|
||||
</button>
|
||||
</footer>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
<main>
|
||||
{{#if showUserOverrideWarning}}
|
||||
<p class="warning">
|
||||
{{ localize "OFT.apps.SidebarTabRearranger.user-override-warning" }}
|
||||
</p>
|
||||
{{/if}}
|
||||
<div class="top-label">
|
||||
{{ localize "OFT.apps.SidebarTabRearranger.top" }}
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue