Moved countLines() and loadFile() from Base to BaseNoGui.

This commit is contained in:
Claudio Indellicati 2014-08-22 18:35:15 +02:00 committed by Cristian Maglie
parent b0d8a504dd
commit 0919b0e4fe
3 changed files with 29 additions and 14 deletions

View File

@ -2478,11 +2478,7 @@ public class Base {
* characters inside a String (and adding 1).
*/
static public int countLines(String what) {
int count = 1;
for (char c : what.toCharArray()) {
if (c == '\n') count++;
}
return count;
return BaseNoGui.countLines(what);
}
@ -2560,10 +2556,8 @@ public class Base {
* Grab the contents of a file as a string.
*/
static public String loadFile(File file) throws IOException {
String[] contents = PApplet.loadStrings(file);
if (contents == null) return null;
return PApplet.join(contents, "\n");
}
return BaseNoGui.loadFile(file);
}
/**

View File

@ -75,6 +75,18 @@ public class BaseNoGui {
return file;
}
/**
* Get the number of lines in a file by counting the number of newline
* characters inside a String (and adding 1).
*/
static public int countLines(String what) {
int count = 1;
for (char c : what.toCharArray()) {
if (c == '\n') count++;
}
return count;
}
static public String getAvrBasePath() {
String path = getHardwarePath() + File.separator + "tools" +
File.separator + "avr" + File.separator + "bin" + File.separator;
@ -349,6 +361,15 @@ public class BaseNoGui {
}
}
/**
* Grab the contents of a file as a string.
*/
static public String loadFile(File file) throws IOException {
String[] contents = PApplet.loadStrings(file);
if (contents == null) return null;
return PApplet.join(contents, "\n");
}
static public void populateImportToLibraryTable() {
// Populate importToLibraryTable
importToLibraryTable = new HashMap<String, Library>();

View File

@ -114,7 +114,7 @@ public class SketchCode {
protected void copyTo(File dest) throws IOException {
Base.saveFile(program, dest);
BaseNoGui.saveFile(program, dest);
}
@ -148,7 +148,7 @@ public class SketchCode {
public int getLineCount() {
return Base.countLines(program);
return BaseNoGui.countLines(program);
}
@ -184,7 +184,7 @@ public class SketchCode {
* Load this piece of code from a file.
*/
public void load() throws IOException {
program = Base.loadFile(file);
program = BaseNoGui.loadFile(file);
if (program.indexOf('\uFFFD') != -1) {
System.err.println(
@ -212,7 +212,7 @@ public class SketchCode {
// TODO re-enable history
//history.record(s, SketchHistory.SAVE);
Base.saveFile(program, file);
BaseNoGui.saveFile(program, file);
setModified(false);
}
@ -221,6 +221,6 @@ public class SketchCode {
* Save this file to another location, used by Sketch.saveAs()
*/
public void saveAs(File newFile) throws IOException {
Base.saveFile(program, newFile);
BaseNoGui.saveFile(program, newFile);
}
}