mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
added global menu item to open new empty window + some refactoring
This commit is contained in:
parent
c7125d2b50
commit
6dfe335707
@ -100,19 +100,6 @@ class AppContext extends Component {
|
|||||||
getComponentByEl(el) {
|
getComponentByEl(el) {
|
||||||
return $(el).closest(".component").prop('component');
|
return $(el).closest(".component").prop('component');
|
||||||
}
|
}
|
||||||
|
|
||||||
async openInNewWindow(notePath) {
|
|
||||||
if (utils.isElectron()) {
|
|
||||||
const {ipcRenderer} = utils.dynamicRequire('electron');
|
|
||||||
|
|
||||||
ipcRenderer.send('create-extra-window', {notePath});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
const url = window.location.protocol + '//' + window.location.host + window.location.pathname + '?extra=1#' + notePath;
|
|
||||||
|
|
||||||
window.open(url, '', 'width=1000,height=800');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const appContext = new AppContext(window.glob.isMainWindow);
|
const appContext = new AppContext(window.glob.isMainWindow);
|
||||||
|
@ -182,4 +182,21 @@ export default class Entrypoints extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createTopLevelNoteCommand() { noteCreateService.createNewTopLevelNote(); }
|
createTopLevelNoteCommand() { noteCreateService.createNewTopLevelNote(); }
|
||||||
|
|
||||||
|
async openInWindowCommand({notePath}) {
|
||||||
|
if (utils.isElectron()) {
|
||||||
|
const {ipcRenderer} = utils.dynamicRequire('electron');
|
||||||
|
|
||||||
|
ipcRenderer.send('create-extra-window', {notePath});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const url = window.location.protocol + '//' + window.location.host + window.location.pathname + '?extra=1#' + notePath;
|
||||||
|
|
||||||
|
window.open(url, '', 'width=1000,height=800');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async openNewWindowCommand() {
|
||||||
|
this.openInWindowCommand({notePath: ''});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ function newTabContextMenu(e) {
|
|||||||
y: e.pageY,
|
y: e.pageY,
|
||||||
items: [
|
items: [
|
||||||
{title: "Open note in new tab", command: "openNoteInNewTab", uiIcon: "arrow-up-right"},
|
{title: "Open note in new tab", command: "openNoteInNewTab", uiIcon: "arrow-up-right"},
|
||||||
{title: "Open note in new window", command: "openNoteInNewWindow", uiIcon: "arrow-up-right"}
|
{title: "Open note in new window", command: "openNoteInNewWindow", uiIcon: "window-open"}
|
||||||
],
|
],
|
||||||
selectMenuItemHandler: ({command}) => {
|
selectMenuItemHandler: ({command}) => {
|
||||||
if (command === 'openNoteInNewTab') {
|
if (command === 'openNoteInNewTab') {
|
||||||
|
@ -82,7 +82,7 @@ export default class TabManager extends Component {
|
|||||||
|
|
||||||
if (filteredTabs.length === 0) {
|
if (filteredTabs.length === 0) {
|
||||||
filteredTabs.push({
|
filteredTabs.push({
|
||||||
notePath: 'root',
|
notePath: this.isMainWindow ? 'root' : '',
|
||||||
active: true
|
active: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -196,7 +196,9 @@ export default class TabManager extends Component {
|
|||||||
async openTabWithNote(notePath, activate, tabId = null) {
|
async openTabWithNote(notePath, activate, tabId = null) {
|
||||||
const tabContext = await this.openEmptyTab(tabId);
|
const tabContext = await this.openEmptyTab(tabId);
|
||||||
|
|
||||||
await tabContext.setNote(notePath, !activate); // if activate is false then send normal noteSwitched event
|
if (notePath) {
|
||||||
|
await tabContext.setNote(notePath, !activate); // if activate is false then send normal noteSwitched event
|
||||||
|
}
|
||||||
|
|
||||||
if (activate) {
|
if (activate) {
|
||||||
this.activateTab(tabContext.tabId, false);
|
this.activateTab(tabContext.tabId, false);
|
||||||
@ -330,7 +332,7 @@ export default class TabManager extends Component {
|
|||||||
|
|
||||||
this.removeTab(tabId);
|
this.removeTab(tabId);
|
||||||
|
|
||||||
appContext.openInNewWindow(notePath);
|
this.triggerCommand('openInWindow', {notePath});
|
||||||
}
|
}
|
||||||
|
|
||||||
async hoistedNoteChangedEvent({hoistedNoteId}) {
|
async hoistedNoteChangedEvent({hoistedNoteId}) {
|
||||||
|
@ -57,7 +57,7 @@ class TreeContextMenu {
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
{ title: 'Open in a new tab <kbd>Ctrl+Click</kbd>', command: "openInTab", uiIcon: "empty", enabled: noSelectedNotes },
|
{ title: 'Open in a new tab <kbd>Ctrl+Click</kbd>', command: "openInTab", uiIcon: "empty", enabled: noSelectedNotes },
|
||||||
{ title: 'Open in a new window', command: "openInWindow", uiIcon: "empty", enabled: noSelectedNotes },
|
{ title: 'Open in a new window', command: "openInWindow", uiIcon: "window-open", enabled: noSelectedNotes },
|
||||||
{ title: 'Insert note after <kbd data-command="createNoteAfter"></kbd>', command: "insertNoteAfter", uiIcon: "plus",
|
{ title: 'Insert note after <kbd data-command="createNoteAfter"></kbd>', command: "insertNoteAfter", uiIcon: "plus",
|
||||||
items: insertNoteAfterEnabled ? this.getNoteTypeItems("insertNoteAfter") : null,
|
items: insertNoteAfterEnabled ? this.getNoteTypeItems("insertNoteAfter") : null,
|
||||||
enabled: insertNoteAfterEnabled && noSelectedNotes },
|
enabled: insertNoteAfterEnabled && noSelectedNotes },
|
||||||
@ -113,9 +113,6 @@ class TreeContextMenu {
|
|||||||
if (command === 'openInTab') {
|
if (command === 'openInTab') {
|
||||||
appContext.tabManager.openTabWithNote(notePath);
|
appContext.tabManager.openTabWithNote(notePath);
|
||||||
}
|
}
|
||||||
else if (command === 'openInWindow') {
|
|
||||||
appContext.openInNewWindow(notePath);
|
|
||||||
}
|
|
||||||
else if (command === "insertNoteAfter") {
|
else if (command === "insertNoteAfter") {
|
||||||
const parentNoteId = this.node.data.parentNoteId;
|
const parentNoteId = this.node.data.parentNoteId;
|
||||||
const isProtected = await treeService.getParentProtectedStatus(this.node);
|
const isProtected = await treeService.getParentProtectedStatus(this.node);
|
||||||
@ -134,7 +131,7 @@ class TreeContextMenu {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.treeWidget.triggerCommand(command, {node: this.node});
|
this.treeWidget.triggerCommand(command, {node: this.node, notePath: notePath});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import BasicWidget from "./basic_widget.js";
|
import BasicWidget from "./basic_widget.js";
|
||||||
import keyboardActionService from "../services/keyboard_actions.js";
|
|
||||||
import utils from "../services/utils.js";
|
import utils from "../services/utils.js";
|
||||||
import syncService from "../services/sync.js";
|
import syncService from "../services/sync.js";
|
||||||
|
|
||||||
@ -39,6 +38,12 @@ const TPL = `
|
|||||||
Sync (<span id="outstanding-syncs-count">0</span>)
|
Sync (<span id="outstanding-syncs-count">0</span>)
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<a class="dropdown-item" data-trigger-command="openNewWindow">
|
||||||
|
<span class="bx bx-window-open"></span>
|
||||||
|
Open new window
|
||||||
|
<kbd data-command="openNewWindow"></kbd>
|
||||||
|
</a>
|
||||||
|
|
||||||
<a class="dropdown-item open-dev-tools-button" data-trigger-command="openDevTools">
|
<a class="dropdown-item open-dev-tools-button" data-trigger-command="openDevTools">
|
||||||
<span class="bx bx-terminal"></span>
|
<span class="bx bx-terminal"></span>
|
||||||
Open Dev Tools
|
Open Dev Tools
|
||||||
|
@ -258,9 +258,9 @@ export default class TabRowWidget extends BasicWidget {
|
|||||||
x: e.pageX,
|
x: e.pageX,
|
||||||
y: e.pageY,
|
y: e.pageY,
|
||||||
items: [
|
items: [
|
||||||
{title: "Move this tab to a new window", command: "moveTabToNewWindow", uiIcon: "empty"},
|
{title: "Move this tab to a new window", command: "moveTabToNewWindow", uiIcon: "window-open"},
|
||||||
{title: "Close all tabs", command: "removeAllTabs", uiIcon: "empty"},
|
{title: "Close all tabs", command: "removeAllTabs", uiIcon: "x"},
|
||||||
{title: "Close all tabs except for this", command: "removeAllTabsExceptForThis", uiIcon: "empty"},
|
{title: "Close all tabs except for this", command: "removeAllTabsExceptForThis", uiIcon: "x"},
|
||||||
],
|
],
|
||||||
selectMenuItemHandler: ({command}) => {
|
selectMenuItemHandler: ({command}) => {
|
||||||
this.triggerCommand(command, {tabId});
|
this.triggerCommand(command, {tabId});
|
||||||
|
@ -193,7 +193,7 @@ const DEFAULT_KEYBOARD_ACTIONS = [
|
|||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
separator: "Tabs"
|
separator: "Tabs & Windows"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
actionName: "openNewTab",
|
actionName: "openNewTab",
|
||||||
@ -219,6 +219,12 @@ const DEFAULT_KEYBOARD_ACTIONS = [
|
|||||||
description: "Activates tab on the left",
|
description: "Activates tab on the left",
|
||||||
scope: "window"
|
scope: "window"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
actionName: "openNewWindow",
|
||||||
|
defaultShortcuts: [],
|
||||||
|
description: "Open new empty window",
|
||||||
|
scope: "window"
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user