From 941451551d95cf1aff6b7df3e930a602545bd393 Mon Sep 17 00:00:00 2001 From: Marien van Overbeek Date: Sun, 3 Sep 2023 10:55:40 +0200 Subject: [PATCH 1/4] Add "always open in new tab" setting --- src/ui/actions.ts | 7 +++++-- src/ui/settings.ts | 15 +++++++++++++++ src/ui/view.ts | 3 ++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/ui/actions.ts b/src/ui/actions.ts index bb05629..a293424 100644 --- a/src/ui/actions.ts +++ b/src/ui/actions.ts @@ -1,17 +1,20 @@ import { MarkdownView, TFile, Vault, Workspace } from "obsidian"; import EventCache from "src/core/EventCache"; +import { FullCalendarSettings } from "./settings"; /** * Open a file in the editor to a given event. * @param cache * @param param1 App * @param id event ID + * @param settings settings from FullCalendar * @returns */ export async function openFileForEvent( cache: EventCache, { workspace, vault }: { workspace: Workspace; vault: Vault }, - id: string + id: string, + settings?: FullCalendarSettings ) { const details = cache.getInfoForEditableEvent(id); if (!details) { @@ -28,7 +31,7 @@ export async function openFileForEvent( if (!leaf) { return; } - if (leaf.getViewState().pinned) { + if (leaf.getViewState().pinned || settings?.alwaysOpenInNewTab) { leaf = workspace.getLeaf("tab"); } await leaf.openFile(file); diff --git a/src/ui/settings.ts b/src/ui/settings.ts index da48222..c08812a 100644 --- a/src/ui/settings.ts +++ b/src/ui/settings.ts @@ -27,6 +27,7 @@ export interface FullCalendarSettings { }; timeFormat24h: boolean; clickToCreateEventFromMonthView: boolean; + alwaysOpenInNewTab: boolean; } export const DEFAULT_SETTINGS: FullCalendarSettings = { @@ -39,6 +40,7 @@ export const DEFAULT_SETTINGS: FullCalendarSettings = { }, timeFormat24h: false, clickToCreateEventFromMonthView: true, + alwaysOpenInNewTab: false, }; const WEEKDAYS = [ @@ -246,6 +248,19 @@ export class FullCalendarSettingTab extends PluginSettingTab { }); }); + new Setting(containerEl) + .setName("Always open events in a new tab") + .setDesc( + "Switch off to only open events in a new tab when the current tab is pinned." + ) + .addToggle((toggle) => { + toggle.setValue(this.plugin.settings.alwaysOpenInNewTab); + toggle.onChange(async (val) => { + this.plugin.settings.alwaysOpenInNewTab = val; + await this.plugin.saveSettings(); + }); + }); + containerEl.createEl("h2", { text: "Manage Calendars" }); addCalendarButton( this.app, diff --git a/src/ui/view.ts b/src/ui/view.ts index 8a70ee7..735eebb 100644 --- a/src/ui/view.ts +++ b/src/ui/view.ts @@ -133,7 +133,8 @@ export class CalendarView extends ItemView { await openFileForEvent( this.plugin.cache, this.app, - info.event.id + info.event.id, + this.plugin.settings ); } else { launchEditModal(this.plugin, info.event.id); From 91e73b8c39771989429f6a784f7e08dcaa382440 Mon Sep 17 00:00:00 2001 From: Marien van Overbeek Date: Sun, 3 Sep 2023 10:52:28 +0200 Subject: [PATCH 2/4] Switch Control: "open" vs "edit" setting --- src/ui/settings.ts | 17 +++++++++++++++++ src/ui/view.ts | 9 ++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/ui/settings.ts b/src/ui/settings.ts index c08812a..861bfc3 100644 --- a/src/ui/settings.ts +++ b/src/ui/settings.ts @@ -28,6 +28,7 @@ export interface FullCalendarSettings { timeFormat24h: boolean; clickToCreateEventFromMonthView: boolean; alwaysOpenInNewTab: boolean; + ctrlClickToOpenFile: boolean; } export const DEFAULT_SETTINGS: FullCalendarSettings = { @@ -41,6 +42,7 @@ export const DEFAULT_SETTINGS: FullCalendarSettings = { timeFormat24h: false, clickToCreateEventFromMonthView: true, alwaysOpenInNewTab: false, + ctrlClickToOpenFile: true, }; const WEEKDAYS = [ @@ -261,6 +263,21 @@ export class FullCalendarSettingTab extends PluginSettingTab { }); }); + new Setting(containerEl) + .setName( + "Click opens the edit dialog (ctrl-click to open event note)" + ) + .setDesc( + "Switch off to have click open note (ctrl-click for edit modal)." + ) + .addToggle((toggle) => { + toggle.setValue(this.plugin.settings.ctrlClickToOpenFile); + toggle.onChange(async (val) => { + this.plugin.settings.ctrlClickToOpenFile = val; + await this.plugin.saveSettings(); + }); + }); + containerEl.createEl("h2", { text: "Manage Calendars" }); addCalendarButton( this.app, diff --git a/src/ui/view.ts b/src/ui/view.ts index 735eebb..b880132 100644 --- a/src/ui/view.ts +++ b/src/ui/view.ts @@ -126,10 +126,13 @@ export class CalendarView extends ItemView { forceNarrow: this.inSidebar, eventClick: async (info) => { try { - if ( + const hasModifierKey = info.jsEvent.getModifierState("Control") || - info.jsEvent.getModifierState("Meta") - ) { + info.jsEvent.getModifierState("Meta"); + const shouldOpenFile = + hasModifierKey && + this.plugin.settings.ctrlClickToOpenFile; + if (shouldOpenFile) { await openFileForEvent( this.plugin.cache, this.app, From c9428b1635638a4275268ff5f214731963bcb057 Mon Sep 17 00:00:00 2001 From: Marien van Overbeek Date: Sat, 28 Oct 2023 17:58:04 +0200 Subject: [PATCH 3/4] Make settings optional --- src/ui/settings.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/ui/settings.ts b/src/ui/settings.ts index 861bfc3..22112b1 100644 --- a/src/ui/settings.ts +++ b/src/ui/settings.ts @@ -26,9 +26,9 @@ export interface FullCalendarSettings { mobile: string; }; timeFormat24h: boolean; - clickToCreateEventFromMonthView: boolean; - alwaysOpenInNewTab: boolean; - ctrlClickToOpenFile: boolean; + clickToCreateEventFromMonthView?: boolean; + alwaysOpenInNewTab?: boolean; + ctrlClickToOpenFile?: boolean; } export const DEFAULT_SETTINGS: FullCalendarSettings = { @@ -242,7 +242,7 @@ export class FullCalendarSettingTab extends PluginSettingTab { .setDesc("Switch off to open day view on click instead.") .addToggle((toggle) => { toggle.setValue( - this.plugin.settings.clickToCreateEventFromMonthView + this.plugin.settings.clickToCreateEventFromMonthView ?? true ); toggle.onChange(async (val) => { this.plugin.settings.clickToCreateEventFromMonthView = val; @@ -256,7 +256,9 @@ export class FullCalendarSettingTab extends PluginSettingTab { "Switch off to only open events in a new tab when the current tab is pinned." ) .addToggle((toggle) => { - toggle.setValue(this.plugin.settings.alwaysOpenInNewTab); + toggle.setValue( + this.plugin.settings.alwaysOpenInNewTab ?? false + ); toggle.onChange(async (val) => { this.plugin.settings.alwaysOpenInNewTab = val; await this.plugin.saveSettings(); @@ -271,7 +273,9 @@ export class FullCalendarSettingTab extends PluginSettingTab { "Switch off to have click open note (ctrl-click for edit modal)." ) .addToggle((toggle) => { - toggle.setValue(this.plugin.settings.ctrlClickToOpenFile); + toggle.setValue( + this.plugin.settings.ctrlClickToOpenFile ?? true + ); toggle.onChange(async (val) => { this.plugin.settings.ctrlClickToOpenFile = val; await this.plugin.saveSettings(); From de4cbaf97487432f4e60b556612ec380ccad523f Mon Sep 17 00:00:00 2001 From: Marien van Overbeek Date: Sat, 28 Oct 2023 18:01:38 +0200 Subject: [PATCH 4/4] Pass single setting instead of all settings --- src/ui/actions.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ui/actions.ts b/src/ui/actions.ts index a293424..9a3cbca 100644 --- a/src/ui/actions.ts +++ b/src/ui/actions.ts @@ -1,20 +1,19 @@ import { MarkdownView, TFile, Vault, Workspace } from "obsidian"; import EventCache from "src/core/EventCache"; -import { FullCalendarSettings } from "./settings"; /** * Open a file in the editor to a given event. * @param cache * @param param1 App * @param id event ID - * @param settings settings from FullCalendar + * @param openInNewTab whether to open in new tab or not * @returns */ export async function openFileForEvent( cache: EventCache, { workspace, vault }: { workspace: Workspace; vault: Vault }, id: string, - settings?: FullCalendarSettings + openInNewTab: boolean ) { const details = cache.getInfoForEditableEvent(id); if (!details) { @@ -31,7 +30,7 @@ export async function openFileForEvent( if (!leaf) { return; } - if (leaf.getViewState().pinned || settings?.alwaysOpenInNewTab) { + if (leaf.getViewState().pinned || openInNewTab) { leaf = workspace.getLeaf("tab"); } await leaf.openFile(file);