From 16f79a52140225d97ec155169f195073d4a953d2 Mon Sep 17 00:00:00 2001 From: Eatgrass Date: Fri, 12 Jan 2024 22:26:43 +0800 Subject: [PATCH] feat: open file and task links (#25) * feat: open file and task * reorder pomodoros emoji --- src/TaskTracker.ts | 15 +++++++++++++++ src/Tasks.ts | 2 +- src/TasksComponent.svelte | 25 +++++++++++++++++++++++-- src/TimerView.ts | 2 +- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/TaskTracker.ts b/src/TaskTracker.ts index 5e2c73b..4a538c0 100644 --- a/src/TaskTracker.ts +++ b/src/TaskTracker.ts @@ -138,6 +138,21 @@ export default class TaskTracker implements TaskTrackerStore { }) } + public openFile() { + if (this.state.file) { + this.plugin.app.workspace.openLinkText(this.state.file.path, '') + } + } + + public openTask = (task: TaskItem) => { + let link = task.path + if (task.blockLink) { + link += `#${task.blockLink}` + } + console.log(link) + this.plugin.app.workspace.openLinkText(`${link}`, '') + } + get pinned() { return this.state.pinned } diff --git a/src/Tasks.ts b/src/Tasks.ts index 73b17e3..9f96b2c 100644 --- a/src/Tasks.ts +++ b/src/Tasks.ts @@ -258,7 +258,7 @@ export function resolveTasks( fileName: file.name, name: detail.description, status: components.status, - blockLink: components.blockLink, + blockLink: components.blockLink.trim(), checked: rawElement.task != '' && rawElement.task != ' ', description: detail.description, done: detail.doneDate?.format(dateformat), diff --git a/src/TasksComponent.svelte b/src/TasksComponent.svelte index 8eb13c2..5873a53 100644 --- a/src/TasksComponent.svelte +++ b/src/TasksComponent.svelte @@ -3,6 +3,8 @@ import TaskItemComponent from 'TaskItemComponent.svelte' import type TaskTracker from 'TaskTracker' import Tasks, { type TaskItem } from 'Tasks' import { settings } from 'stores' +import { Menu } from 'obsidian' + export let tasks: Tasks export let tracker: TaskTracker export let render: (content: string, el: HTMLElement) => void @@ -63,7 +65,7 @@ const progressText = (item: TaskItem) => { let max = Math.max(expected, actual) if (max > 10) { if (unfinished > 0) { - return `🍅 x ${actual} ◌ x ${unfinished}` + return `◌ x ${unfinished} 🍅 x ${actual}` } else { return `🍅 x ${expected} 🥫 x ${Math.abs(unfinished)}` } @@ -84,6 +86,20 @@ const progressText = (item: TaskItem) => { : `- -` } } + +const openFile = () => { + tracker.openFile() +} + +const showTaskMenu = (task: TaskItem) => (e: MouseEvent) => { + const menu = new Menu() + menu.addItem((item) => { + item.setTitle('Open').onClick(() => { + tracker.openTask(task) + }) + }) + menu.showAtMouseEvent(e) +} @@ -133,7 +149,7 @@ const progressText = (item: TaskItem) => { > {/if} - + {$tracker.file.name} @@ -212,6 +228,7 @@ const progressText = (item: TaskItem) => { on:click={() => { activeTask(item) }} + on:contextmenu={showTaskMenu(item)} style="background: linear-gradient(to right, rgba(var(--color-green-rgb),0.25) {progress( item, )}%, transparent 0%)" @@ -290,6 +307,10 @@ const progressText = (item: TaskItem) => { padding-right: 5px; } +.pomodoro-tasks-file-name { + cursor: pointer; +} + .pomodoro-tasks-header-title .pomodoro-tasks-count { width: 50px; } diff --git a/src/TimerView.ts b/src/TimerView.ts index 427a72c..20127f3 100644 --- a/src/TimerView.ts +++ b/src/TimerView.ts @@ -38,7 +38,7 @@ export class TimerView extends ItemView { '', this, ) - }, + } }, }) }