diff --git a/main.ts b/main.ts index 9c70cf5..bbeadef 100644 --- a/main.ts +++ b/main.ts @@ -36,6 +36,7 @@ import { EmbeddedTemplateManager } from './src/templates/embeddedTemplates'; import { FolderSuggest } from './src/ui/components/FolderSuggest'; import { SUPPORTED_PAPER_SIZES } from './src/utils/paperSizeMapper'; import { PluginLifecycle } from './src/plugin/PluginLifecycle'; +import { CommandRegistry } from './src/plugin/CommandRegistry'; import * as path from 'path'; import * as fs from 'fs'; @@ -46,6 +47,7 @@ export class obsidianTypstPDFExport extends Plugin { embeddedTemplateManager: EmbeddedTemplateManager; currentExportController: AbortController | null = null; private lifecycle: PluginLifecycle; + private commandRegistry: CommandRegistry; // Type predicate to filter for markdown TFiles private isMarkdownFile(file: TAbstractFile): file is TFile { @@ -59,6 +61,9 @@ export class obsidianTypstPDFExport extends Plugin { // Initialize core plugin functionality await this.lifecycle.initialize(); + // Initialize command registry + this.commandRegistry = new CommandRegistry(this); + // Register custom icon addIcon('typst-pdf-export', ` @@ -71,7 +76,7 @@ export class obsidianTypstPDFExport extends Plugin { }); // Register commands - this.registerCommands(); + this.commandRegistry.registerCommands(); // Register event handlers this.registerEventHandlers(); @@ -232,34 +237,6 @@ export class obsidianTypstPDFExport extends Plugin { } } - private registerCommands(): void { - // Export current note command - this.addCommand({ - id: 'export-current-note', - name: 'Export current note(s)', - editorCallback: (editor: Editor, view: MarkdownView) => { - this.exportCurrentNote(view); - } - }); - - // Export with configuration command - this.addCommand({ - id: 'export-with-config', - name: 'Export with configuration…', - editorCallback: (editor: Editor, view: MarkdownView) => { - this.showExportModal(view); - } - }); - - // Check dependencies command - this.addCommand({ - id: 'check-dependencies', - name: 'Check Pandoc and Typst dependencies', - callback: () => { - this.showDependencyStatus(); - } - }); - } private registerEventHandlers(): void { // Add context menu item @@ -360,7 +337,7 @@ export class obsidianTypstPDFExport extends Plugin { /** * Export the current note with default settings */ - private async exportCurrentNote(view: MarkdownView): Promise { + async exportCurrentNote(view: MarkdownView): Promise { const file = view.file; if (!file) { new Notice('No active file to export'); @@ -373,7 +350,7 @@ export class obsidianTypstPDFExport extends Plugin { /** * Show the export configuration modal */ - private async showExportModal(view: MarkdownView): Promise { + async showExportModal(view: MarkdownView): Promise { const file = view.file; if (!file) { new Notice('No active file to export'); diff --git a/src/plugin/CommandRegistry.ts b/src/plugin/CommandRegistry.ts new file mode 100644 index 0000000..1f08a79 --- /dev/null +++ b/src/plugin/CommandRegistry.ts @@ -0,0 +1,43 @@ +/** + * Command Registration + * Handles registration of all plugin commands and their callbacks + */ + +import { Editor, MarkdownView } from 'obsidian'; +import type { obsidianTypstPDFExport } from '../../main'; + +export class CommandRegistry { + constructor(private plugin: obsidianTypstPDFExport) {} + + /** + * Register all plugin commands + */ + registerCommands(): void { + // Export current note command + this.plugin.addCommand({ + id: 'export-current-note', + name: 'Export current note(s)', + editorCallback: (editor: Editor, view: MarkdownView) => { + this.plugin.exportCurrentNote(view); + } + }); + + // Export with configuration command + this.plugin.addCommand({ + id: 'export-with-config', + name: 'Export with configuration…', + editorCallback: (editor: Editor, view: MarkdownView) => { + this.plugin.showExportModal(view); + } + }); + + // Check dependencies command + this.plugin.addCommand({ + id: 'check-dependencies', + name: 'Check Pandoc and Typst dependencies', + callback: () => { + this.plugin.showDependencyStatus(); + } + }); + } +} \ No newline at end of file