diff --git a/manifest.json b/manifest.json
index 528dd4d..9014c6b 100644
--- a/manifest.json
+++ b/manifest.json
@@ -2,7 +2,7 @@
"id": "periodic-notes",
"name": "Periodic Notes",
"description": "Create/manage your daily, weekly, and monthly notes",
- "version": "0.0.13",
+ "version": "0.0.14",
"author": "Liam Cain",
"authorUrl": "https://github.com/liamcain/",
"isDesktopOnly": false,
diff --git a/package.json b/package.json
index a7f8ae4..6b97845 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "obsidian-periodic-notes",
- "version": "0.0.13",
+ "version": "0.0.14",
"description": "Create/manage daily, weekly, and monthly notes",
"author": "liamcain",
"main": "main.js",
@@ -14,7 +14,7 @@
"dependencies": {
"@popperjs/core": "2.9.1",
"obsidian": "obsidianmd/obsidian-api#master",
- "obsidian-daily-notes-interface": "0.8.4",
+ "obsidian-daily-notes-interface": "0.9.0",
"svelte": "3.35.0",
"tslib": "2.1.0"
},
diff --git a/src/icons.ts b/src/icons.ts
new file mode 100644
index 0000000..bfb7070
--- /dev/null
+++ b/src/icons.ts
@@ -0,0 +1,21 @@
+export const calendarDayIcon = `
+
+
+
+
+`;
+
+export const calendarWeekIcon = `
+
+
+
+
+`;
+
+export const calendarMonthIcon = `
+
+
+
+
+
+`;
diff --git a/src/index.ts b/src/index.ts
index 94f2d2f..3d45c0f 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,9 +1,10 @@
import type moment from "moment";
-import { App, Plugin } from "obsidian";
+import { addIcon, App, Plugin } from "obsidian";
import { getCommands, openPeriodicNote, periodConfigs } from "./commands";
import { SETTINGS_UPDATED } from "./events";
-import { PeriodicNoteCreateModal } from "./modal";
+import { calendarDayIcon, calendarMonthIcon, calendarWeekIcon } from "./icons";
+import { showFileMenu } from "./modal";
import {
DEFAULT_SETTINGS,
IPeriodicity,
@@ -26,10 +27,10 @@ export default class PeriodicNotesPlugin extends Plugin {
public settings: ISettings;
public isInitialLoad: boolean;
- private ribbonEls: HTMLElement[];
+ private ribbonEl: HTMLElement;
async onload(): Promise {
- this.ribbonEls = [];
+ this.ribbonEl = null;
this.updateSettings = this.updateSettings.bind(this);
@@ -37,6 +38,10 @@ export default class PeriodicNotesPlugin extends Plugin {
this.addSettingTab(new PeriodicNotesSettingsTab(this.app, this));
this.app.workspace.onLayoutReady(this.onLayoutReady.bind(this));
+
+ addIcon("calendar-day", calendarDayIcon);
+ addIcon("calendar-week", calendarWeekIcon);
+ addIcon("calendar-month", calendarMonthIcon);
}
onLayoutReady(): void {
@@ -63,33 +68,27 @@ export default class PeriodicNotesPlugin extends Plugin {
}
private configureRibbonIcons() {
- for (const ribbonEl of this.ribbonEls) {
- ribbonEl.detach();
- }
+ this.ribbonEl?.detach();
const configuredPeriodicities = ["daily", "weekly", "monthly"].filter(
(periodicity) => this.settings[periodicity].enabled
);
- if (configuredPeriodicities.length > 1) {
- this.ribbonEls.push(
- this.addRibbonIcon(
- "calendar-with-checkmark",
- "Open periodic note",
- () => new PeriodicNoteCreateModal(this.app, this.settings).open()
- )
- );
- } else if (configuredPeriodicities.length === 1) {
+ if (configuredPeriodicities.length) {
const periodicity = configuredPeriodicities[0] as IPeriodicity;
const config = periodConfigs[periodicity];
- this.ribbonEls.push(
- this.addRibbonIcon(
- "calendar-with-checkmark",
- `Open ${config.relativeUnit}'s note`,
- () => openPeriodicNote(periodicity, window.moment(), false)
- )
+ this.ribbonEl = this.addRibbonIcon(
+ `calendar-${config.unitOfTime}`,
+ `Open ${config.relativeUnit}`,
+ () => openPeriodicNote(periodicity, window.moment(), false)
);
+ this.ribbonEl.addEventListener("contextmenu", (ev: MouseEvent) => {
+ showFileMenu(this.app, this.settings, {
+ x: ev.pageX,
+ y: ev.pageY,
+ });
+ });
}
}
diff --git a/src/modal.ts b/src/modal.ts
index 74e8609..503dc8e 100644
--- a/src/modal.ts
+++ b/src/modal.ts
@@ -1,8 +1,31 @@
-import { App, Modal } from "obsidian";
+import { App, Menu, Modal, Point } from "obsidian";
import { openPeriodicNote, periodConfigs } from "./commands";
import type { IPeriodicity, ISettings } from "./settings";
+export function showFileMenu(
+ app: App,
+ settings: ISettings,
+ position: Point
+): void {
+ const contextMenu = new Menu(app);
+
+ ["daily", "weekly", "monthly"]
+ .filter((periodicity) => settings[periodicity].enabled)
+ .forEach((periodicity: IPeriodicity) => {
+ const config = periodConfigs[periodicity];
+ contextMenu.addItem((item) =>
+ item
+ .setTitle(`Open ${config.relativeUnit}`)
+ .setIcon(`calendar-${config.unitOfTime}`)
+ .onClick(() => {
+ openPeriodicNote(periodicity, window.moment(), false);
+ })
+ );
+ });
+
+ contextMenu.showAtPosition(position);
+}
export class PeriodicNoteCreateModal extends Modal {
constructor(app: App, settings: ISettings) {
super(app);
diff --git a/yarn.lock b/yarn.lock
index 5d683fe..ae133f1 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3272,10 +3272,10 @@ object.pick@^1.3.0:
dependencies:
isobject "^3.0.1"
-obsidian-daily-notes-interface@0.8.4:
- version "0.8.4"
- resolved "https://registry.yarnpkg.com/obsidian-daily-notes-interface/-/obsidian-daily-notes-interface-0.8.4.tgz#530cec611878c2d2ae94ba868490df5bf17c8ccf"
- integrity sha512-REKQtAuIOKDbvNH/th1C1gWmJWCP5tRn9T/mfZGZt4Zncgko7McXK0aSKFtEInipvgbZJ2nScivvyLdiWluSMw==
+obsidian-daily-notes-interface@0.9.0:
+ version "0.9.0"
+ resolved "https://registry.yarnpkg.com/obsidian-daily-notes-interface/-/obsidian-daily-notes-interface-0.9.0.tgz#6a8996917899097c99ed62264a28e231a297d3c6"
+ integrity sha512-vzqOLgjTJi+jeT654eRgyEA2PfqeNI23Fe955VwqnRpAjkarr6qcllpC9cs1XBgpjmRm/XRIqXFdLsO+1z1RGg==
dependencies:
obsidian obsidianmd/obsidian-api#master
tslib "2.1.0"