Skip to content

Commit

Permalink
Making things compatible with 3.0b4 and up
Browse files Browse the repository at this point in the history
  • Loading branch information
joelmoniz committed Sep 24, 2015
1 parent 959c59e commit 7baf58b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
8 changes: 4 additions & 4 deletions resources/mode.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ authors = [Joel Moniz](http://joelmoniz.com)
url = https://github.com/joelmoniz/REPLmode
sentence = Adds an REPL Console to view the output of code typed into it immediately. Also gives the PDE the ability to hot swap code.
paragraph = This mode adds in a Read-Evaluate-Print-Loop console to processing in the form of a tab at the bottom. The console enables users to type in processing code and to view the output of this code immediately. Each subsequent line of code shows the output incrementally, much like how an REPL Console for any interpretive language (like Python, and the Linux bash terminal) would. The console also provides options to undo commands, to convert the valid commands entered so far into a function, and so on. Ths mode also gives the PDE the ability to hot swap code, wherein the output corresponding to changes made in a running sketch can be viewed by simply saving the sketch, without restarting it.
version = 6
prettyVersion = 1.2.8b
version = 7
prettyVersion = 1.2.9b
imports = processing.mode.java.JavaMode
lastUpdated = 1439146839000
lastUpdated = 1443120511000
maxRevision = 0
minRevision = 0239
minRevision = 0242
10 changes: 7 additions & 3 deletions src/jm/mode/replmode/REPLEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ of the License, or (at your option) any later version.

import processing.app.Base;
import processing.app.Mode;
import processing.app.Platform;
import processing.app.Preferences;
import processing.app.RunnerListener;
import processing.app.Sketch;
import processing.app.SketchCode;
import processing.app.SketchException;
import processing.app.Util;
import processing.app.ui.EditorException;
import processing.app.ui.EditorFooter;
import processing.app.ui.EditorState;
import processing.mode.java.JavaBuild;
Expand Down Expand Up @@ -93,15 +96,16 @@ public class REPLEditor extends JavaEditor {

REPLMode replMode;

protected REPLEditor(Base base, String path, EditorState state, Mode mode) {
protected REPLEditor(Base base, String path, EditorState state, Mode mode)
throws EditorException {
super(base, path, state, mode);

replMode = (REPLMode) mode;
replRuntime = null;
runtime = null;

try {
untitledFolderLocation = Base.createTempFolder("untitled", "repl", null);
untitledFolderLocation = Util.createTempFolder("untitled", "repl", null);

(new File(untitledFolderLocation, sketch.getFolder().getName())).mkdirs();
File subdir = new File(untitledFolderLocation, sketch.getFolder()
Expand Down Expand Up @@ -352,7 +356,7 @@ public void actionPerformed(ActionEvent e) {
item = new JMenuItem("Report a bug");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Base.openURL("https://github.com/joelmoniz/REPLmode/issues/new");
Platform.openURL("https://github.com/joelmoniz/REPLmode/issues/new");
}
});
replHelpMenu.add(item);
Expand Down
17 changes: 12 additions & 5 deletions src/jm/mode/replmode/REPLMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ of the License, or (at your option) any later version.
import java.io.File;

import processing.app.Base;
import processing.app.ui.Editor;
import processing.app.ui.EditorState;
import processing.app.Mode;
import processing.app.Platform;
import processing.app.RunnerListener;
import processing.app.Sketch;
import processing.app.SketchException;
import processing.app.ui.Editor;
import processing.app.ui.EditorException;
import processing.app.ui.EditorState;
import processing.mode.java.JavaBuild;
import processing.mode.java.JavaMode;
import processing.mode.java.runner.Runner;
Expand Down Expand Up @@ -78,7 +80,7 @@ public REPLMode(Base base, File folder) {
* Do this to use the JavaMode's examples, libraries and reference, since
* all of them are perfectly applicable to the REPL Mode
*/
File javamodeFolder = Base.getContentFile("modes/java");
File javamodeFolder = Platform.getContentFile("modes/java");
examplesFolder = new File(javamodeFolder, "examples");
librariesFolder = new File(javamodeFolder, "libraries");
referenceFolder = new File(javamodeFolder, "reference");
Expand All @@ -103,9 +105,10 @@ public String getTitle() {

/**
* Create a new editor associated with this mode.
* @throws EditorException
*/
@Override
public Editor createEditor(Base base, String path, EditorState state) {
public Editor createEditor(Base base, String path, EditorState state) throws EditorException {
/*
* Teensy little hack to show the welcome screen when the first time an
* Editor is created, but not after that. Required since an REPLMode object
Expand Down Expand Up @@ -190,7 +193,11 @@ public Runner handleLaunch(Sketch sketch, RunnerListener listener,
new Thread(new Runnable() {
public void run() {
isRunning = true;
runtime.launch(present); // this blocks until finished
if (present) {
runtime.present(null);
} else {
runtime.launch(null);
}
isRunning = false;
}
}).start();
Expand Down
23 changes: 13 additions & 10 deletions src/jm/mode/replmode/REPLRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ of the License, or (at your option) any later version.
import java.net.URL;
import java.util.Map;

import processing.app.Base;
import processing.app.Platform;
import processing.app.RunnerListener;
import processing.app.SketchException;
import processing.app.exec.StreamRedirectThread;
import processing.core.PApplet;
import processing.data.StringList;
import processing.mode.java.JavaBuild;
import processing.mode.java.runner.MessageSiphon;
import processing.mode.java.runner.Runner;
Expand Down Expand Up @@ -200,20 +201,20 @@ public void run() {
* @return True if the VM was launched
*/
public boolean launchREPLVirtualMachine() {
return launchVirtualMachine(false);
return launchVirtualMachine(false, null);
}

/**
* Pretty much the same as the launchVirtualMachine() of the base Runner
* class, except that this adds in an extra VM argument for the hot swapper
*/
@Override
public boolean launchVirtualMachine(boolean presenting) {
public boolean launchVirtualMachine(boolean presenting, String[] args) {
int port = 8000 + (int) (Math.random() * 1000);
String portStr = String.valueOf(port);

String[] vmParams = getMachineParams();
String[] sketchParams = getSketchParams(presenting);
StringList vmParams = getMachineParams();
StringList sketchParams = getSketchParams(presenting, args);

/**
* This contains the string representing the VM argument for the hot
Expand All @@ -239,11 +240,13 @@ public boolean launchVirtualMachine(boolean presenting) {
String jdwpArg = "-agentlib:jdwp=transport=dt_socket,address="
+ portStr + ",server=y,suspend=y";
// Everyone works the same under Java 7 (also on OS X)
String[] commandArgs =
new String[] { Base.getJavaPath(), jdwpArg,hotSwapArg };
commandArgs = PApplet.concat(commandArgs, vmParams);
commandArgs = PApplet.concat(commandArgs, sketchParams);
launchJava(commandArgs);
StringList commandArgs = new StringList();
commandArgs.append(Platform.getJavaPath());
commandArgs.append(jdwpArg);
commandArgs.append(hotSwapArg);
commandArgs.append(vmParams);
commandArgs.append(sketchParams);
launchJava(commandArgs.array());

/*
* This part seems to be used to get the vm, that is in turn used not only
Expand Down

0 comments on commit 7baf58b

Please sign in to comment.