From 5672dfaf9e9d78286fff875f434aeb475a177145 Mon Sep 17 00:00:00 2001 From: SebastianMC Date: Wed, 7 Sep 2022 21:44:16 +0200 Subject: [PATCH 1/2] Ticker #3: added new plugin setting to enable/disable status bar entry --- src/main.ts | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index 307f439..b351232 100644 --- a/src/main.ts +++ b/src/main.ts @@ -28,11 +28,13 @@ import { interface CustomSortPluginSettings { additionalSortspecFile: string suspended: boolean + statusBarEntryEnabled: boolean } const DEFAULT_SETTINGS: CustomSortPluginSettings = { 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' @@ -105,8 +107,10 @@ export default class CustomSortPlugin extends Plugin { await this.loadSettings(); // This adds a status bar item to the bottom of the app. Does not work on mobile apps. - this.statusBarItemEl = this.addStatusBarItem(); - this.updateStatusBar() + if (this.settings.statusBarEntryEnabled) { + this.statusBarItemEl = this.addStatusBarItem(); + this.updateStatusBar() + } addIcons(); @@ -284,5 +288,30 @@ class CustomSortSettingTab extends PluginSettingTab { this.plugin.settings.additionalSortspecFile = value; 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) { + // for sanity + this.plugin.statusBarItemEl.detach() + } + } + await this.plugin.saveSettings(); + })); } } From d44a386167c885e4c39524a1fe7f864cbd9d062d Mon Sep 17 00:00:00 2001 From: SebastianMC Date: Wed, 7 Sep 2022 21:51:33 +0200 Subject: [PATCH 2/2] Ticket #3: added new plugin setting to enable/disable status bar entry - comment clean up --- src/main.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index b351232..c50c883 100644 --- a/src/main.ts +++ b/src/main.ts @@ -307,7 +307,6 @@ class CustomSortSettingTab extends PluginSettingTab { } else { // disabling if (this.plugin.statusBarItemEl) { - // for sanity this.plugin.statusBarItemEl.detach() } }