1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-12-05 22:57:29 +02:00

Desktop: Add friendly default filenames to export options (#2749)

* Add friendly default filenames to export options

* remove extension from safefilename call

* Load parent folder for all exports

* convert foldername and filename to friendly versions separatly

* Add null guards to the filename export
This commit is contained in:
Caleb John
2020-04-02 17:24:33 -06:00
committed by GitHub
parent 0512fa6208
commit ff7775b344
2 changed files with 29 additions and 9 deletions

View File

@@ -2,6 +2,9 @@ const { _ } = require('lib/locale');
const { bridge } = require('electron').remote.require('./bridge');
const InteropService = require('lib/services/InteropService');
const Setting = require('lib/models/Setting');
const Note = require('lib/models/Note.js');
const Folder = require('lib/models/Folder.js');
const { friendlySafeFilename } = require('lib/path-utils');
const md5 = require('md5');
const url = require('url');
const { shim } = require('lib/shim');
@@ -92,6 +95,29 @@ class InteropServiceHelper {
return this.exportNoteTo_('printer', noteId, options);
}
static async defaultFilename(noteIds, fileExtension) {
const note = await Note.load(noteIds[0]);
// In a rare case the passed not will be null, use the id for filename
if (note === null) {
const filename = friendlySafeFilename(noteIds[0], 100);
return `${filename}.${fileExtension}`;
}
const folder = await Folder.load(note.parent_id);
const filename = friendlySafeFilename(note.title, 100);
// In a less rare case the folder will be null, just ignore it
if (folder === null) {
return `${filename}.${fileExtension}`;
}
const foldername = friendlySafeFilename(folder.title, 100);
// friendlySafeFilename assumes that the file extension is added after
return `${foldername} - ${filename}.${fileExtension}`;
}
static async export(dispatch, module, options = null) {
if (!options) options = {};
@@ -100,6 +126,7 @@ class InteropServiceHelper {
if (module.target === 'file') {
path = bridge().showSaveDialog({
filters: [{ name: module.description, extensions: module.fileExtensions }],
defaultPath: await this.defaultFilename(options.sourceNoteIds, module.fileExtensions[0]),
});
} else {
path = bridge().showOpenDialog({