From 3ecda83c1acbdbb19ddd12a274047b74327df6e3 Mon Sep 17 00:00:00 2001 From: Aleix Soler Date: Sun, 25 May 2025 10:53:54 +0200 Subject: [PATCH] feat: add quick commands settings --- constants/defaults.ts | 1 + integrations/settings/settings-ui.ts | 68 ++++++++++++++++++++++++++++ models/types.ts | 1 + 3 files changed, 70 insertions(+) diff --git a/constants/defaults.ts b/constants/defaults.ts index cbe487f..c3de4b1 100644 --- a/constants/defaults.ts +++ b/constants/defaults.ts @@ -25,6 +25,7 @@ export const DEFAULT_SETTINGS: NoteStatusSettings = { tagPrefix: 'obsidian-note-status', strictStatuses: false, // Default to show all statuses from frontmatter excludeUnknownStatus: true, // Default to exclude unknown status files for better performance + quickStatusCommands: ['active', 'completed'], // Add default quick commands }; /** diff --git a/integrations/settings/settings-ui.ts b/integrations/settings/settings-ui.ts index 33ae528..0952d54 100644 --- a/integrations/settings/settings-ui.ts +++ b/integrations/settings/settings-ui.ts @@ -38,6 +38,7 @@ export class NoteStatusSettingsUI { this.renderUISettings(containerEl, settings); this.renderTagSettings(containerEl, settings); this.renderCustomStatusSettings(containerEl, settings); + this.renderQuickCommandsSettings(containerEl, settings); } /** @@ -168,6 +169,73 @@ export class NoteStatusSettingsUI { .addToggle(toggle => toggle .setValue(settings.strictStatuses || false) .onChange(value => this.callbacks.onSettingChange('strictStatuses', value))); + + } + + /** + * Renders the quick commands configuration section + */ + private renderQuickCommandsSettings(containerEl: HTMLElement, settings: any): void { + new Setting(containerEl) + .setName('Quick status commands') + .setDesc('Select which statuses should have dedicated commands in the command palette. These can be assigned hotkeys for quick access.') + .setHeading(); + + const quickCommandsContainer = containerEl.createDiv({ cls: 'quick-commands-container' }); + + // Get all available statuses from service + const allStatuses = this.getAllAvailableStatuses(settings); + const currentQuickCommands = settings.quickStatusCommands || []; + + allStatuses.forEach(status => { + const setting = new Setting(quickCommandsContainer) + .setName(`${status.icon} ${status.name}`) + .addToggle(toggle => toggle + .setValue(currentQuickCommands.includes(status.name)) + .onChange(async (value) => { + const updatedCommands = value + ? [...currentQuickCommands.filter((cmd: string) => cmd !== status.name), status.name] + : currentQuickCommands.filter((cmd: string) => cmd !== status.name); + + await this.callbacks.onSettingChange('quickStatusCommands', updatedCommands); + })); + + if (status.description) { + setting.setDesc(status.description); + } + }); + + if (allStatuses.length === 0) { + quickCommandsContainer.createDiv({ + text: 'No statuses available. Enable templates or add custom statuses first.', + cls: 'setting-item-description' + }); + } + } +/** + * Get all available statuses from templates and custom statuses + */ + private getAllAvailableStatuses(settings: any): Array<{name: string, icon: string, description?: string}> { + const statuses: Array<{name: string, icon: string, description?: string}> = []; + + // Add custom statuses + statuses.push(...settings.customStatuses); + + // Add template statuses if not using custom only + if (!settings.useCustomStatusesOnly) { + for (const templateId of settings.enabledTemplates) { + const template = PREDEFINED_TEMPLATES.find(t => t.id === templateId); + if (template) { + for (const status of template.statuses) { + if (!statuses.find(s => s.name === status.name)) { + statuses.push(status); + } + } + } + } + } + + return statuses.filter(s => s.name !== 'unknown'); } /** diff --git a/models/types.ts b/models/types.ts index d1ddb48..72b8808 100644 --- a/models/types.ts +++ b/models/types.ts @@ -28,6 +28,7 @@ export interface NoteStatusSettings { tagPrefix: string; // Prefix for the status tag (default: 'status') strictStatuses: boolean; // Whether to only show known statuses excludeUnknownStatus: boolean; // Whether to exclude files with unknown status from the status pane + quickStatusCommands: string[]; } /**