* Convert the current note to a task by adding required task frontmatter. * Opens the task edit modal pre-populated with the note's existing data.
()
| 1212 | * Opens the task edit modal pre-populated with the note's existing data. |
| 1213 | */ |
| 1214 | async convertCurrentNoteToTask(): Promise<void> { |
| 1215 | const activeFile = this.app.workspace.getActiveFile(); |
| 1216 | if (!activeFile) { |
| 1217 | new Notice(this.i18n.translate("commands.convertCurrentNoteToTask.noActiveFile")); |
| 1218 | return; |
| 1219 | } |
| 1220 | |
| 1221 | // Check if this note is already a task |
| 1222 | const existingTask = await this.cacheManager.getTaskInfo(activeFile.path); |
| 1223 | if (existingTask) { |
| 1224 | new Notice(this.i18n.translate("commands.convertCurrentNoteToTask.alreadyTask")); |
| 1225 | return; |
| 1226 | } |
| 1227 | |
| 1228 | // Read existing frontmatter and body from the file |
| 1229 | const metadata = this.app.metadataCache.getFileCache(activeFile); |
| 1230 | const frontmatter: Record<string, unknown> = metadata?.frontmatter || {}; |
| 1231 | const content = await this.app.vault.read(activeFile); |
| 1232 | |
| 1233 | const taskInfo = buildCurrentNoteConversionTaskInfo({ |
| 1234 | path: activeFile.path, |
| 1235 | basename: activeFile.basename, |
| 1236 | content, |
| 1237 | frontmatter, |
| 1238 | settings: this.settings, |
| 1239 | }); |
| 1240 | |
| 1241 | // Open the task edit modal with the constructed TaskInfo |
| 1242 | new TaskEditModal(this.app, this, { |
| 1243 | task: taskInfo, |
| 1244 | onTaskUpdated: (updatedTask) => { |
| 1245 | new Notice( |
| 1246 | this.i18n.translate("commands.convertCurrentNoteToTask.success", { |
| 1247 | title: updatedTask.title, |
| 1248 | }) |
| 1249 | ); |
| 1250 | }, |
| 1251 | }).open(); |
| 1252 | } |
| 1253 | |
| 1254 | /** |
| 1255 | * Open the task selector with create modal. |
no test coverage detected