@@ -140,7 +140,7 @@ protected void nameCode(String newName) {
140
140
141
141
// Add the extension here, this simplifies some of the logic below.
142
142
if (newName .indexOf ('.' ) == -1 ) {
143
- newName += "." + sketch . getDefaultExtension () ;
143
+ newName += "." + Sketch . DEFAULT_SKETCH_EXTENSION ;
144
144
}
145
145
146
146
// if renaming to the same thing as before, just ignore.
@@ -167,17 +167,17 @@ protected void nameCode(String newName) {
167
167
return ;
168
168
}
169
169
170
- String newExtension = newName . substring ( dot + 1 ). toLowerCase ( );
171
- if (!validExtension ( newExtension )) {
170
+ FileUtils . SplitFile split = FileUtils . splitFilename ( newName );
171
+ if (!Sketch . EXTENSIONS . contains ( split . extension )) {
172
172
Base .showWarning (tr ("Problem with rename" ),
173
- I18n .format (
174
- tr ( " \" .{0} \" is not a valid extension." ), newExtension
175
- ), null );
173
+ I18n .format (tr ( " \" .{0} \" is not a valid extension." ),
174
+ split . extension ),
175
+ null );
176
176
return ;
177
177
}
178
178
179
179
// Don't let the user create the main tab as a .java file instead of .pde
180
- if (!isDefaultExtension ( newExtension )) {
180
+ if (!split . extension . equals ( Sketch . DEFAULT_SKETCH_EXTENSION )) {
181
181
if (renamingCode ) { // If creating a new tab, don't show this error
182
182
if (current .isPrimary ()) { // If this is the main tab, disallow
183
183
Base .showWarning (tr ("Problem with rename" ),
@@ -189,14 +189,9 @@ protected void nameCode(String newName) {
189
189
}
190
190
}
191
191
192
- // dots are allowed for the .pde and .java, but not in the name
193
- // make sure the user didn't name things poo.time.pde
194
- // or something like that (nothing against poo time)
195
- String shortName = newName .substring (0 , dot );
196
- String sanitaryName = BaseNoGui .sanitizeName (shortName );
197
- if (!shortName .equals (sanitaryName )) {
198
- newName = sanitaryName + "." + newExtension ;
199
- }
192
+ // Sanitize name
193
+ String sanitaryName = BaseNoGui .sanitizeName (split .basename );
194
+ newName = sanitaryName + "." + split .extension ;
200
195
201
196
// In Arduino, we want to allow files with the same name but different
202
197
// extensions, so compare the full names (including extensions). This
@@ -1058,23 +1053,6 @@ private boolean hasDefaultExtension(SketchCode code) {
1058
1053
return code .isExtension (sketch .getDefaultExtension ());
1059
1054
}
1060
1055
1061
-
1062
- /**
1063
- * True if the specified extension is the default file extension.
1064
- */
1065
- private boolean isDefaultExtension (String what ) {
1066
- return what .equals (sketch .getDefaultExtension ());
1067
- }
1068
-
1069
-
1070
- /**
1071
- * Check this extension (no dots, please) against the list of valid
1072
- * extensions.
1073
- */
1074
- private boolean validExtension (String what ) {
1075
- return Sketch .EXTENSIONS .contains (what );
1076
- }
1077
-
1078
1056
/**
1079
1057
* Create the data folder if it does not exist already. As a convenience,
1080
1058
* it also returns the data folder, since it's likely about to be used.
0 commit comments