From c7ebe20dae37875f510a60387e5dd9623aa6d2d7 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 5 Feb 2022 12:36:17 -0500 Subject: [PATCH] more clarifications and warnings cleanup --- app/src/processing/app/Sketch.java | 32 +++++++-------------------- app/src/processing/app/ui/Editor.java | 9 ++++++-- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 42320de3f..f454c5898 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -344,7 +344,7 @@ public class Sketch { } // ask for new name of file (internal to window) - // TODO maybe just popup a text area? + // TODO maybe just pop up a text area? renamingCode = true; String prompt = (currentIndex == 0) ? Language.text("editor.sketch.rename.description") : @@ -461,8 +461,8 @@ public class Sketch { // Also ignoring case here, because I don't want to write/maintain/debug // a bunch of platform-specific quirks: macOS is case-insensitive but // preserving, Windows is insensitive, *nix is sensitive and preserving, - // and someday we're all gonna die, and I'm comfortable with this piece - // of code working not being essential to the story of my life on Earth. + // and someday we're all gonna die, and I'm comfortable that writing the + // necessary code is not essential to the story of my life on Earth. if (renamingCode) { if (newName.equalsIgnoreCase(current.getFileName())) { // exit quietly for the 'rename' case. @@ -837,10 +837,7 @@ public class Sketch { public boolean saveAs() throws IOException { String newParentDir = null; String newName = null; -// String oldName = folder.getName(); - // TODO rewrite this to use shared version from PApplet (But because that - // specifies a callback function, this needs to wait until the refactoring) final String PROMPT = Language.text("save"); // https://github.com/processing/processing4/issues/77 @@ -985,13 +982,8 @@ public class Sketch { code[i].saveAs(newFile); } - // While the old path to the main .pde is still set, remove the entry from - // the Recent menu so that it's not sticking around after the rename. - // If untitled, it won't be in the menu, so there's no point. -// if (!isUntitled()) { -// Recent.remove(editor); -// } - // Folks didn't like this behavior, so shutting it off + // We were removing the old folder from the Recent menu, but folks + // did not like that behavior, so we shut it off in 3.5.4 and 4.x. // https://github.com/processing/processing/issues/5902 // save the main tab with its new name @@ -1201,8 +1193,6 @@ public class Sketch { // reset all the state information for the sketch object String oldPath = getMainFilePath(); primaryFile = code[0].getFile(); -// String newPath = getMainFilePath(); -// editor.base.renameRecent(oldPath, newPath); name = sketchName; folder = sketchFolder; @@ -1210,21 +1200,15 @@ public class Sketch { codeFolder = new File(folder, "code"); dataFolder = new File(folder, "data"); - // set the main file to be the current tab - //setCurrentCode(0); - // nah, this might just annoy people - // Name changed, rebuild the sketch menus calcModified(); -// System.out.println("modified is now " + modified); editor.updateTitle(); editor.getBase().rebuildSketchbook(); if (renaming) { - // only update the Recent menu if it's a rename, not a Save As + // Update the Recent menu if a Rename event (but not Save As) // https://github.com/processing/processing/issues/5902 Recent.rename(editor, oldPath); } -// editor.header.rebuild(); } @@ -1697,8 +1681,8 @@ public class Sketch { /** - * Return true if the name is valid for a Processing sketch. Extensions of the form .foo are - * ignored. + * Return true if the name is valid for a Processing sketch. + * Extensions of the form .foo are ignored. */ public static boolean isSanitaryName(String name) { final int dot = name.lastIndexOf('.'); diff --git a/app/src/processing/app/ui/Editor.java b/app/src/processing/app/ui/Editor.java index 36e3f4e29..a3e38a11d 100644 --- a/app/src/processing/app/ui/Editor.java +++ b/app/src/processing/app/ui/Editor.java @@ -1336,6 +1336,7 @@ public abstract class Editor extends JFrame implements RunnerListener { } + @SuppressWarnings("unused") public void insertText(String what) { startCompoundEdit(); int caret = getCaretOffset(); @@ -1350,6 +1351,7 @@ public abstract class Editor extends JFrame implements RunnerListener { } + @SuppressWarnings("unused") public void setSelectedText(String what) { textarea.setSelectedText(what); } @@ -1415,6 +1417,7 @@ public abstract class Editor extends JFrame implements RunnerListener { /** * Replace the text on a specified line. */ + @SuppressWarnings("unused") public void setLineText(int line, String what) { startCompoundEdit(); textarea.select(getLineStartOffset(line), getLineStopOffset(line)); @@ -2076,7 +2079,7 @@ public abstract class Editor extends JFrame implements RunnerListener { * Check if the sketch is modified and ask user to save changes. * @return false if canceling the close/quit operation */ - @SuppressWarnings("BooleanMethodIsAlwaysInverted") + @SuppressWarnings({"BooleanMethodIsAlwaysInverted", "RedundantIfStatement"}) public boolean checkModified() { if (!sketch.isModified()) return true; @@ -2283,7 +2286,9 @@ public abstract class Editor extends JFrame implements RunnerListener { * Bug 276. */ public boolean handleSave(boolean immediately) { -// handleStop(); // 0136 + // This was a mistake (rectified in 0136) that would cause long-running + // sketches to be interrupted, causing much sadness. + //handleStop(); if (sketch.isUntitled()) { return handleSaveAs();