2022-12-02 16:46:14 +01:00
|
|
|
import OnClickButtonWidget from "./onclick_button.js";
|
2022-12-19 23:19:47 +01:00
|
|
|
import linkContextMenuService from "../../menus/link_context_menu.js";
|
|
|
|
import utils from "../../services/utils.js";
|
2022-12-01 13:07:23 +01:00
|
|
|
import appContext from "../../components/app_context.js";
|
2025-02-11 19:16:11 +02:00
|
|
|
import type FNote from "../../entities/fnote.js";
|
2022-08-05 16:44:26 +02:00
|
|
|
|
2022-12-02 16:46:14 +01:00
|
|
|
export default class OpenNoteButtonWidget extends OnClickButtonWidget {
|
2025-02-11 19:16:11 +02:00
|
|
|
|
|
|
|
private noteToOpen: FNote;
|
|
|
|
|
|
|
|
constructor(noteToOpen: FNote) {
|
2022-12-19 23:19:47 +01:00
|
|
|
super();
|
2021-11-20 12:49:12 +01:00
|
|
|
|
2022-12-19 23:19:47 +01:00
|
|
|
this.noteToOpen = noteToOpen;
|
2021-11-20 12:49:12 +01:00
|
|
|
|
2024-12-22 22:23:26 +02:00
|
|
|
this.title(() => utils.escapeHtml(this.noteToOpen.title))
|
2022-12-19 23:19:47 +01:00
|
|
|
.icon(() => this.noteToOpen.getIcon())
|
|
|
|
.onClick((widget, evt) => this.launch(evt))
|
|
|
|
.onAuxClick((widget, evt) => this.launch(evt))
|
2025-02-11 19:16:11 +02:00
|
|
|
.onContextMenu((evt) => {
|
|
|
|
if (evt) {
|
|
|
|
linkContextMenuService.openContextMenu(this.noteToOpen.noteId, evt);
|
|
|
|
}
|
|
|
|
});
|
2022-12-19 23:19:47 +01:00
|
|
|
}
|
2021-10-05 22:08:02 +02:00
|
|
|
|
2025-02-11 19:16:11 +02:00
|
|
|
async launch(evt: JQuery.ClickEvent | JQuery.TriggeredEvent | JQuery.ContextMenuEvent) {
|
2023-09-06 14:49:01 +00:00
|
|
|
if (evt.which === 3) {
|
|
|
|
return;
|
|
|
|
}
|
2022-12-19 23:19:47 +01:00
|
|
|
const ctrlKey = utils.isCtrlKey(evt);
|
2021-09-16 23:09:48 +02:00
|
|
|
|
2022-12-19 23:19:47 +01:00
|
|
|
if ((evt.which === 1 && ctrlKey) || evt.which === 2) {
|
|
|
|
await appContext.tabManager.openInNewTab(this.noteToOpen.noteId);
|
|
|
|
} else {
|
|
|
|
await appContext.tabManager.openInSameTab(this.noteToOpen.noteId);
|
|
|
|
}
|
2021-09-16 23:09:48 +02:00
|
|
|
}
|
2021-10-05 22:08:02 +02:00
|
|
|
|
|
|
|
initialRenderCompleteEvent() {
|
|
|
|
// we trigger refresh above
|
|
|
|
}
|
2021-09-16 23:09:48 +02:00
|
|
|
}
|