mirror of
https://github.com/zadam/trilium.git
synced 2024-09-21 08:06:03 +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
|
@ -249,6 +249,18 @@ export default class TabManager extends Component {
|
|||
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.
|
||||
*/
|
||||
|
|
|
@ -22,9 +22,8 @@ export default class BookmarkButtons extends FlexContainer {
|
|||
|
||||
const buttonWidget = note.hasLabel("bookmarkFolder")
|
||||
? new BookmarkFolderWidget(note)
|
||||
: new OpenNoteButtonWidget().targetNote(note.noteId);
|
||||
|
||||
buttonWidget.class("launcher-button");
|
||||
: new OpenNoteButtonWidget(note)
|
||||
.class("launcher-button");
|
||||
|
||||
this.child(buttonWidget);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ const DROPDOWN_TPL = `
|
|||
min-width: 400px;
|
||||
max-height: 500px;
|
||||
padding: 7px 15px 0 15px;
|
||||
font-size: 110%;
|
||||
font-size: 1.2rem;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,30 +42,18 @@ export default class NoteLauncher extends AbstractLauncher {
|
|||
|
||||
if (!evt) {
|
||||
// keyboard shortcut
|
||||
await this.openInSameTab(targetNoteId, hoistedNoteId);
|
||||
await appContext.tabManager.openInSameTab(targetNoteId, hoistedNoteId);
|
||||
} else {
|
||||
const ctrlKey = utils.isCtrlKey(evt);
|
||||
|
||||
if ((evt.which === 1 && ctrlKey) || evt.which === 2) {
|
||||
await this.openInNewTab(targetNoteId, hoistedNoteId);
|
||||
await appContext.tabManager.openInNewTab(targetNoteId, hoistedNoteId);
|
||||
} 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() {
|
||||
const targetNoteId = this.launcherNote.getRelationValue('targetNote');
|
||||
|
||||
|
|
|
@ -1,38 +1,29 @@
|
|||
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 froca from "../../services/froca.js";
|
||||
|
||||
// FIXME: this widget might not be useful anymore
|
||||
|
||||
export default class OpenNoteButtonWidget extends OnClickButtonWidget {
|
||||
targetNote(noteId) {
|
||||
froca.getNote(noteId).then(note => {
|
||||
if (!note) {
|
||||
console.log(`Note ${noteId} has not been found. This might happen on the first run before the target note is created.`);
|
||||
constructor(noteToOpen) {
|
||||
super();
|
||||
|
||||
if (!this.retried) {
|
||||
this.retried = true;
|
||||
this.noteToOpen = noteToOpen;
|
||||
|
||||
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());
|
||||
this.title(() => {
|
||||
const n = froca.getNoteFromCache(noteId);
|
||||
|
||||
// always fresh, always decoded (when protected session is available)
|
||||
return n.title;
|
||||
});
|
||||
|
||||
this.refreshIcon();
|
||||
});
|
||||
|
||||
this.onClick(() => appContext.tabManager.openTabWithNoteWithHoisting(noteId, true));
|
||||
|
||||
return this;
|
||||
if ((evt.which === 1 && ctrlKey) || evt.which === 2) {
|
||||
await appContext.tabManager.openInNewTab(this.noteToOpen.noteId);
|
||||
} else {
|
||||
await appContext.tabManager.openInSameTab(this.noteToOpen.noteId);
|
||||
}
|
||||
}
|
||||
|
||||
initialRenderCompleteEvent() {
|
||||
|
|
Loading…
Reference in a new issue