Skip to content

[IDE 1.5.x] Command-line / GUI refactor. #2328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 73 commits into from
Nov 18, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
a601372
Explicitely store a layout type for a library
matthijskooijman Jul 7, 2014
af0d8c7
Let Sketch.getExtensions() return a List
matthijskooijman Jul 8, 2014
43dac3a
Use SketchCode.isExtension in more places
matthijskooijman Jul 8, 2014
e994c52
Don't store the extension in SketchCode
matthijskooijman Jul 8, 2014
9bc1824
Removed unused Base.getBoardsViaNetwork() and related member.
cmaglie Aug 26, 2014
dd911bc
Removed some trivial warnings
cmaglie Jan 26, 2014
026dd50
Removed some warning from Editor class
cmaglie Jan 26, 2014
479b974
Refactoring of Theme class
cmaglie Jan 26, 2014
93562a7
Refactored and simplified EditorConsole class.
cmaglie Jan 26, 2014
872897d
Splitted GUI and Streams in EditorConsole
cmaglie Jan 26, 2014
af19257
Rationalized Preferences and Theme classes.
cmaglie Jan 31, 2014
e6563cf
Removed GUI dependencies from SketchCode class.
bitron Jan 30, 2014
79ab98f
Make Compiler independent from Sketch.
bitron Jan 30, 2014
bbd3782
Reintroduced 'Next Tab' and 'Prev Tab' click actions
cmaglie Feb 1, 2014
54f3f53
Applied (a sort of) decorator pattern to SketchCodeDoc.
cmaglie Feb 1, 2014
b61f2a4
Made Compiler and PdePreprocessor independent from Preferences.
bitron Apr 5, 2014
21de7bd
Moved some code from Sketch to SketchData.
bitron Apr 7, 2014
18a8d4d
Created PApplet and PConstants wrapper classes.
cmaglie Aug 19, 2014
e0f680b
Drop dependency from processing-core project.
cmaglie Aug 19, 2014
50f89d9
Refactored OS detection subroutine.
cmaglie Aug 19, 2014
be96ae3
Removed no more used 'core' project
cmaglie Sep 24, 2014
057106f
Moved version info to BaseNoGui new class (work in progress).
bitron Aug 21, 2014
118826e
Moved getAvrBasePath() and related methods from Base to BaseNoGui (wo…
bitron Aug 21, 2014
7776ffa
Moved packages, currentDirectory and portableFolder (and related meth…
bitron Aug 21, 2014
4c1b187
Moved platform (and related methods) from Base to BaseNoGui (work in …
bitron Aug 21, 2014
4443911
Moved getBoardPreferences() and related methods from Base to BaseNoGu…
bitron Aug 21, 2014
64c6fe5
Moved saveFile() from Base to BaseNoGui (work in progress).
bitron Aug 21, 2014
c666274
Moved libraries and importToLibraryTable (and related methods) from B…
bitron Aug 21, 2014
e83462b
Changed dependency from Preferences to PreferencesData in processing.…
bitron Aug 21, 2014
1bb2da8
Moved some initialization code from Base to BaseNoGui.
bitron Aug 21, 2014
a43d207
Removed dependency from Base in the uploaders.
bitron Aug 21, 2014
fa0d37d
Added notifier interface and classes.
bitron Aug 21, 2014
d6bd77e
Removed dependency from Base in PreferencesData.
bitron Aug 21, 2014
bc6b488
Removed leftover references to Base in BaseNoGui.
bitron Aug 21, 2014
1c37189
Removed unused parameter (base).
bitron Aug 21, 2014
bff6f28
Renamed user notifier classes.
bitron Aug 21, 2014
74f59c2
Changed UserNotifier from interface to abstract class.
bitron Aug 21, 2014
eb28480
Moved showWarning() implementation from Base to BaseNoGui.
bitron Aug 21, 2014
b278c19
Removed dependency from Base in all Platform classes.
bitron Aug 22, 2014
22be22a
Removed self class references from Base.
bitron Aug 22, 2014
f2d92bb
Removed dependency from Preferences in a bunch of classes.
bitron Aug 22, 2014
b7d1846
Moved some code from Base to BaseNoGui and removed leftover self clas…
bitron Aug 22, 2014
afbbe77
Moved the sketch building code from Sketch to Compiler.
bitron Aug 22, 2014
5db851c
Moved the sketch structure check code from Editor to SketchData.
bitron Aug 22, 2014
1c8a4e9
Added sketch structure check to the build method of Compile.
bitron Aug 22, 2014
612f4c9
Moved discoveryManager from Base to BaseNoGui.
bitron Aug 22, 2014
7c58be3
Fixed wrong sketch structure check in Editor and SketchData.
bitron Aug 22, 2014
36fd0bf
Moved removeDescendants() and removeDir() from Base to BaseNoGui.
bitron Aug 22, 2014
4b69baa
Removed last dependency from Base in processing.app.Platform.
bitron Aug 22, 2014
b0d8a50
Moved isSanitaryName() and sanitizeName() from Sketch to BaseNoGui.
bitron Aug 22, 2014
0919b0e
Moved countLines() and loadFile() from Base to BaseNoGui.
bitron Aug 22, 2014
83c6137
Split UploaderAndMonitorFactory in two distinct classes.
bitron Aug 25, 2014
998142d
Moved last showError() method for Base to BaseNoGui.
bitron Aug 25, 2014
061d1f1
Moved the sketch uploading code from Sketch to Compiler.
bitron Aug 25, 2014
8687a78
Removed leftover dependency from SketchCodeDocument in SketchData.
bitron Aug 25, 2014
abe6ff5
Moved onBoardOrPortChange() and related members/methods from Base to …
bitron Aug 25, 2014
443f7a7
Moved some parameter processing methods from Base to BaseNoGui.
bitron Aug 25, 2014
10af59f
Moved some code from Base to BaseNoGui into new getSketchbookPath() m…
bitron Aug 26, 2014
2058263
Moved portableSketchbookFolder from Base to BaseNoGui.
bitron Aug 26, 2014
26a8b37
Refactored Base.getDefaultSketchbookFolder() method.
bitron Aug 26, 2014
035e57e
Moved getDefaultSketchbookFolder() from Base to BaseNoGui and other m…
bitron Aug 26, 2014
6d28e12
Moved commandline parsing code from Base/BaseNoGui to new Commandline…
bitron Aug 26, 2014
4d3599b
Moved getBuildFolder() and related members/methods from Base to BaseN…
bitron Aug 26, 2014
2702cce
Added main() and init() methods to BaseNoGui.
bitron Sep 10, 2014
c222310
Fixed wrong sketch structure check.
bitron Sep 18, 2014
b2a88ec
Removed inheritance relationship between SketchCodeDocument and Sketc…
bitron Sep 18, 2014
1974d77
Added new command line options.
bitron Sep 19, 2014
2de206c
Modified preferences initialization in BaseNoGui.
bitron Sep 23, 2014
ba8eade
Split IDE into 2 projects.
cmaglie Sep 23, 2014
d1f4e03
arduino-core project is now correctly compiled through ant build script
cmaglie Sep 24, 2014
98bdc7b
Moved specialized Platform classes and related resources to the 'ardu…
bitron Sep 25, 2014
820fc65
Created 'arduino-builder' project.
bitron Sep 25, 2014
7b2ed12
Temporarily disabled I18N test
cmaglie Oct 25, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moved some code from Sketch to SketchData.
  • Loading branch information
bitron authored and cmaglie committed Nov 13, 2014
commit 21de7bdea389f5e3f3d9d9d97bd6f1b18a31acc0
180 changes: 35 additions & 145 deletions app/src/processing/app/Sketch.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,9 @@ public class Sketch {

private Editor editor;

/** main pde file for this sketch. */
private File primaryFile;

/** true if any of the files have been modified. */
private boolean modified;

/** folder that contains this sketch */
private File folder;

/** data folder location for this sketch (may not exist yet) */
private File dataFolder;

/** code folder location for this sketch (may not exist yet) */
private File codeFolder;

private SketchCodeDocument current;
private int currentIndex;

Expand All @@ -85,14 +73,7 @@ public class Sketch {
*/
public Sketch(Editor _editor, File file) throws IOException {
editor = _editor;
data = new SketchData();
primaryFile = file;

// get the name of the sketch by chopping .pde or .java
// off of the main file name
String mainFilename = primaryFile.getName();
int suffixLength = getDefaultExtension().length() + 1;
data.setName(mainFilename.substring(0, mainFilename.length() - suffixLength));
data = new SketchData(file);

// lib/build must exist when the application is started
// it is added to the CLASSPATH by default, but if it doesn't
Expand All @@ -113,9 +94,6 @@ public Sketch(Editor _editor, File file) throws IOException {
tempBuildFolder = Base.getBuildFolder();
//Base.addBuildFolderToClassPath();

folder = new File(file.getParent());
//System.out.println("sketch dir is " + folder);

load();
}

Expand All @@ -135,60 +113,7 @@ public Sketch(Editor _editor, File file) throws IOException {
* in which case the load happens each time "run" is hit.
*/
protected void load() throws IOException {
codeFolder = new File(folder, "code");
dataFolder = new File(folder, "data");

// get list of files in the sketch folder
String list[] = folder.list();

// reset these because load() may be called after an
// external editor event. (fix for 0099)
data.clearCodeDocs();

List<String> extensions = getExtensions();

for (String filename : list) {
// Ignoring the dot prefix files is especially important to avoid files
// with the ._ prefix on Mac OS X. (You'll see this with Mac files on
// non-HFS drives, i.e. a thumb drive formatted FAT32.)
if (filename.startsWith(".")) continue;

// Don't let some wacko name a directory blah.pde or bling.java.
if (new File(folder, filename).isDirectory()) continue;

// figure out the name without any extension
String base = filename;
// now strip off the .pde and .java extensions
for (String extension : extensions) {
if (base.toLowerCase().endsWith("." + extension)) {
base = base.substring(0, base.length() - (extension.length() + 1));

// Don't allow people to use files with invalid names, since on load,
// it would be otherwise possible to sneak in nasty filenames. [0116]
if (Sketch.isSanitaryName(base)) {
data.addCode(new SketchCodeDocument(new File(folder, filename)));
} else {
System.err.println(I18n.format("File name {0} is invalid: ignored", filename));
}
}
}
}

if (data.getCodeCount() == 0)
throw new IOException(_("No valid code files found"));

// move the main class to the first tab
// start at 1, if it's at zero, don't bother
for (SketchCode code : data.getCodes()) {
//if (code[i].file.getName().equals(mainFilename)) {
if (code.getFile().equals(primaryFile)) {
data.moveCodeToFront(code);
break;
}
}

// sort the entries at the top
data.sortCode();
data.load();

// set the main file to be the current tab
if (editor != null) {
Expand Down Expand Up @@ -335,7 +260,7 @@ protected void nameCode(String newName) {
I18n.format(
_("A file named \"{0}\" already exists in \"{1}\""),
c.getFileName(),
folder.getAbsolutePath()
data.getFolder().getAbsolutePath()
));
return;
}
Expand Down Expand Up @@ -364,7 +289,7 @@ protected void nameCode(String newName) {
}


File newFile = new File(folder, newName);
File newFile = new File(data.getFolder(), newName);
// if (newFile.exists()) { // yay! users will try anything
// Base.showMessage("Nope",
// "A file named \"" + newFile + "\" already exists\n" +
Expand All @@ -386,7 +311,7 @@ protected void nameCode(String newName) {
if (currentIndex == 0) {
// get the new folder name/location
String folderName = newName.substring(0, newName.indexOf('.'));
File newFolder = new File(folder.getParentFile(), folderName);
File newFolder = new File(data.getFolder().getParentFile(), folderName);
if (newFolder.exists()) {
Base.showWarning(_("Cannot Rename"),
I18n.format(
Expand Down Expand Up @@ -434,7 +359,7 @@ protected void nameCode(String newName) {
}

// now rename the sketch folder and re-open
boolean success = folder.renameTo(newFolder);
boolean success = data.getFolder().renameTo(newFolder);
if (!success) {
Base.showWarning(_("Error"), _("Could not rename the sketch. (2)"), null);
return;
Expand Down Expand Up @@ -479,7 +404,7 @@ protected void nameCode(String newName) {
I18n.format(
"Could not create the file \"{0}\" in \"{1}\"",
newFile,
folder.getAbsolutePath()
data.getFolder().getAbsolutePath()
), e);
return;
}
Expand Down Expand Up @@ -534,7 +459,7 @@ public void handleDeleteCode() {
// to do a save on the handleNew()

// delete the entire sketch
Base.removeDir(folder);
Base.removeDir(data.getFolder());

// get the changes into the sketchbook menu
//sketchbook.rebuildMenus();
Expand Down Expand Up @@ -680,10 +605,7 @@ public boolean accept(File dir, String name) {
}
}

for (SketchCode code : data.getCodes()) {
if (code.isModified())
code.save();
}
data.save();
calcModified();
return true;
}
Expand Down Expand Up @@ -720,10 +642,10 @@ protected boolean saveAs() throws IOException {

if (isReadOnly() || isUntitled()) {
// default to the sketchbook folder
fd.setSelectedFile(new File(Base.getSketchbookFolder().getAbsolutePath(), folder.getName()));
fd.setSelectedFile(new File(Base.getSketchbookFolder().getAbsolutePath(), data.getFolder().getName()));
} else {
// default to the parent folder of where this was
fd.setSelectedFile(folder);
fd.setSelectedFile(data.getFolder());
}

int returnVal = fd.showSaveDialog(editor);
Expand Down Expand Up @@ -755,7 +677,7 @@ protected boolean saveAs() throws IOException {
}

// check if the paths are identical
if (newFolder.equals(folder)) {
if (newFolder.equals(data.getFolder())) {
// just use "save" here instead, because the user will have received a
// message (from the operating system) about "do you want to replace?"
return save();
Expand All @@ -764,7 +686,7 @@ protected boolean saveAs() throws IOException {
// check to see if the user is trying to save this sketch inside itself
try {
String newPath = newFolder.getCanonicalPath() + File.separator;
String oldPath = folder.getCanonicalPath() + File.separator;
String oldPath = data.getFolder().getCanonicalPath() + File.separator;

if (newPath.indexOf(oldPath) == 0) {
Base.showWarning(_("How very Borges of you"),
Expand Down Expand Up @@ -800,20 +722,20 @@ protected boolean saveAs() throws IOException {
}

// re-copy the data folder (this may take a while.. add progress bar?)
if (dataFolder.exists()) {
if (data.getDataFolder().exists()) {
File newDataFolder = new File(newFolder, "data");
Base.copyDir(dataFolder, newDataFolder);
Base.copyDir(data.getDataFolder(), newDataFolder);
}

// re-copy the code folder
if (codeFolder.exists()) {
if (data.getCodeFolder().exists()) {
File newCodeFolder = new File(newFolder, "code");
Base.copyDir(codeFolder, newCodeFolder);
Base.copyDir(data.getCodeFolder(), newCodeFolder);
}

// copy custom applet.html file if one exists
// http://dev.processing.org/bugs/show_bug.cgi?id=485
File customHtml = new File(folder, "applet.html");
File customHtml = new File(data.getFolder(), "applet.html");
if (customHtml.exists()) {
File newHtml = new File(newFolder, "applet.html");
Base.copyFile(customHtml, newHtml);
Expand Down Expand Up @@ -912,19 +834,19 @@ public boolean addFile(File sourceFile) {

//if (!codeFolder.exists()) codeFolder.mkdirs();
prepareCodeFolder();
destFile = new File(codeFolder, filename);
destFile = new File(data.getCodeFolder(), filename);

} else {
for (String extension : getExtensions()) {
for (String extension : data.getExtensions()) {
String lower = filename.toLowerCase();
if (lower.endsWith("." + extension)) {
destFile = new File(this.folder, filename);
destFile = new File(data.getFolder(), filename);
codeExtension = extension;
}
}
if (codeExtension == null) {
prepareDataFolder();
destFile = new File(dataFolder, filename);
destFile = new File(data.getDataFolder(), filename);
}
}

Expand Down Expand Up @@ -1511,14 +1433,14 @@ public boolean exportApplication(String destPath,
* but not its contents.
*/
protected void ensureExistence() {
if (folder.exists()) return;
if (data.getFolder().exists()) return;

Base.showWarning(_("Sketch Disappeared"),
_("The sketch folder has disappeared.\n " +
"Will attempt to re-save in the same location,\n" +
"but anything besides the code will be lost."), null);
try {
folder.mkdirs();
data.getFolder().mkdirs();
modified = true;

for (SketchCode code : data.getCodes()) {
Expand All @@ -1542,7 +1464,7 @@ protected void ensureExistence() {
* volumes or folders without appropriate permissions.
*/
public boolean isReadOnly() {
String apath = folder.getAbsolutePath();
String apath = data.getFolder().getAbsolutePath();
for (File folder : Base.getLibrariesPath()) {
if (apath.startsWith(folder.getAbsolutePath()))
return true;
Expand Down Expand Up @@ -1591,15 +1513,15 @@ public boolean isDefaultExtension(String what) {
* extensions.
*/
public boolean validExtension(String what) {
return getExtensions().contains(what);
return data.getExtensions().contains(what);
}


/**
* Returns the default extension for this editor setup.
*/
public String getDefaultExtension() {
return "ino";
return data.getDefaultExtension();
}

static private List<String> hiddenExtensions = Arrays.asList("ino", "pde");
Expand All @@ -1608,13 +1530,6 @@ public List<String> getHiddenExtensions() {
return hiddenExtensions;
}

/**
* Returns a String[] array of proper extensions.
*/
public List<String> getExtensions() {
return Arrays.asList("ino", "pde", "c", "cpp", "h");
}


// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Expand All @@ -1630,36 +1545,19 @@ public String getName() {
}


/**
* Returns a file object for the primary .pde of this sketch.
*/
public File getPrimaryFile() {
return primaryFile;
}


/**
* Returns path to the main .pde file for this sketch.
*/
public String getMainFilePath() {
return primaryFile.getAbsolutePath();
//return code[0].file.getAbsolutePath();
return data.getMainFilePath();
}


/**
* Returns the sketch folder.
*/
public File getFolder() {
return folder;
}


/**
* Returns the location of the sketch's data folder. (It may not exist yet.)
*/
public File getDataFolder() {
return dataFolder;
return data.getFolder();
}


Expand All @@ -1668,18 +1566,10 @@ public File getDataFolder() {
* it also returns the data folder, since it's likely about to be used.
*/
public File prepareDataFolder() {
if (!dataFolder.exists()) {
dataFolder.mkdirs();
if (!data.getDataFolder().exists()) {
data.getDataFolder().mkdirs();
}
return dataFolder;
}


/**
* Returns the location of the sketch's code folder. (It may not exist yet.)
*/
public File getCodeFolder() {
return codeFolder;
return data.getDataFolder();
}


Expand All @@ -1688,10 +1578,10 @@ public File getCodeFolder() {
* it also returns the code folder, since it's likely about to be used.
*/
public File prepareCodeFolder() {
if (!codeFolder.exists()) {
codeFolder.mkdirs();
if (!data.getCodeFolder().exists()) {
data.getCodeFolder().mkdirs();
}
return codeFolder;
return data.getCodeFolder();
}


Expand Down
Loading