mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-26 20:54:22 +01:00
Merge 3e3593d23d8262e74c5f3afefe01ec6713829bee into 3278173ef810935e07808deed58783c1bc7ca4cf
This commit is contained in:
commit
edf76dc215
@ -1779,6 +1779,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
|
||||
} else {
|
||||
String properParent = fileName.substring(0, fileName.length() - 4);
|
||||
File properFolder;
|
||||
|
||||
Object[] options = {tr("OK"), tr("Cancel")};
|
||||
String prompt = I18n.format(tr("The file \"{0}\" needs to be inside\n" +
|
||||
@ -1787,36 +1788,61 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
fileName,
|
||||
properParent);
|
||||
|
||||
int result = JOptionPane.showOptionDialog(this, prompt, tr("Moving"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
|
||||
properFolder = new File(sketchFile.getParent(), properParent);
|
||||
|
||||
int result;
|
||||
if (parentFolderContainsSketchName(sketchFile, properParent)) {
|
||||
|
||||
// properFolder needs to be created one level above
|
||||
properFolder = new File(new File(sketchFile.getParent()).getParent(), properParent);
|
||||
|
||||
// ask for different confirmation
|
||||
prompt = I18n.format(tr("The file \"{0}\" needs to be inside\n" +
|
||||
"a sketch folder named \"{1}\".\n" +
|
||||
"Renaming folder \"{2}\" into \"{3}\"\n" +
|
||||
"Continue?"),
|
||||
fileName,
|
||||
properParent,
|
||||
sketchFile.getParent(),
|
||||
properFolder);
|
||||
|
||||
result = JOptionPane.showOptionDialog(this, prompt, tr("Renaming"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
|
||||
} else {
|
||||
result = JOptionPane.showOptionDialog(this, prompt, tr("Moving"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
|
||||
}
|
||||
|
||||
if (result != JOptionPane.YES_OPTION) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// create properly named folder
|
||||
File properFolder = new File(sketchFile.getParent(), properParent);
|
||||
if (properFolder.exists()) {
|
||||
Base.showWarning(tr("Error"), I18n.format(tr("A folder named \"{0}\" already exists. " +
|
||||
"Can't open sketch."), properParent), null);
|
||||
return false;
|
||||
}
|
||||
|
||||
// copy the sketch inside
|
||||
File properPdeFile = new File(properFolder, sketchFile.getName());
|
||||
try {
|
||||
if (parentFolderContainsSketchName(sketchFile, properParent)) {
|
||||
File dir = new File(sketchFile.getParent());
|
||||
dir.renameTo(properFolder);
|
||||
} else {
|
||||
// Create folder
|
||||
if (!properFolder.mkdirs()) {
|
||||
//throw new IOException("Couldn't create sketch folder");
|
||||
Base.showWarning(tr("Error"), tr("Could not create the sketch folder."), null);
|
||||
return false;
|
||||
}
|
||||
// copy the sketch inside
|
||||
File properPdeFile = new File(properFolder, sketchFile.getName());
|
||||
try {
|
||||
Base.copyFile(sketchFile, properPdeFile);
|
||||
// remove the original file, so user doesn't get confused
|
||||
sketchFile.delete();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Base.showWarning(tr("Error"), tr("Could not copy to a proper location."), e);
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove the original file, so user doesn't get confused
|
||||
sketchFile.delete();
|
||||
|
||||
// update with the new path
|
||||
file = properPdeFile;
|
||||
|
||||
@ -1839,6 +1865,11 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean parentFolderContainsSketchName(File sketchFile, String sketchName) {
|
||||
String dir = sketchFile.getParent().toLowerCase();
|
||||
return dir.contains(sketchName.toLowerCase());
|
||||
}
|
||||
|
||||
public void updateTitle() {
|
||||
if (sketchController == null) {
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user