Commit Graph

558 Commits

Author SHA1 Message Date
Cristian Maglie 5244daa5d1 Use the same Comparator to sort EditorTab and SketchFile 2016-11-07 12:13:30 +01:00
Cristian Maglie c35469ea81 Updated translations strings 2016-11-07 10:48:18 +01:00
Cristian Maglie 8c5b064956 Added error message if a referenced core is not found 2016-11-07 10:48:04 +01:00
Martino Facchin 12eb09f0b9 Fix NPE if referred core is nonexistent
Fixes #5502
2016-10-27 12:46:44 +02:00
Cristian Maglie 31a9029c1d Updated i18n strings 2016-10-05 15:55:32 +02:00
Cristian Maglie 7883835b84 If an archive is corrupted (CRC error) retry the download
Previously the CRC error was quite annoying to recover because
the user needed to manually delete the corrupted file from the
staging folder (without knowing the exact path of the file to
remove).

Now the IDE tries autonomously to resolve the situation by
removing the file and downloading it again.

Fixes #5394 #4303
2016-10-05 12:56:40 +02:00
Cristian Maglie 653a05273d Check sanitaryName only on basename without extension
This regression originates from:

8725bb1e Clean up sketch loading

before this commit the sketch name sanitization was made on the sketch
name without the extension.
After 8725bb1e instead the name sanitization is made on the filename, so
including the ".ino" extension.

This lead to a weird corner case, caused by the limit of 63 characters
on the sketch name: before 8725bb1e it would be possible to save a sketch
with a name of exactly 63 characters, but after 8725bb1e this sketch will
suddenly becomes invalid becuase the 63 chars name + extension would exceed
the 63 characters limit.

This commit fix this regression.

Fix #5431
2016-10-03 17:00:08 +02:00
Martino Facchin 0a8e7a14f1 Make sure DiscoveryManager is not null when calling it
Solves #5413
2016-10-03 11:07:10 +02:00
Cristian Maglie ec2e9a642a Added all missing @Override annotations 2016-09-29 20:15:57 +02:00
Cristian Maglie 46dfd7603c Removed warning about accessing a non-accessible member of an enclosing type 2016-09-29 20:15:56 +02:00
Cristian Maglie bd7e76533a Removed redundant type specifiers for generics 2016-09-29 20:15:56 +02:00
Cristian Maglie 72a1d928b4 Removed useless cast 2016-09-29 20:15:56 +02:00
Cristian Maglie 4d579f7652 Removed extra semicolon 2016-09-29 20:15:56 +02:00
Cristian Maglie 53e456936d Silenced lint warnings in ContributedLibrary
Comparing strings with `==` operator triggers a lint4j warning.
This refactoring avoids the use of `thisVersion == otherVersion`.
2016-09-29 20:15:55 +02:00
Cristian Maglie 5c097c03c5 Fixed regression: trivial error on String comparison
Fix #5423

The regression has been introduced in:
72f815b Refactor file adding and renaming, and save as handling
2016-09-29 18:21:09 +02:00
Martino Facchin 69fd6debbd Starting version 1.6.13 2016-09-22 12:42:35 +02:00
Cristian Maglie e1c2d0dfcd Updated translations from transifex 2016-09-21 10:07:01 +02:00
Cristian Maglie 0ddc8e6300 Fixed wrong string check 2016-08-31 19:12:09 +02:00
Cristian Maglie 7d27c43ff2 Launch DiscoveryManager after populating indexes 2016-08-31 19:11:24 +02:00
Martino Facchin 84ede60df8 Start board discovery after loading all platforms 2016-08-30 16:22:40 +02:00
Martino Facchin e3177a5ed8 Starting version 1.6.12 2016-08-26 18:27:00 +02:00
Martino Facchin 29e79c8157 update API to v1 2016-08-26 16:42:44 +02:00
Martino Facchin efc07a1c0e Add Cloud API integration
This method discovers if a connected board needs an additional core and helps the user downloading it via BoardManager
2016-08-26 16:42:44 +02:00
Matthijs Kooijman 59b70c8373 Randomize the the build path name
Previously, this used a hash of the sketch filename, so the same build
path would be generated for the same sketch between multiple
compilations. Now that the build path is stored, this requirement has
disappeared, so a random filename can be generated again. While here,
this commit also changes the prefix from "build" to "arduino_build_",
which makes it a bit more clear what the directory's purpose is.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman 4f0af2af57 Store the build path used in Sketch
Previously, everywhere where it was needed, the path was requested from
BaseNoGui. Because the path is based on a hash of the sketch filename,
every caller would get the same path for the same sketch.

However, it makes more sense to store the path used for a given sketch
inside the Sketch object. This prevents having to pass around or
regenerate the build path everywhere, and no longer requires the build
path to be deterministic (though it still is in this commit).

This allows removing some methods and constructors of which two versions
were available - one with a build path argument and one without.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman c4e77a7c3c Let SketchFile figure out if it is primary by itself
Previously, the caller of the constructor did this, but now that
SketchFile keeps a reference to its containing sketch, it can figure it
out itself.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman 1d15c434dc Let `SketchFile.delete()` call `Sketch.removeFile()`
Previously, callers of `SketchFile.delete()` would also call
`Sketch.removeFile()`, but letting SketchFile handle this is more
robust.

This is possible now that SketchFile keeps a reference to Sketch and
makes updating the Sketch file list less fragile.

Eventually this might be further decoupled by letting SketchFile
broadcast a "deleted" event instead.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman aae0bc4c47 Rename `SketchFile.deleteFile()` to `delete()`
The extra "File" in the name was a bit redundant, and this is more
consistent with `Sketch.delete()`.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman ccec28ea45 Move sketch deletion from SketchController into Sketch
This isn't much code, but it makes deletion more consistent with
renaming and saving with the SketchController handling the UI part and
Sketch actually doing the delete.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman 85d48394a4 Merge `Sketch.renameFileTo()` into `SketchFile.renameTo()`
Now that SketchFile keeps a reference to its Sketch,
`SketchFile.renameTo()` can call `Sketch.checkNewFilename()`, so there
is no need for the renaming itself to go through Sketch.

This changes the parameter for `SketchFile.renameTo()` from File to
String, to enforce that only the filename is changed, not the directory
name.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman 74e5228a0f Let SketchFile store a reference to the Sketch it belongs to
This allows simplifying some other things later.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman c0f41cae5d Remove `Base.removeDir()` and `Base.removeDescendants()`
These methods shouldn't really be in Base (or BaseNoGui, which did the
actual work), especially since there is already a
`FileUtils.recursiveDelete()` which just does the same thing. This
commit removes the code from Base and BaseNoGui and instead uses the
method from FileUtils.

There is one difference between these methods: the Base methods did not
delete files if the "compiler.save_build_files" preference was set.
However, the Base methods were only used when deleting a sketch, or
deleting an existing folder before overwriting it on save as, so this
preference didn't actually do what it was supposed to anyway, so
dropping it shouldn't be a problem.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman 72f815bcf9 Refactor file adding and renaming, and save as handling
This commits replaces a significant part of the code handling these
features. A lot of responsibilities are moved from SketchController to
Sketch, though the code involved is rewritten mostly.

Most of the handling now happens inside Sketch, including various checks
against the new filename. Basically SketchController processes the user
input to decide what needs to be done, and Sketch checks if it can be
done and does it.

If problems occur, an IOException is thrown, using a translated error
message that is shown by SketchController as-is. This might not be the
best way to transfer error messages (regular IOExceptions might contain
less-friendly messages), so this might need further improvement later.

In addition to moving around code and responsibilities, this code also
changes behaviour in some places:
 - Because Sketch and SketchFile are now in control of renames and
   saves, they can update their internal state after a rename. This
   removes the need for reloading the entire sketch after a rename or
   save as and allows `Editor.handleOpenUnchecked()` to be removed.
 - When renaming the entire sketch, all files used to be saved before
   renaming, since the sketch would be re-opened after renaming. Since
   the re-opening no longer happens, there is no longer a need to save
   the sketch, so any unsaved changes remain unsaved in the editor after
   renaming the sketch.
 - When renaming or adding new files, duplicate filenames are detected.
   Initially, this happened case sensitively, but it was later changed to
   use case insensitive matching to prevent problems on Windows (where
   filenames cannot differ in just case). To prevent complexity, this
   did not distinguish between systems. In commit 5fbf9621f6 (Sketch
   rename: allowig a case change rename if NOT on windows), the
   intention was to only do case insensitive checking on Windows, but it
   effectively disabled all checking on other systems, making the check
   not catch duplicate filenames at all.

   With this commit, all these checks are done using `File.equals()`
   instead of comparing strings, which is already aware of the case
   sensitivity of the platform and should act accordingly.
 - Some error messages were changed.
 - When adding a file, an empty file is not created directly, but only a
   SketchFile and EditorTab is added. When the sketch is saved, the file
   is created.
 - When importing a file that already exists (thus overwriting it),
   instead of replacing the SketchFile instance, this just lets the
   EditorTab reload its contents. This was broken since the introduction
   of EditorTab. The file would be replaced, but not this was not
   reflected in the editor, which is now fixed. This change allows
   `Sketch.replaceFile()` to be removed.
 - When importing a file that does not exist yet (thus adding it), a tab
   is now also added for it (in addition to a SketchFile). This was
   broken since the introduction of EditorTab, and would result in the
   file being added, but not shown in the editor.

This commit adds a `Sketch.renameFileTo()` method, to rename a single
file within the sketch. It would be better to integrate its contents
into `Sketch.renameTo()`, but that does not have access to the `Sketch`
instance it is contained in. This will be changed in a future commit.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman 9705e1e734 Use `File.getParentFile()` in Sketch constructor
No need to call the File constructor ourselves, if
`File.getParentFile()` can just do that for us.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman 57a237752d Clean up pde to ino renaming
This makes a few related changes:
 - `FileUtils.replaceExtension()` is introduced to handle replacing the
   .pde extension with .ino.
 - Instead of iterating .pde files on disk, this iterates SketchFiles in
   memory, saving another lookup from filename -> SketchFile later.
 - `SketchController.renameCodeToInoExtension()` is removed. Now it no
   longer needs to look up the SketchFile and FileUtils handles the
   extension replacement, this method did not have any reason to exist
   anymore.
 - Instead of hardcoding the .pde extension, a new
   Sketch.OLD_SKETCH_EXTENSIONS constant is introduced.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman 0c62ac8985 Do not store the sketch name in Sketch
Sketch already stores the sketch folder, and the sketch name should be
identical to the folder name. In the case where the filename passed to
the sketch constructor is not the primary .ino file (named after the
sketch), this will slightly change behaviour. However, the calling code
should prevent this from happening, and with the old code, some internal
assumptions were probably violated, so this changes makes handling this
situation a bit more robust.

Since the actual filename passed to Sketch is no longer used, it is no
longer required to pass the name of the primary .ino file. At some
point, the constructor should probably be changed to accept a folder
name instead of a filename, but that would require a lot of changes
to trace this back through the code, so this is something for later.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman 7a73d0b3db Change `Compiler.pathToSketch` from String to File
Keeping filenames as File objects for as long as possible is generally a
good idea and this removes a dependency on `Sketch.getMainFilePath()`,
so it can be removed later.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman 959fba7865 Let Sketch.getPrimaryFile return a SketchFile
Previously, it returned a File object, which the Sketch separately
stored from the primary SketchFile. By letting it just return the
SketchFile, and let callers query that for the filename, Sketch does not
need to store the File object itself and there is less chance of info
getting out of sync.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman 86d20b8726 Do not store the "data" folder in Sketch
Instead, just the File object when requested. It is not used during
normal operation (just when adding files, or using save as), so no point
in already creating the object in the constructor.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman 8e0d007ce2 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.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman dfa60dacc1 Store a SketchCode instance in RunnerException
Previously, the index of the SketchCode instance in the list kept by
Sketch was kept, which isn't really robust.

With this change, Sketch.indexOfCode is no longer needed and is removed.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman a07a9ff895 Move `SketchController.prepareDataFolder()` to Sketch 2016-08-26 16:42:44 +02:00
Matthijs Kooijman a4e2e80c1c Let importLibrary use `Sketch.SKETCH_EXTENSIONS`
For determining if the current file was a sketch file, it previously
(indirectly) used a hardcoded "ino" comparison. Now, it uses
`SKETCH_EXTENSIONS` so it also applies to .pde files and the hardcoded
"ino" (and the methods leading up to it) can be removed.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman 5e68b66c5e Clean up SketchController.nameCode a bit
This lets it use FileUtils.splitFilename and reference Sketch.EXTENSIONS
and the new Sketch.DEFAULT_SKETCH_EXTENSION directly, allowing to remove
a few helper functions.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman d70900e5ad Let `Sketch.getPrettyName()` hide extension for .ino and .pde only
Before, `getPrettyName()` would return the extension-less name for all
files. There were a lot of places that checked for .ino and/or .pde
files and and called `getPrettyName()` for those, and `getFileName()`
for others. By moving this check into `getPrettyName()`, all those
callers become more simple, and more consistent (there were 5 different
checks to basically achieve the same thing).

There are small changes in behaviour, where .pde is now also hidden but
was not before. Also, the print header now shows extensions for other
files, which makes it more consistent with the tab names. For cases
where the old behaviour was still required, `Sketch.getBaseName()` was
added.

At the same time, the actual handling of the filenames is simplified by
using methods from FileUtils.

With this change `Sketch.getFileNameWithExtensionIfNotIno()` and
`SketchController.getHiddenExtensions()` are no longer needed and are
removed.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman dd5c1787fd Move `isModified()` from SketchController to Sketch
Also, update any code that uses it, removing the dependency on
SketchController entirely if possible.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman 629953e20d Rename Sketch and SketchData classes
Sketch is now called SketchController, since it didn't really represent
a sketch, but just handled the GUI-related stuff for a given sketch
(note that it is not strictly a controller in the MVC-sense, but it does
have a similar function). SketchData more accurately represented the
actual sketch, so it is now called Sketch. Below, the new names are
used.

Editor now keeps both a current Sketch and SketchController object, and
the Sketch object is created by Editor and passed to SketchController,
instead passing a File and letting SketchController create the Sketch.
Wherever possible, code now uses the Sketch directly (or indirectly,
through the new `SketchController.getSketch()`) and the accessors in
SketchController that merely forwarded to Sketch have been removed.
There are few things that now live in SketchController but should be
moved to Sketch (`isModified()`, `isUntitled()`), so some of the code
still has a dependency on SketchController that should be removed later.

This commit mostly renames classes, methods and variables, it should not
change the behaviour in any way.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman f3d8ba219f Remove support for a "code" folder in sketches
When adding a file to a sketch (using drag and drop, or the Sketch ->
Add file... menu item), .o, .a and .so files would be saved into a
"code" subdirectory of the sketch. This seems to be a remnant of
processing, where also .dll and .jar files could be added to a sketch to
be used. In the Arduino IDE, these code files serve no special purpose,
and are not treated specially, so it makes no sense to keep this code
around.

One implication of this is that when "save as" is used, a "code"
subdirectory is no longer copied, which might affect people using this
"code" subdirectory for other purposes.

Similarly, there is support for a "data" subdirectory, in which all
other files (that are not sketch source files) are stored, and which is
also copied on "save as". Support for this folder is kept intact, since
this appears occasionally used (the ESP8266 project uses it to store and
upload additional data files, for example).

This change was discussed on the mailing list in the "Anyone using
"data" and "code" subdirectories in sketches?" thread:
https://groups.google.com/a/arduino.cc/forum/#!msg/developers/zPlraPq55ho/ejrLqITnAgAJ
2016-08-26 16:42:44 +02:00
Matthijs Kooijman 31284feb9b Merge `SketchData.sortCodes()` into `addCode()`
By now, all calls to `addCode()` were followed by a call to
`sortCodes()`, and it seems like a task for SketchData to keep its list
sorted. Previously, this separation made some sense, since `addCode()`
was also used while loading a sketch, and you would only want to sort
once. Now, sketch loading uses a SortedSet, so this is no longer a
requirement.
2016-08-26 16:42:44 +02:00
Matthijs Kooijman f7fdd08695 Do not show invalid sketch filename warnings on reload
With this commit, any warnings about invalid sketch filenames are not
shown when the sketch is reloaded. This reloading happens whenever the
IDE window is focused, so re-logging warnings all the time isn't really
helpful, so this hides them.
2016-08-26 16:42:44 +02:00