diff --git a/src/public/app/components/root_command_executor.js b/src/public/app/components/root_command_executor.js index 6bf44a3f2..2c524c735 100644 --- a/src/public/app/components/root_command_executor.js +++ b/src/public/app/components/root_command_executor.js @@ -54,6 +54,15 @@ export default class RootCommandExecutor extends Component { openService.openNoteExternally(noteId, mime); } } + + openNoteCustomCommand() { + const noteId = appContext.tabManager.getActiveContextNoteId(); + const mime = appContext.tabManager.getActiveContextNoteMime() + + if (noteId) { + openService.openNoteCustom(noteId, mime); + } + } enterProtectedSessionCommand() { protectedSessionService.enterProtectedSession(); diff --git a/src/public/app/doc_notes/launchbar_command_launcher.html b/src/public/app/doc_notes/launchbar_command_launcher.html index eb228f06a..68eb051a2 100644 --- a/src/public/app/doc_notes/launchbar_command_launcher.html +++ b/src/public/app/doc_notes/launchbar_command_launcher.html @@ -1 +1 @@ -

Keyboard launcher for this launcher action can be configured in Options -> Launchers.

+

Keyboard shortcut for this launcher action can be configured in Options -> Shortcuts.

diff --git a/src/public/app/doc_notes/launchbar_note_launcher.html b/src/public/app/doc_notes/launchbar_note_launcher.html index 3c68ad82a..403c6e2b4 100644 --- a/src/public/app/doc_notes/launchbar_note_launcher.html +++ b/src/public/app/doc_notes/launchbar_note_launcher.html @@ -3,7 +3,7 @@
  1. target - note which should be opened upon activating the launcher
  2. hoistedNote - optional, will change the hoisted note before opening the target note
  3. -
  4. keyboardLauncher - optional, pressing the keyboard launcher will open the note
  5. +
  6. keyboardShortcut - optional, pressing the keyboard shortcut will open the note

Launchbar displays the title / icon from the launcher which does not necessarily mirror those of the target note.

diff --git a/src/public/app/doc_notes/launchbar_script_launcher.html b/src/public/app/doc_notes/launchbar_script_launcher.html index 0a17bf523..49e315487 100644 --- a/src/public/app/doc_notes/launchbar_script_launcher.html +++ b/src/public/app/doc_notes/launchbar_script_launcher.html @@ -2,7 +2,7 @@
  1. script - relation to the script note which should be executed upon launcher activation
  2. -
  3. keyboardLauncher - optional, pressing the keyboard launcher will activate the launcher
  4. +
  5. keyboardShortcut - optional, pressing the keyboard shortcut will activate the launcher

Example script

diff --git a/src/public/app/services/open.js b/src/public/app/services/open.js index 4ced214b4..6c79d9417 100644 --- a/src/public/app/services/open.js +++ b/src/public/app/services/open.js @@ -41,6 +41,62 @@ function downloadAttachment(attachmentId) { download(url); } +async function openNoteCustom(noteId, mime) { + if (utils.isElectron()) { + const resp = await server.post(`notes/${noteId}/save-to-tmp-dir`); + const filePath = resp.tmpFilePath; + const { exec } = utils.dynamicRequire('child_process'); + const platform = process.platform; + if (platform === 'linux') { + const terminals = ['gnome-terminal', 'konsole', 'xterm', 'xfce4-terminal', 'mate-terminal', 'rxvt', 'terminator', 'terminology']; + const openFileWithTerminal = (terminal) => { + const command = `${terminal} -e 'mimeopen -d "${filePath}"'`; + console.log(`Open Note custom: ${command} `); + exec(command, (error, stdout, stderr) => { + if (error) { + console.error(`Open Note custom: Failed to open file with ${terminal}: ${error}`); + searchTerminal(terminals.indexOf(terminal) + 1); + } else { + console.log(`Open Note custom: File opened with ${terminal}. ${stdout}`); + } + }); + }; + const searchTerminal = (index) => { + const terminal = terminals[index]; + if (!terminal) { + console.error('Open Note custom: No terminal found!'); + open(getFileUrl(noteId), { url: true }); + return; + } + exec(`which ${terminal}`, (error, stdout, stderr) => { + if (stdout.trim()) { + openFileWithTerminal(terminal); + } else { + searchTerminal(index + 1); + } + }); + }; + searchTerminal(0); + } else if (platform === 'win32') { + if (filePath.indexOf("/") !== -1) { + //Note that the path separator must be \ instead of / + filePath = filePath.replace(/\//g, "\\"); + } + const command = `rundll32.exe shell32.dll,OpenAs_RunDLL ` + filePath; + exec(command, (err, stdout, stderr) => { + if (err) { + console.error("Open Note custom: ", err); + open(getFileUrl(noteId), { url: true }); + return; + } + }); + } else { + console.log('Currently "Open Note custom" only supports linux and windows systems'); + open(getFileUrl(noteId), { url: true }); + } + } + } + function downloadNoteRevision(noteId, noteRevisionId) { const url = getUrlForDownload(`api/revisions/${noteRevisionId}/download`); @@ -108,4 +164,5 @@ export default { getUrlForDownload, openNoteExternally, openAttachmentExternally, + openNoteCustom, } diff --git a/src/public/app/widgets/buttons/note_actions.js b/src/public/app/widgets/buttons/note_actions.js index f0f5b3419..ac552f4b5 100644 --- a/src/public/app/widgets/buttons/note_actions.js +++ b/src/public/app/widgets/buttons/note_actions.js @@ -40,6 +40,7 @@ const TPL = ` Open note externally + Open note custom (beta) Import files Export note Delete note @@ -79,6 +80,7 @@ export default class NoteActionsWidget extends NoteContextAwareWidget { this.$widget.on('click', '.dropdown-item', () => this.$widget.find("[data-toggle='dropdown']").dropdown('toggle')); this.$openNoteExternallyButton = this.$widget.find(".open-note-externally-button"); + this.$openNoteCustomButton = this.$widget.find(".open-note-custom-button"); this.$deleteNoteButton = this.$widget.find(".delete-note-button"); this.$deleteNoteButton.on("click", () => { @@ -102,6 +104,7 @@ export default class NoteActionsWidget extends NoteContextAwareWidget { this.$renderNoteButton.toggle(note.type === 'render'); this.$openNoteExternallyButton.toggle(utils.isElectron()); + this.$openNoteCustomButton.toggle(utils.isElectron()); } async convertNoteIntoAttachmentCommand() { diff --git a/src/public/app/widgets/type_widgets/editable_text.js b/src/public/app/widgets/type_widgets/editable_text.js index f6c2a662e..8d16b2b4f 100644 --- a/src/public/app/widgets/type_widgets/editable_text.js +++ b/src/public/app/widgets/type_widgets/editable_text.js @@ -51,7 +51,7 @@ const TPL = ` cursor: text !important; } - .note-detail-editable-text *:not(figure):first-child { + .note-detail-editable-text *:not(figure,.include-note):first-child { margin-top: 0 !important; }