mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-22 08:22:04 +03:00
Merge remote-tracking branch 'arduino/ide-1.5.x' into HEAD
This commit is contained in:
@ -654,7 +654,10 @@ public class Base {
|
||||
|
||||
// Make an empty pde file
|
||||
File newbieFile = new File(newbieDir, newbieName + ".ino");
|
||||
new FileOutputStream(newbieFile); // create the file
|
||||
if (!newbieFile.createNewFile()) {
|
||||
throw new IOException();
|
||||
}
|
||||
FileUtils.copyFile(new File(getContentFile("examples"), "01.Basics" + File.separator + "BareMinimum" + File.separator + "BareMinimum.ino"), newbieFile);
|
||||
return newbieFile.getAbsolutePath();
|
||||
}
|
||||
|
||||
|
77
app/src/processing/app/CaretAwareUndoableEdit.java
Normal file
77
app/src/processing/app/CaretAwareUndoableEdit.java
Normal file
@ -0,0 +1,77 @@
|
||||
package processing.app;
|
||||
|
||||
import processing.app.syntax.JEditTextArea;
|
||||
|
||||
import javax.swing.undo.CannotRedoException;
|
||||
import javax.swing.undo.CannotUndoException;
|
||||
import javax.swing.undo.UndoableEdit;
|
||||
|
||||
public class CaretAwareUndoableEdit implements UndoableEdit {
|
||||
|
||||
private final UndoableEdit undoableEdit;
|
||||
private final int caretPosition;
|
||||
|
||||
public CaretAwareUndoableEdit(UndoableEdit undoableEdit, JEditTextArea textArea) {
|
||||
this.undoableEdit = undoableEdit;
|
||||
this.caretPosition = textArea.getCaretPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() throws CannotUndoException {
|
||||
undoableEdit.undo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return undoableEdit.canUndo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redo() throws CannotRedoException {
|
||||
undoableEdit.redo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRedo() {
|
||||
return undoableEdit.canRedo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void die() {
|
||||
undoableEdit.die();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addEdit(UndoableEdit undoableEdit) {
|
||||
return this.undoableEdit.addEdit(undoableEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replaceEdit(UndoableEdit undoableEdit) {
|
||||
return this.undoableEdit.replaceEdit(undoableEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSignificant() {
|
||||
return undoableEdit.isSignificant();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPresentationName() {
|
||||
return undoableEdit.getPresentationName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUndoPresentationName() {
|
||||
return undoableEdit.getUndoPresentationName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRedoPresentationName() {
|
||||
return undoableEdit.getRedoPresentationName();
|
||||
}
|
||||
|
||||
public int getCaretPosition() {
|
||||
return caretPosition;
|
||||
}
|
||||
}
|
@ -137,7 +137,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
JMenuItem undoItem, redoItem;
|
||||
protected UndoAction undoAction;
|
||||
protected RedoAction redoAction;
|
||||
UndoManager undo;
|
||||
LastUndoableEditAwareUndoManager undo;
|
||||
// used internally, and only briefly
|
||||
CompoundEdit compoundEdit;
|
||||
|
||||
@ -476,7 +476,6 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
|
||||
protected void buildMenuBar() {
|
||||
JMenuBar menubar = new JMenuBar();
|
||||
menubar = new JMenuBar();
|
||||
menubar.add(buildFileMenu());
|
||||
menubar.add(buildEditMenu());
|
||||
menubar.add(buildSketchMenu());
|
||||
@ -1344,6 +1343,10 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
//System.out.println("Unable to undo: " + ex);
|
||||
//ex.printStackTrace();
|
||||
}
|
||||
if (undo.getLastUndoableEdit() != null && undo.getLastUndoableEdit() instanceof CaretAwareUndoableEdit) {
|
||||
CaretAwareUndoableEdit undoableEdit = (CaretAwareUndoableEdit) undo.getLastUndoableEdit();
|
||||
textarea.setCaretPosition(undoableEdit.getCaretPosition() - 1);
|
||||
}
|
||||
updateUndoState();
|
||||
redoAction.updateRedoState();
|
||||
}
|
||||
@ -1383,6 +1386,10 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
//System.out.println("Unable to redo: " + ex);
|
||||
//ex.printStackTrace();
|
||||
}
|
||||
if (undo.getLastUndoableEdit() != null && undo.getLastUndoableEdit() instanceof CaretAwareUndoableEdit) {
|
||||
CaretAwareUndoableEdit undoableEdit = (CaretAwareUndoableEdit) undo.getLastUndoableEdit();
|
||||
textarea.setCaretPosition(undoableEdit.getCaretPosition());
|
||||
}
|
||||
updateRedoState();
|
||||
undoAction.updateUndoState();
|
||||
}
|
||||
@ -1664,7 +1671,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
compoundEdit.addEdit(e.getEdit());
|
||||
|
||||
} else if (undo != null) {
|
||||
undo.addEdit(e.getEdit());
|
||||
undo.addEdit(new CaretAwareUndoableEdit(e.getEdit(), textarea));
|
||||
undoAction.updateUndoState();
|
||||
redoAction.updateRedoState();
|
||||
}
|
||||
|
31
app/src/processing/app/LastUndoableEditAwareUndoManager.java
Normal file
31
app/src/processing/app/LastUndoableEditAwareUndoManager.java
Normal file
@ -0,0 +1,31 @@
|
||||
package processing.app;
|
||||
|
||||
import javax.swing.undo.CannotRedoException;
|
||||
import javax.swing.undo.CannotUndoException;
|
||||
import javax.swing.undo.UndoManager;
|
||||
import javax.swing.undo.UndoableEdit;
|
||||
|
||||
public class LastUndoableEditAwareUndoManager extends UndoManager {
|
||||
|
||||
private UndoableEdit lastUndoableEdit;
|
||||
|
||||
public LastUndoableEditAwareUndoManager() {
|
||||
this.lastUndoableEdit = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void undo() throws CannotUndoException {
|
||||
lastUndoableEdit = super.editToBeUndone();
|
||||
super.undo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void redo() throws CannotRedoException {
|
||||
lastUndoableEdit = super.editToBeRedone();
|
||||
super.redo();
|
||||
}
|
||||
|
||||
public UndoableEdit getLastUndoableEdit() {
|
||||
return lastUndoableEdit;
|
||||
}
|
||||
}
|
@ -76,7 +76,7 @@ public class Platform {
|
||||
public File getSettingsFolder() throws Exception {
|
||||
// otherwise make a .processing directory int the user's home dir
|
||||
File home = new File(System.getProperty("user.home"));
|
||||
File dataFolder = new File(home, ".arduino");
|
||||
File dataFolder = new File(home, ".arduino15");
|
||||
return dataFolder;
|
||||
|
||||
/*
|
||||
|
@ -27,7 +27,7 @@ package processing.app;
|
||||
import java.io.*;
|
||||
|
||||
import javax.swing.text.Document;
|
||||
import javax.swing.undo.*;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
|
||||
@ -55,7 +55,7 @@ public class SketchCode {
|
||||
* Editor.undo will be set to this object when this code is the tab
|
||||
* that's currently the front.
|
||||
*/
|
||||
private UndoManager undo = new UndoManager();
|
||||
private LastUndoableEditAwareUndoManager undo = new LastUndoableEditAwareUndoManager();
|
||||
|
||||
// saved positions from last time this tab was used
|
||||
private int selectionStart;
|
||||
@ -221,7 +221,7 @@ public class SketchCode {
|
||||
}
|
||||
|
||||
|
||||
public UndoManager getUndo() {
|
||||
public LastUndoableEditAwareUndoManager getUndo() {
|
||||
return undo;
|
||||
}
|
||||
|
||||
|
@ -32,20 +32,22 @@ import processing.app.helpers.filefilters.OnlyDirs;
|
||||
|
||||
public class TargetPackage {
|
||||
|
||||
String name;
|
||||
File folder;
|
||||
private final String name;
|
||||
|
||||
Map<String, TargetPlatform> platforms = new HashMap<String, TargetPlatform>();
|
||||
|
||||
public TargetPackage(String _name, File _folder) {
|
||||
name = _name;
|
||||
folder = _folder;
|
||||
public TargetPackage(String name, File folder) {
|
||||
this.name = name;
|
||||
|
||||
String[] platformsList = folder.list(new OnlyDirs());
|
||||
for (String platformName : platformsList) {
|
||||
File platformFolder = new File(folder, platformName);
|
||||
TargetPlatform platform = new TargetPlatform(platformName, platformFolder);
|
||||
platforms.put(platformName, platform);
|
||||
if (platformsList != null) {
|
||||
for (String platformName : platformsList) {
|
||||
File platformFolder = new File(folder, platformName);
|
||||
if (platformFolder.exists() && platformFolder.canRead()) {
|
||||
TargetPlatform platform = new TargetPlatform(platformName, platformFolder);
|
||||
platforms.put(platformName, platform);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ public class TargetPlatform {
|
||||
|
||||
try {
|
||||
File boardsFile = new File(_folder, "boards.txt");
|
||||
if (boardsFile.exists()) {
|
||||
if (boardsFile.exists() && boardsFile.canRead()) {
|
||||
PreferencesMap boardPreferences = new PreferencesMap();
|
||||
boardPreferences.load(boardsFile);
|
||||
boards = boardPreferences.createFirstLevelMap();
|
||||
@ -69,15 +69,16 @@ public class TargetPlatform {
|
||||
|
||||
try {
|
||||
File platformsFile = new File(_folder, "platform.txt");
|
||||
if (platformsFile.exists())
|
||||
if (platformsFile.exists() && platformsFile.canRead()) {
|
||||
preferences.load(platformsFile);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error loading platforms from platform.txt: " + e);
|
||||
}
|
||||
|
||||
try {
|
||||
File programmersFile = new File(_folder, "programmers.txt");
|
||||
if (programmersFile.exists()) {
|
||||
if (programmersFile.exists() && programmersFile.canRead()) {
|
||||
PreferencesMap prefs = new PreferencesMap();
|
||||
prefs.load(programmersFile);
|
||||
programmers = prefs.createFirstLevelMap();
|
||||
|
@ -35,6 +35,27 @@ public class FileUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void copyFile(File source, File dest) throws IOException {
|
||||
FileInputStream fis = null;
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fis = new FileInputStream(source);
|
||||
fos = new FileOutputStream(dest);
|
||||
byte[] buf = new byte[4096];
|
||||
int readBytes = -1;
|
||||
while ((readBytes = fis.read(buf, 0, buf.length)) != -1) {
|
||||
fos.write(buf, 0, readBytes);
|
||||
}
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
fis.close();
|
||||
}
|
||||
if (fos != null) {
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void copy(File sourceFolder, File destFolder) throws IOException {
|
||||
for (File file : sourceFolder.listFiles()) {
|
||||
File destFile = new File(destFolder, file.getName());
|
||||
@ -44,24 +65,7 @@ public class FileUtils {
|
||||
}
|
||||
copy(file, destFile);
|
||||
} else {
|
||||
FileInputStream fis = null;
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
fos = new FileOutputStream(destFile);
|
||||
byte[] buf = new byte[4096];
|
||||
int readBytes = -1;
|
||||
while ((readBytes = fis.read(buf, 0, buf.length)) != -1) {
|
||||
fos.write(buf, 0, readBytes);
|
||||
}
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
fis.close();
|
||||
}
|
||||
if (fos != null) {
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
copyFile(file, destFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class PreferencesMap extends LinkedHashMap<String, String> {
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
*/
|
||||
public void load(File file) throws FileNotFoundException, IOException {
|
||||
public void load(File file) throws IOException {
|
||||
load(new FileInputStream(file));
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ public class Platform extends processing.app.Platform {
|
||||
|
||||
|
||||
public File getSettingsFolder() throws Exception {
|
||||
return new File(getLibraryFolder(), "Arduino");
|
||||
return new File(getLibraryFolder(), "Arduino15");
|
||||
}
|
||||
|
||||
|
||||
|
@ -188,7 +188,7 @@ public class Platform extends processing.app.Platform {
|
||||
String appDataPath =
|
||||
Registry.getStringValue(REGISTRY_ROOT_KEY.CURRENT_USER, keyPath, "AppData");
|
||||
|
||||
File dataFolder = new File(appDataPath, "Arduino");
|
||||
File dataFolder = new File(appDataPath, "Arduino15");
|
||||
return dataFolder;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user