mirror of
https://github.com/zadam/trilium.git
synced 2024-11-11 09:46:25 +08:00
bookmark buttons should behave similarly as other launcher buttons in respect to context menu, ctrl-click, left click
This commit is contained in:
parent
db5e76fe8c
commit
8c4dda45ef
5 changed files with 36 additions and 46 deletions
|
@ -249,6 +249,18 @@ export default class TabManager extends Component {
|
||||||
return noteContext;
|
return noteContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async openInNewTab(targetNoteId, hoistedNoteId = null) {
|
||||||
|
const noteContext = await this.openEmptyTab(null, hoistedNoteId || this.getActiveContext().hoistedNoteId);
|
||||||
|
|
||||||
|
await noteContext.setNote(targetNoteId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async openInSameTab(targetNoteId, hoistedNoteId = null) {
|
||||||
|
const activeContext = this.getActiveContext();
|
||||||
|
await activeContext.setHoistedNoteId(hoistedNoteId || activeContext.hoistedNoteId);
|
||||||
|
await activeContext.setNote(targetNoteId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the requested notePath is within current note hoisting scope then keep the note hoisting also for the new tab.
|
* If the requested notePath is within current note hoisting scope then keep the note hoisting also for the new tab.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -22,9 +22,8 @@ export default class BookmarkButtons extends FlexContainer {
|
||||||
|
|
||||||
const buttonWidget = note.hasLabel("bookmarkFolder")
|
const buttonWidget = note.hasLabel("bookmarkFolder")
|
||||||
? new BookmarkFolderWidget(note)
|
? new BookmarkFolderWidget(note)
|
||||||
: new OpenNoteButtonWidget().targetNote(note.noteId);
|
: new OpenNoteButtonWidget(note)
|
||||||
|
.class("launcher-button");
|
||||||
buttonWidget.class("launcher-button");
|
|
||||||
|
|
||||||
this.child(buttonWidget);
|
this.child(buttonWidget);
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ const DROPDOWN_TPL = `
|
||||||
min-width: 400px;
|
min-width: 400px;
|
||||||
max-height: 500px;
|
max-height: 500px;
|
||||||
padding: 7px 15px 0 15px;
|
padding: 7px 15px 0 15px;
|
||||||
font-size: 110%;
|
font-size: 1.2rem;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,30 +42,18 @@ export default class NoteLauncher extends AbstractLauncher {
|
||||||
|
|
||||||
if (!evt) {
|
if (!evt) {
|
||||||
// keyboard shortcut
|
// keyboard shortcut
|
||||||
await this.openInSameTab(targetNoteId, hoistedNoteId);
|
await appContext.tabManager.openInSameTab(targetNoteId, hoistedNoteId);
|
||||||
} else {
|
} else {
|
||||||
const ctrlKey = utils.isCtrlKey(evt);
|
const ctrlKey = utils.isCtrlKey(evt);
|
||||||
|
|
||||||
if ((evt.which === 1 && ctrlKey) || evt.which === 2) {
|
if ((evt.which === 1 && ctrlKey) || evt.which === 2) {
|
||||||
await this.openInNewTab(targetNoteId, hoistedNoteId);
|
await appContext.tabManager.openInNewTab(targetNoteId, hoistedNoteId);
|
||||||
} else {
|
} else {
|
||||||
await this.openInSameTab(targetNoteId, hoistedNoteId);
|
await appContext.tabManager.openInSameTab(targetNoteId, hoistedNoteId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async openInNewTab(targetNoteId, hoistedNoteId) {
|
|
||||||
const noteContext = await appContext.tabManager.openEmptyTab(null, hoistedNoteId);
|
|
||||||
|
|
||||||
await noteContext.setNote(targetNoteId);
|
|
||||||
}
|
|
||||||
|
|
||||||
async openInSameTab(targetNoteId, hoistedNoteId) {
|
|
||||||
const activeContext = appContext.tabManager.getActiveContext();
|
|
||||||
await activeContext.setHoistedNoteId(hoistedNoteId);
|
|
||||||
await activeContext.setNote(targetNoteId);
|
|
||||||
}
|
|
||||||
|
|
||||||
getTargetNoteId() {
|
getTargetNoteId() {
|
||||||
const targetNoteId = this.launcherNote.getRelationValue('targetNote');
|
const targetNoteId = this.launcherNote.getRelationValue('targetNote');
|
||||||
|
|
||||||
|
|
|
@ -1,38 +1,29 @@
|
||||||
import OnClickButtonWidget from "./onclick_button.js";
|
import OnClickButtonWidget from "./onclick_button.js";
|
||||||
|
import linkContextMenuService from "../../menus/link_context_menu.js";
|
||||||
|
import utils from "../../services/utils.js";
|
||||||
import appContext from "../../components/app_context.js";
|
import appContext from "../../components/app_context.js";
|
||||||
import froca from "../../services/froca.js";
|
|
||||||
|
|
||||||
// FIXME: this widget might not be useful anymore
|
|
||||||
|
|
||||||
export default class OpenNoteButtonWidget extends OnClickButtonWidget {
|
export default class OpenNoteButtonWidget extends OnClickButtonWidget {
|
||||||
targetNote(noteId) {
|
constructor(noteToOpen) {
|
||||||
froca.getNote(noteId).then(note => {
|
super();
|
||||||
if (!note) {
|
|
||||||
console.log(`Note ${noteId} has not been found. This might happen on the first run before the target note is created.`);
|
|
||||||
|
|
||||||
if (!this.retried) {
|
this.noteToOpen = noteToOpen;
|
||||||
this.retried = true;
|
|
||||||
|
|
||||||
setTimeout(() => this.targetNote(noteId), 15000); // should be higher than timeout for checkHiddenSubtree
|
this.title(() => this.noteToOpen.title)
|
||||||
}
|
.icon(() => this.noteToOpen.getIcon())
|
||||||
|
.onClick((widget, evt) => this.launch(evt))
|
||||||
|
.onAuxClick((widget, evt) => this.launch(evt))
|
||||||
|
.onContextMenu(evt => linkContextMenuService.openContextMenu(this.noteToOpen.noteId, null, evt));
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
async launch(evt) {
|
||||||
}
|
const ctrlKey = utils.isCtrlKey(evt);
|
||||||
|
|
||||||
this.icon(note.getIcon());
|
if ((evt.which === 1 && ctrlKey) || evt.which === 2) {
|
||||||
this.title(() => {
|
await appContext.tabManager.openInNewTab(this.noteToOpen.noteId);
|
||||||
const n = froca.getNoteFromCache(noteId);
|
} else {
|
||||||
|
await appContext.tabManager.openInSameTab(this.noteToOpen.noteId);
|
||||||
// always fresh, always decoded (when protected session is available)
|
}
|
||||||
return n.title;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.refreshIcon();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.onClick(() => appContext.tabManager.openTabWithNoteWithHoisting(noteId, true));
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initialRenderCompleteEvent() {
|
initialRenderCompleteEvent() {
|
||||||
|
|
Loading…
Reference in a new issue