feat: add bookmark from recent files + calendar middle-click
- Recent files right-click now has 'Add to bookmarks' option - Calendar: middle-click on day/week/quarter/month/year opens in new tab - Added openPeriodNoteInLeaf() method for opening period notes in a specific leaf
This commit is contained in:
+37
@@ -376,6 +376,43 @@ export default class WaypointPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Open period note in a specific leaf (for middle-click) ──
|
||||||
|
async openPeriodNoteInLeaf(period: 'day' | 'week' | 'month' | 'quarter' | 'year', date: moment.Moment, leaf: any): Promise<void> {
|
||||||
|
type PeriodConfig = { settings: PeriodNoteSettings; label: string };
|
||||||
|
const configs: Record<string, PeriodConfig> = {
|
||||||
|
day: { settings: this.settings.daily, label: 'Daily' },
|
||||||
|
week: { settings: this.settings.weekly, label: 'Weekly' },
|
||||||
|
month: { settings: this.settings.monthly, label: 'Monthly' },
|
||||||
|
quarter: { settings: this.settings.quarterly, label: 'Quarterly' },
|
||||||
|
year: { settings: this.settings.yearly, label: 'Yearly' },
|
||||||
|
};
|
||||||
|
const config = configs[period];
|
||||||
|
if (!config) return;
|
||||||
|
const { settings: periodSettings } = config;
|
||||||
|
const filename = date.format(periodSettings.nameFormat) + '.md';
|
||||||
|
const fullPath = periodSettings.folder ? `${periodSettings.folder}/${filename}` : filename;
|
||||||
|
let file = this.app.vault.getFileByPath(fullPath);
|
||||||
|
if (!file) {
|
||||||
|
try {
|
||||||
|
const templatePath = periodSettings.templateFile + '.md';
|
||||||
|
const templateFile = this.app.vault.getFileByPath(templatePath);
|
||||||
|
if (templateFile) {
|
||||||
|
const templateContent = await this.app.vault.read(templateFile);
|
||||||
|
file = await this.app.vault.create(fullPath, templateContent);
|
||||||
|
} else {
|
||||||
|
const content = `---\ntype: ${periodSettings.typeProperty}\ndate: ${date.format('YYYY-MM-DD')}\n---\n\n`;
|
||||||
|
file = await this.app.vault.create(fullPath, content);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
new Notice(`Failed to create ${config.label.toLowerCase()} note: ${err.message}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (file) {
|
||||||
|
await leaf.openFile(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ── Period note navigation (next/prev from current file) ──
|
// ── Period note navigation (next/prev from current file) ──
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -84,18 +84,36 @@ export class WaypointView extends ItemView {
|
|||||||
qEl.addEventListener('click', () => {
|
qEl.addEventListener('click', () => {
|
||||||
this.plugin.openPeriodNote('quarter', displayDate);
|
this.plugin.openPeriodNote('quarter', displayDate);
|
||||||
});
|
});
|
||||||
|
qEl.addEventListener('mousedown', (event: MouseEvent) => {
|
||||||
|
if (event.button === 1) {
|
||||||
|
event.preventDefault();
|
||||||
|
this.plugin.openPeriodNoteInLeaf('quarter', displayDate, this.app.workspace.getLeaf('tab'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const mLabel = displayDate.format('MMMM');
|
const mLabel = displayDate.format('MMMM');
|
||||||
const mEl = breadcrumb.createSpan({ cls: 'waypoint-clickable', text: mLabel });
|
const mEl = breadcrumb.createSpan({ cls: 'waypoint-clickable', text: mLabel });
|
||||||
mEl.addEventListener('click', () => {
|
mEl.addEventListener('click', () => {
|
||||||
this.plugin.openPeriodNote('month', displayDate);
|
this.plugin.openPeriodNote('month', displayDate);
|
||||||
});
|
});
|
||||||
|
mEl.addEventListener('mousedown', (event: MouseEvent) => {
|
||||||
|
if (event.button === 1) {
|
||||||
|
event.preventDefault();
|
||||||
|
this.plugin.openPeriodNoteInLeaf('month', displayDate, this.app.workspace.getLeaf('tab'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const yLabel = displayDate.format('YYYY');
|
const yLabel = displayDate.format('YYYY');
|
||||||
const yEl = breadcrumb.createSpan({ cls: 'waypoint-clickable', text: yLabel });
|
const yEl = breadcrumb.createSpan({ cls: 'waypoint-clickable', text: yLabel });
|
||||||
yEl.addEventListener('click', () => {
|
yEl.addEventListener('click', () => {
|
||||||
this.plugin.openPeriodNote('year', displayDate);
|
this.plugin.openPeriodNote('year', displayDate);
|
||||||
});
|
});
|
||||||
|
yEl.addEventListener('mousedown', (event: MouseEvent) => {
|
||||||
|
if (event.button === 1) {
|
||||||
|
event.preventDefault();
|
||||||
|
this.plugin.openPeriodNoteInLeaf('year', displayDate, this.app.workspace.getLeaf('tab'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Right: ◀ Today ▶
|
// Right: ◀ Today ▶
|
||||||
const todayGroup = topRow.createDiv({ cls: 'waypoint-calendar-today-group' });
|
const todayGroup = topRow.createDiv({ cls: 'waypoint-calendar-today-group' });
|
||||||
@@ -148,6 +166,13 @@ export class WaypointView extends ItemView {
|
|||||||
const monday = week.days[0].date;
|
const monday = week.days[0].date;
|
||||||
this.plugin.openPeriodNote('week', monday);
|
this.plugin.openPeriodNote('week', monday);
|
||||||
});
|
});
|
||||||
|
wnCell.addEventListener('mousedown', (event: MouseEvent) => {
|
||||||
|
if (event.button === 1) {
|
||||||
|
event.preventDefault();
|
||||||
|
const file = this.app.workspace.getLeaf('tab');
|
||||||
|
this.plugin.openPeriodNoteInLeaf('week', monday, file);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
for (const day of week.days) {
|
for (const day of week.days) {
|
||||||
const cell = row.createEl('td', { cls: 'waypoint-day' });
|
const cell = row.createEl('td', { cls: 'waypoint-day' });
|
||||||
@@ -173,6 +198,13 @@ export class WaypointView extends ItemView {
|
|||||||
cell.addEventListener('click', () => {
|
cell.addEventListener('click', () => {
|
||||||
this.plugin.openPeriodNote('day', day.date);
|
this.plugin.openPeriodNote('day', day.date);
|
||||||
});
|
});
|
||||||
|
cell.addEventListener('mousedown', (event: MouseEvent) => {
|
||||||
|
if (event.button === 1) {
|
||||||
|
event.preventDefault();
|
||||||
|
const file = this.app.workspace.getLeaf('tab');
|
||||||
|
this.plugin.openPeriodNoteInLeaf('day', day.date, file);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,14 +290,23 @@ export class WaypointView extends ItemView {
|
|||||||
.setIcon('file-plus')
|
.setIcon('file-plus')
|
||||||
.onClick(() => this.focusFile(file, 'tab')),
|
.onClick(() => this.focusFile(file, 'tab')),
|
||||||
);
|
);
|
||||||
|
menu.addItem((item) =>
|
||||||
|
item
|
||||||
|
.setSection('action')
|
||||||
|
.setTitle('Add to bookmarks')
|
||||||
|
.setIcon('bookmark')
|
||||||
|
.onClick(() => {
|
||||||
|
this.plugin.addBookmark(file.path, file.basename, 'file');
|
||||||
|
new Notice(`Bookmarked: ${file.basename}`);
|
||||||
|
}),
|
||||||
|
);
|
||||||
const tfile = this.app.vault.getAbstractFileByPath(file.path);
|
const tfile = this.app.vault.getAbstractFileByPath(file.path);
|
||||||
if (tfile) {
|
if (tfile) {
|
||||||
this.app.workspace.trigger('file-menu', menu, tfile, 'link-context-menu');
|
this.app.workspace.trigger('file-menu', menu, tfile, 'link-context-menu');
|
||||||
}
|
}
|
||||||
menu.showAtPosition({ x: event.clientX, y: event.clientY });
|
menu.showAtPosition({ x: event.clientX, y: event.clientY });
|
||||||
});
|
});
|
||||||
|
// Left click
|
||||||
// Left click
|
|
||||||
navFileTitle.addEventListener('click', (event: MouseEvent) => {
|
navFileTitle.addEventListener('click', (event: MouseEvent) => {
|
||||||
const newLeaf = Keymap.isModEvent(event);
|
const newLeaf = Keymap.isModEvent(event);
|
||||||
this.focusFile(file, newLeaf);
|
this.focusFile(file, newLeaf);
|
||||||
|
|||||||
Reference in New Issue
Block a user