Skip to content

Commit 89ab3a0

Browse files
committed
New schema handler
1 parent ccda7fb commit 89ab3a0

3 files changed

Lines changed: 79 additions & 1 deletion

File tree

app/ant/processing/app/Schema.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package processing.app;
2+
3+
import processing.app.ui.Editor;
4+
5+
public class Schema {
6+
public static Editor handleSchema(String input, Base base) {
7+
return null;
8+
}
9+
}

app/src/processing/app/Base.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import processing.core.*;
4545
import processing.data.StringList;
4646

47-
4847
/**
4948
* The base class for the main processing application.
5049
* Primary role of this class is for platform identification and
@@ -1367,6 +1366,11 @@ private File moveLikeSketchFolder(File pdeFile, String baseName) throws IOExcept
13671366
* @param schemeUri the full URI, including pde://
13681367
*/
13691368
public Editor handleScheme(String schemeUri) {
1369+
var result = Schema.handleSchema(schemeUri, this);
1370+
if (result != null) {
1371+
return result;
1372+
}
1373+
13701374
String location = schemeUri.substring(6);
13711375
if (location.length() > 0) {
13721376
// if it leads with a slash, then it's a file url

app/src/processing/app/Schema.kt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package processing.app
2+
3+
import processing.app.ui.Editor
4+
import java.io.File
5+
import java.net.URI
6+
import java.net.URLDecoder
7+
import java.nio.charset.StandardCharsets
8+
9+
10+
class Schema {
11+
companion object{
12+
private var base: Base? = null
13+
@JvmStatic
14+
fun handleSchema(input: String, base: Base): Editor?{
15+
this.base = base
16+
val uri = URI.create(input)
17+
return when (uri.host) {
18+
null -> handleLocalFile(uri.path)
19+
"sketch" -> handleSketch(uri)
20+
"preferences" -> handlePreferences(uri)
21+
else -> handleRemoteFile(uri)
22+
}
23+
}
24+
private fun handleLocalFile(input: String): Editor?{
25+
return base?.handleOpen(input)
26+
}
27+
private fun handleSketch(uri: URI): Editor?{
28+
val paths = uri.path.split("/")
29+
return when(paths.getOrNull(1)){
30+
"base64" -> handleSketchBase64(uri)
31+
else -> null
32+
}
33+
}
34+
private fun handleSketchBase64(uri: URI): Editor?{
35+
val tempSketchFolder = SketchName.nextFolder(Base.untitledFolder);
36+
tempSketchFolder.mkdirs()
37+
val tempSketchFile = File(tempSketchFolder, "${tempSketchFolder.name}.pde")
38+
val sketchB64 = uri.path.replace("/base64/", "")
39+
val sketch = java.util.Base64.getDecoder().decode(sketchB64)
40+
tempSketchFile.writeBytes(sketch)
41+
val editor = base?.handleOpenUntitled(tempSketchFile.absolutePath)
42+
return editor
43+
}
44+
45+
private fun handlePreferences(uri: URI): Editor?{
46+
val options = uri.query?.split("&")
47+
?.map { it.split("=") }
48+
?.associate {
49+
URLDecoder.decode(it[0], StandardCharsets.UTF_8) to
50+
URLDecoder.decode(it[1], StandardCharsets.UTF_8)
51+
}
52+
?: emptyMap()
53+
for ((key, value) in options){
54+
Preferences.set(key, value)
55+
}
56+
Preferences.save()
57+
58+
return null
59+
}
60+
61+
private fun handleRemoteFile(uri: URI): Editor?{
62+
return null
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)