From 8a392e1c06cce7386189f18a40edc104e7bf973f Mon Sep 17 00:00:00 2001 From: mic704b Date: Sun, 19 Jan 2020 00:30:15 +1100 Subject: [PATCH] Desktop: Fixes #2254: Fix pdf export when mouse over non-selected note in notelist. (#2255) --- ElectronClient/app/app.js | 1 + ElectronClient/app/gui/NoteText.jsx | 22 ++++++++++++------- ElectronClient/app/gui/utils/NoteListUtils.js | 1 + 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ElectronClient/app/app.js b/ElectronClient/app/app.js index e245fdb92f..6f5102a85c 100644 --- a/ElectronClient/app/app.js +++ b/ElectronClient/app/app.js @@ -462,6 +462,7 @@ class Application extends BaseApplication { this.dispatch({ type: 'WINDOW_COMMAND', name: 'exportPdf', + noteId: null, }); }, }); diff --git a/ElectronClient/app/gui/NoteText.jsx b/ElectronClient/app/gui/NoteText.jsx index 7293847ea9..c903ad8220 100644 --- a/ElectronClient/app/gui/NoteText.jsx +++ b/ElectronClient/app/gui/NoteText.jsx @@ -1103,9 +1103,11 @@ class NoteTextComponent extends React.Component { if (!command) return; let fn = null; + let args = null; if (command.name === 'exportPdf') { fn = this.commandSavePdf; + args = {noteId: command.noteId}; } else if (command.name === 'print') { fn = this.commandPrint; } @@ -1157,7 +1159,7 @@ class NoteTextComponent extends React.Component { requestAnimationFrame(() => { fn = fn.bind(this); - fn(); + fn(args); }); } @@ -1250,7 +1252,7 @@ class NoteTextComponent extends React.Component { setTimeout(async () => { if (target === 'pdf') { try { - const pdfData = await InteropServiceHelper.exportNoteToPdf(this.state.note.id, { + const pdfData = await InteropServiceHelper.exportNoteToPdf(options.noteId, { printBackground: true, pageSize: Setting.value('export.pdfPageSize'), landscape: Setting.value('export.pdfPageOrientation') === 'landscape', @@ -1262,7 +1264,7 @@ class NoteTextComponent extends React.Component { } } else if (target === 'printer') { try { - await InteropServiceHelper.printNote(this.state.note.id, { + await InteropServiceHelper.printNote(options.noteId, { printBackground: true, }); } catch (error) { @@ -1276,18 +1278,20 @@ class NoteTextComponent extends React.Component { }, 100); } - async commandSavePdf() { + async commandSavePdf(args) { try { - if (!this.state.note) throw new Error(_('Only one note can be printed or exported to PDF at a time.')); + if (!this.state.note && !args.noteId) throw new Error(_('Only one note can be exported to PDF at a time.')); + + const note = (!args.noteId ? this.state.note : await Note.load(args.noteId)); const path = bridge().showSaveDialog({ filters: [{ name: _('PDF File'), extensions: ['pdf'] }], - defaultPath: safeFilename(this.state.note.title), + defaultPath: safeFilename(note.title), }); if (!path) return; - await this.printTo_('pdf', { path: path }); + await this.printTo_('pdf', { path: path, noteId: args.noteId }); } catch (error) { bridge().showErrorMessageBox(error.message); } @@ -1295,7 +1299,9 @@ class NoteTextComponent extends React.Component { async commandPrint() { try { - await this.printTo_('printer'); + if (!this.state.note) throw new Error(_('Only one note can be printed at a time.')); + + await this.printTo_('printer', { noteId: this.state.note.id }); } catch (error) { bridge().showErrorMessageBox(error.message); } diff --git a/ElectronClient/app/gui/utils/NoteListUtils.js b/ElectronClient/app/gui/utils/NoteListUtils.js index ec7f9a51b0..0b43dd5a0c 100644 --- a/ElectronClient/app/gui/utils/NoteListUtils.js +++ b/ElectronClient/app/gui/utils/NoteListUtils.js @@ -171,6 +171,7 @@ class NoteListUtils { props.dispatch({ type: 'WINDOW_COMMAND', name: 'exportPdf', + noteId: noteIds[0], }); }, })