Skip to content

Commit 656e482

Browse files
author
Charles Feval
committed
Move to today
1 parent 6a20164 commit 656e482

File tree

5 files changed

+69
-4
lines changed

5 files changed

+69
-4
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"author": "Charles Feval",
55
"description": "Track your tasks across all the notes in your workspace. Organize your day. Plan your work",
66
"authorUrl": "https://fev.al",
7-
"version": "1.8.4",
7+
"version": "1.9",
88
"minAppVersion": "1.0.0",
99
"isDesktopOnly": false
1010
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-pw",
3-
"version": "1.8.4",
3+
"version": "1.9",
44
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
55
"main": "main.js",
66
"scripts": {

src/Commands/MoveToTodayCommand.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { LineOperations } from "../domain/LineOperations";
2+
import { TodoStatus } from "../domain/TodoItem";
3+
import { FileOperations } from "../domain/FileOperations";
4+
import { ProletarianWizardSettings } from "../domain/ProletarianWizardSettings";
5+
import { ObsidianFile } from "../infrastructure/ObsidianFile";
6+
import { Command, Editor, Hotkey, MarkdownView, TFile, App } from "obsidian";
7+
import { DateTime } from "luxon";
8+
9+
export class MoveToTodayCommand implements Command {
10+
constructor(
11+
private lineOperations: LineOperations,
12+
private settings?: ProletarianWizardSettings,
13+
private app?: App
14+
) {}
15+
16+
id: string = "pw-move-todo-to-today-command";
17+
name: string = "Mark todo to today";
18+
icon?: string = "dot";
19+
mobileOnly?: boolean = false;
20+
callback?: () => any;
21+
checkCallback?: (checking: boolean) => boolean | void;
22+
editorCallback(editor: Editor, view: MarkdownView) {
23+
const lineNumber = editor.getCursor("from").line;
24+
let line = editor.getLine(lineNumber);
25+
const todo = this.lineOperations.toTodo(line, lineNumber);
26+
if (todo.isTodo) {
27+
const dueDateAttribute = this.settings?.dueDateAttribute || "due";
28+
29+
if (view.file && this.app) {
30+
const fileOperations = new FileOperations(this.settings);
31+
const obsidianFile = new ObsidianFile(this.app, view.file);
32+
const todoWithFile = {
33+
...todo.todo,
34+
file: obsidianFile,
35+
line: lineNumber,
36+
};
37+
38+
fileOperations
39+
.updateAttributeAsync(
40+
todoWithFile,
41+
this.settings.dueDateAttribute,
42+
DateTime.now().toISODate()
43+
)
44+
.then(() => {
45+
// File operations will handle the update
46+
})
47+
.catch(console.error);
48+
}
49+
}
50+
}
51+
editorCheckCallback?: (
52+
checking: boolean,
53+
editor: Editor,
54+
view: MarkdownView
55+
) => boolean | void;
56+
hotkeys?: Hotkey[] = [];
57+
}

src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ObsidianFile } from "./infrastructure/ObsidianFile";
66
import { App, MarkdownView, Plugin, PluginManifest, TFile } from "obsidian";
77
import { TodoIndex } from "./domain/TodoIndex";
88
import { ToggleTodoCommand } from "./Commands/ToggleTodoCommand";
9+
import { MoveToTodayCommand } from "./Commands/MoveToTodayCommand";
910
import { LineOperations } from "./domain/LineOperations";
1011
import { ToggleOngoingTodoCommand } from "./Commands/ToggleOngoingTodoCommand";
1112
import { ProletarianWizardSettingsTab } from "./Views/ProletarianWizardSettingsTab";
@@ -106,6 +107,7 @@ export default class ProletarianWizard extends Plugin {
106107
this.app
107108
)
108109
);
110+
this.addCommand(new MoveToTodayCommand(lineOperations, this.settings, this.app));
109111
this.addCommand(openPlanningCommand);
110112
this.addCommand(openNewPlanningCommand);
111113
this.addCommand(openPlanningCurrentCommand);

src/ui/TodoItemComponent.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { StandardDependencies } from "./StandardDependencies";
1111
import { PwEvent } from "src/events/PwEvent";
1212
import { Sound } from "./SoundPlayer";
1313
import { Random } from "src/Random";
14+
import { DateTime } from "luxon";
1415

1516
function priorityToIcon(
1617
attributes: IDictionary<string | boolean> | undefined
@@ -167,10 +168,15 @@ export function TodoItemComponent({todo, deps, playSound, dontCrossCompleted, di
167168
})
168169
menu.addSeparator()
169170
menu.addItem((item) => {
171+
item.setTitle("🗓️ Move to today")
172+
item.setIcon("calendar")
173+
item.onClick((evt) => fileOperations.updateAttributeAsync(todo, settings.dueDateAttribute, DateTime.now().toISODate()).then())
174+
})
175+
menu.addItem((item) => {
170176
item.setTitle("📌 Toggle selected")
171177
item.setIcon("pin")
172178
item.onClick((evt) => {
173-
fileOperations.updateAttributeAsync(todo, settings.selectedAttribute, !todo.attributes[settings.selectedAttribute])
179+
fileOperations.updateAttributeAsync(todo, settings.selectedAttribute, !todo.attributes[settings.selectedAttribute])
174180
})
175181
})
176182
menu.showAtMouseEvent(evt)
@@ -244,4 +250,4 @@ export function TodoItemComponent({todo, deps, playSound, dontCrossCompleted, di
244250
</div>
245251
</>;
246252

247-
}
253+
}

0 commit comments

Comments
 (0)