Desktop: Fixes #2254: Fix pdf export when mouse over non-selected note in notelist. (#2255)

pull/2314/head
mic704b 2020-01-19 00:30:15 +11:00 committed by Laurent Cozic
parent d9d75d6c71
commit 8a392e1c06
3 changed files with 16 additions and 8 deletions

View File

@ -462,6 +462,7 @@ class Application extends BaseApplication {
this.dispatch({
type: 'WINDOW_COMMAND',
name: 'exportPdf',
noteId: null,
});
},
});

View File

@ -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);
}

View File

@ -171,6 +171,7 @@ class NoteListUtils {
props.dispatch({
type: 'WINDOW_COMMAND',
name: 'exportPdf',
noteId: noteIds[0],
});
},
})