Ticket #4: Feature Request: Activate / Deactivate Custom Sort through command
- added two new commands to enable/suspend the plugin - intentionally put in the description convenient names: sort-on and sort-off - code area was not covered by unit tests, not adding new one at this point (simple logic, fresh mind ;-)
This commit is contained in:
parent
52a28f63d7
commit
9962d9e76e
|
@ -499,7 +499,7 @@ export class SortingSpecProcessor {
|
|||
|
||||
this.recentErrorMessage =
|
||||
`File: ${this.currentSortingSpecContainerFilePath}\n` +
|
||||
(hasLineContext ? `Line #${this.currentEntryLineIdx}: "${this.currentEntryLine}"\n` : '') +
|
||||
(hasLineContext ? `Specification line #${this.currentEntryLineIdx}: "${this.currentEntryLine}"\n` : '') +
|
||||
`Problem: ${code}:${problemLabel}\n` +
|
||||
`Details: ${details}`
|
||||
this.problemAlreadyReportedForCurrentLine = true
|
||||
|
|
68
src/main.ts
68
src/main.ts
|
@ -101,25 +101,9 @@ export default class CustomSortPlugin extends Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async onload() {
|
||||
console.log("loading custom-sort");
|
||||
|
||||
await this.loadSettings();
|
||||
|
||||
// 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.updateStatusBar()
|
||||
}
|
||||
|
||||
addIcons();
|
||||
|
||||
// Create an icon button in the left ribbon.
|
||||
this.ribbonIconEl = this.addRibbonIcon(
|
||||
this.settings.suspended ? ICON_SORT_SUSPENDED : ICON_SORT_ENABLED_NOT_APPLIED,
|
||||
'Toggle custom sorting', (evt: MouseEvent) => {
|
||||
// Clicking the icon toggles between the states of custom sort plugin
|
||||
this.settings.suspended = !this.settings.suspended;
|
||||
// Safe to suspend when suspended and re-enable when enabled
|
||||
switchPluginStateTo(enabled: boolean, updateRibbonBtnIcon: boolean = true) {
|
||||
this.settings.suspended = !enabled;
|
||||
this.saveSettings()
|
||||
let iconToSet: string
|
||||
if (this.settings.suspended) {
|
||||
|
@ -147,14 +131,40 @@ export default class CustomSortPlugin extends Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
if (updateRibbonBtnIcon) {
|
||||
setIcon(this.ribbonIconEl, iconToSet)
|
||||
}
|
||||
|
||||
this.updateStatusBar();
|
||||
}
|
||||
|
||||
async onload() {
|
||||
console.log("loading custom-sort");
|
||||
|
||||
await this.loadSettings();
|
||||
|
||||
// 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.updateStatusBar()
|
||||
}
|
||||
|
||||
addIcons();
|
||||
|
||||
// Create an icon button in the left ribbon.
|
||||
this.ribbonIconEl = this.addRibbonIcon(
|
||||
this.settings.suspended ? ICON_SORT_SUSPENDED : ICON_SORT_ENABLED_NOT_APPLIED,
|
||||
'Toggle custom sorting', (evt: MouseEvent) => {
|
||||
// Clicking the icon toggles between the states of custom sort plugin
|
||||
this.switchPluginStateTo(this.settings.suspended)
|
||||
});
|
||||
|
||||
this.addSettingTab(new CustomSortSettingTab(this.app, this));
|
||||
|
||||
this.registerEventHandlers()
|
||||
|
||||
this.registerCommands()
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
|
@ -187,6 +197,24 @@ export default class CustomSortPlugin extends Plugin {
|
|||
);
|
||||
}
|
||||
|
||||
registerCommands() {
|
||||
const plugin: CustomSortPlugin = this
|
||||
this.addCommand({
|
||||
id: 'enable-custom-sorting',
|
||||
name: 'Enable and apply the custom sorting, (re)parsing the sorting configuration first. Sort-on.',
|
||||
callback: () => {
|
||||
plugin.switchPluginStateTo(true, true)
|
||||
}
|
||||
});
|
||||
this.addCommand({
|
||||
id: 'suspend-custom-sorting',
|
||||
name: 'Suspend the custom sorting. Sort-off.',
|
||||
callback: () => {
|
||||
plugin.switchPluginStateTo(false, true)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
initialize() {
|
||||
this.app.workspace.onLayoutReady(() => {
|
||||
this.patchFileExplorerFolder();
|
||||
|
@ -276,7 +304,7 @@ class CustomSortSettingTab extends PluginSettingTab {
|
|||
|
||||
containerEl.empty();
|
||||
|
||||
containerEl.createEl('h2', {text: 'Settings for custom sorting plugin'});
|
||||
containerEl.createEl('h2', {text: 'Settings for Custom File Explorer Sorting Plugin'});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Path to the designated note containing sorting specification')
|
||||
|
|
Loading…
Reference in New Issue