mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
Moved countLines() and loadFile() from Base to BaseNoGui.
This commit is contained in:
committed by
Cristian Maglie
parent
b0d8a504dd
commit
0919b0e4fe
@ -2478,11 +2478,7 @@ public class Base {
|
|||||||
* characters inside a String (and adding 1).
|
* characters inside a String (and adding 1).
|
||||||
*/
|
*/
|
||||||
static public int countLines(String what) {
|
static public int countLines(String what) {
|
||||||
int count = 1;
|
return BaseNoGui.countLines(what);
|
||||||
for (char c : what.toCharArray()) {
|
|
||||||
if (c == '\n') count++;
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2560,10 +2556,8 @@ public class Base {
|
|||||||
* Grab the contents of a file as a string.
|
* Grab the contents of a file as a string.
|
||||||
*/
|
*/
|
||||||
static public String loadFile(File file) throws IOException {
|
static public String loadFile(File file) throws IOException {
|
||||||
String[] contents = PApplet.loadStrings(file);
|
return BaseNoGui.loadFile(file);
|
||||||
if (contents == null) return null;
|
}
|
||||||
return PApplet.join(contents, "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,6 +75,18 @@ public class BaseNoGui {
|
|||||||
return file;
|
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() {
|
static public String getAvrBasePath() {
|
||||||
String path = getHardwarePath() + File.separator + "tools" +
|
String path = getHardwarePath() + File.separator + "tools" +
|
||||||
File.separator + "avr" + File.separator + "bin" + File.separator;
|
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() {
|
static public void populateImportToLibraryTable() {
|
||||||
// Populate importToLibraryTable
|
// Populate importToLibraryTable
|
||||||
importToLibraryTable = new HashMap<String, Library>();
|
importToLibraryTable = new HashMap<String, Library>();
|
||||||
|
@ -114,7 +114,7 @@ public class SketchCode {
|
|||||||
|
|
||||||
|
|
||||||
protected void copyTo(File dest) throws IOException {
|
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() {
|
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.
|
* Load this piece of code from a file.
|
||||||
*/
|
*/
|
||||||
public void load() throws IOException {
|
public void load() throws IOException {
|
||||||
program = Base.loadFile(file);
|
program = BaseNoGui.loadFile(file);
|
||||||
|
|
||||||
if (program.indexOf('\uFFFD') != -1) {
|
if (program.indexOf('\uFFFD') != -1) {
|
||||||
System.err.println(
|
System.err.println(
|
||||||
@ -212,7 +212,7 @@ public class SketchCode {
|
|||||||
// TODO re-enable history
|
// TODO re-enable history
|
||||||
//history.record(s, SketchHistory.SAVE);
|
//history.record(s, SketchHistory.SAVE);
|
||||||
|
|
||||||
Base.saveFile(program, file);
|
BaseNoGui.saveFile(program, file);
|
||||||
setModified(false);
|
setModified(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,6 +221,6 @@ public class SketchCode {
|
|||||||
* Save this file to another location, used by Sketch.saveAs()
|
* Save this file to another location, used by Sketch.saveAs()
|
||||||
*/
|
*/
|
||||||
public void saveAs(File newFile) throws IOException {
|
public void saveAs(File newFile) throws IOException {
|
||||||
Base.saveFile(program, newFile);
|
BaseNoGui.saveFile(program, newFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user