Skip to content

Commit fe6047e

Browse files
committed
write text files with \r\n on Windows (fixes #3455)
1 parent 580316b commit fe6047e

File tree

3 files changed

+21
-29
lines changed

3 files changed

+21
-29
lines changed

app/src/processing/app/Sketch.java

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public class Sketch {
7070

7171
private SketchCode current;
7272
private int currentIndex;
73+
7374
/**
7475
* Number of sketchCode objects (tabs) in the current sketch. Note that this
7576
* will be the same as code.length, because the getCode() method returns
@@ -83,28 +84,6 @@ public class Sketch {
8384
/** Moved out of Editor and into here for cleaner access. */
8485
private boolean untitled;
8586

86-
// /** Class path determined during build. */
87-
// private String classPath;
88-
//
89-
// /**
90-
// * This is *not* the "Processing" libraries path, this is the Java libraries
91-
// * path, as in java.library.path=BlahBlah, which identifies search paths for
92-
// * DLLs or JNILIBs. (It's Java's LD_LIBRARY_PATH, for you UNIX fans.)
93-
// */
94-
// private String javaLibraryPath;
95-
//
96-
// /**
97-
// * List of library folders, set up in the preprocess() method.
98-
// */
99-
// private ArrayList<Library> importedLibraries;
100-
// //private ArrayList<File> importedLibraries;
101-
102-
/**
103-
* Most recent, default build path. This will contain the .java files that
104-
* have been preprocessed, as well as any .class files that were compiled.
105-
*/
106-
// private File buildFolder;
107-
10887

10988
/**
11089
* Used by the command-line version to create a sketch object.
@@ -336,10 +315,10 @@ public void handleRenameCode() {
336315
// TODO maybe just popup a text area?
337316
renamingCode = true;
338317
String prompt = (currentIndex == 0) ?
339-
Language.text("editor.sketch.rename.description") : Language.text("editor.tab.rename.description");
318+
Language.text("editor.sketch.rename.description") :
319+
Language.text("editor.tab.rename.description");
340320
String oldName = (current.isExtension(mode.getDefaultExtension())) ?
341321
current.getPrettyName() : current.getFileName();
342-
// editor.status.edit(prompt, oldName);
343322
promptForTabName(prompt + ":", oldName);
344323
}
345324

@@ -788,8 +767,10 @@ public boolean save() throws IOException {
788767
if (!saveAs()) return false;
789768
}
790769

791-
for (int i = 0; i < codeCount; i++) {
792-
if (code[i].isModified()) code[i].save();
770+
for (SketchCode sc : code) {
771+
if (sc.isModified()) {
772+
sc.save();
773+
}
793774
}
794775
calcModified();
795776
return true;

app/src/processing/app/Util.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ static public void copyFile(File sourceFile,
148148

149149

150150
/**
151-
* Grab the contents of a file as a string.
151+
* Grab the contents of a file as a string. Connects lines with \n,
152+
* even if the input file used \r\n.
152153
*/
153154
static public String loadFile(File file) throws IOException {
154155
String[] contents = PApplet.loadStrings(file);
@@ -158,9 +159,15 @@ static public String loadFile(File file) throws IOException {
158159

159160

160161
/**
161-
* Spew the contents of a String object out to a file.
162+
* Spew the contents of a String object out to a file. As of 3.0 beta 2,
163+
* this will replace and write \r\n for newlines on Windows.
164+
* https://github.com/processing/processing/issues/3455
162165
*/
163166
static public void saveFile(String str, File file) throws IOException {
167+
if (Base.isWindows()) {
168+
String[] lines = str.split("\\r?\\n");
169+
str = PApplet.join(lines, "\r\n");
170+
}
164171
File temp = File.createTempFile(file.getName(), null, file.getParentFile());
165172
try {
166173
// fix from cjwant to prevent symlinks from being destroyed.
@@ -185,7 +192,7 @@ static public void saveFile(String str, File file) throws IOException {
185192
boolean result = file.delete();
186193
if (!result) {
187194
throw new IOException("Could not remove old version of " +
188-
file.getAbsolutePath());
195+
file.getAbsolutePath());
189196
}
190197
}
191198
boolean result = temp.renameTo(file);

core/todo.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ X throw an error when using methods that require sketchPath outside setup()
66
X https://github.com/processing/processing/issues/3433
77
X cursor(CROSS) breaks when using surface.setTitle()
88
X https://github.com/processing/processing/issues/3472
9+
X Fix null pointer exception in setVertex
10+
X https://github.com/processing/processing/pull/3553
11+
X https://github.com/processing/processing/issues/3550
912

1013
fixed earlier
1114
X blend() and copy() are not pixel accurate for copy/scale
@@ -16,6 +19,7 @@ andres/jakub
1619
X toggling between noLights and PointLight in draw() behaving strangely
1720
X https://github.com/processing/processing/issues/3546
1821

22+
_ implement strip(), lstrip(), rstrip?
1923

2024
docs
2125
_ note that full screen and present are now different

0 commit comments

Comments
 (0)