Skip to content

Commit e35af3e

Browse files
Saving sketch with the same name as a class #196
1 parent f692b8a commit e35af3e

4 files changed

Lines changed: 688 additions & 158 deletions

File tree

app/src/processing/app/Sketch.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,43 @@ static final boolean asciiLetter(char c) {
17201720
static public String sanitizeName(String origName) {
17211721
char orig[] = origName.toCharArray();
17221722
StringBuilder sb = new StringBuilder();
1723+
boolean keywordFlag = false;
1724+
1725+
// Opening the reservedKeywords.txt file to be check if the 'origName'
1726+
// is a 'Reserved Keyword' in Processing or class Name or primitive.
1727+
String keywordFileName = "reservedKeywords.txt";
1728+
File keywordFile = new File(keywordFileName);
1729+
1730+
try {
1731+
FileReader fileReader = new FileReader(keywordFile);
1732+
BufferedReader bufferedReader = new BufferedReader(fileReader);
1733+
1734+
String keyword;
1735+
1736+
while ((keyword = bufferedReader.readLine()) != null) {
1737+
1738+
if (origName.equalsIgnoreCase(keyword) == true) {
1739+
keywordFlag = true;
1740+
break;
1741+
}
1742+
}
1743+
}
1744+
catch (FileNotFoundException ex) {
1745+
System.out.println("File not found!");
1746+
}
1747+
catch(IOException ex) {
1748+
System.out.println("IOException");
1749+
}
1750+
1751+
// If 'origName' is found in the 'reservedKeywords.txt' file
1752+
// Pop up a Warning message
1753+
if (keywordFlag == true) {
1754+
Messages.showWarning(Language.text("check_name.messages.is_reserved_keyword"),
1755+
Language.interpolate("check_name.messages.is_reserved_keyword.description", origName));
1756+
return "bad_sketch_name_please_fix";
1757+
}
1758+
1759+
17231760

17241761
// Can't lead with a digit (or anything besides a letter), so prefix with
17251762
// "sketch_". In 1.x this prefixed with an underscore, but those get shaved

0 commit comments

Comments
 (0)