Skip to content

Commit 9c9e1ff

Browse files
committed
add mode and editor
1 parent 0f95bfd commit 9c9e1ff

20 files changed

+1517
-24
lines changed

build.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<project name="processing.r" default="install" basedir="./">
3-
<property name="mode.name" value="processing.r" />
3+
<property name="mode.name" value="RLangMode" />
44
<!-- folder to install modes in (probably a folder called "modes" inside your sketchbook folder) -->
55
<property name="processing.modes" location="/Users/gaoce/Documents/Processing/modes" />
66
<!-- path to your processing executable. -->
@@ -75,8 +75,8 @@
7575
<copy todir="${bundle}/mode">
7676
<fileset dir="lib/" />
7777
</copy>
78-
<replaceregexp file="${bundle}/mode.properties" flags="g" match="@@version@@" replace="${build.number}" />
79-
<replaceregexp file="${bundle}/mode.properties" flags="g" match="@@pretty-version@@" replace="${release}" />
78+
<replaceregexp file="${bundle}/mode.properties" flags="g" match="@@version@@" replace="11" />
79+
<replaceregexp file="${bundle}/mode.properties" flags="g" match="@@pretty-version@@" replace="1" />
8080
</target>
8181
<!-- - - - - - - - - - - - - - - - - - - - - - -
8282
INSTALL

resources/keywords.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# additional keywords for JavaScript mode
2+
# https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words
3+
4+
debugger KEYWORD1
5+
var KEYWORD1
6+
function KEYWORD1
7+
typeof KEYWORD1
8+
delete KEYWORD1
9+
throw KEYWORD1
10+
with KEYWORD1
11+
in KEYWORD1
12+
13+
prototype KEYWORD1
14+
arguments KEYWORD1
15+
#callee KEYWORD1
16+
17+
enum KEYWORD1
18+
export KEYWORD1
19+
let KEYWORD1
20+
yield KEYWORD1
21+
undefined KEYWORD1
22+
const KEYWORD1
23+
24+
# some specials
25+
26+
console KEYWORD1
27+
window KEYWORD1
28+
document KEYWORD1
29+
30+
alert KEYWORD3

resources/mode.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name = R Language Mode
2+
authorList = [Ce Gao](http://gaocegege.com)
3+
url = https://github.com/gaocegege/Processing.R
4+
sentence = Tweak hard-coded numbers in your code and see the result in real-time.
5+
paragraph = When a sketch is being executed in tweak mode, all hard-coded numbers become interactive and can be modified by clicking and dragging to the left or right. When a value change, the PDE will update the running sketch with the new value and the result will be visible immediately. This mode is useful if you want to refine a certain feature/color/behaviour in your sketch, if you want to experiment freely with numbers, or if you try to understand someone else's code. other uses are welcome.
6+
version = @@version@@
7+
prettyVersion = @@pretty-version@@

resources/theme/buttons-2x.png

5.6 KB
Loading

resources/theme/buttons.png

2.47 KB
Loading

resources/theme/mode-2x.png

124 KB
Loading

resources/theme/mode.png

62.8 KB
Loading

resources/theme/theme.txt

Whitespace-only changes.

src/rprocessing/IOUtil.java

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package rprocessing;
2+
3+
import static java.nio.file.FileVisitResult.CONTINUE;
4+
5+
import java.io.ByteArrayOutputStream;
6+
import java.io.IOException;
7+
import java.io.InputStream;
8+
import java.nio.charset.Charset;
9+
import java.nio.file.FileVisitOption;
10+
import java.nio.file.FileVisitResult;
11+
import java.nio.file.Files;
12+
import java.nio.file.Path;
13+
import java.nio.file.SimpleFileVisitor;
14+
import java.nio.file.attribute.BasicFileAttributes;
15+
import java.util.EnumSet;
16+
17+
/**
18+
*
19+
* @author github.com/gaocegege
20+
*/
21+
public class IOUtil {
22+
23+
private static final Charset UTF8 = Charset.forName("utf-8");
24+
25+
public static class ResourceReader {
26+
private final Class<?> clazz;
27+
28+
public ResourceReader(final Class<?> clazz) {
29+
this.clazz = clazz;
30+
}
31+
32+
public String readText(final String resource) {
33+
return IOUtil.readResourceAsText(clazz, resource);
34+
}
35+
}
36+
37+
public static String readResourceAsText(final Class<?> clazz, final String resource) {
38+
try (final InputStream in = clazz.getResourceAsStream(resource)) {
39+
return readText(in);
40+
} catch (final IOException e) {
41+
throw new RuntimeException(e);
42+
}
43+
}
44+
45+
public static String readText(final InputStream in) throws IOException {
46+
return new String(readFully(in), UTF8);
47+
}
48+
49+
public static String readText(final Path path) throws IOException {
50+
return new String(Files.readAllBytes(path), UTF8);
51+
}
52+
53+
/**
54+
* Recursively deletes the given directory or file.
55+
* @param target Path of file to be deleted.
56+
* @throws IOException
57+
*/
58+
public static void rm(final Path target) throws IOException {
59+
Files.walkFileTree(target, new SimpleFileVisitor<Path>() {
60+
@Override
61+
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs)
62+
throws IOException {
63+
Files.delete(file);
64+
return CONTINUE;
65+
}
66+
67+
@Override
68+
public FileVisitResult postVisitDirectory(final Path dir, final IOException exc)
69+
throws IOException {
70+
if (exc != null) {
71+
throw exc;
72+
}
73+
Files.delete(dir);
74+
return CONTINUE;
75+
}
76+
});
77+
}
78+
79+
public static void copy(final Path src, final Path target) throws IOException {
80+
final Path dest = Files.isDirectory(target) ? target.resolve(src.getFileName()) : target;
81+
final EnumSet<FileVisitOption> doNotResolveLinks = EnumSet.noneOf(FileVisitOption.class);
82+
Files.walkFileTree(src, doNotResolveLinks, Integer.MAX_VALUE, new TreeCopier(src, dest));
83+
}
84+
85+
public static byte[] readFully(final InputStream in) throws IOException {
86+
try (final ByteArrayOutputStream bytes = new ByteArrayOutputStream(1024)) {
87+
final byte[] buf = new byte[1024];
88+
int n;
89+
while ((n = in.read(buf)) != -1) {
90+
bytes.write(buf, 0, n);
91+
}
92+
return bytes.toByteArray();
93+
}
94+
}
95+
}

src/rprocessing/TreeCopier.java

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package rprocessing;
2+
3+
/*
4+
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions
8+
* are met:
9+
*
10+
* - Redistributions of source code must retain the above copyright
11+
* notice, this list of conditions and the following disclaimer.
12+
*
13+
* - Redistributions in binary form must reproduce the above copyright
14+
* notice, this list of conditions and the following disclaimer in the
15+
* documentation and/or other materials provided with the distribution.
16+
*
17+
* - Neither the name of Oracle nor the names of its
18+
* contributors may be used to endorse or promote products derived
19+
* from this software without specific prior written permission.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
34+
import static java.nio.file.FileVisitResult.CONTINUE;
35+
import static java.nio.file.FileVisitResult.SKIP_SUBTREE;
36+
import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES;
37+
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
38+
39+
import java.io.IOException;
40+
import java.nio.file.FileAlreadyExistsException;
41+
import java.nio.file.FileSystemLoopException;
42+
import java.nio.file.FileVisitResult;
43+
import java.nio.file.FileVisitor;
44+
import java.nio.file.Files;
45+
import java.nio.file.Path;
46+
import java.nio.file.attribute.BasicFileAttributes;
47+
import java.nio.file.attribute.FileTime;
48+
49+
class TreeCopier implements FileVisitor<Path> {
50+
51+
/**
52+
* Copy source file to target location.
53+
*/
54+
static void copyFile(final Path source, final Path target) {
55+
try {
56+
Files.copy(source, target, COPY_ATTRIBUTES, REPLACE_EXISTING);
57+
} catch (final IOException x) {
58+
System.err.format("Unable to copy: %s: %s%n", source, x);
59+
}
60+
}
61+
62+
private final Path source;
63+
private final Path target;
64+
65+
TreeCopier(final Path source, final Path target) {
66+
this.source = source;
67+
this.target = target;
68+
}
69+
70+
@Override
71+
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) {
72+
// before visiting entries in a directory we copy the directory
73+
// (okay if directory already exists).
74+
final Path newdir = target.resolve(source.relativize(dir));
75+
try {
76+
Files.copy(dir, newdir, COPY_ATTRIBUTES);
77+
} catch (final FileAlreadyExistsException x) {
78+
// ignore
79+
} catch (final IOException x) {
80+
System.err.format("Unable to create: %s: %s%n", newdir, x);
81+
return SKIP_SUBTREE;
82+
}
83+
return CONTINUE;
84+
}
85+
86+
@Override
87+
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) {
88+
copyFile(file, target.resolve(source.relativize(file)));
89+
return CONTINUE;
90+
}
91+
92+
@Override
93+
public FileVisitResult postVisitDirectory(final Path dir, final IOException exc) {
94+
// fix up modification time of directory when done
95+
if (exc == null) {
96+
final Path newdir = target.resolve(source.relativize(dir));
97+
try {
98+
final FileTime time = Files.getLastModifiedTime(dir);
99+
Files.setLastModifiedTime(newdir, time);
100+
} catch (final IOException x) {
101+
System.err.format("Unable to copy all attributes to: %s: %s%n", newdir, x);
102+
}
103+
}
104+
return CONTINUE;
105+
}
106+
107+
@Override
108+
public FileVisitResult visitFileFailed(final Path file, final IOException exc) {
109+
if (exc instanceof FileSystemLoopException) {
110+
System.err.println("cycle detected: " + file);
111+
} else {
112+
System.err.format("Unable to copy: %s: %s%n", file, exc);
113+
}
114+
return CONTINUE;
115+
}
116+
}

0 commit comments

Comments
 (0)