From d4380e9887859b587029d05e4b939f3845456222 Mon Sep 17 00:00:00 2001 From: neauoire Date: Sun, 3 Nov 2019 09:45:03 -0500 Subject: [PATCH] Added export shortcut --- desktop/sources/scripts/lib/source.js | 13 +++++++++---- desktop/sources/scripts/ronin.js | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/desktop/sources/scripts/lib/source.js b/desktop/sources/scripts/lib/source.js index cd10a99..8176c61 100644 --- a/desktop/sources/scripts/lib/source.js +++ b/desktop/sources/scripts/lib/source.js @@ -56,9 +56,14 @@ function Source () { } this.download = (name, content, type) => { - const pom = document.createElement('a') - pom.setAttribute('download', name) - pom.setAttribute('href', 'data:' + type + ';charset=utf-8,' + encodeURIComponent(content)) - pom.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window })) + console.info('Source', `Downloading ${name}(${type})`) + const link = document.createElement('a') + link.setAttribute('download', name) + if (type === 'image/png' || type === 'image/jpeg') { + link.setAttribute('href', content) + } else { + link.setAttribute('href', 'data:' + type + ';charset=utf-8,' + encodeURIComponent(content)) + } + link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window })) } } diff --git a/desktop/sources/scripts/ronin.js b/desktop/sources/scripts/ronin.js index 7494e4c..993d2c7 100644 --- a/desktop/sources/scripts/ronin.js +++ b/desktop/sources/scripts/ronin.js @@ -38,7 +38,7 @@ function Ronin () { 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', 'Save As', 'CmdOrCtrl+Shift+S', () => { this.source.saveAs() }) + this.acels.set('File', 'Export Image', 'CmdOrCtrl+E', () => { this.source.download('export.png', ronin.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() })