()
| 91 | } |
| 92 | |
| 93 | async onload() { |
| 94 | log.logMessage("Loading QuickAdd"); |
| 95 | setQuickAddInstance(this); |
| 96 | |
| 97 | await this.loadSettings(); |
| 98 | settingsStore.replaceState(this.settings); |
| 99 | this.unsubscribeSettingsStore = settingsStore.subscribe((settings) => { |
| 100 | this.settings = settings; |
| 101 | this.requestSave(); |
| 102 | }); |
| 103 | |
| 104 | this.addCommand({ |
| 105 | id: "runQuickAdd", |
| 106 | name: QUICK_ADD_COMMAND_LABELS.run, |
| 107 | callback: () => { |
| 108 | ChoiceSuggester.Open(this, this.settings.choices, { |
| 109 | includeTemplateFolderRow: true, |
| 110 | }); |
| 111 | }, |
| 112 | }); |
| 113 | |
| 114 | this.addCommand({ |
| 115 | id: "runTemplateFromFolder", |
| 116 | name: QUICK_ADD_COMMAND_LABELS.runTemplateFromFolder, |
| 117 | callback: () => { |
| 118 | void runTemplateFromFolder(this.app, this, { |
| 119 | choiceExecutor: new ChoiceExecutor(this.app, this), |
| 120 | }); |
| 121 | }, |
| 122 | }); |
| 123 | |
| 124 | this.addCommand({ |
| 125 | id: "applyTemplateToActiveFile", |
| 126 | name: QUICK_ADD_COMMAND_LABELS.applyTemplate, |
| 127 | checkCallback: (checking) => { |
| 128 | const file = this.app.workspace.getActiveFile(); |
| 129 | const available = file?.extension === "md"; |
| 130 | if (checking) return available; |
| 131 | if (!available) return; |
| 132 | |
| 133 | void applyTemplateToNote(this.app, this, { |
| 134 | file, |
| 135 | choiceExecutor: new ChoiceExecutor(this.app, this), |
| 136 | }); |
| 137 | }, |
| 138 | }); |
| 139 | |
| 140 | this.registerEvent( |
| 141 | this.app.workspace.on("file-menu", (menu, abstractFile) => { |
| 142 | if (!(abstractFile instanceof TFile)) return; |
| 143 | if (abstractFile.extension !== "md") return; |
| 144 | |
| 145 | menu.addItem((item) => |
| 146 | item |
| 147 | // Aligns with the command-palette label |
| 148 | // (QUICK_ADD_COMMAND_LABELS.applyTemplate) so the same action reads |
| 149 | // consistently across both surfaces. Obsidian prefixes commands with |
| 150 | // "QuickAdd:"; the file menu is unprefixed, so add it here. |
nothing calls this directly
no test coverage detected