grab contents of edit area before run

This commit is contained in:
benfry
2011-01-26 22:20:42 +00:00
parent b9d14b44d5
commit 2ddca09981
8 changed files with 88 additions and 55 deletions

View File

@@ -1897,6 +1897,37 @@ public abstract class Editor extends JFrame implements RunnerListener {
}
/**
* Grab current contents of the sketch window, advance the console,
* stop any other running sketches... not in that order.
*/
public void prepareRun() {
internalCloseRunner();
statusEmpty();
// do this to advance/clear the terminal window / dos prompt / etc
for (int i = 0; i < 10; i++) System.out.println();
// clear the console on each run, unless the user doesn't want to
if (Preferences.getBoolean("console.auto_clear")) {
console.clear();
}
// make sure the user didn't hide the sketch folder
sketch.ensureExistence();
// make sure any edits have been stored
//current.setProgram(editor.getText());
sketch.getCurrentCode().setProgram(getText());
// if an external editor is being used, need to grab the
// latest version of the code from the file.
if (Preferences.getBoolean("editor.external")) {
sketch.reload();
}
}
/**
* Halt the current runner for whatever reason. Might be the VM dying,
* the window closing, an error...

View File

@@ -450,6 +450,23 @@ public abstract class Mode {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
* Create a fresh applet/application folder if the 'delete target folder'
* pref has been set in the preferences.
*/
public void prepareExportFolder(File targetFolder) {
if (targetFolder != null) {
// Nuke the old applet/application folder because it can cause trouble
if (Preferences.getBoolean("export.delete_target_folder")) {
System.out.println("temporarily skipping deletion of " + targetFolder);
// Base.removeDir(targetFolder);
// targetFolder.renameTo(dest);
}
// Create a fresh output folder (needed before preproc is run next)
targetFolder.mkdirs();
}
}
// public void handleNew() {
// base.handleNew();
// }

View File

@@ -134,7 +134,7 @@ public class Sketch {
load();
}
/**
* Build the list of files.
@@ -215,6 +215,19 @@ public class Sketch {
}
/**
* Reload the current sketch. Used to update the text area when
* an external editor is in use.
*/
public void reload() {
// set current to null so that the tab gets updated
// http://dev.processing.org/bugs/show_bug.cgi?id=515
current = null;
// nuke previous files and settings
load();
}
protected void replaceCode(SketchCode newCode) {
for (int i = 0; i < codeCount; i++) {
if (code[i].getFileName().equals(newCode.getFileName())) {
@@ -1130,6 +1143,7 @@ public class Sketch {
* not null, and if preferences say to do so when exporting.
* @param targetFolder is something like applet, application, android...
*/
/*
public void prepareBuild(File targetFolder) throws SketchException {
// make sure the user didn't hide the sketch folder
ensureExistence();
@@ -1161,6 +1175,7 @@ public class Sketch {
targetFolder.mkdirs();
}
}
*/
/**

View File

@@ -64,7 +64,8 @@ class AndroidBuild extends JavaBuild {
manifest = new Manifest(sketch);
// grab code from current editing window (GUI only)
sketch.prepareBuild(null);
// prepareExport(null);
// build the preproc and get to work
AndroidPreprocessor preproc = new AndroidPreprocessor(sketch, getPackageName());
if (!preproc.parseSketchSize()) {

View File

@@ -510,6 +510,7 @@ public class AndroidEditor extends JavaEditor implements DeviceListener {
* Build the sketch and run it inside an emulator with the debugger.
*/
public void handleRunEmulator() {
prepareRun();
AVD.ensureEclairAVD(sdk);
try {
runSketchOnDevice(Environment.getInstance().getEmulator(), "debug");

View File

@@ -48,6 +48,7 @@ public class JavaBuild {
"(?:^|\\s|;)package\\s+(\\S+)\\;";
protected Sketch sketch;
protected Mode mode;
// what happens in the build, stays in the build.
// (which is to say that everything below this line, stays within this class)
@@ -82,6 +83,7 @@ public class JavaBuild {
public JavaBuild(Sketch sketch) {
this.sketch = sketch;
this.mode = sketch.getMode();
}
@@ -383,7 +385,7 @@ public class JavaBuild {
int dot = item.lastIndexOf('.');
// http://dev.processing.org/bugs/show_bug.cgi?id=1145
String entry = (dot == -1) ? item : item.substring(0, dot);
Library library = sketch.getMode().getLibrary(entry);
Library library = mode.getLibrary(entry);
if (library != null) {
if (!importedLibraries.contains(library)) {
@@ -658,7 +660,8 @@ public class JavaBuild {
* Handle export to applet.
*/
public boolean exportApplet(File appletFolder) throws SketchException, IOException {
sketch.prepareBuild(appletFolder);
mode.prepareExportFolder(appletFolder);
srcFolder = sketch.makeTempFolder();
binFolder = sketch.makeTempFolder();
String foundName = build(srcFolder, binFolder);
@@ -926,7 +929,6 @@ public class JavaBuild {
if (renderer.equals("OPENGL")) {
openglApplet = true;
}
Mode mode = sketch.getMode();
if (is == null) {
if (openglApplet) {
is = mode.getContentStream("applet/template-opengl.html");
@@ -1070,7 +1072,8 @@ public class JavaBuild {
int exportPlatform,
int exportBits) throws IOException, SketchException {
File destFolder = new File(destPath);
sketch.prepareBuild(destFolder);
// sketch.prepareBuild(destFolder);
mode.prepareExportFolder(destFolder);
// build the sketch
File srcFolder = sketch.makeTempFolder();
@@ -1097,8 +1100,6 @@ public class JavaBuild {
/// where all the skeleton info lives
Mode mode = sketch.getMode();
/// on macosx, need to copy .app skeleton since that's
/// also where the jar files will be placed
File dotAppFolder = null;

View File

@@ -1,37 +1,15 @@
package processing.mode.java;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.io.*;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.*;
import javax.swing.border.*;
import processing.app.*;
import processing.app.Base;
import processing.app.Editor;
import processing.app.EditorToolbar;
import processing.app.Formatter;
import processing.app.Mode;
import processing.app.Preferences;
import processing.app.SketchException;
public class JavaEditor extends Editor {
JavaMode jmode;
@@ -481,24 +459,11 @@ public class JavaEditor extends Editor {
}
return true;
}
protected void prepareRun() {
internalCloseRunner();
toolbar.activate(JavaToolbar.RUN);
statusEmpty();
// do this to advance/clear the terminal window / dos prompt / etc
for (int i = 0; i < 10; i++) System.out.println();
// clear the console on each run, unless the user doesn't want to
if (Preferences.getBoolean("console.auto_clear")) {
console.clear();
}
}
public void handleRun() {
toolbar.activate(JavaToolbar.RUN);
prepareRun();
try {
jmode.handleRun(sketch, this);
@@ -509,6 +474,8 @@ public class JavaEditor extends Editor {
public void handlePresent() {
toolbar.activate(JavaToolbar.RUN);
prepareRun();
try {
jmode.handlePresent(sketch, this);

View File

@@ -5,8 +5,8 @@
The build is broken! The build is broken!
I'm currently doing major work on the innards of the PDE.
As such, the current SVN (mostly just within /app)
will be a mess for a few days/weeks as I sort that out.
As such, the current SVN will be a mess for a few days/weeks
as I sort that out.
As always, if you need a working build, use a tagged version
of a release build, i.e. tags/processing-0192 for Android,