diff --git a/desktop/sources/scripts/lib/source.js b/desktop/sources/scripts/lib/source.js index 7c007c1..d058150 100644 --- a/desktop/sources/scripts/lib/source.js +++ b/desktop/sources/scripts/lib/source.js @@ -35,9 +35,9 @@ function Source () { this.saveAs(name, content, type, callback) } - this.saveAs = (name, content, type = 'text/plain', callback) => { + this.saveAs = (name, ext, content, type = 'text/plain', callback) => { console.log('Source', 'Save new file..') - this.download(name, content, type, callback) + this.download(name, ext, content, type, callback) } this.revert = () => { @@ -55,10 +55,9 @@ function Source () { reader.readAsText(file, 'UTF-8') } - this.download = (name, content, type, settings = 'charset=utf-8') => { - console.info('Source', `Downloading ${name}(${type})`) + this.download = (name, ext, content, type, settings = 'charset=utf-8') => { const link = document.createElement('a') - link.setAttribute('download', name) + link.setAttribute('download', `${name}-${timestamp()}.${ext}`) if (type === 'image/png' || type === 'image/jpeg') { link.setAttribute('href', content) } else { @@ -66,4 +65,9 @@ function Source () { } link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window })) } + + function timestamp (d = new Date(), e = new Date(d)) { + const ms = e - d.setHours(0, 0, 0, 0) + return (ms / 8640 / 10000).toFixed(6).substr(2, 6) + } } diff --git a/desktop/sources/scripts/ronin.js b/desktop/sources/scripts/ronin.js index d2fe0fd..33ee184 100644 --- a/desktop/sources/scripts/ronin.js +++ b/desktop/sources/scripts/ronin.js @@ -39,8 +39,8 @@ function Ronin () { window.addEventListener('drop', this.onDrop) this.acels.set('File', 'New', 'CmdOrCtrl+N', () => { this.source.new(); this.surface.clear(); this.commander.clear() }) - this.acels.set('File', 'Save', 'CmdOrCtrl+S', () => { this.source.save('export.lisp', this.commander._input.value, 'text/plain') }) - this.acels.set('File', 'Export Image', 'CmdOrCtrl+E', () => { this.source.download('export.png', this.surface.el.toDataURL('image/png', 1.0), 'image/png') }) + this.acels.set('File', 'Save', 'CmdOrCtrl+S', () => { this.source.download('ronin', 'lisp', this.commander._input.value, 'text/plain') }) + this.acels.set('File', 'Export Image', 'CmdOrCtrl+E', () => { this.source.download('ronin', 'png', this.surface.el.toDataURL('image/png', 1.0), 'image/png') }) this.acels.set('File', 'Open', 'CmdOrCtrl+O', () => { this.source.open('lisp', this.whenOpen) }) this.acels.set('File', 'Revert', 'CmdOrCtrl+W', () => { this.source.revert() }) this.acels.set('View', 'Toggle Guides', 'CmdOrCtrl+Shift+H', () => { this.surface.toggleGuides() })