Skip to content

Commit

Permalink
feat: open file and task links (#25)
Browse files Browse the repository at this point in the history
* feat: open file and task
* reorder pomodoros emoji
  • Loading branch information
eatgrass authored Jan 12, 2024
1 parent a940e02 commit 16f79a5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/TaskTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
25 changes: 23 additions & 2 deletions src/TasksComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)}`
}
Expand All @@ -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)
}
</script>

<!-- svelte-ignore a11y-click-events-have-key-events -->
Expand Down Expand Up @@ -133,7 +149,7 @@ const progressText = (item: TaskItem) => {
>
{/if}
</span>
<span class="pomodoro-tasks-file-name">
<span class="pomodoro-tasks-file-name" on:click={openFile}>
{$tracker.file.name}
</span>
<span class="pomodoro-tasks-count">
Expand Down Expand Up @@ -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%)"
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/TimerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class TimerView extends ItemView {
'',
this,
)
},
}
},
})
}
Expand Down

0 comments on commit 16f79a5

Please sign in to comment.