From 3b70fc67fdb781804cec1da3f35d1753ebd16606 Mon Sep 17 00:00:00 2001 From: benfry Date: Thu, 11 Oct 2007 21:16:03 +0000 Subject: [PATCH] mark untitled sketches as modified on addFile(), replace untitled window contents (not window) on open, prevent identical sketches from being re-opened. --This line, and those below, will be ignored-- M app/src/processing/app/Base.java M app/src/processing/app/Sketch.java M app/src/processing/app/Editor.java M todo.txt M core/todo.txt --- app/src/processing/app/Base.java | 30 +++-- app/src/processing/app/Editor.java | 176 ++--------------------------- app/src/processing/app/Sketch.java | 15 ++- core/todo.txt | 104 +++++++++-------- todo.txt | 16 +++ 5 files changed, 116 insertions(+), 225 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index c641fcea0..1b89cf2cb 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -591,14 +591,24 @@ public class Base { File file = new File(path); if (!file.exists()) return null; - Editor markedForClose = null; + // Cycle through open windows to make sure that it's not already open. + for (int i = 0; i < editorCount; i++) { + if (editors[i].sketch.path.equals(path)) { + editors[i].toFront(); + return editors[i]; + } + } + + // If the active editor window is an untitled, and un-modified document, + // just replace it with the file that's being opened. if (activeEditor != null) { - Sketch sketch = activeEditor.sketch; - if (sketch.isUntitled() && !sketch.isModified()) { + Sketch activeSketch = activeEditor.sketch; + if (activeSketch.isUntitled() && !activeSketch.isModified()) { // if it's an untitled, unmodified document, it can be replaced. // except in cases where a second blank window is being opened. if (!path.startsWith(untitledFolder.getAbsolutePath())) { - markedForClose = activeEditor; + activeEditor.handleOpenUnchecked(path, 0, 0, 0, 0); + return activeEditor; } } } @@ -613,12 +623,12 @@ public class Base { } editors[editorCount++] = editor; - if (markedForClose != null) { - Point p = markedForClose.getLocation(); - handleClose(markedForClose, false); - // open the new window in - editor.setLocation(p); - } +// if (markedForClose != null) { +// Point p = markedForClose.getLocation(); +// handleClose(markedForClose, false); +// // open the new window in +// editor.setLocation(p); +// } // now that we're ready, show the window // (don't do earlier, cuz we might move it based on a window being closed) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index c92f66db0..da241598f 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -282,53 +282,10 @@ public class Editor extends JFrame { } } } - // } catch (Exception e) { - // e.printStackTrace(); - // } - - //DataFlavor[] flavors = transferable.getTransferDataFlavors(); - //for (int i = 0; i < flavors.length; i++) { - //System.out.println(flavors[i]); - //} - - //int successful = handleImport(list); - - /* - for (int i = 0; i < flavors.length; i++) { - try { - //System.out.println(flavors[i]); - //System.out.println(transferable.getTransferData(flavors[i])); - Object stuff = transferable.getTransferData(flavors[i]); - if (!(stuff instanceof java.util.List)) continue; - java.util.List list = (java.util.List) stuff; - - for (int j = 0; j < list.size(); j++) { - Object item = list.get(j); - if (item instanceof File) { - File file = (File) item; - - // see if this is a .pde file to be opened - String filename = file.getName(); - if (filename.endsWith(".pde")) { - String name = filename.substring(0, filename.length() - 4); - File parent = file.getParentFile(); - if (name.equals(parent.getName())) { - base.handleOpen(file.getAbsolutePath()); - // Only opens the first sketch dragged into the window - return true; - } - } - - if (sketch.addFile(file)) { - successful++; - } - } - } - */ - } catch (Exception e) { - e.printStackTrace(); - return false; - } + } catch (Exception e) { + e.printStackTrace(); + return false; + } if (successful == 0) { error("No files were added to the sketch."); @@ -341,66 +298,6 @@ public class Editor extends JFrame { } return true; } - - /* - private void handleImport(java.util.List list) { - for (int j = 0; j < list.size(); j++) { - Object item = list.get(j); - File file = null; - if (item instanceof File) { - file = (File) item; - } else if (item instanceof String) { - file = new File((String) item); - } - - // see if this is a .pde file to be opened - String filename = file.getName(); - if (filename.endsWith(".pde")) { - String name = filename.substring(0, filename.length() - 4); - File parent = file.getParentFile(); - if (name.equals(parent.getName())) { - base.handleOpen(file.getAbsolutePath()); - // Only opens the first sketch dragged into the window - return true; - } - } - - if (sketch.addFile(file)) { - successful++; - } - } - } - - - private java.util.List textURIListToFileList(String data) { - String[] pieces = PApplet.splitTokens(data, "\r\n"); - return Arrays.asList(pieces); - //java.util.List list = new ArrayList(pieces); - //return list; - */ - - /* - java.util.List list = new java.util.ArrayList(1); - for (java.util.StringTokenizer st = new java.util.StringTokenizer(data, "\r\n"); - st.hasMoreTokens();) { - String s = st.nextToken(); - if (s.startsWith("#")) { - // the line is a comment (as per the RFC 2483) - continue; - } - try { - java.net.URI uri = new java.net.URI(s); - java.io.File file = new java.io.File(uri); - list.add(file); - } catch (java.net.URISyntaxException e) { - // malformed URI - } catch (IllegalArgumentException e) { - // the URI is not a valid 'file:' URI - } - } - return list; - */ - //} }); // System.out.println("t1"); @@ -421,7 +318,7 @@ public class Editor extends JFrame { // System.out.println("t4"); // Open the document that was passed in - handleOpen2(path); + handleOpenInternal(path); // System.out.println("t5"); @@ -483,7 +380,6 @@ public class Editor extends JFrame { textarea.setEditable(!external); saveMenuItem.setEnabled(!external); saveAsMenuItem.setEnabled(!external); - //beautifyMenuItem.setEnabled(!external); TextAreaPainter painter = textarea.getPainter(); if (external) { @@ -1444,35 +1340,6 @@ public class Editor extends JFrame { } - /** - * Open a sketch given the full path to the .pde file. - * Pass in 'null' to prompt the user for the name of the sketch. - */ - /* - public void handleOpen(final String ipath) { - // haven't run across a case where i can verify that this works - // because open is usually very fast. - buttons.activate(EditorButtons.OPEN); - - SwingUtilities.invokeLater(new Runnable() { - public void run() { - String path = ipath; - if (path == null) { // "open..." selected from the menu - path = sketchbook.handleOpenPrompt(); - } - if (path != null) { - base.handleOpen(path); - } - //doClose(); - //handleOpenPath = path; - //checkModified(HANDLE_OPEN); - }}); - // Off in thread land, so don't clear yet - //buttons.clear(); - } - */ - - /** * Open a sketch from a particular path, but don't check to save changes. * Used by Sketch.saveAs() to re-open a sketch after the "Save As" @@ -1480,11 +1347,13 @@ public class Editor extends JFrame { protected void handleOpenUnchecked(String path, int codeIndex, int selStart, int selStop, int scrollPos) { doClose(); - handleOpen2(path); + handleOpenInternal(path); + // Replacing a document that may be untitled. If this is an actual + // untitled document, then editor.untitled will be set by Base. + untitled = false; sketch.setCurrent(codeIndex); textarea.select(selStart, selStop); - //textarea.updateScrollBars(); textarea.setScrollPosition(scrollPos); } @@ -1494,28 +1363,7 @@ public class Editor extends JFrame { * see if the modifications (if any) to the previous sketch * need to be saved. */ - protected void handleOpen2(String path) { - // disabling this behavior for 0126 - /* - if (sketch != null) { - // if leaving an empty sketch (i.e. the default) do an - // auto-clean right away - try { - // don't clean if we're re-opening the same file - String oldPath = sketch.code[0].file.getCanonicalPath(); - String newPath = new File(path).getCanonicalPath(); - if (!oldPath.equals(newPath)) { - if (Base.calcFolderSize(sketch.folder) == 0) { - Base.removeDir(sketch.folder); - //sketchbook.rebuildMenus(); - //sketchbook.rebuildMenusAsync(); - base.rebuildMenusAsync(); - } - } - } catch (Exception e) { } // oh well - } - */ - + protected void handleOpenInternal(String path) { try { // check to make sure that this .pde file is // in a folder of the same name @@ -1525,10 +1373,6 @@ public class Editor extends JFrame { String pdeName = parentName + ".pde"; File altFile = new File(file.getParent(), pdeName); - //System.out.println("path = " + file.getParent()); - //System.out.println("name = " + file.getName()); - //System.out.println("pname = " + parentName); - if (pdeName.equals(file.getName())) { // no beef with this guy diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 27438db33..10396d57b 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -60,6 +60,8 @@ public class Sketch { */ boolean modified; + public String path; + public File folder; public File dataFolder; public File codeFolder; @@ -90,6 +92,7 @@ public class Sketch { */ public Sketch(Editor editor, String path) throws IOException { this.editor = editor; + this.path = path; File mainFile = new File(path); //System.out.println("main file is " + mainFile); @@ -985,7 +988,7 @@ public class Sketch { // now do the work of adding the file boolean result = addFile(sourceFile); - + if (result) { editor.message("One file added to the sketch."); } @@ -1098,6 +1101,16 @@ public class Sketch { } setCurrent(newName); editor.header.repaint(); + if (editor.untitled) { + // Mark the new code as modified so that the sketch is saved + current.modified = true; + } + } else { + if (editor.untitled) { + // If a file has been added, mark the main code as modified so + // that the sketch is properly saved. + code[0].modified = true; + } } return true; } diff --git a/core/todo.txt b/core/todo.txt index a4e21edf2..772c432cc 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -7,50 +7,25 @@ X also textMode(SCREEN) X http://dev.processing.org/bugs/show_bug.cgi?id=91 o replaceAll() not supported by 1.1 o http://dev.processing.org/bugs/show_bug.cgi?id=561 +o make version of loadBytes that checks length of the stream first +o this might not be worth it +o the number of cases where this works is small (half of url streams) +o and who knows if the value returned will be correct +o (i.e. will it be the uncompressed or compressed size of the data?) + +createGraphics() issues X offscreen buffers fail with texture mapping X pixels not being set opaque (only with textures?) X http://dev.processing.org/bugs/show_bug.cgi?id=594 +_ add note to createGraphics() docs that opacity at edges is binary +X PGraphics problem with fillColor +X http://dev.processing.org/bugs/show_bug.cgi?id=468 - -_ PGraphics problem with fillColor -_ http://dev.processing.org/bugs/show_bug.cgi?id=468 - -_ text characters showing up as opaque rectangles in tga files - -_ fix svg caps/joins for opengl -_ http://dev.processing.org/bugs/show_bug.cgi?id=628 - -_ should loadFont() work with ttf files (instead of createFont?) - -_ opengl mipmaps are leaking (regression in spite of #150 fix) -_ http://dev.processing.org/bugs/show_bug.cgi?id=610 - -_ 100x100 issues are exhibited on bh140c PCs, test and fix! -_ http://dev.processing.org/bugs/show_bug.cgi?id=197 -_ width/height on problem machine prints out as: -_ 100,200 and 128,200 - -_ loadBytes() and saveStream() functions badly need optimization! -_ don't bother using a buffering stream, just handle internally. gah! -_ make version of loadBytes that checks length of the stream first -_ this might not be worth it -_ the number of cases where this works is small (half of url streams) -_ and who knows if the value returned will be correct -_ (i.e. will it be the uncompressed or compressed size of the data?) - -_ update the reference to cover parseXxxx() stuff -_ also add notes about parseInt/Float(blah, otherwise) - -_ having shut off the defaults reset, background not getting called for java2d -_ so this will make that other stuff regress again -_ background not being set properly -_ http://dev.processing.org/bugs/show_bug.cgi?id=454 -_ why aren't background() / defaults() being called for opengl? -_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Contribution_3DOpenGL;action=display;num=1118784331 - -new bugs (organize later) -_ draw() called twice in vista with java 1.6 -_ http://dev.processing.org/bugs/show_bug.cgi?id=587 +_ Java2D textLinePlacedImpl should check for ENABLE_NATIVE_FONTS hint +_ http://dev.processing.org/bugs/show_bug.cgi?id=633 +_ also try to check native font on textFont() commands +_ in case the hint() has been enabled in the meantime +_ or rather, always load native font, even w/o the hint() being set _ an image marked RGB but with 0s for the alpha won't draw in JAVA2D _ images with 0x00 in their high bits being drawn transparent @@ -74,6 +49,47 @@ _ is fill() not coloring textures properly? _ don't need to apply tint() to textures, supposed to use fill color Hope this helps: If you haven't tracked it down yet... it's in PTriangle, when a flat-shaded textured triangle is drawn, then the rgb of the tint isn't used. So, for example, if the triangle renderer branches to drawsegment_texture32() the tint rgb won't be used, whereas if it branches to drawsegment_gouraud_texture32() then the tint rgb WILL be used. Alpha gets used from tint, because all alpha has to do is be != 255, but for rgb to get used they values have to differ among vertices (which won't happen via the image() routine for example). The quick fix might be to insert an additional test in setIntensities() to check if parent.tint is true, and if so then force gouraud shading, INTERPOLATE_RGB=true. +fixed in 0125 by ewjordan +X accuracy in P3D is very low +X http://dev.processing.org/bugs/show_bug.cgi?id=95 +X textured polys throwing a lot of exceptions (ouch) +X http://dev.processing.org/bugs/show_bug.cgi?id=546 +X polygons in z axis with nonzero x or y not filling properly +X http://dev.processing.org/bugs/show_bug.cgi?id=547 + +_ text characters showing up as opaque rectangles in tga files + +_ fix svg caps/joins for opengl +_ http://dev.processing.org/bugs/show_bug.cgi?id=628 + +_ should loadFont() work with ttf files (instead of createFont?) + +_ opengl mipmaps are leaking (regression in spite of #150 fix) +_ http://dev.processing.org/bugs/show_bug.cgi?id=610 + +_ 100x100 issues are exhibited on bh140c PCs, test and fix! +_ http://dev.processing.org/bugs/show_bug.cgi?id=197 +_ width/height on problem machine prints out as: +_ 100,200 and 128,200 + +_ loadBytes() and saveStream() functions badly need optimization! +_ don't bother using a buffering stream, just handle internally. gah! + +_ update the reference to cover parseXxxx() stuff +_ also add notes about parseInt/Float(blah, otherwise) + +_ having shut off the defaults reset, background not getting called for java2d +_ so this will make that other stuff regress again +_ in particular, when the applet is resized, but renderer not changed +_ background not being set properly +_ http://dev.processing.org/bugs/show_bug.cgi?id=454 +_ why aren't background() / defaults() being called for opengl? +_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Contribution_3DOpenGL;action=display;num=1118784331 + +new bugs (organize later) +_ draw() called twice in vista with java 1.6 +_ http://dev.processing.org/bugs/show_bug.cgi?id=587 + _ add gluegen-rt back to the applet export _ http://download.java.net/media/jogl/builds/nightly/javadoc_public/com/sun/opengl/util/JOGLAppletLauncher.html @@ -88,14 +104,6 @@ _ ortho() behaving differently in P3D vs OPENGL _ http://dev.processing.org/bugs/show_bug.cgi?id=100 _ only happens on the first round -graphics stuff being sorted out by ewjordan -_ accuracy in P3D is very low -_ http://dev.processing.org/bugs/show_bug.cgi?id=95 -_ textured polys throwing a lot of exceptions (ouch) -_ http://dev.processing.org/bugs/show_bug.cgi?id=546 -_ polygons in z axis with nonzero x or y not filling properly -_ http://dev.processing.org/bugs/show_bug.cgi?id=547 - _ look into capabilities stuff from mike creighton _ also sets the aa mode on the pc so it no longer needs control panel bunk diff --git a/todo.txt b/todo.txt index f54307a84..a4348fa85 100644 --- a/todo.txt +++ b/todo.txt @@ -1,7 +1,18 @@ 0127 pde +X mark untitled sketches as modified when adding files +X opening an already open sketch will result in two identical sketches open +X just bring the other window to the front +X http://dev.processing.org/bugs/show_bug.cgi?id=636 +X replace untitled windows with opened sketches +X but do so without opening a new window and hiding the other +_ closing last sketch window... open an untitled document? +_ http://dev.processing.org/bugs/show_bug.cgi?id=634 +_ remove the "ask for sketch name on create" +_ also remove shift-click behavior _ mark examples as untitled (rather than read-only) +_ put the "had to rename sketch" message in the msg bar documentation @@ -18,6 +29,9 @@ _ move reference folder around so that it matches site organization _ otherwise several links break on the main faq page _ match() method +_ auto-delete of sketches might be dangerous +_ and probably no longer necessary + JSyn Installer build 011 java.vm.version = 1.5.0_07-87 @@ -577,6 +591,8 @@ PDE / Compiler & Preprocessor _ Update ANTLR grammar to support 1.5 syntax _ http://dev.processing.org/bugs/show_bug.cgi?id=598 +_ preproc cant handle labels to break/continue nested loops +_ http://dev.processing.org/bugs/show_bug.cgi?id=631 _ imports inside comments are being included _ toInt() needs to go away in time for the book.. fix parser bugs _ using a processing keyword as a variable name gives unhelpful error message