mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-30 19:52:13 +01:00
Working on how sketches are marked readonly.
Initial refactorings: stopped using static members (static is evil)
This commit is contained in:
parent
cb292d6114
commit
52fd3845ca
@ -1772,10 +1772,6 @@ public class Base {
|
|||||||
return boardsCustomMenus;
|
return boardsCustomMenus;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public String getSketchbookLibrariesPath() {
|
|
||||||
return BaseNoGui.getSketchbookLibrariesFolder().getAbsolutePath();
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getDefaultSketchbookFolderOrPromptForIt() {
|
public File getDefaultSketchbookFolderOrPromptForIt() {
|
||||||
|
|
||||||
File sketchbookFolder = BaseNoGui.getDefaultSketchbookFolder();
|
File sketchbookFolder = BaseNoGui.getDefaultSketchbookFolder();
|
||||||
|
@ -93,7 +93,7 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(Sketch sketch) {
|
public boolean test(Sketch sketch) {
|
||||||
return PreferencesData.getBoolean("editor.save_on_verify") && sketch.isModified() && !sketch.isReadOnly();
|
return PreferencesData.getBoolean("editor.save_on_verify") && sketch.isModified() && !sketch.isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(Sketch sketch) {
|
public boolean test(Sketch sketch) {
|
||||||
return sketch.isReadOnly();
|
return sketch.isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2282,7 +2282,7 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
statusNotice(tr("Saving..."));
|
statusNotice(tr("Saving..."));
|
||||||
boolean saved = false;
|
boolean saved = false;
|
||||||
try {
|
try {
|
||||||
boolean wasReadOnly = sketch.isReadOnly();
|
boolean wasReadOnly = sketch.isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath());
|
||||||
String previousMainFilePath = sketch.getMainFilePath();
|
String previousMainFilePath = sketch.getMainFilePath();
|
||||||
saved = sketch.save();
|
saved = sketch.save();
|
||||||
if (saved) {
|
if (saved) {
|
||||||
@ -2395,7 +2395,7 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
*/
|
*/
|
||||||
synchronized public void handleExport(final boolean usingProgrammer) {
|
synchronized public void handleExport(final boolean usingProgrammer) {
|
||||||
if (PreferencesData.getBoolean("editor.save_on_verify")) {
|
if (PreferencesData.getBoolean("editor.save_on_verify")) {
|
||||||
if (sketch.isModified() && !sketch.isReadOnly()) {
|
if (sketch.isModified() && !sketch.isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) {
|
||||||
handleSave(true);
|
handleSave(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ public class Sketch {
|
|||||||
ensureExistence();
|
ensureExistence();
|
||||||
|
|
||||||
// if read-only, give an error
|
// if read-only, give an error
|
||||||
if (isReadOnly()) {
|
if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) {
|
||||||
// if the files are read-only, need to first do a "save as".
|
// if the files are read-only, need to first do a "save as".
|
||||||
Base.showMessage(tr("Sketch is Read-Only"),
|
Base.showMessage(tr("Sketch is Read-Only"),
|
||||||
tr("Some files are marked \"read-only\", so you'll\n" +
|
tr("Some files are marked \"read-only\", so you'll\n" +
|
||||||
@ -162,7 +162,7 @@ public class Sketch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if read-only, give an error
|
// if read-only, give an error
|
||||||
if (isReadOnly()) {
|
if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) {
|
||||||
// if the files are read-only, need to first do a "save as".
|
// if the files are read-only, need to first do a "save as".
|
||||||
Base.showMessage(tr("Sketch is Read-Only"),
|
Base.showMessage(tr("Sketch is Read-Only"),
|
||||||
tr("Some files are marked \"read-only\", so you'll\n" +
|
tr("Some files are marked \"read-only\", so you'll\n" +
|
||||||
@ -432,7 +432,7 @@ public class Sketch {
|
|||||||
ensureExistence();
|
ensureExistence();
|
||||||
|
|
||||||
// if read-only, give an error
|
// if read-only, give an error
|
||||||
if (isReadOnly()) {
|
if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) {
|
||||||
// if the files are read-only, need to first do a "save as".
|
// if the files are read-only, need to first do a "save as".
|
||||||
Base.showMessage(tr("Sketch is Read-Only"),
|
Base.showMessage(tr("Sketch is Read-Only"),
|
||||||
tr("Some files are marked \"read-only\", so you'll\n" +
|
tr("Some files are marked \"read-only\", so you'll\n" +
|
||||||
@ -558,7 +558,7 @@ public class Sketch {
|
|||||||
// don't do anything if not actually modified
|
// don't do anything if not actually modified
|
||||||
//if (!modified) return false;
|
//if (!modified) return false;
|
||||||
|
|
||||||
if (isReadOnly()) {
|
if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) {
|
||||||
// if the files are read-only, need to first do a "save as".
|
// if the files are read-only, need to first do a "save as".
|
||||||
Base.showMessage(tr("Sketch is read-only"),
|
Base.showMessage(tr("Sketch is read-only"),
|
||||||
tr("Some files are marked \"read-only\", so you'll\n" +
|
tr("Some files are marked \"read-only\", so you'll\n" +
|
||||||
@ -637,7 +637,7 @@ public class Sketch {
|
|||||||
protected boolean saveAs() throws IOException {
|
protected boolean saveAs() throws IOException {
|
||||||
// get new name for folder
|
// get new name for folder
|
||||||
FileDialog fd = new FileDialog(editor, tr("Save sketch folder as..."), FileDialog.SAVE);
|
FileDialog fd = new FileDialog(editor, tr("Save sketch folder as..."), FileDialog.SAVE);
|
||||||
if (isReadOnly() || isUntitled()) {
|
if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath()) || isUntitled()) {
|
||||||
// default to the sketchbook folder
|
// default to the sketchbook folder
|
||||||
fd.setDirectory(BaseNoGui.getSketchbookFolder().getAbsolutePath());
|
fd.setDirectory(BaseNoGui.getSketchbookFolder().getAbsolutePath());
|
||||||
} else {
|
} else {
|
||||||
@ -772,7 +772,7 @@ public class Sketch {
|
|||||||
ensureExistence();
|
ensureExistence();
|
||||||
|
|
||||||
// if read-only, give an error
|
// if read-only, give an error
|
||||||
if (isReadOnly()) {
|
if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) {
|
||||||
// if the files are read-only, need to first do a "save as".
|
// if the files are read-only, need to first do a "save as".
|
||||||
Base.showMessage(tr("Sketch is Read-Only"),
|
Base.showMessage(tr("Sketch is Read-Only"),
|
||||||
tr("Some files are marked \"read-only\", so you'll\n" +
|
tr("Some files are marked \"read-only\", so you'll\n" +
|
||||||
@ -1223,25 +1223,27 @@ public class Sketch {
|
|||||||
* Returns true if this is a read-only sketch. Used for the
|
* Returns true if this is a read-only sketch. Used for the
|
||||||
* examples directory, or when sketches are loaded from read-only
|
* examples directory, or when sketches are loaded from read-only
|
||||||
* volumes or folders without appropriate permissions.
|
* volumes or folders without appropriate permissions.
|
||||||
|
* @param librariesPaths
|
||||||
|
* @param examplesPath
|
||||||
*/
|
*/
|
||||||
public boolean isReadOnly() {
|
public boolean isReadOnly(List<File> librariesPaths, String examplesPath) {
|
||||||
String apath = data.getFolder().getAbsolutePath();
|
String apath = data.getFolder().getAbsolutePath();
|
||||||
for (File folder : BaseNoGui.getLibrariesPath()) {
|
for (File folder : librariesPaths) {
|
||||||
if (apath.startsWith(folder.getAbsolutePath()))
|
if (apath.startsWith(folder.getAbsolutePath())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (apath.startsWith(BaseNoGui.getExamplesPath()) ||
|
|
||||||
apath.startsWith(Base.getSketchbookLibrariesPath())) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// canWrite() doesn't work on directories
|
return sketchIsSystemExample(apath, examplesPath) || sketchFilesAreReadOnly();
|
||||||
// } else if (!folder.canWrite()) {
|
}
|
||||||
|
|
||||||
// check to see if each modified code file can be written to
|
private boolean sketchIsSystemExample(String apath, String examplesPath) {
|
||||||
|
return apath.startsWith(examplesPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean sketchFilesAreReadOnly() {
|
||||||
for (SketchCode code : data.getCodes()) {
|
for (SketchCode code : data.getCodes()) {
|
||||||
if (code.isModified() && code.fileReadOnly() && code.fileExists()) {
|
if (code.isModified() && code.fileReadOnly() && code.fileExists()) {
|
||||||
// System.err.println("found a read-only file " + code[i].file);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,9 +69,6 @@ public class BaseNoGui {
|
|||||||
// maps #included files to their library folder
|
// maps #included files to their library folder
|
||||||
public static Map<String, LibraryList> importToLibraryTable;
|
public static Map<String, LibraryList> importToLibraryTable;
|
||||||
|
|
||||||
// maps library name to their library folder
|
|
||||||
static private LibraryList libraries;
|
|
||||||
|
|
||||||
// XXX: Remove this field
|
// XXX: Remove this field
|
||||||
static private List<File> librariesFolders;
|
static private List<File> librariesFolders;
|
||||||
|
|
||||||
@ -237,10 +234,6 @@ public class BaseNoGui {
|
|||||||
return getHardwareFolder().getAbsolutePath();
|
return getHardwareFolder().getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
static public LibraryList getLibraries() {
|
|
||||||
return libraries;
|
|
||||||
}
|
|
||||||
|
|
||||||
static public List<File> getLibrariesPath() {
|
static public List<File> getLibrariesPath() {
|
||||||
return librariesFolders;
|
return librariesFolders;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user