changes to editor and sketchbook

This commit is contained in:
benfry
2003-12-04 03:44:42 +00:00
parent 31b91b4fc7
commit 3801dce966
3 changed files with 85 additions and 236 deletions

View File

@@ -410,10 +410,10 @@ public class PdeEditor extends JFrame
skOpen(sketchDir, sketchName);
} else {
skNew();
skNew2(true);
}
} else {
skNew();
skNew2(true);
}
@@ -1498,11 +1498,9 @@ public class PdeEditor extends JFrame
}
public void checkModified2() {
//System.out.println("checkmodified2");
switch (checking) {
case SK_NEW: skNew2(); break;
case SK_OPEN: skOpen2(openingPath, openingName); break;
//case DO_OPEN: doOpen2(); break;
case DO_QUIT: doQuit2(); break;
}
checking = 0;
@@ -1515,17 +1513,20 @@ public class PdeEditor extends JFrame
checkModified(SK_NEW);
}
protected void skNew2() {
try {
// does all the plumbing to create a new project
// then calls handleOpen to load it up
/**
* Does all the plumbing to create a new project
* then calls handleOpen to load it up.
* @param startup true if the app is starting (auto-create a sketch)
*/
protected void skNew2(boolean startup) {
try {
File sketchDir = null;
String sketchName = null;
if (PdePreferences.getBoolean("sketchbook.prompt")) {
if (PdePreferences.getBoolean("sketchbook.prompt") && !startup) {
FileDialog fd = new FileDialog(new Frame(),
"Save new sketch as:",
"Create new sketch named",
FileDialog.SAVE);
fd.setDirectory(PdePreferences.get("sketchbook.path"));
fd.show();
@@ -1661,11 +1662,8 @@ public class PdeEditor extends JFrame
sketchDir = isketchDir;
setSketchModified(false);
//historyFile = new File(sketchFile.getParent(), "history.gz");
history.setPath(sketchFile.getParent());
//base.rebuildHistoryMenu(historyFile.getPath());
history.setPath(sketchFile.getParent(), readOnlySketch());
history.rebuildMenu();
//historyLast = program;
history.lastRecorded = program;
header.reset();
@@ -1683,6 +1681,16 @@ public class PdeEditor extends JFrame
}
/**
* Returns true if this is a read-only sketch. Used for the
* examples directory, or when sketches are loaded from read-only
* volumes or folders without appropraite permissions.
*/
public boolean readOnlySketch() {
return false;
}
public void doSave() {
// true if lastfile not set, otherwise false, meaning no prompt
//handleSave(lastFile == null);

View File

@@ -38,10 +38,12 @@ import javax.swing.undo.*;
public class PdeSketchbook {
PdeEditor editor;
//JMenu sketchbookMenu;
JMenu menu;
File sketchbookFolder;
String sketchbookPath;
String sketchbookPath; // canonical path
File examplesFolder;
String examplesPath; // canonical path (for comparison)
public PdeSketchbook(PdeEditor editor) {
@@ -74,15 +76,8 @@ public class PdeSketchbook {
sketchbookFolder.mkdirs();
}
/*
sketchbookFolder = new File(PdePreferences.get("sketchbook.path"));
sketchbookPath = sketchbookFolder.getAbsolutePath();
if (!sketchbookFolder.exists()) {
System.err.println("sketchbook folder doesn't exist, " +
"making a new one");
sketchbookFolder.mkdirs();
}
*/
sketchbookPath = sketchbookFolder.getCanonicalPath();
} else {
sketchbookFolder = new File(sketchbookPath);
}
@@ -120,176 +115,16 @@ public class PdeSketchbook {
public JMenu rebuildMenu() {
menu.removeAll();
File prey = new File(sketchbookFolder, entries[j]);
File pde = new File(prey, entries[j] + ".pde");
try {
//MenuItem newSketchItem = new MenuItem("New Sketch");
//newSketchItem.addActionListener(this);
//menu.add(newSkechItem);
//menu.addSeparator();
addSketches(menu, sketchbookFolder);
// TODO add examples folder here too
/*
// files for the current user (for now, most likely 'default')
// header knows what the current user is
String userPath = sketchbookPath +
File.separator + editor.userName;
File userFolder = new File(userPath);
if (!userFolder.exists()) {
System.err.println("sketchbook folder for '" + editor.userName +
"' doesn't exist, creating a new one");
userFolder.mkdirs();
}
*/
/*
SketchbookMenuListener userMenuListener =
new SketchbookMenuListener(userPath);
String entries[] = new File(userPath).list();
boolean added = false;
for (int j = 0; j < entries.length; j++) {
if (entries[j].equals(".") ||
entries[j].equals("..") ||
entries[j].equals("CVS")) continue;
//entries[j].equals(".cvsignore")) continue;
added = true;
if (new File(userPath, entries[j] + File.separator +
entries[j] + ".pde").exists()) {
MenuItem item = new MenuItem(entries[j]);
item.addActionListener(userMenuListener);
menu.add(item);
}
//submenu.add(entries[j]);
}
if (!added) {
MenuItem item = new MenuItem("No sketches");
item.setEnabled(false);
menu.add(item);
}
menu.addSeparator();
*/
/*
if (addSketches(menu, userFolder, false)) {
menu.addSeparator();
}
if (!addSketches(menu, sketchbookFolder, true)) {
JMenuItem item = new JMenuItem("No sketches");
item.setEnabled(false);
menu.add(item);
}
*/
/*
// doesn't seem that refresh is worthy of its own menu item
// people can stop and restart p5 if they want to muck with it
menu.addSeparator();
MenuItem item = new MenuItem("Refresh");
item.addActionListener(this);
menu.add(item);
*/
} catch (IOException e) {
e.printStackTrace();
}
return menu;
}
protected boolean addSketches(JMenu menu, File folder) throws IOException {
// skip .DS_Store files, etc
if (!folder.isDirectory()) return false;
String list[] = folder.list();
SketchbookMenuListener listener =
new SketchbookMenuListener(folder.getAbsolutePath());
boolean ifound = false;
for (int i = 0; i < list.length; i++) {
//if (list[i].equals(editor.userName) && root) continue;
if (list[i].equals(".") ||
list[i].equals("..") ||
list[i].equals("CVS")) continue;
File subfolder = new File(folder, list[i]);
if (new File(subfolder, list[i] + ".pde").exists()) {
JMenuItem item = new JMenuItem(list[i]);
item.addActionListener(listener);
menu.add(item);
ifound = true;
} else { // might contain other dirs, get recursive
JMenu submenu = new JMenu(list[i]);
// needs to be separate var
// otherwise would set ifound to false
boolean found = addSketches(submenu, subfolder); //, false);
if (found) {
menu.add(submenu);
ifound = true;
}
}
}
return ifound;
}
/**
* clear out projects that are empty
*/
public void clean() {
if (!PdePreferences.getBoolean("sketchbook.auto_clean")) return;
//String userPath = base.sketchbookPath + File.separator + userName;
//File userFolder = new File(userPath);
File sketchbookFolder = new File(PdePreferences.get("sketchbook.path"));
//System.out.println("auto cleaning");
if (sketchbookFolder.exists()) {
//String entries[] = new File(userPath).list();
String entries[] = sketchbookFolder.list();
if (entries != null) {
for (int j = 0; j < entries.length; j++) {
//System.out.println(entries[j] + " " + entries.length);
if ((entries[j].equals(".")) ||
(entries[j].equals(".."))) continue;
//File prey = new File(userPath, entries[j]);
File prey = new File(sketchbookFolder, entries[j]);
File pde = new File(prey, entries[j] + ".pde");
// make sure this is actually a sketch folder with a .pde,
// not a .DS_Store file or another random user folder
if (pde.exists()) {
if (PdeBase.calcFolderSize(prey) == 0) {
//System.out.println("i want to remove " + prey);
PdeBase.removeDir(prey);
//} else {
//System.out.println("not removign because size is " +
// calcFolderSize(prey));
}
// make sure this is actually a sketch folder with a .pde,
// not a .DS_Store file or another random user folder
if (pde.exists()) {
if (PdeBase.calcFolderSize(prey) == 0) {
//System.out.println("i want to remove " + prey);
PdeBase.removeDir(prey);
}
//File prey = new File(preyDir, entries[j] + ".pde");
//if (prey.exists()) {
//if (prey.length() == 0) {
// this is a candidate for deletion, but make sure
// that the user hasn't added anything else to the folder
//System.out.println("remove: " + prey);
// removeDir(preyDir);
//}
//} else {
//System.out.println(prey + " doesn't exist.. weird");
//}
}
}
}

View File

@@ -6,43 +6,14 @@ o http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs
X make components all swing components
X switch to swing menus (for linux), because motif widgets are nasty
X moved 'find in reference' to the help menu
_ why are cmd keys for menus not working (on mac only?)
examples/readonly
_ how to handle examples: read only, somewhere inside lib
_ move examples to folder that goes w/ p5 app
_ set examples somehow read-only
_ 'save as' from examples puts into examples dir.. :(
_ make it default to the user's sketch dir
_ don't allow editing of multiple files in this release
_ but support multiple java/pde files through the 'add file' option
_ "new text java/pde file" menu item
_ option for having multiple files open
X eliminate the requirement for a 'data' folder
X only create 'data' folder when it's needed/used
X auto-create code and data folder via 'add files to sketch..'
_ sketch.properties should go into user.home
_ otherwise moving sketch folder will kill it
_ may need to start putting properties somewhere besides lib
_ home directory (or preferences folder under macos9)
_ open mode
_ on application open, override 'open' mode
_ and just open an empty sketch in the sketchbook folder
_ check if file is read-only, and if so, ask where to put sketch
_ when 'skNew' is cancelled in 'open' mode, nullpointerex at the top
_ need ui for tabs
_ only create 'data' folder when it's needed/used
_ auto-create code and data folder via 'add files to sketch..'
_ "add library" menu item and submenu
_ iterate through the 'library' folders
_ eliminate the requirement for a 'data' folder
_ fix code for changing the sketch folder
X may need to start putting properties somewhere besides lib
X home directory (or preferences folder under macos9)
_ if sketchbook.dir is set, makes new sketchbook folder
_ reads sketchbook properly from other folder
@@ -55,16 +26,32 @@ _ bring this up on bboard and get votes
_ win2k: my documents, macosx: ~/Documents,
_ macos9: hd:Users?, linux: ~/sketchbook
. . . . . . . . .
0069+
_ tabbed interface for multiple files
_ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;action=display;num=1052077800;start=0
_ why are cmd keys for menus not working (on mac only?)
_ put screenshots into sketch folder
_ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Syntax;action=display;num=1046185738;start=0
examples/readonly
_ check if file is read-only, and if so, ask where to put sketch
_ how to handle examples: read only, somewhere inside lib
_ move examples to folder that goes w/ p5 app
_ set examples somehow read-only
_ 'save as' from examples puts into examples dir.. :(
_ make it default to the user's sketch dir
_ don't allow editing of multiple files in this release
_ but support multiple java/pde files through the 'add file' option
API WORK
_ open mode
_ on application open, override 'open' mode
_ and just open an empty sketch in the sketchbook folder
_ when 'skNew' is cancelled in 'open' mode, nullpointerex at the top
_ "add library" menu item and submenu
_ iterate through the 'library' folders
_ fix code for changing the sketch folder
api changes
_ libraries: static and non-static init for libs
_ final stop() for static shutdown of lib
_ but also potential stop() for individual items
@@ -73,6 +60,28 @@ _ if people have other threads they've spawned, impossible to stop
_ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Syntax;action=display;num=1067383998
_ BImage.smooth() ?
_ rewrite bagel code..
_ for this release, because it will break things along with the lib stuff
_ switch to PImage, PApplet, etc
_ update() mode should be finished before beta
_ change copyrights on the files again
0069+
_ option for having multiple files open
_ need ui for tabs from casey
_ tabbed interface for multiple files
_ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;action=display;num=1052077800;start=0
_ "new text java/pde file" menu item
_ get new simong code in there
_ put screenshots into their sketch folder
_ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Syntax;action=display;num=1046185738;start=0
_ add a method BApplet.setPath() or something like that
bugsies
_ find/replace hangs when recapitalizing things
@@ -989,9 +998,6 @@ _ 7 day search on discourse board
api work
_ merge BImage/BGraphics into BLayer/Pixels ?
_ update() mode should be finished before beta
_ for int i for 0 to b.length
_ for i from 0 upto b.length