refactor: extract CommandRegistry from main.ts
Extract command registration logic into dedicated CommandRegistry class to improve separation of concerns and reduce main.ts complexity. - Create src/plugin/CommandRegistry.ts (~35 lines) - Move registerCommands() method to CommandRegistry - Extract all 3 command definitions with callbacks: * export-current-note * export-with-config * check-dependencies - Update main.ts to delegate to CommandRegistry - Change exportCurrentNote() and showExportModal() to public - Remove old registerCommands() method from main.ts Part of comprehensive refactoring plan (main.ts: 1792 lines → 6 modules). Step 1.2 complete. Commands functionality preserved. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2 files changed
+51
-31
No files matched your search
@@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user