diff --git a/README.txt b/README.txt index 1aaf8e7..2803865 100644 --- a/README.txt +++ b/README.txt @@ -62,6 +62,7 @@ Library - (open name ~scale) Imports a graphic file with format. - (import name ~shape) Imports a graphic file with format. - (export ~format ~quality) Exports a graphic file with format. +- (files) Returns the list of loaded files. - (print string) Exports string to file. - (pos ~x ~y) Returns a position shape. - (line ax ay bx by) Returns a line shape. diff --git a/index.html b/index.html index ade82e3..8213ec8 100644 --- a/index.html +++ b/index.html @@ -593,15 +593,7 @@ function Client () { this.onMouseOut = (e) => { this.mouseOrigin = null } - this.onDrag = (e) => { - e.stopPropagation() - e.preventDefault() - e.dataTransfer.dropEffect = 'copy' - } - this.onDrop = (e) => { - e.preventDefault() - e.stopPropagation() - const file = e.dataTransfer.files[0] + this.parseFile = (file) => { if (file.name.indexOf('.lisp') > -1) { this.source.read(file, this.whenOpen) this.log('Loaded ' + file.name) @@ -617,6 +609,18 @@ function Client () { console.warn('Unknown format', file) } } + this.onDrag = (e) => { + e.stopPropagation() + e.preventDefault() + e.dataTransfer.dropEffect = 'copy' + } + this.onDrop = (e) => { + e.preventDefault() + e.stopPropagation() + for (const file of e.dataTransfer.files) { + this.parseFile(file) + } + } this.cache = { data: {}, set: (key, content) => { @@ -900,6 +904,9 @@ function Library (client) { const type = `image/${format === 'jpeg' || format === 'jpg' ? 'jpeg' : 'png'}` client.source.write('ronin', format, client.surface.el.toDataURL(type, quality), type) } + this.files = () => { + return Object.keys(client.cache.data) + } this.pos = (x = 0, y = 0) => { // Returns a position shape. return { x, y } } diff --git a/scripts/client.js b/scripts/client.js index 407108e..9979055 100644 --- a/scripts/client.js +++ b/scripts/client.js @@ -158,17 +158,7 @@ function Client () { this.mouseOrigin = null } - this.onDrag = (e) => { - e.stopPropagation() - e.preventDefault() - e.dataTransfer.dropEffect = 'copy' - } - - this.onDrop = (e) => { - e.preventDefault() - e.stopPropagation() - const file = e.dataTransfer.files[0] - + this.parseFile = (file) => { if (file.name.indexOf('.lisp') > -1) { this.source.read(file, this.whenOpen) this.log('Loaded ' + file.name) @@ -185,6 +175,20 @@ function Client () { } } + this.onDrag = (e) => { + e.stopPropagation() + e.preventDefault() + e.dataTransfer.dropEffect = 'copy' + } + + this.onDrop = (e) => { + e.preventDefault() + e.stopPropagation() + for (const file of e.dataTransfer.files) { + this.parseFile(file) + } + } + this.cache = { data: {}, set: (key, content) => { diff --git a/scripts/library.js b/scripts/library.js index 8c8c997..465c366 100644 --- a/scripts/library.js +++ b/scripts/library.js @@ -25,6 +25,10 @@ function Library (client) { client.source.write('ronin', format, client.surface.el.toDataURL(type, quality), type) } + this.files = () => { + return Object.keys(client.cache.data) + } + // Shapes this.pos = (x = 0, y = 0) => { // Returns a position shape.