Skip to content

Commit 1dc3b33

Browse files
committed
Add commands to change the status of the note on active tab
1 parent b363564 commit 1dc3b33

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/front-matter-manager.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,20 @@ export class FrontMatterManager {
131131

132132
editor.setCursor({ line: targetLine, ch: 0 });
133133
}
134+
135+
async changeStatus(status: string): Promise<void> {
136+
const activeFile = this.app.workspace.getActiveFile();
137+
if (!activeFile) {
138+
new Notice("No active file found.");
139+
return;
140+
}
141+
await this.frontMatterManager.updateProperty(
142+
activeFile,
143+
(frontmatter) => {
144+
frontmatter.status = status;
145+
return frontmatter;
146+
}
147+
);
148+
new Notice(`Updated status to ${status}`);
149+
}
134150
}

src/main.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,30 @@ export default class TimeTreePlugin extends Plugin {
5656
},
5757
});
5858

59+
this.addCommand({
60+
id: "change-status-todo",
61+
name: "Change status to todo",
62+
callback: async () => {
63+
await this.changeStatus("todo");
64+
},
65+
});
66+
67+
this.addCommand({
68+
id: "change-status-doing",
69+
name: "Change status to doing",
70+
callback: async () => {
71+
await this.changeStatus("doing");
72+
},
73+
});
74+
75+
this.addCommand({
76+
id: "change-status-done",
77+
name: "Change status to done",
78+
callback: async () => {
79+
await this.changeStatus("done");
80+
},
81+
});
82+
5983
this.buttonObserver = new MutationObserver((mutations) => {
6084
mutations.forEach((mutation) => {
6185
mutation.addedNodes.forEach((node) => {
@@ -196,6 +220,22 @@ export default class TimeTreePlugin extends Plugin {
196220
editor.setCursor({ line: cursor.line, ch: cursor.ch + 4 });
197221
}
198222

223+
async changeStatus(status: string): Promise<void> {
224+
const activeFile = this.app.workspace.getActiveFile();
225+
if (!activeFile) {
226+
new Notice("No active file found.");
227+
return;
228+
}
229+
await this.frontMatterManager.updateProperty(
230+
activeFile,
231+
(frontmatter) => {
232+
frontmatter.status = status;
233+
return frontmatter;
234+
}
235+
);
236+
new Notice(`Updated status to ${status}`);
237+
}
238+
199239
scheduleComputeTimeTree(): void {
200240
// Clear any existing interval
201241
if (this.computeIntervalHandle) {

0 commit comments

Comments
 (0)