mirror of
https://github.com/laurent22/joplin.git
synced 2025-03-03 15:32:30 +02:00
Electron: Resolves #237: Export to PDF and print option
This commit is contained in:
parent
dbe1833f92
commit
eef106c99b
@ -205,7 +205,7 @@ class Application extends BaseApplication {
|
||||
const module = ioModules[i];
|
||||
if (module.type === 'exporter') {
|
||||
exportItems.push({
|
||||
label: module.format + ' - ' + module.description,
|
||||
label: module.fullLabel(),
|
||||
screens: ['Main'],
|
||||
click: async () => {
|
||||
await InteropServiceHelper.export(this.dispatch.bind(this), module);
|
||||
@ -214,12 +214,8 @@ class Application extends BaseApplication {
|
||||
} else {
|
||||
for (let j = 0; j < module.sources.length; j++) {
|
||||
const moduleSource = module.sources[j];
|
||||
let label = [module.format + ' - ' + module.description];
|
||||
if (module.sources.length > 1) {
|
||||
label.push('(' + (moduleSource === 'file' ? _('File') : _('Directory')) + ')');
|
||||
}
|
||||
importItems.push({
|
||||
label: label.join(' '),
|
||||
label: module.fullLabel(moduleSource),
|
||||
screens: ['Main'],
|
||||
click: async () => {
|
||||
let path = null;
|
||||
@ -269,6 +265,17 @@ class Application extends BaseApplication {
|
||||
}
|
||||
}
|
||||
|
||||
exportItems.push({
|
||||
label: 'PDF - ' + _('PDF File'),
|
||||
screens: ['Main'],
|
||||
click: async () => {
|
||||
this.dispatch({
|
||||
type: 'WINDOW_COMMAND',
|
||||
name: 'exportPdf',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const template = [
|
||||
{
|
||||
label: _('File'),
|
||||
@ -310,6 +317,18 @@ class Application extends BaseApplication {
|
||||
}, {
|
||||
label: _('Export'),
|
||||
submenu: exportItems,
|
||||
}, {
|
||||
type: 'separator',
|
||||
}, {
|
||||
label: _('Print'),
|
||||
accelerator: 'CommandOrControl+P',
|
||||
screens: ['Main'],
|
||||
click: () => {
|
||||
this.dispatch({
|
||||
type: 'WINDOW_COMMAND',
|
||||
name: 'print',
|
||||
});
|
||||
}
|
||||
}, {
|
||||
type: 'separator',
|
||||
platforms: ['darwin'],
|
||||
|
@ -102,7 +102,7 @@ class NoteListComponent extends React.Component {
|
||||
const module = ioModules[i];
|
||||
if (module.type !== 'exporter') continue;
|
||||
|
||||
exportMenu.append(new MenuItem({ label: module.format + ' - ' + module.description , click: async () => {
|
||||
exportMenu.append(new MenuItem({ label: module.fullLabel() , click: async () => {
|
||||
await InteropServiceHelper.export(this.props.dispatch.bind(this), module, { sourceNoteIds: noteIds });
|
||||
}}));
|
||||
}
|
||||
|
@ -240,6 +240,10 @@ class NoteTextComponent extends React.Component {
|
||||
if ('syncStarted' in nextProps && !nextProps.syncStarted && !this.isModified()) {
|
||||
await this.reloadNote(nextProps, { noReloadIfLocalChanges: true });
|
||||
}
|
||||
|
||||
if (nextProps.windowCommand) {
|
||||
this.doCommand(nextProps.windowCommand);
|
||||
}
|
||||
}
|
||||
|
||||
isModified() {
|
||||
@ -362,7 +366,7 @@ class NoteTextComponent extends React.Component {
|
||||
webviewReady: true,
|
||||
});
|
||||
|
||||
// if (Setting.value('env') === 'dev') this.webview_.openDevTools();
|
||||
if (Setting.value('env') === 'dev') this.webview_.openDevTools();
|
||||
}
|
||||
|
||||
webview_ref(element) {
|
||||
@ -426,6 +430,38 @@ class NoteTextComponent extends React.Component {
|
||||
this.scheduleSave();
|
||||
}
|
||||
|
||||
async doCommand(command) {
|
||||
if (!command) return;
|
||||
|
||||
let commandProcessed = true;
|
||||
|
||||
if (command.name === 'exportPdf' && this.webview_) {
|
||||
const path = bridge().showSaveDialog({
|
||||
filters: [{ name: _('PDF File'), extensions: ['pdf']}]
|
||||
});
|
||||
|
||||
if (path) {
|
||||
this.webview_.printToPDF({}, (error, data) => {
|
||||
if (error) {
|
||||
bridge().showErrorMessageBox(error.message);
|
||||
} else {
|
||||
shim.fsDriver().writeFile(path, data, 'buffer');
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (command.name === 'print' && this.webview_) {
|
||||
this.webview_.print();
|
||||
} else {
|
||||
commandProcessed = false;
|
||||
}
|
||||
|
||||
if (commandProcessed) {
|
||||
this.props.dispatch({
|
||||
type: 'WINDOW_COMMAND',
|
||||
name: null,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async commandAttachFile() {
|
||||
const filePaths = bridge().showOpenDialog({
|
||||
@ -710,6 +746,7 @@ const mapStateToProps = (state) => {
|
||||
showAdvancedOptions: state.settings.showAdvancedOptions,
|
||||
syncStarted: state.syncStarted,
|
||||
newNote: state.newNote,
|
||||
windowCommand: state.windowCommand,
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -495,9 +495,30 @@ class MdToHtml {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.katex .mfrac .frac-line:before {
|
||||
/* top: 50%; */
|
||||
/* padding-bottom: .7em; */
|
||||
@media print {
|
||||
body {
|
||||
height: auto !important;
|
||||
}
|
||||
|
||||
a.checkbox {
|
||||
border: 1pt solid ` + style.htmlColor + `;
|
||||
border-radius: 2pt;
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
line-height: 1em;
|
||||
text-align: center;
|
||||
top: .4em;
|
||||
}
|
||||
|
||||
a.checkbox.tick:after {
|
||||
content: "X";
|
||||
}
|
||||
|
||||
a.checkbox.tick {
|
||||
top: 0;
|
||||
left: -0.02em;
|
||||
color: ` + style.htmlColor + `;
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
|
@ -35,7 +35,11 @@ class FsDriverNode extends FsDriverBase {
|
||||
|
||||
async writeFile(path, string, encoding = 'base64') {
|
||||
try {
|
||||
return await fs.writeFile(path, string, { encoding: encoding });
|
||||
if (encoding === 'buffer') {
|
||||
return await fs.writeFile(path, string);
|
||||
} else {
|
||||
return await fs.writeFile(path, string, { encoding: encoding });
|
||||
}
|
||||
} catch (error) {
|
||||
throw this.fsErrorToJsError_(error, path);
|
||||
}
|
||||
|
@ -81,6 +81,17 @@ class InteropService {
|
||||
|
||||
this.modules_ = importModules.concat(exportModules);
|
||||
|
||||
this.modules_ = this.modules_.map((a) => {
|
||||
a.fullLabel = function(moduleSource = null) {
|
||||
const label = [this.format.toUpperCase() + ' - ' + this.description];
|
||||
if (moduleSource && this.sources.length > 1) {
|
||||
label.push('(' + (moduleSource === 'file' ? _('File') : _('Directory')) + ')');
|
||||
}
|
||||
return label.join(' ');
|
||||
};
|
||||
return a;
|
||||
});
|
||||
|
||||
return this.modules_;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user