Merge pull request #5 from SebastianMC/#3-feature-request-disable-status-bar-entry

#3 feature request disable status bar entry
This commit is contained in:
SebastianMC 2022-09-07 21:56:09 +02:00 committed by GitHub
commit 52a28f63d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 3 deletions

View File

@ -28,11 +28,13 @@ import {
interface CustomSortPluginSettings { interface CustomSortPluginSettings {
additionalSortspecFile: string additionalSortspecFile: string
suspended: boolean suspended: boolean
statusBarEntryEnabled: boolean
} }
const DEFAULT_SETTINGS: CustomSortPluginSettings = { const DEFAULT_SETTINGS: CustomSortPluginSettings = {
additionalSortspecFile: 'Inbox/Inbox.md', additionalSortspecFile: 'Inbox/Inbox.md',
suspended: true // if false by default, it would be hard to handle the auto-parse after plugin install suspended: true, // if false by default, it would be hard to handle the auto-parse after plugin install
statusBarEntryEnabled: true
} }
const SORTSPEC_FILE_NAME: string = 'sortspec.md' const SORTSPEC_FILE_NAME: string = 'sortspec.md'
@ -105,8 +107,10 @@ export default class CustomSortPlugin extends Plugin {
await this.loadSettings(); await this.loadSettings();
// This adds a status bar item to the bottom of the app. Does not work on mobile apps. // This adds a status bar item to the bottom of the app. Does not work on mobile apps.
if (this.settings.statusBarEntryEnabled) {
this.statusBarItemEl = this.addStatusBarItem(); this.statusBarItemEl = this.addStatusBarItem();
this.updateStatusBar() this.updateStatusBar()
}
addIcons(); addIcons();
@ -284,5 +288,29 @@ class CustomSortSettingTab extends PluginSettingTab {
this.plugin.settings.additionalSortspecFile = value; this.plugin.settings.additionalSortspecFile = value;
await this.plugin.saveSettings(); await this.plugin.saveSettings();
})); }));
new Setting(containerEl)
.setName('Enable the status bar entry')
.setDesc('The status bar entry shows the label `Custom sort:ON` or `Custom sort:OFF`, representing the current state of the plugin.')
.addToggle(toggle => toggle
.setValue(this.plugin.settings.statusBarEntryEnabled)
.onChange(async (value) => {
this.plugin.settings.statusBarEntryEnabled = value;
if (value) {
// Enabling
if (this.plugin.statusBarItemEl) {
// for sanity
this.plugin.statusBarItemEl.detach()
}
this.plugin.statusBarItemEl = this.plugin.addStatusBarItem();
this.plugin.updateStatusBar()
} else { // disabling
if (this.plugin.statusBarItemEl) {
this.plugin.statusBarItemEl.detach()
}
}
await this.plugin.saveSettings();
}));
} }
} }