Skip to content

Commit 52a28f6

Browse files
authored
Merge pull request #5 from SebastianMC/#3-feature-request-disable-status-bar-entry
#3 feature request disable status bar entry
2 parents 6801041 + d44a386 commit 52a28f6

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/main.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ import {
2828
interface CustomSortPluginSettings {
2929
additionalSortspecFile: string
3030
suspended: boolean
31+
statusBarEntryEnabled: boolean
3132
}
3233

3334
const DEFAULT_SETTINGS: CustomSortPluginSettings = {
3435
additionalSortspecFile: 'Inbox/Inbox.md',
35-
suspended: true // if false by default, it would be hard to handle the auto-parse after plugin install
36+
suspended: true, // if false by default, it would be hard to handle the auto-parse after plugin install
37+
statusBarEntryEnabled: true
3638
}
3739

3840
const SORTSPEC_FILE_NAME: string = 'sortspec.md'
@@ -105,8 +107,10 @@ export default class CustomSortPlugin extends Plugin {
105107
await this.loadSettings();
106108

107109
// This adds a status bar item to the bottom of the app. Does not work on mobile apps.
108-
this.statusBarItemEl = this.addStatusBarItem();
109-
this.updateStatusBar()
110+
if (this.settings.statusBarEntryEnabled) {
111+
this.statusBarItemEl = this.addStatusBarItem();
112+
this.updateStatusBar()
113+
}
110114

111115
addIcons();
112116

@@ -284,5 +288,29 @@ class CustomSortSettingTab extends PluginSettingTab {
284288
this.plugin.settings.additionalSortspecFile = value;
285289
await this.plugin.saveSettings();
286290
}));
291+
292+
new Setting(containerEl)
293+
.setName('Enable the status bar entry')
294+
.setDesc('The status bar entry shows the label `Custom sort:ON` or `Custom sort:OFF`, representing the current state of the plugin.')
295+
.addToggle(toggle => toggle
296+
.setValue(this.plugin.settings.statusBarEntryEnabled)
297+
.onChange(async (value) => {
298+
this.plugin.settings.statusBarEntryEnabled = value;
299+
if (value) {
300+
// Enabling
301+
if (this.plugin.statusBarItemEl) {
302+
// for sanity
303+
this.plugin.statusBarItemEl.detach()
304+
}
305+
this.plugin.statusBarItemEl = this.plugin.addStatusBarItem();
306+
this.plugin.updateStatusBar()
307+
308+
} else { // disabling
309+
if (this.plugin.statusBarItemEl) {
310+
this.plugin.statusBarItemEl.detach()
311+
}
312+
}
313+
await this.plugin.saveSettings();
314+
}));
287315
}
288316
}

0 commit comments

Comments
 (0)