Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always open in new tab setting #497

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/ui/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import EventCache from "src/core/EventCache";
* @param cache
* @param param1 App
* @param id event ID
* @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
id: string,
openInNewTab: boolean
) {
const details = cache.getInfoForEditableEvent(id);
if (!details) {
Expand All @@ -28,7 +30,7 @@ export async function openFileForEvent(
if (!leaf) {
return;
}
if (leaf.getViewState().pinned) {
if (leaf.getViewState().pinned || openInNewTab) {
leaf = workspace.getLeaf("tab");
}
await leaf.openFile(file);
Expand Down
40 changes: 38 additions & 2 deletions src/ui/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export interface FullCalendarSettings {
mobile: string;
};
timeFormat24h: boolean;
clickToCreateEventFromMonthView: boolean;
clickToCreateEventFromMonthView?: boolean;
alwaysOpenInNewTab?: boolean;
ctrlClickToOpenFile?: boolean;
}

export const DEFAULT_SETTINGS: FullCalendarSettings = {
Expand All @@ -39,6 +41,8 @@ export const DEFAULT_SETTINGS: FullCalendarSettings = {
},
timeFormat24h: false,
clickToCreateEventFromMonthView: true,
alwaysOpenInNewTab: false,
ctrlClickToOpenFile: true,
};

const WEEKDAYS = [
Expand Down Expand Up @@ -238,14 +242,46 @@ 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;
await this.plugin.saveSettings();
});
});

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 ?? false
);
toggle.onChange(async (val) => {
this.plugin.settings.alwaysOpenInNewTab = val;
await this.plugin.saveSettings();
});
});

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 ?? true
);
toggle.onChange(async (val) => {
this.plugin.settings.ctrlClickToOpenFile = val;
await this.plugin.saveSettings();
});
});

containerEl.createEl("h2", { text: "Manage Calendars" });
addCalendarButton(
this.app,
Expand Down
12 changes: 8 additions & 4 deletions src/ui/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,18 @@ 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,
info.event.id
info.event.id,
this.plugin.settings
);
} else {
launchEditModal(this.plugin, info.event.id);
Expand Down