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