Added export shortcut

This commit is contained in:
neauoire 2019-11-03 09:45:03 -05:00
parent b4beaf03af
commit d4380e9887
2 changed files with 10 additions and 5 deletions

View File

@ -56,9 +56,14 @@ function Source () {
} }
this.download = (name, content, type) => { this.download = (name, content, type) => {
const pom = document.createElement('a') console.info('Source', `Downloading ${name}(${type})`)
pom.setAttribute('download', name) const link = document.createElement('a')
pom.setAttribute('href', 'data:' + type + ';charset=utf-8,' + encodeURIComponent(content)) link.setAttribute('download', name)
pom.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window })) 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 }))
} }
} }

View File

@ -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', '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', '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', 'Open', 'CmdOrCtrl+O', () => { this.source.open('lisp', this.whenOpen) })
this.acels.set('File', 'Revert', 'CmdOrCtrl+W', () => { this.source.revert() }) this.acels.set('File', 'Revert', 'CmdOrCtrl+W', () => { this.source.revert() })
this.acels.set('View', 'Toggle Guides', 'CmdOrCtrl+Shift+H', () => { this.surface.toggleGuides() }) this.acels.set('View', 'Toggle Guides', 'CmdOrCtrl+Shift+H', () => { this.surface.toggleGuides() })