1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-03-14 11:29:26 +01:00

Rename SketchCode to SketchFile

That name more accurately reflects its purpose: It represents a single
file within a sketch. This just updates the class name and variable
names referring to these objects and some comments, so no behaviour
should change.
This commit is contained in:
Matthijs Kooijman 2015-12-17 16:06:02 +01:00 committed by Martino Facchin
parent dfa60dacc1
commit 8e0d007ce2
9 changed files with 126 additions and 126 deletions

View File

@ -1640,13 +1640,13 @@ public class Editor extends JFrame implements RunnerListener {
selectTab((currentTabIndex - 1 + tabs.size()) % tabs.size()); selectTab((currentTabIndex - 1 + tabs.size()) % tabs.size());
} }
public EditorTab findTab(final SketchCode doc) { public EditorTab findTab(final SketchFile file) {
return tabs.get(findTabIndex(doc)); return tabs.get(findTabIndex(file));
} }
public int findTabIndex(final SketchCode doc) { public int findTabIndex(final SketchFile file) {
for (int i = 0; i < tabs.size(); ++i) { for (int i = 0; i < tabs.size(); ++i) {
if (tabs.get(i).getSketchCode() == doc) if (tabs.get(i).getSketchFile() == file)
return i; return i;
} }
return -1; return -1;
@ -1660,9 +1660,9 @@ public class Editor extends JFrame implements RunnerListener {
tabs.clear(); tabs.clear();
currentTabIndex = -1; currentTabIndex = -1;
tabs.ensureCapacity(sketch.getCodeCount()); tabs.ensureCapacity(sketch.getCodeCount());
for (SketchCode code : sketch.getCodes()) { for (SketchFile file : sketch.getFiles()) {
try { try {
addTab(code, null); addTab(file, null);
} catch(IOException e) { } catch(IOException e) {
// TODO: Improve / move error handling // TODO: Improve / move error handling
System.err.println(e); System.err.println(e);
@ -1674,15 +1674,15 @@ public class Editor extends JFrame implements RunnerListener {
/** /**
* Add a new tab. * Add a new tab.
* *
* @param code * @param file
* The file to show in the tab. * The file to show in the tab.
* @param contents * @param contents
* The contents to show in the tab, or null to load the * The contents to show in the tab, or null to load the contents from
* contents from the given file. * the given file.
* @throws IOException * @throws IOException
*/ */
protected void addTab(SketchCode code, String contents) throws IOException { protected void addTab(SketchFile file, String contents) throws IOException {
EditorTab tab = new EditorTab(this, code, contents); EditorTab tab = new EditorTab(this, file, contents);
tabs.add(tab); tabs.add(tab);
} }
@ -1999,7 +1999,7 @@ public class Editor extends JFrame implements RunnerListener {
if (sketchController == null) { if (sketchController == null) {
return; return;
} }
SketchCode current = getCurrentTab().getSketchCode(); SketchFile current = getCurrentTab().getSketchFile();
if (current.isPrimary()) { if (current.isPrimary()) {
setTitle(I18n.format(tr("{0} | Arduino {1}"), sketch.getName(), setTitle(I18n.format(tr("{0} | Arduino {1}"), sketch.getName(),
BaseNoGui.VERSION_NAME_LONG)); BaseNoGui.VERSION_NAME_LONG));
@ -2635,7 +2635,7 @@ public class Editor extends JFrame implements RunnerListener {
printerJob.setPrintable(getCurrentTab().getTextArea()); printerJob.setPrintable(getCurrentTab().getTextArea());
} }
// set the name of the job to the code name // set the name of the job to the code name
printerJob.setJobName(getCurrentTab().getSketchCode().getPrettyName()); printerJob.setJobName(getCurrentTab().getSketchFile().getPrettyName());
if (printerJob.printDialog()) { if (printerJob.printDialog()) {
try { try {

View File

@ -244,11 +244,11 @@ public class EditorHeader extends JComponent {
int x = scale(6); // offset from left edge of the component int x = scale(6); // offset from left edge of the component
int i = 0; int i = 0;
for (EditorTab tab : tabs) { for (EditorTab tab : tabs) {
SketchCode code = tab.getSketchCode(); SketchFile file = tab.getSketchFile();
String codeName = code.getPrettyName(); String filename = file.getPrettyName();
// if modified, add the li'l glyph next to the name // if modified, add the li'l glyph next to the name
String text = " " + codeName + (code.isModified() ? " \u00A7" : " "); String text = " " + filename + (file.isModified() ? " \u00A7" : " ");
int textWidth = (int) int textWidth = (int)
font.getStringBounds(text, g.getFontRenderContext()).getWidth(); font.getStringBounds(text, g.getFontRenderContext()).getWidth();
@ -325,9 +325,9 @@ public class EditorHeader extends JComponent {
int i = 0; int i = 0;
for (EditorTab tab : editor.getTabs()) { for (EditorTab tab : editor.getTabs()) {
SketchCode code = tab.getSketchCode(); SketchFile file = tab.getSketchFile();
final int index = i++; final int index = i++;
item = new JMenuItem(code.getPrettyName()); item = new JMenuItem(file.getPrettyName());
item.addActionListener((ActionEvent e) -> { item.addActionListener((ActionEvent e) -> {
editor.selectTab(index); editor.selectTab(index);
}); });

View File

@ -65,11 +65,11 @@ import processing.app.tools.DiscourseFormat;
/** /**
* Single tab, editing a single file, in the main window. * Single tab, editing a single file, in the main window.
*/ */
public class EditorTab extends JPanel implements SketchCode.TextStorage { public class EditorTab extends JPanel implements SketchFile.TextStorage {
protected Editor editor; protected Editor editor;
protected SketchTextArea textarea; protected SketchTextArea textarea;
protected RTextScrollPane scrollPane; protected RTextScrollPane scrollPane;
protected SketchCode code; protected SketchFile file;
protected boolean modified; protected boolean modified;
/** Is external editing mode currently enabled? */ /** Is external editing mode currently enabled? */
protected boolean external; protected boolean external;
@ -79,32 +79,32 @@ public class EditorTab extends JPanel implements SketchCode.TextStorage {
* *
* @param editor * @param editor
* The Editor this tab runs in * The Editor this tab runs in
* @param code * @param file
* The file to display in this tab * The file to display in this tab
* @param contents * @param contents
* Initial contents to display in this tab. Can be used when * Initial contents to display in this tab. Can be used when editing
* editing a file that doesn't exist yet. If null is passed, * a file that doesn't exist yet. If null is passed, code.load() is
* code.load() is called and displayed instead. * called and displayed instead.
* @throws IOException * @throws IOException
*/ */
public EditorTab(Editor editor, SketchCode code, String contents) public EditorTab(Editor editor, SketchFile file, String contents)
throws IOException { throws IOException {
super(new BorderLayout()); super(new BorderLayout());
// Load initial contents contents from file if nothing was specified. // Load initial contents contents from file if nothing was specified.
if (contents == null) { if (contents == null) {
contents = code.load(); contents = file.load();
modified = false; modified = false;
} else { } else {
modified = true; modified = true;
} }
this.editor = editor; this.editor = editor;
this.code = code; this.file = file;
RSyntaxDocument document = createDocument(contents); RSyntaxDocument document = createDocument(contents);
this.textarea = createTextArea(document); this.textarea = createTextArea(document);
this.scrollPane = createScrollPane(this.textarea); this.scrollPane = createScrollPane(this.textarea);
code.setStorage(this); file.setStorage(this);
applyPreferences(); applyPreferences();
add(this.scrollPane, BorderLayout.CENTER); add(this.scrollPane, BorderLayout.CENTER);
@ -292,14 +292,14 @@ public class EditorTab extends JPanel implements SketchCode.TextStorage {
textarea.setEditable(false); textarea.setEditable(false);
// Detach from the code, since we are no longer the authoritative source // Detach from the code, since we are no longer the authoritative source
// for file contents. // for file contents.
code.setStorage(null); file.setStorage(null);
// Reload, in case the file contents already changed. // Reload, in case the file contents already changed.
reload(); reload();
} else { } else {
textarea.setBackground(Theme.getColor("editor.bgcolor")); textarea.setBackground(Theme.getColor("editor.bgcolor"));
textarea.setHighlightCurrentLine(Theme.getBoolean("editor.linehighlight")); textarea.setHighlightCurrentLine(Theme.getBoolean("editor.linehighlight"));
textarea.setEditable(true); textarea.setEditable(true);
code.setStorage(this); file.setStorage(this);
// Reload once just before disabling external mode, to ensure we have // Reload once just before disabling external mode, to ensure we have
// the latest contents. // the latest contents.
reload(); reload();
@ -337,10 +337,10 @@ public class EditorTab extends JPanel implements SketchCode.TextStorage {
private void reload() { private void reload() {
String text; String text;
try { try {
text = code.load(); text = file.load();
} catch (IOException e) { } catch (IOException e) {
System.err.println(I18n.format("Warning: Failed to reload file: \"{0}\"", System.err.println(I18n.format("Warning: Failed to reload file: \"{0}\"",
code.getFileName())); file.getFileName()));
return; return;
} }
setText(text); setText(text);
@ -366,10 +366,10 @@ public class EditorTab extends JPanel implements SketchCode.TextStorage {
} }
/** /**
* Get the SketchCodeDocument that is being edited in this tab. * Get the SketchFile that is being edited in this tab.
*/ */
public SketchCode getSketchCode() { public SketchFile getSketchFile() {
return this.code; return this.file;
} }
/** /**
@ -429,8 +429,8 @@ public class EditorTab extends JPanel implements SketchCode.TextStorage {
} }
/** /**
* Clear modified status. Should only be called by SketchCode through * Clear modified status. Should only be called by SketchFile through the
* the TextStorage interface. * TextStorage interface.
*/ */
public void clearModified() { public void clearModified() {
setModified(false); setModified(false);

View File

@ -91,7 +91,7 @@ public class SketchController {
* Handler for the Rename Code menu option. * Handler for the Rename Code menu option.
*/ */
public void handleRenameCode() { public void handleRenameCode() {
SketchCode current = editor.getCurrentTab().getSketchCode(); SketchFile current = editor.getCurrentTab().getSketchFile();
editor.status.clearState(); editor.status.clearState();
// make sure the user didn't hide the sketch folder // make sure the user didn't hide the sketch folder
@ -132,7 +132,7 @@ public class SketchController {
* where they diverge. * where they diverge.
*/ */
protected void nameCode(String newName) { protected void nameCode(String newName) {
SketchCode current = editor.getCurrentTab().getSketchCode(); SketchFile current = editor.getCurrentTab().getSketchFile();
int currentIndex = editor.getCurrentTabIndex(); int currentIndex = editor.getCurrentTabIndex();
// make sure the user didn't hide the sketch folder // make sure the user didn't hide the sketch folder
@ -196,12 +196,12 @@ public class SketchController {
// In Arduino, we want to allow files with the same name but different // In Arduino, we want to allow files with the same name but different
// extensions, so compare the full names (including extensions). This // extensions, so compare the full names (including extensions). This
// might cause problems: http://dev.processing.org/bugs/show_bug.cgi?id=543 // might cause problems: http://dev.processing.org/bugs/show_bug.cgi?id=543
for (SketchCode c : sketch.getCodes()) { for (SketchFile file : sketch.getFiles()) {
if (newName.equalsIgnoreCase(c.getFileName()) && OSUtils.isWindows()) { if (newName.equalsIgnoreCase(file.getFileName()) && OSUtils.isWindows()) {
Base.showMessage(tr("Error"), Base.showMessage(tr("Error"),
I18n.format( I18n.format(
tr("A file named \"{0}\" already exists in \"{1}\""), tr("A file named \"{0}\" already exists in \"{1}\""),
c.getFileName(), file.getFileName(),
sketch.getFolder().getAbsolutePath() sketch.getFolder().getAbsolutePath()
)); ));
return; return;
@ -218,9 +218,9 @@ public class SketchController {
} }
if (renamingCode && current.isPrimary()) { if (renamingCode && current.isPrimary()) {
for (SketchCode code : sketch.getCodes()) { for (SketchFile file : sketch.getFiles()) {
if (sanitaryName.equalsIgnoreCase(code.getBaseName()) && if (sanitaryName.equalsIgnoreCase(file.getBaseName()) &&
code.isExtension("cpp")) { file.isExtension("cpp")) {
Base.showMessage(tr("Error"), Base.showMessage(tr("Error"),
I18n.format(tr("You can't rename the sketch to \"{0}\"\n" I18n.format(tr("You can't rename the sketch to \"{0}\"\n"
+ "because the sketch already has a .cpp file with that name."), + "because the sketch already has a .cpp file with that name."),
@ -271,7 +271,7 @@ public class SketchController {
// first get the contents of the editor text area // first get the contents of the editor text area
if (current.isModified()) { if (current.isModified()) {
try { try {
// save this new SketchCode // save this new SketchFile
current.save(); current.save();
} catch (Exception e) { } catch (Exception e) {
Base.showWarning(tr("Error"), tr("Could not rename the sketch. (0)"), e); Base.showWarning(tr("Error"), tr("Could not rename the sketch. (0)"), e);
@ -291,8 +291,8 @@ public class SketchController {
// save each of the other tabs because this is gonna be re-opened // save each of the other tabs because this is gonna be re-opened
try { try {
for (SketchCode code : sketch.getCodes()) { for (SketchFile file : sketch.getFiles()) {
code.save(); file.save();
} }
} catch (Exception e) { } catch (Exception e) {
Base.showWarning(tr("Error"), tr("Could not rename the sketch. (1)"), e); Base.showWarning(tr("Error"), tr("Could not rename the sketch. (1)"), e);
@ -350,9 +350,9 @@ public class SketchController {
return; return;
} }
ensureExistence(); ensureExistence();
SketchCode code = new SketchCode(newFile, false); SketchFile file = new SketchFile(newFile, false);
try { try {
editor.addTab(code, ""); editor.addTab(file, "");
} catch (IOException e) { } catch (IOException e) {
Base.showWarning(tr("Error"), Base.showWarning(tr("Error"),
I18n.format( I18n.format(
@ -360,8 +360,8 @@ public class SketchController {
), e); ), e);
return; return;
} }
sketch.addCode(code); sketch.addFile(file);
editor.selectTab(editor.findTabIndex(code)); editor.selectTab(editor.findTabIndex(file));
} }
// update the tabs // update the tabs
@ -373,7 +373,7 @@ public class SketchController {
* Remove a piece of code from the sketch and from the disk. * Remove a piece of code from the sketch and from the disk.
*/ */
public void handleDeleteCode() throws IOException { public void handleDeleteCode() throws IOException {
SketchCode current = editor.getCurrentTab().getSketchCode(); SketchFile current = editor.getCurrentTab().getSketchFile();
editor.status.clearState(); editor.status.clearState();
// make sure the user didn't hide the sketch folder // make sure the user didn't hide the sketch folder
ensureExistence(); ensureExistence();
@ -427,7 +427,7 @@ public class SketchController {
} }
// remove code from the list // remove code from the list
sketch.removeCode(current); sketch.removeFile(current);
// just set current tab to the main tab // just set current tab to the main tab
editor.selectTab(0); editor.selectTab(0);
@ -512,13 +512,13 @@ public class SketchController {
private boolean renameCodeToInoExtension(File pdeFile) { private boolean renameCodeToInoExtension(File pdeFile) {
for (SketchCode c : sketch.getCodes()) { for (SketchFile file : sketch.getFiles()) {
if (!c.getFile().equals(pdeFile)) if (!file.getFile().equals(pdeFile))
continue; continue;
String pdeName = pdeFile.getPath(); String pdeName = pdeFile.getPath();
pdeName = pdeName.substring(0, pdeName.length() - 4) + ".ino"; pdeName = pdeName.substring(0, pdeName.length() - 4) + ".ino";
return c.renameTo(new File(pdeName)); return file.renameTo(new File(pdeName));
} }
return false; return false;
} }
@ -563,8 +563,8 @@ public class SketchController {
// make sure there doesn't exist a .cpp file with that name already // make sure there doesn't exist a .cpp file with that name already
// but ignore this situation for the first tab, since it's probably being // but ignore this situation for the first tab, since it's probably being
// resaved (with the same name) to another location/folder. // resaved (with the same name) to another location/folder.
for (SketchCode code : sketch.getCodes()) { for (SketchFile file : sketch.getFiles()) {
if (!code.isPrimary() && newName.equalsIgnoreCase(code.getBaseName())) { if (!file.isPrimary() && newName.equalsIgnoreCase(file.getBaseName())) {
Base.showMessage(tr("Error"), Base.showMessage(tr("Error"),
I18n.format(tr("You can't save the sketch as \"{0}\"\n" + I18n.format(tr("You can't save the sketch as \"{0}\"\n" +
"because the sketch already has a file with that name."), newName "because the sketch already has a file with that name."), newName
@ -608,10 +608,10 @@ public class SketchController {
newFolder.mkdirs(); newFolder.mkdirs();
// save the other tabs to their new location // save the other tabs to their new location
for (SketchCode code : sketch.getCodes()) { for (SketchFile file : sketch.getFiles()) {
if (code.isPrimary()) continue; if (file.isPrimary()) continue;
File newFile = new File(newFolder, code.getFileName()); File newFile = new File(newFolder, file.getFileName());
code.saveAs(newFile); file.saveAs(newFile);
} }
// re-copy the data folder (this may take a while.. add progress bar?) // re-copy the data folder (this may take a while.. add progress bar?)
@ -622,7 +622,7 @@ public class SketchController {
// save the main tab with its new name // save the main tab with its new name
File newFile = new File(newFolder, newName + ".ino"); File newFile = new File(newFolder, newName + ".ino");
sketch.getCode(0).saveAs(newFile); sketch.getFile(0).saveAs(newFile);
editor.handleOpenUnchecked(newFile, editor.handleOpenUnchecked(newFile,
editor.getCurrentTabIndex(), editor.getCurrentTabIndex(),
@ -765,16 +765,16 @@ public class SketchController {
} }
if (!isData) { if (!isData) {
SketchCode newCode = new SketchCode(destFile, false); SketchFile newFile = new SketchFile(destFile, false);
if (replacement) { if (replacement) {
sketch.replaceCode(newCode); sketch.replaceFile(newFile);
} else { } else {
ensureExistence(); ensureExistence();
sketch.addCode(newCode); sketch.addFile(newFile);
} }
editor.selectTab(editor.findTabIndex(newCode)); editor.selectTab(editor.findTabIndex(newFile));
} }
return true; return true;
} }
@ -800,8 +800,8 @@ public class SketchController {
// import statements into the main sketch file (code[0]) // import statements into the main sketch file (code[0])
// if the current code is a .java file, insert into current // if the current code is a .java file, insert into current
//if (current.flavor == PDE) { //if (current.flavor == PDE) {
SketchCode code = editor.getCurrentTab().getSketchCode(); SketchFile file = editor.getCurrentTab().getSketchFile();
if (code.isExtension(Sketch.SKETCH_EXTENSIONS)) if (file.isExtension(Sketch.SKETCH_EXTENSIONS))
editor.selectTab(0); editor.selectTab(0);
// could also scan the text in the file to see if each import // could also scan the text in the file to see if each import
@ -895,8 +895,8 @@ public class SketchController {
File tempFolder = FileUtils.createTempFolder("arduino_modified_sketch_"); File tempFolder = FileUtils.createTempFolder("arduino_modified_sketch_");
FileUtils.copy(sketch.getFolder(), tempFolder); FileUtils.copy(sketch.getFolder(), tempFolder);
for (SketchCode sc : Stream.of(sketch.getCodes()).filter(SketchCode::isModified).collect(Collectors.toList())) { for (SketchFile file : Stream.of(sketch.getFiles()).filter(SketchFile::isModified).collect(Collectors.toList())) {
Files.write(Paths.get(tempFolder.getAbsolutePath(), sc.getFileName()), sc.getProgram().getBytes()); Files.write(Paths.get(tempFolder.getAbsolutePath(), file.getFileName()), file.getProgram().getBytes());
} }
return Paths.get(tempFolder.getAbsolutePath(), sketch.getPrimaryFile().getName()).toString(); return Paths.get(tempFolder.getAbsolutePath(), sketch.getPrimaryFile().getName()).toString();
@ -998,8 +998,8 @@ public class SketchController {
try { try {
sketch.getFolder().mkdirs(); sketch.getFolder().mkdirs();
for (SketchCode code : sketch.getCodes()) { for (SketchFile file : sketch.getFiles()) {
code.save(); // this will force a save file.save(); // this will force a save
} }
calcModified(); calcModified();
@ -1034,8 +1034,8 @@ public class SketchController {
} }
private boolean sketchFilesAreReadOnly() { private boolean sketchFilesAreReadOnly() {
for (SketchCode code : sketch.getCodes()) { for (SketchFile file : sketch.getFiles()) {
if (code.isModified() && code.fileReadOnly() && code.fileExists()) { if (file.isModified() && file.fileReadOnly() && file.fileExists()) {
return true; return true;
} }
} }

View File

@ -66,8 +66,8 @@ public class FixEncoding implements Tool {
} }
try { try {
for (int i = 0; i < sketch.getCodeCount(); i++) { for (int i = 0; i < sketch.getCodeCount(); i++) {
SketchCode code = sketch.getCode(i); SketchFile file = sketch.getFile(i);
editor.findTab(code).setText(loadWithLocalEncoding(code.getFile())); editor.findTab(file).setText(loadWithLocalEncoding(file.getFile()));
} }
} catch (IOException e) { } catch (IOException e) {
String msg = String msg =

View File

@ -613,9 +613,9 @@ public class Compiler implements MessageConsumer {
} }
private RunnerException placeException(String message, String fileName, int line) { private RunnerException placeException(String message, String fileName, int line) {
for (SketchCode code : sketch.getCodes()) { for (SketchFile file : sketch.getFiles()) {
if (new File(fileName).getName().equals(code.getFileName())) { if (new File(fileName).getName().equals(file.getFileName())) {
return new RunnerException(message, code, line); return new RunnerException(message, file, line);
} }
} }
return null; return null;

View File

@ -41,11 +41,11 @@ public class Sketch {
*/ */
private String name; private String name;
private List<SketchCode> codes = new ArrayList<SketchCode>(); private List<SketchFile> files = new ArrayList<SketchFile>();
private static final Comparator<SketchCode> CODE_DOCS_COMPARATOR = new Comparator<SketchCode>() { private static final Comparator<SketchFile> CODE_DOCS_COMPARATOR = new Comparator<SketchFile>() {
@Override @Override
public int compare(SketchCode x, SketchCode y) { public int compare(SketchFile x, SketchFile y) {
if (x.isPrimary() && !y.isPrimary()) if (x.isPrimary() && !y.isPrimary())
return -1; return -1;
if (y.isPrimary() && !x.isPrimary()) if (y.isPrimary() && !x.isPrimary())
@ -72,7 +72,7 @@ public class Sketch {
folder = new File(file.getParent()); folder = new File(file.getParent());
dataFolder = new File(folder, "data"); dataFolder = new File(folder, "data");
codes = listSketchFiles(true); files = listSketchFiles(true);
} }
static public File checkSketchFile(File file) { static public File checkSketchFile(File file) {
@ -107,9 +107,9 @@ public class Sketch {
* not. * not.
*/ */
public boolean reload() throws IOException { public boolean reload() throws IOException {
List<SketchCode> reloaded = listSketchFiles(false); List<SketchFile> reloaded = listSketchFiles(false);
if (!reloaded.equals(codes)) { if (!reloaded.equals(files)) {
codes = reloaded; files = reloaded;
return true; return true;
} }
return false; return false;
@ -119,16 +119,16 @@ public class Sketch {
* Scan this sketch's directory for files that should be loaded as * Scan this sketch's directory for files that should be loaded as
* part of this sketch. Doesn't modify this SketchData instance, just * part of this sketch. Doesn't modify this SketchData instance, just
* returns a filtered and sorted list of File objects ready to be * returns a filtered and sorted list of File objects ready to be
* passed to the SketchCode constructor. * passed to the SketchFile constructor.
* *
* @param showWarnings * @param showWarnings
* When true, any invalid filenames will show a warning. * When true, any invalid filenames will show a warning.
*/ */
private List<SketchCode> listSketchFiles(boolean showWarnings) throws IOException { private List<SketchFile> listSketchFiles(boolean showWarnings) throws IOException {
Set<SketchCode> result = new TreeSet<>(CODE_DOCS_COMPARATOR); Set<SketchFile> result = new TreeSet<>(CODE_DOCS_COMPARATOR);
for (File file : FileUtils.listFiles(folder, false, EXTENSIONS)) { for (File file : FileUtils.listFiles(folder, false, EXTENSIONS)) {
if (BaseNoGui.isSanitaryName(file.getName())) { if (BaseNoGui.isSanitaryName(file.getName())) {
result.add(new SketchCode(file, file.equals(primaryFile))); result.add(new SketchFile(file, file.equals(primaryFile)));
} else if (showWarnings) { } else if (showWarnings) {
System.err.println(I18n.format(tr("File name {0} is invalid: ignored"), file.getName())); System.err.println(I18n.format(tr("File name {0} is invalid: ignored"), file.getName()));
} }
@ -153,18 +153,18 @@ public class Sketch {
} }
public void save() throws IOException { public void save() throws IOException {
for (SketchCode code : getCodes()) { for (SketchFile file : getFiles()) {
if (code.isModified()) if (file.isModified())
code.save(); file.save();
} }
} }
public int getCodeCount() { public int getCodeCount() {
return codes.size(); return files.size();
} }
public SketchCode[] getCodes() { public SketchFile[] getFiles() {
return codes.toArray(new SketchCode[0]); return files.toArray(new SketchFile[0]);
} }
/** /**
@ -182,26 +182,26 @@ public class Sketch {
//return code[0].file.getAbsolutePath(); //return code[0].file.getAbsolutePath();
} }
public void addCode(SketchCode sketchCode) { public void addFile(SketchFile file) {
codes.add(sketchCode); files.add(file);
Collections.sort(codes, CODE_DOCS_COMPARATOR); Collections.sort(files, CODE_DOCS_COMPARATOR);
} }
protected void replaceCode(SketchCode newCode) { protected void replaceFile(SketchFile newCode) {
for (SketchCode code : codes) { for (SketchFile file : files) {
if (code.getFileName().equals(newCode.getFileName())) { if (file.getFileName().equals(newCode.getFileName())) {
codes.set(codes.indexOf(code), newCode); files.set(files.indexOf(file), newCode);
return; return;
} }
} }
} }
public SketchCode getCode(int i) { public SketchFile getFile(int i) {
return codes.get(i); return files.get(i);
} }
protected void removeCode(SketchCode which) { protected void removeFile(SketchFile which) {
if (!codes.remove(which)) if (!files.remove(which))
System.err.println("removeCode: internal error.. could not find code"); System.err.println("removeCode: internal error.. could not find code");
} }
@ -221,8 +221,8 @@ public class Sketch {
* Is any of the files in this sketch modified? * Is any of the files in this sketch modified?
*/ */
public boolean isModified() { public boolean isModified() {
for (SketchCode code : codes) { for (SketchFile file : files) {
if (code.isModified()) if (file.isModified())
return true; return true;
} }
return false; return false;

View File

@ -1,5 +1,5 @@
/* /*
SketchCode - data class for a single file inside a sketch SketchFile - data class for a single file inside a sketch
Part of the Processing project - http://processing.org Part of the Processing project - http://processing.org
Copyright (c) 2004-08 Ben Fry and Casey Reas Copyright (c) 2004-08 Ben Fry and Casey Reas
@ -36,9 +36,9 @@ import java.util.stream.Stream;
import static processing.app.I18n.tr; import static processing.app.I18n.tr;
/** /**
* Represents a single tab of a sketch. * Represents a file within a sketch.
*/ */
public class SketchCode { public class SketchFile {
/** /**
* File object for where this code is located * File object for where this code is located
@ -53,7 +53,7 @@ public class SketchCode {
/** /**
* Interface for an in-memory storage of text file contents. This is * Interface for an in-memory storage of text file contents. This is
* intended to allow a GUI to keep modified text in memory, and allow * intended to allow a GUI to keep modified text in memory, and allow
* SketchCode to check for changes when needed. * SketchFile to check for changes when needed.
*/ */
public static interface TextStorage { public static interface TextStorage {
/** Get the current text */ /** Get the current text */
@ -77,14 +77,14 @@ public class SketchCode {
private TextStorage storage; private TextStorage storage;
/** /**
* Create a new SketchCode * Create a new SketchFile
* *
* @param file * @param file
* The file this SketchCode represents * The file this SketchFile represents
* @param primary * @param primary
* Whether this file is the primary file of the sketch * Whether this file is the primary file of the sketch
*/ */
public SketchCode(File file, boolean primary) { public SketchFile(File file, boolean primary) {
this.file = file; this.file = file;
this.primary = primary; this.primary = primary;
} }
@ -211,7 +211,7 @@ public class SketchCode {
} }
public boolean equals(Object o) { public boolean equals(Object o) {
return (o instanceof SketchCode) && file.equals(((SketchCode) o).file); return (o instanceof SketchFile) && file.equals(((SketchFile) o).file);
} }
/** /**

View File

@ -23,7 +23,7 @@
package processing.app.debug; package processing.app.debug;
import processing.app.SketchCode; import processing.app.SketchFile;
/** /**
* An exception with a line number attached that occurs * An exception with a line number attached that occurs
@ -32,7 +32,7 @@ import processing.app.SketchCode;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class RunnerException extends Exception { public class RunnerException extends Exception {
protected String message; protected String message;
protected SketchCode codeFile; protected SketchFile codeFile;
protected int codeLine; protected int codeLine;
protected int codeColumn; protected int codeColumn;
protected boolean showStackTrace; protected boolean showStackTrace;
@ -46,17 +46,17 @@ public class RunnerException extends Exception {
this(message, null, -1, -1, showStackTrace); this(message, null, -1, -1, showStackTrace);
} }
public RunnerException(String message, SketchCode file, int line) { public RunnerException(String message, SketchFile file, int line) {
this(message, file, line, -1, true); this(message, file, line, -1, true);
} }
public RunnerException(String message, SketchCode file, int line, int column) { public RunnerException(String message, SketchFile file, int line, int column) {
this(message, file, line, column, true); this(message, file, line, column, true);
} }
public RunnerException(String message, SketchCode file, int line, int column, public RunnerException(String message, SketchFile file, int line, int column,
boolean showStackTrace) { boolean showStackTrace) {
this.message = message; this.message = message;
this.codeFile = file; this.codeFile = file;
@ -85,12 +85,12 @@ public class RunnerException extends Exception {
} }
public SketchCode getCodeFile() { public SketchFile getCodeFile() {
return codeFile; return codeFile;
} }
public void setCodeFile(SketchCode file) { public void setCodeFile(SketchFile file) {
codeFile = file; codeFile = file;
} }