mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-13 10:29:35 +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:
parent
dfa60dacc1
commit
8e0d007ce2
@ -1640,13 +1640,13 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
selectTab((currentTabIndex - 1 + tabs.size()) % tabs.size());
|
||||
}
|
||||
|
||||
public EditorTab findTab(final SketchCode doc) {
|
||||
return tabs.get(findTabIndex(doc));
|
||||
public EditorTab findTab(final SketchFile file) {
|
||||
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) {
|
||||
if (tabs.get(i).getSketchCode() == doc)
|
||||
if (tabs.get(i).getSketchFile() == file)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
@ -1660,9 +1660,9 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
tabs.clear();
|
||||
currentTabIndex = -1;
|
||||
tabs.ensureCapacity(sketch.getCodeCount());
|
||||
for (SketchCode code : sketch.getCodes()) {
|
||||
for (SketchFile file : sketch.getFiles()) {
|
||||
try {
|
||||
addTab(code, null);
|
||||
addTab(file, null);
|
||||
} catch(IOException e) {
|
||||
// TODO: Improve / move error handling
|
||||
System.err.println(e);
|
||||
@ -1674,15 +1674,15 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
/**
|
||||
* Add a new tab.
|
||||
*
|
||||
* @param code
|
||||
* @param file
|
||||
* The file to show in the tab.
|
||||
* @param contents
|
||||
* The contents to show in the tab, or null to load the
|
||||
* contents from the given file.
|
||||
* The contents to show in the tab, or null to load the contents from
|
||||
* the given file.
|
||||
* @throws IOException
|
||||
*/
|
||||
protected void addTab(SketchCode code, String contents) throws IOException {
|
||||
EditorTab tab = new EditorTab(this, code, contents);
|
||||
protected void addTab(SketchFile file, String contents) throws IOException {
|
||||
EditorTab tab = new EditorTab(this, file, contents);
|
||||
tabs.add(tab);
|
||||
}
|
||||
|
||||
@ -1999,7 +1999,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
if (sketchController == null) {
|
||||
return;
|
||||
}
|
||||
SketchCode current = getCurrentTab().getSketchCode();
|
||||
SketchFile current = getCurrentTab().getSketchFile();
|
||||
if (current.isPrimary()) {
|
||||
setTitle(I18n.format(tr("{0} | Arduino {1}"), sketch.getName(),
|
||||
BaseNoGui.VERSION_NAME_LONG));
|
||||
@ -2635,7 +2635,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
printerJob.setPrintable(getCurrentTab().getTextArea());
|
||||
}
|
||||
// set the name of the job to the code name
|
||||
printerJob.setJobName(getCurrentTab().getSketchCode().getPrettyName());
|
||||
printerJob.setJobName(getCurrentTab().getSketchFile().getPrettyName());
|
||||
|
||||
if (printerJob.printDialog()) {
|
||||
try {
|
||||
|
@ -244,11 +244,11 @@ public class EditorHeader extends JComponent {
|
||||
int x = scale(6); // offset from left edge of the component
|
||||
int i = 0;
|
||||
for (EditorTab tab : tabs) {
|
||||
SketchCode code = tab.getSketchCode();
|
||||
String codeName = code.getPrettyName();
|
||||
SketchFile file = tab.getSketchFile();
|
||||
String filename = file.getPrettyName();
|
||||
|
||||
// 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)
|
||||
font.getStringBounds(text, g.getFontRenderContext()).getWidth();
|
||||
@ -325,9 +325,9 @@ public class EditorHeader extends JComponent {
|
||||
|
||||
int i = 0;
|
||||
for (EditorTab tab : editor.getTabs()) {
|
||||
SketchCode code = tab.getSketchCode();
|
||||
SketchFile file = tab.getSketchFile();
|
||||
final int index = i++;
|
||||
item = new JMenuItem(code.getPrettyName());
|
||||
item = new JMenuItem(file.getPrettyName());
|
||||
item.addActionListener((ActionEvent e) -> {
|
||||
editor.selectTab(index);
|
||||
});
|
||||
|
@ -65,11 +65,11 @@ import processing.app.tools.DiscourseFormat;
|
||||
/**
|
||||
* 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 SketchTextArea textarea;
|
||||
protected RTextScrollPane scrollPane;
|
||||
protected SketchCode code;
|
||||
protected SketchFile file;
|
||||
protected boolean modified;
|
||||
/** Is external editing mode currently enabled? */
|
||||
protected boolean external;
|
||||
@ -79,32 +79,32 @@ public class EditorTab extends JPanel implements SketchCode.TextStorage {
|
||||
*
|
||||
* @param editor
|
||||
* The Editor this tab runs in
|
||||
* @param code
|
||||
* @param file
|
||||
* The file to display in this tab
|
||||
* @param contents
|
||||
* Initial contents to display in this tab. Can be used when
|
||||
* editing a file that doesn't exist yet. If null is passed,
|
||||
* code.load() is called and displayed instead.
|
||||
* Initial contents to display in this tab. Can be used when editing
|
||||
* a file that doesn't exist yet. If null is passed, code.load() is
|
||||
* called and displayed instead.
|
||||
* @throws IOException
|
||||
*/
|
||||
public EditorTab(Editor editor, SketchCode code, String contents)
|
||||
public EditorTab(Editor editor, SketchFile file, String contents)
|
||||
throws IOException {
|
||||
super(new BorderLayout());
|
||||
|
||||
// Load initial contents contents from file if nothing was specified.
|
||||
if (contents == null) {
|
||||
contents = code.load();
|
||||
contents = file.load();
|
||||
modified = false;
|
||||
} else {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
this.editor = editor;
|
||||
this.code = code;
|
||||
this.file = file;
|
||||
RSyntaxDocument document = createDocument(contents);
|
||||
this.textarea = createTextArea(document);
|
||||
this.scrollPane = createScrollPane(this.textarea);
|
||||
code.setStorage(this);
|
||||
file.setStorage(this);
|
||||
applyPreferences();
|
||||
add(this.scrollPane, BorderLayout.CENTER);
|
||||
|
||||
@ -292,14 +292,14 @@ public class EditorTab extends JPanel implements SketchCode.TextStorage {
|
||||
textarea.setEditable(false);
|
||||
// Detach from the code, since we are no longer the authoritative source
|
||||
// for file contents.
|
||||
code.setStorage(null);
|
||||
file.setStorage(null);
|
||||
// Reload, in case the file contents already changed.
|
||||
reload();
|
||||
} else {
|
||||
textarea.setBackground(Theme.getColor("editor.bgcolor"));
|
||||
textarea.setHighlightCurrentLine(Theme.getBoolean("editor.linehighlight"));
|
||||
textarea.setEditable(true);
|
||||
code.setStorage(this);
|
||||
file.setStorage(this);
|
||||
// Reload once just before disabling external mode, to ensure we have
|
||||
// the latest contents.
|
||||
reload();
|
||||
@ -337,10 +337,10 @@ public class EditorTab extends JPanel implements SketchCode.TextStorage {
|
||||
private void reload() {
|
||||
String text;
|
||||
try {
|
||||
text = code.load();
|
||||
text = file.load();
|
||||
} catch (IOException e) {
|
||||
System.err.println(I18n.format("Warning: Failed to reload file: \"{0}\"",
|
||||
code.getFileName()));
|
||||
file.getFileName()));
|
||||
return;
|
||||
}
|
||||
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() {
|
||||
return this.code;
|
||||
public SketchFile getSketchFile() {
|
||||
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
|
||||
* the TextStorage interface.
|
||||
* Clear modified status. Should only be called by SketchFile through the
|
||||
* TextStorage interface.
|
||||
*/
|
||||
public void clearModified() {
|
||||
setModified(false);
|
||||
|
@ -91,7 +91,7 @@ public class SketchController {
|
||||
* Handler for the Rename Code menu option.
|
||||
*/
|
||||
public void handleRenameCode() {
|
||||
SketchCode current = editor.getCurrentTab().getSketchCode();
|
||||
SketchFile current = editor.getCurrentTab().getSketchFile();
|
||||
|
||||
editor.status.clearState();
|
||||
// make sure the user didn't hide the sketch folder
|
||||
@ -132,7 +132,7 @@ public class SketchController {
|
||||
* where they diverge.
|
||||
*/
|
||||
protected void nameCode(String newName) {
|
||||
SketchCode current = editor.getCurrentTab().getSketchCode();
|
||||
SketchFile current = editor.getCurrentTab().getSketchFile();
|
||||
int currentIndex = editor.getCurrentTabIndex();
|
||||
|
||||
// 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
|
||||
// extensions, so compare the full names (including extensions). This
|
||||
// might cause problems: http://dev.processing.org/bugs/show_bug.cgi?id=543
|
||||
for (SketchCode c : sketch.getCodes()) {
|
||||
if (newName.equalsIgnoreCase(c.getFileName()) && OSUtils.isWindows()) {
|
||||
for (SketchFile file : sketch.getFiles()) {
|
||||
if (newName.equalsIgnoreCase(file.getFileName()) && OSUtils.isWindows()) {
|
||||
Base.showMessage(tr("Error"),
|
||||
I18n.format(
|
||||
tr("A file named \"{0}\" already exists in \"{1}\""),
|
||||
c.getFileName(),
|
||||
file.getFileName(),
|
||||
sketch.getFolder().getAbsolutePath()
|
||||
));
|
||||
return;
|
||||
@ -218,9 +218,9 @@ public class SketchController {
|
||||
}
|
||||
|
||||
if (renamingCode && current.isPrimary()) {
|
||||
for (SketchCode code : sketch.getCodes()) {
|
||||
if (sanitaryName.equalsIgnoreCase(code.getBaseName()) &&
|
||||
code.isExtension("cpp")) {
|
||||
for (SketchFile file : sketch.getFiles()) {
|
||||
if (sanitaryName.equalsIgnoreCase(file.getBaseName()) &&
|
||||
file.isExtension("cpp")) {
|
||||
Base.showMessage(tr("Error"),
|
||||
I18n.format(tr("You can't rename the sketch to \"{0}\"\n"
|
||||
+ "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
|
||||
if (current.isModified()) {
|
||||
try {
|
||||
// save this new SketchCode
|
||||
// save this new SketchFile
|
||||
current.save();
|
||||
} catch (Exception 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
|
||||
try {
|
||||
for (SketchCode code : sketch.getCodes()) {
|
||||
code.save();
|
||||
for (SketchFile file : sketch.getFiles()) {
|
||||
file.save();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Base.showWarning(tr("Error"), tr("Could not rename the sketch. (1)"), e);
|
||||
@ -350,9 +350,9 @@ public class SketchController {
|
||||
return;
|
||||
}
|
||||
ensureExistence();
|
||||
SketchCode code = new SketchCode(newFile, false);
|
||||
SketchFile file = new SketchFile(newFile, false);
|
||||
try {
|
||||
editor.addTab(code, "");
|
||||
editor.addTab(file, "");
|
||||
} catch (IOException e) {
|
||||
Base.showWarning(tr("Error"),
|
||||
I18n.format(
|
||||
@ -360,8 +360,8 @@ public class SketchController {
|
||||
), e);
|
||||
return;
|
||||
}
|
||||
sketch.addCode(code);
|
||||
editor.selectTab(editor.findTabIndex(code));
|
||||
sketch.addFile(file);
|
||||
editor.selectTab(editor.findTabIndex(file));
|
||||
}
|
||||
|
||||
// update the tabs
|
||||
@ -373,7 +373,7 @@ public class SketchController {
|
||||
* Remove a piece of code from the sketch and from the disk.
|
||||
*/
|
||||
public void handleDeleteCode() throws IOException {
|
||||
SketchCode current = editor.getCurrentTab().getSketchCode();
|
||||
SketchFile current = editor.getCurrentTab().getSketchFile();
|
||||
editor.status.clearState();
|
||||
// make sure the user didn't hide the sketch folder
|
||||
ensureExistence();
|
||||
@ -427,7 +427,7 @@ public class SketchController {
|
||||
}
|
||||
|
||||
// remove code from the list
|
||||
sketch.removeCode(current);
|
||||
sketch.removeFile(current);
|
||||
|
||||
// just set current tab to the main tab
|
||||
editor.selectTab(0);
|
||||
@ -512,13 +512,13 @@ public class SketchController {
|
||||
|
||||
|
||||
private boolean renameCodeToInoExtension(File pdeFile) {
|
||||
for (SketchCode c : sketch.getCodes()) {
|
||||
if (!c.getFile().equals(pdeFile))
|
||||
for (SketchFile file : sketch.getFiles()) {
|
||||
if (!file.getFile().equals(pdeFile))
|
||||
continue;
|
||||
|
||||
String pdeName = pdeFile.getPath();
|
||||
pdeName = pdeName.substring(0, pdeName.length() - 4) + ".ino";
|
||||
return c.renameTo(new File(pdeName));
|
||||
return file.renameTo(new File(pdeName));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -563,8 +563,8 @@ public class SketchController {
|
||||
// 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
|
||||
// resaved (with the same name) to another location/folder.
|
||||
for (SketchCode code : sketch.getCodes()) {
|
||||
if (!code.isPrimary() && newName.equalsIgnoreCase(code.getBaseName())) {
|
||||
for (SketchFile file : sketch.getFiles()) {
|
||||
if (!file.isPrimary() && newName.equalsIgnoreCase(file.getBaseName())) {
|
||||
Base.showMessage(tr("Error"),
|
||||
I18n.format(tr("You can't save the sketch as \"{0}\"\n" +
|
||||
"because the sketch already has a file with that name."), newName
|
||||
@ -608,10 +608,10 @@ public class SketchController {
|
||||
newFolder.mkdirs();
|
||||
|
||||
// save the other tabs to their new location
|
||||
for (SketchCode code : sketch.getCodes()) {
|
||||
if (code.isPrimary()) continue;
|
||||
File newFile = new File(newFolder, code.getFileName());
|
||||
code.saveAs(newFile);
|
||||
for (SketchFile file : sketch.getFiles()) {
|
||||
if (file.isPrimary()) continue;
|
||||
File newFile = new File(newFolder, file.getFileName());
|
||||
file.saveAs(newFile);
|
||||
}
|
||||
|
||||
// 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
|
||||
File newFile = new File(newFolder, newName + ".ino");
|
||||
sketch.getCode(0).saveAs(newFile);
|
||||
sketch.getFile(0).saveAs(newFile);
|
||||
|
||||
editor.handleOpenUnchecked(newFile,
|
||||
editor.getCurrentTabIndex(),
|
||||
@ -765,16 +765,16 @@ public class SketchController {
|
||||
}
|
||||
|
||||
if (!isData) {
|
||||
SketchCode newCode = new SketchCode(destFile, false);
|
||||
SketchFile newFile = new SketchFile(destFile, false);
|
||||
|
||||
if (replacement) {
|
||||
sketch.replaceCode(newCode);
|
||||
sketch.replaceFile(newFile);
|
||||
|
||||
} else {
|
||||
ensureExistence();
|
||||
sketch.addCode(newCode);
|
||||
sketch.addFile(newFile);
|
||||
}
|
||||
editor.selectTab(editor.findTabIndex(newCode));
|
||||
editor.selectTab(editor.findTabIndex(newFile));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -800,8 +800,8 @@ public class SketchController {
|
||||
// import statements into the main sketch file (code[0])
|
||||
// if the current code is a .java file, insert into current
|
||||
//if (current.flavor == PDE) {
|
||||
SketchCode code = editor.getCurrentTab().getSketchCode();
|
||||
if (code.isExtension(Sketch.SKETCH_EXTENSIONS))
|
||||
SketchFile file = editor.getCurrentTab().getSketchFile();
|
||||
if (file.isExtension(Sketch.SKETCH_EXTENSIONS))
|
||||
editor.selectTab(0);
|
||||
|
||||
// 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_");
|
||||
FileUtils.copy(sketch.getFolder(), tempFolder);
|
||||
|
||||
for (SketchCode sc : Stream.of(sketch.getCodes()).filter(SketchCode::isModified).collect(Collectors.toList())) {
|
||||
Files.write(Paths.get(tempFolder.getAbsolutePath(), sc.getFileName()), sc.getProgram().getBytes());
|
||||
for (SketchFile file : Stream.of(sketch.getFiles()).filter(SketchFile::isModified).collect(Collectors.toList())) {
|
||||
Files.write(Paths.get(tempFolder.getAbsolutePath(), file.getFileName()), file.getProgram().getBytes());
|
||||
}
|
||||
|
||||
return Paths.get(tempFolder.getAbsolutePath(), sketch.getPrimaryFile().getName()).toString();
|
||||
@ -998,8 +998,8 @@ public class SketchController {
|
||||
try {
|
||||
sketch.getFolder().mkdirs();
|
||||
|
||||
for (SketchCode code : sketch.getCodes()) {
|
||||
code.save(); // this will force a save
|
||||
for (SketchFile file : sketch.getFiles()) {
|
||||
file.save(); // this will force a save
|
||||
}
|
||||
calcModified();
|
||||
|
||||
@ -1034,8 +1034,8 @@ public class SketchController {
|
||||
}
|
||||
|
||||
private boolean sketchFilesAreReadOnly() {
|
||||
for (SketchCode code : sketch.getCodes()) {
|
||||
if (code.isModified() && code.fileReadOnly() && code.fileExists()) {
|
||||
for (SketchFile file : sketch.getFiles()) {
|
||||
if (file.isModified() && file.fileReadOnly() && file.fileExists()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -66,8 +66,8 @@ public class FixEncoding implements Tool {
|
||||
}
|
||||
try {
|
||||
for (int i = 0; i < sketch.getCodeCount(); i++) {
|
||||
SketchCode code = sketch.getCode(i);
|
||||
editor.findTab(code).setText(loadWithLocalEncoding(code.getFile()));
|
||||
SketchFile file = sketch.getFile(i);
|
||||
editor.findTab(file).setText(loadWithLocalEncoding(file.getFile()));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
String msg =
|
||||
|
@ -613,9 +613,9 @@ public class Compiler implements MessageConsumer {
|
||||
}
|
||||
|
||||
private RunnerException placeException(String message, String fileName, int line) {
|
||||
for (SketchCode code : sketch.getCodes()) {
|
||||
if (new File(fileName).getName().equals(code.getFileName())) {
|
||||
return new RunnerException(message, code, line);
|
||||
for (SketchFile file : sketch.getFiles()) {
|
||||
if (new File(fileName).getName().equals(file.getFileName())) {
|
||||
return new RunnerException(message, file, line);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -41,11 +41,11 @@ public class Sketch {
|
||||
*/
|
||||
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
|
||||
public int compare(SketchCode x, SketchCode y) {
|
||||
public int compare(SketchFile x, SketchFile y) {
|
||||
if (x.isPrimary() && !y.isPrimary())
|
||||
return -1;
|
||||
if (y.isPrimary() && !x.isPrimary())
|
||||
@ -72,7 +72,7 @@ public class Sketch {
|
||||
|
||||
folder = new File(file.getParent());
|
||||
dataFolder = new File(folder, "data");
|
||||
codes = listSketchFiles(true);
|
||||
files = listSketchFiles(true);
|
||||
}
|
||||
|
||||
static public File checkSketchFile(File file) {
|
||||
@ -107,9 +107,9 @@ public class Sketch {
|
||||
* not.
|
||||
*/
|
||||
public boolean reload() throws IOException {
|
||||
List<SketchCode> reloaded = listSketchFiles(false);
|
||||
if (!reloaded.equals(codes)) {
|
||||
codes = reloaded;
|
||||
List<SketchFile> reloaded = listSketchFiles(false);
|
||||
if (!reloaded.equals(files)) {
|
||||
files = reloaded;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -119,16 +119,16 @@ public class Sketch {
|
||||
* Scan this sketch's directory for files that should be loaded as
|
||||
* part of this sketch. Doesn't modify this SketchData instance, just
|
||||
* returns a filtered and sorted list of File objects ready to be
|
||||
* passed to the SketchCode constructor.
|
||||
* passed to the SketchFile constructor.
|
||||
*
|
||||
* @param showWarnings
|
||||
* When true, any invalid filenames will show a warning.
|
||||
*/
|
||||
private List<SketchCode> listSketchFiles(boolean showWarnings) throws IOException {
|
||||
Set<SketchCode> result = new TreeSet<>(CODE_DOCS_COMPARATOR);
|
||||
private List<SketchFile> listSketchFiles(boolean showWarnings) throws IOException {
|
||||
Set<SketchFile> result = new TreeSet<>(CODE_DOCS_COMPARATOR);
|
||||
for (File file : FileUtils.listFiles(folder, false, EXTENSIONS)) {
|
||||
if (BaseNoGui.isSanitaryName(file.getName())) {
|
||||
result.add(new SketchCode(file, file.equals(primaryFile)));
|
||||
result.add(new SketchFile(file, file.equals(primaryFile)));
|
||||
} else if (showWarnings) {
|
||||
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 {
|
||||
for (SketchCode code : getCodes()) {
|
||||
if (code.isModified())
|
||||
code.save();
|
||||
for (SketchFile file : getFiles()) {
|
||||
if (file.isModified())
|
||||
file.save();
|
||||
}
|
||||
}
|
||||
|
||||
public int getCodeCount() {
|
||||
return codes.size();
|
||||
return files.size();
|
||||
}
|
||||
|
||||
public SketchCode[] getCodes() {
|
||||
return codes.toArray(new SketchCode[0]);
|
||||
public SketchFile[] getFiles() {
|
||||
return files.toArray(new SketchFile[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -182,26 +182,26 @@ public class Sketch {
|
||||
//return code[0].file.getAbsolutePath();
|
||||
}
|
||||
|
||||
public void addCode(SketchCode sketchCode) {
|
||||
codes.add(sketchCode);
|
||||
Collections.sort(codes, CODE_DOCS_COMPARATOR);
|
||||
public void addFile(SketchFile file) {
|
||||
files.add(file);
|
||||
Collections.sort(files, CODE_DOCS_COMPARATOR);
|
||||
}
|
||||
|
||||
protected void replaceCode(SketchCode newCode) {
|
||||
for (SketchCode code : codes) {
|
||||
if (code.getFileName().equals(newCode.getFileName())) {
|
||||
codes.set(codes.indexOf(code), newCode);
|
||||
protected void replaceFile(SketchFile newCode) {
|
||||
for (SketchFile file : files) {
|
||||
if (file.getFileName().equals(newCode.getFileName())) {
|
||||
files.set(files.indexOf(file), newCode);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SketchCode getCode(int i) {
|
||||
return codes.get(i);
|
||||
public SketchFile getFile(int i) {
|
||||
return files.get(i);
|
||||
}
|
||||
|
||||
protected void removeCode(SketchCode which) {
|
||||
if (!codes.remove(which))
|
||||
protected void removeFile(SketchFile which) {
|
||||
if (!files.remove(which))
|
||||
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?
|
||||
*/
|
||||
public boolean isModified() {
|
||||
for (SketchCode code : codes) {
|
||||
if (code.isModified())
|
||||
for (SketchFile file : files) {
|
||||
if (file.isModified())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -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
|
||||
|
||||
Copyright (c) 2004-08 Ben Fry and Casey Reas
|
||||
@ -36,9 +36,9 @@ import java.util.stream.Stream;
|
||||
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
|
||||
@ -53,7 +53,7 @@ public class SketchCode {
|
||||
/**
|
||||
* 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
|
||||
* SketchCode to check for changes when needed.
|
||||
* SketchFile to check for changes when needed.
|
||||
*/
|
||||
public static interface TextStorage {
|
||||
/** Get the current text */
|
||||
@ -77,14 +77,14 @@ public class SketchCode {
|
||||
private TextStorage storage;
|
||||
|
||||
/**
|
||||
* Create a new SketchCode
|
||||
* Create a new SketchFile
|
||||
*
|
||||
* @param file
|
||||
* The file this SketchCode represents
|
||||
* The file this SketchFile represents
|
||||
* @param primary
|
||||
* 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.primary = primary;
|
||||
}
|
||||
@ -211,7 +211,7 @@ public class SketchCode {
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return (o instanceof SketchCode) && file.equals(((SketchCode) o).file);
|
||||
return (o instanceof SketchFile) && file.equals(((SketchFile) o).file);
|
||||
}
|
||||
|
||||
/**
|
@ -23,7 +23,7 @@
|
||||
|
||||
package processing.app.debug;
|
||||
|
||||
import processing.app.SketchCode;
|
||||
import processing.app.SketchFile;
|
||||
|
||||
/**
|
||||
* An exception with a line number attached that occurs
|
||||
@ -32,7 +32,7 @@ import processing.app.SketchCode;
|
||||
@SuppressWarnings("serial")
|
||||
public class RunnerException extends Exception {
|
||||
protected String message;
|
||||
protected SketchCode codeFile;
|
||||
protected SketchFile codeFile;
|
||||
protected int codeLine;
|
||||
protected int codeColumn;
|
||||
protected boolean showStackTrace;
|
||||
@ -46,17 +46,17 @@ public class RunnerException extends Exception {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
public RunnerException(String message, SketchCode file, int line, int column,
|
||||
public RunnerException(String message, SketchFile file, int line, int column,
|
||||
boolean showStackTrace) {
|
||||
this.message = message;
|
||||
this.codeFile = file;
|
||||
@ -85,12 +85,12 @@ public class RunnerException extends Exception {
|
||||
}
|
||||
|
||||
|
||||
public SketchCode getCodeFile() {
|
||||
public SketchFile getCodeFile() {
|
||||
return codeFile;
|
||||
}
|
||||
|
||||
|
||||
public void setCodeFile(SketchCode file) {
|
||||
public void setCodeFile(SketchFile file) {
|
||||
codeFile = file;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user