mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-19 08:52:15 +01:00
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.
This commit is contained in:
parent
5792ec212b
commit
d70900e5ad
@ -245,9 +245,7 @@ public class EditorHeader extends JComponent {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
for (EditorTab tab : tabs) {
|
for (EditorTab tab : tabs) {
|
||||||
SketchCode code = tab.getSketchCode();
|
SketchCode code = tab.getSketchCode();
|
||||||
|
String codeName = code.getPrettyName();
|
||||||
String codeName = code.isExtension(sketch.getHiddenExtensions()) ?
|
|
||||||
code.getPrettyName() : code.getFileName();
|
|
||||||
|
|
||||||
// if modified, add the li'l glyph next to the name
|
// if modified, add the li'l glyph next to the name
|
||||||
String text = " " + codeName + (code.isModified() ? " \u00A7" : " ");
|
String text = " " + codeName + (code.isModified() ? " \u00A7" : " ");
|
||||||
@ -329,8 +327,7 @@ public class EditorHeader extends JComponent {
|
|||||||
for (EditorTab tab : editor.getTabs()) {
|
for (EditorTab tab : editor.getTabs()) {
|
||||||
SketchCode code = tab.getSketchCode();
|
SketchCode code = tab.getSketchCode();
|
||||||
final int index = i++;
|
final int index = i++;
|
||||||
item = new JMenuItem(code.isExtension(sketch.getDefaultExtension()) ?
|
item = new JMenuItem(code.getPrettyName());
|
||||||
code.getPrettyName() : code.getFileName());
|
|
||||||
item.addActionListener((ActionEvent e) -> {
|
item.addActionListener((ActionEvent e) -> {
|
||||||
editor.selectTab(index);
|
editor.selectTab(index);
|
||||||
});
|
});
|
||||||
|
@ -41,7 +41,6 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -120,8 +119,7 @@ public class SketchController {
|
|||||||
renamingCode = true;
|
renamingCode = true;
|
||||||
String prompt = current.isPrimary() ?
|
String prompt = current.isPrimary() ?
|
||||||
"New name for sketch:" : "New name for file:";
|
"New name for sketch:" : "New name for file:";
|
||||||
String oldName = (current.isExtension("ino")) ? current.getPrettyName()
|
String oldName = current.getPrettyName();
|
||||||
: current.getFileName();
|
|
||||||
editor.status.edit(prompt, oldName);
|
editor.status.edit(prompt, oldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +224,7 @@ public class SketchController {
|
|||||||
|
|
||||||
if (renamingCode && current.isPrimary()) {
|
if (renamingCode && current.isPrimary()) {
|
||||||
for (SketchCode code : sketch.getCodes()) {
|
for (SketchCode code : sketch.getCodes()) {
|
||||||
if (sanitaryName.equalsIgnoreCase(code.getPrettyName()) &&
|
if (sanitaryName.equalsIgnoreCase(code.getBaseName()) &&
|
||||||
code.isExtension("cpp")) {
|
code.isExtension("cpp")) {
|
||||||
Base.showMessage(tr("Error"),
|
Base.showMessage(tr("Error"),
|
||||||
I18n.format(tr("You can't rename the sketch to \"{0}\"\n"
|
I18n.format(tr("You can't rename the sketch to \"{0}\"\n"
|
||||||
@ -400,7 +398,7 @@ public class SketchController {
|
|||||||
String prompt = current.isPrimary() ?
|
String prompt = current.isPrimary() ?
|
||||||
tr("Are you sure you want to delete this sketch?") :
|
tr("Are you sure you want to delete this sketch?") :
|
||||||
I18n.format(tr("Are you sure you want to delete \"{0}\"?"),
|
I18n.format(tr("Are you sure you want to delete \"{0}\"?"),
|
||||||
current.getFileNameWithExtensionIfNotIno());
|
current.getPrettyName());
|
||||||
int result = JOptionPane.showOptionDialog(editor,
|
int result = JOptionPane.showOptionDialog(editor,
|
||||||
prompt,
|
prompt,
|
||||||
tr("Delete"),
|
tr("Delete"),
|
||||||
@ -571,7 +569,7 @@ public class SketchController {
|
|||||||
// but ignore this situation for the first tab, since it's probably being
|
// but ignore this situation for the first tab, since it's probably being
|
||||||
// resaved (with the same name) to another location/folder.
|
// resaved (with the same name) to another location/folder.
|
||||||
for (SketchCode code : sketch.getCodes()) {
|
for (SketchCode code : sketch.getCodes()) {
|
||||||
if (!code.isPrimary() && newName.equalsIgnoreCase(code.getPrettyName())) {
|
if (!code.isPrimary() && newName.equalsIgnoreCase(code.getBaseName())) {
|
||||||
Base.showMessage(tr("Error"),
|
Base.showMessage(tr("Error"),
|
||||||
I18n.format(tr("You can't save the sketch as \"{0}\"\n" +
|
I18n.format(tr("You can't save the sketch as \"{0}\"\n" +
|
||||||
"because the sketch already has a file with that name."), newName
|
"because the sketch already has a file with that name."), newName
|
||||||
@ -1081,12 +1079,6 @@ public class SketchController {
|
|||||||
return Sketch.EXTENSIONS.contains(what);
|
return Sketch.EXTENSIONS.contains(what);
|
||||||
}
|
}
|
||||||
|
|
||||||
static private final List<String> hiddenExtensions = Arrays.asList("ino", "pde");
|
|
||||||
|
|
||||||
public List<String> getHiddenExtensions() {
|
|
||||||
return hiddenExtensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the data folder if it does not exist already. As a convenience,
|
* Create the data folder if it does not exist already. As a convenience,
|
||||||
* it also returns the data folder, since it's likely about to be used.
|
* it also returns the data folder, since it's likely about to be used.
|
||||||
|
@ -585,7 +585,7 @@ public class Compiler implements MessageConsumer {
|
|||||||
|
|
||||||
if (exception != null) {
|
if (exception != null) {
|
||||||
SketchCode code = sketch.getCode(exception.getCodeIndex());
|
SketchCode code = sketch.getCode(exception.getCodeIndex());
|
||||||
String fileName = (code.isExtension("ino") || code.isExtension("pde")) ? code.getPrettyName() : code.getFileName();
|
String fileName = code.getPrettyName();
|
||||||
int lineNum = exception.getCodeLine() + 1;
|
int lineNum = exception.getCodeLine() + 1;
|
||||||
s = fileName + ":" + lineNum + ": error: " + error + msg;
|
s = fileName + ":" + lineNum + ": error: " + error + msg;
|
||||||
}
|
}
|
||||||
|
@ -161,22 +161,30 @@ public class SketchCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the filename include extension.
|
||||||
|
*/
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
return file.getName();
|
return file.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the filename without extension for normal sketch files
|
||||||
|
* (Sketch.SKETCH_EXTENSIONS) and the filename with extension for all
|
||||||
|
* others.
|
||||||
|
*/
|
||||||
public String getPrettyName() {
|
public String getPrettyName() {
|
||||||
String prettyName = getFileName();
|
if (isExtension(Sketch.SKETCH_EXTENSIONS))
|
||||||
int dot = prettyName.lastIndexOf('.');
|
return getBaseName();
|
||||||
return prettyName.substring(0, dot);
|
else
|
||||||
|
return getFileName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFileNameWithExtensionIfNotIno() {
|
/**
|
||||||
if (getFileName().endsWith(".ino")) {
|
* Returns the filename without extension
|
||||||
return getPrettyName();
|
*/
|
||||||
}
|
public String getBaseName() {
|
||||||
return getFileName();
|
return FileUtils.splitFilename(file).basename;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExtension(String... extensions) {
|
public boolean isExtension(String... extensions) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user