trilium/src/public/javascripts/services/entrypoints.js

164 lines
5 KiB
JavaScript
Raw Normal View History

import utils from "./utils.js";
import treeService from "./tree.js";
import dateNoteService from "./date_notes.js";
import hoistedNoteService from "./hoisted_note.js";
import treeCache from "./tree_cache.js";
import server from "./server.js";
2020-01-12 18:15:23 +08:00
import appContext from "./app_context.js";
2020-01-22 05:54:16 +08:00
import Component from "../widgets/component.js";
2020-01-22 05:54:16 +08:00
export default class Entrypoints extends Component {
2020-02-15 16:43:47 +08:00
constructor(appContext, parent) {
super(appContext, parent);
2020-01-22 05:54:16 +08:00
// hot keys are active also inside inputs and content editables
jQuery.hotkeys.options.filterInputAcceptingElements = false;
jQuery.hotkeys.options.filterContentEditable = false;
jQuery.hotkeys.options.filterTextInputs = false;
2019-02-10 02:25:55 +08:00
2020-01-22 05:54:16 +08:00
$(document).on('click', "a[data-action='note-revision']", async event => {
const linkEl = $(event.target);
const noteId = linkEl.attr('data-note-path');
const noteRevisionId = linkEl.attr('data-note-revision-id');
2020-01-22 05:54:16 +08:00
const attributesDialog = await import("../dialogs/note_revisions.js");
2020-01-22 05:54:16 +08:00
attributesDialog.showNoteRevisionsDialog(noteId, noteRevisionId);
return false;
2019-11-21 05:48:32 +08:00
});
}
2020-02-17 02:23:49 +08:00
openDevToolsEvent() {
2020-01-22 05:54:16 +08:00
if (utils.isElectron()) {
require('electron').remote.getCurrentWindow().toggleDevTools();
}
}
2020-02-17 02:23:49 +08:00
findInTextEvent() {
2020-01-23 03:48:56 +08:00
if (!utils.isElectron()) {
return;
2020-01-22 05:54:16 +08:00
}
2020-01-23 03:48:56 +08:00
const {remote} = require('electron');
const {FindInPage} = require('electron-find');
const findInPage = new FindInPage(remote.getCurrentWebContents(), {
offsetTop: 10,
offsetRight: 10,
boxBgColor: 'var(--main-background-color)',
boxShadowColor: '#000',
inputColor: 'var(--input-text-color)',
inputBgColor: 'var(--input-background-color)',
inputFocusColor: '#555',
textColor: 'var(--main-text-color)',
textHoverBgColor: '#555',
caseSelectedColor: 'var(--main-border-color)'
});
2020-01-22 05:54:16 +08:00
}
2020-02-17 02:23:49 +08:00
async createNoteIntoDayNoteEvent() {
const todayNote = await dateNoteService.getTodayNote();
2019-11-20 03:53:04 +08:00
const {note} = await server.post(`notes/${todayNote.noteId}/children?target=into`, {
title: 'new note',
content: '',
type: 'text',
isProtected: todayNote.isProtected
});
await treeService.expandToNote(note.noteId);
2020-02-10 04:13:05 +08:00
const tabContext = appContext.tabManager.openEmptyTab();
appContext.tabManager.activateTab(tabContext.tabId);
2020-01-25 00:54:47 +08:00
await tabContext.setNote(note.noteId);
2019-12-28 17:28:12 +08:00
2020-02-17 02:21:17 +08:00
appContext.triggerEvent('focusAndSelectTitle');
2020-01-22 05:54:16 +08:00
}
2020-02-17 02:23:49 +08:00
async toggleNoteHoistingEvent() {
const note = appContext.tabManager.getActiveTabNote();
2020-02-11 03:57:56 +08:00
const hoistedNoteId = hoistedNoteService.getHoistedNoteId();
if (note.noteId === hoistedNoteId) {
hoistedNoteService.unhoist();
}
else {
const note = await treeCache.getNote(note.noteId);
2020-02-11 03:57:56 +08:00
if (note.type !== 'search') {
hoistedNoteService.setHoistedNoteId(note.noteId);
}
2020-02-11 03:57:56 +08:00
}
2020-01-22 05:54:16 +08:00
}
2019-11-20 06:02:54 +08:00
2020-02-17 02:23:49 +08:00
copyWithoutFormattingEvent() {
2020-01-22 05:54:16 +08:00
utils.copySelectionToClipboard();
}
2020-01-23 02:41:19 +08:00
2020-02-17 02:23:49 +08:00
toggleFullscreenEvent() {
2020-01-23 02:41:19 +08:00
if (utils.isElectron()) {
const win = require('electron').remote.getCurrentWindow();
if (win.isFullScreenable()) {
win.setFullScreen(!win.isFullScreen());
}
}
else {
// outside of electron this is handled by the browser
this.$widget.find(".toggle-fullscreen-button").hide();
}
}
2020-02-17 02:23:49 +08:00
toggleZenModeEvent() {
2020-01-23 02:41:19 +08:00
if (!this.zenModeActive) {
$(".hide-in-zen-mode,.gutter").addClass("hidden-by-zen-mode");
$("#container").addClass("zen-mode");
this.zenModeActive = true;
}
else {
// not hiding / showing explicitly since element might be hidden also for other reasons
$(".hide-in-zen-mode,.gutter").removeClass("hidden-by-zen-mode");
$("#container").removeClass("zen-mode");
this.zenModeActive = false;
}
}
2020-02-17 02:23:49 +08:00
reloadFrontendAppEvent() {
2020-01-23 02:41:19 +08:00
utils.reloadApp();
}
2020-02-17 02:23:49 +08:00
logoutEvent() {
2020-01-23 02:41:19 +08:00
const $logoutForm = $('<form action="logout" method="POST">')
.append($(`<input type="hidden" name="_csrf" value="${glob.csrfToken}"/>`));
$("body").append($logoutForm);
$logoutForm.trigger('submit');
}
2020-02-17 02:23:49 +08:00
showOptionsEvent() {
2020-01-23 02:41:19 +08:00
import("../dialogs/options.js").then(d => d.showDialog())
}
2020-02-17 02:23:49 +08:00
showHelpEvent() {
2020-01-23 02:41:19 +08:00
import("../dialogs/help.js").then(d => d.showDialog())
}
2020-02-17 02:23:49 +08:00
showSQLConsoleEvent() {
2020-01-23 02:41:19 +08:00
import("../dialogs/sql_console.js").then(d => d.showDialog())
}
2020-02-17 02:23:49 +08:00
showBackendLogEvent() {
2020-01-23 02:41:19 +08:00
import("../dialogs/backend_log.js").then(d => d.showDialog())
}
2020-02-17 02:23:49 +08:00
backInNoteHistoryEvent() {
2020-01-23 02:41:19 +08:00
window.history.back();
}
2020-02-17 02:23:49 +08:00
forwardInNoteHistoryEvent() {
2020-01-23 02:41:19 +08:00
window.history.forward();
}
}