Implement the startingSidebarTab setting (closes #3)
This commit is contained in:
parent
7340f981db
commit
321a4ab0eb
3 changed files with 62 additions and 0 deletions
|
|
@ -12,6 +12,13 @@
|
|||
"startSidebarExpanded": {
|
||||
"name": "Start Sidebar Expanded",
|
||||
"hint": "(v13+) Starts the right-hand sidebar expanded when logging in."
|
||||
},
|
||||
"startingSidebarTab": {
|
||||
"name": "Starting Sidebar Tab",
|
||||
"hint": "(v13+) Determines what sidebar tab to have selected initially when loading Foundry",
|
||||
"choices": {
|
||||
"blank": "No Custom Default Tab"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { __ID } from "../consts.mjs";
|
||||
import { chatSidebarBackground } from "../settings/chatSidebarBackground.mjs";
|
||||
import { preventUserConfigOpen } from "../settings/preventUserConfigOpen.mjs";
|
||||
import { startingSidebarTab } from "../settings/startingSidebarTab.mjs";
|
||||
import { startSidebarExpanded } from "../settings/startSidebarExpanded.mjs";
|
||||
|
||||
Hooks.once(`init`, () => {
|
||||
|
|
@ -9,4 +10,6 @@ Hooks.once(`init`, () => {
|
|||
chatSidebarBackground.register();
|
||||
preventUserConfigOpen.register();
|
||||
startSidebarExpanded.register();
|
||||
|
||||
startingSidebarTab();
|
||||
});
|
||||
|
|
|
|||
52
module/settings/startingSidebarTab.mjs
Normal file
52
module/settings/startingSidebarTab.mjs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import { __ID } from "../consts.mjs";
|
||||
import { Logger } from "../utils/Logger.mjs";
|
||||
|
||||
const key = `startingSidebarTab`;
|
||||
|
||||
export function startingSidebarTab() {
|
||||
Logger.log(`Registering ${key} setting`);
|
||||
|
||||
// #region Registration
|
||||
game.settings.register(__ID, key, {
|
||||
name: `OFT.setting.${key}.name`,
|
||||
hint: `OFT.setting.${key}.hint`,
|
||||
type: new foundry.data.fields.StringField({
|
||||
blank: true,
|
||||
nullable: false,
|
||||
required: true,
|
||||
choices: () => {
|
||||
const tabs = Object.entries(CONFIG.ui.sidebar.TABS);
|
||||
|
||||
const tabChoices = {
|
||||
"": `OFT.setting.${key}.choices.blank`,
|
||||
};
|
||||
for (const [id, data] of tabs) {
|
||||
let { documentName, gmOnly, tooltip: name } = data;
|
||||
if (gmOnly && !game.user.isGM) { continue };
|
||||
|
||||
if (documentName) {
|
||||
name ??= foundry.utils.getDocumentClass(documentName).metadata.labelPlural;
|
||||
};
|
||||
|
||||
tabChoices[id] = name;
|
||||
};
|
||||
|
||||
return tabChoices;
|
||||
},
|
||||
}),
|
||||
config: true,
|
||||
requiresReload: false,
|
||||
});
|
||||
// #endregion Registration
|
||||
|
||||
// #region Implementation
|
||||
Hooks.once(`ready`, () => {
|
||||
const defaultTab = game.settings.get(__ID, key);
|
||||
if (defaultTab) {
|
||||
Logger.debug(`Changing tab to:`, defaultTab);
|
||||
ui.sidebar.changeTab(defaultTab, `primary`);
|
||||
};
|
||||
});
|
||||
// #endregion Implementation
|
||||
};
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue