Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 68 additions & 51 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -1130,67 +1130,18 @@ protected Mode findMode(String id) {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


boolean breakTime = false;
String[] months = {
"jan", "feb", "mar", "apr", "may", "jun",
"jul", "aug", "sep", "oct", "nov", "dec"
};


/**
* Create a new untitled document in a new sketch window.
*/
public void handleNew() {
try {
File newbieDir = null;
String newbieName = null;
String newbieName = generateNewSketchName();

// In 0126, untitled sketches will begin in the temp folder,
// and then moved to a new location because Save will default to Save As.
// File sketchbookDir = getSketchbookFolder();
File newbieParentDir = untitledFolder;

String prefix = Preferences.get("editor.untitled.prefix");

// Use a generic name like sketch_031008a, the date plus a char
int index = 0;
String format = Preferences.get("editor.untitled.suffix");
String suffix = null;
if (format == null) {
Calendar cal = Calendar.getInstance();
int day = cal.get(Calendar.DAY_OF_MONTH); // 1..31
int month = cal.get(Calendar.MONTH); // 0..11
suffix = months[month] + PApplet.nf(day, 2);
} else {
//SimpleDateFormat formatter = new SimpleDateFormat("yyMMdd");
//SimpleDateFormat formatter = new SimpleDateFormat("MMMdd");
//String purty = formatter.format(new Date()).toLowerCase();
SimpleDateFormat formatter = new SimpleDateFormat(format);
suffix = formatter.format(new Date());
}
do {
if (index == 26) {
// In 0159, avoid running past z by sending people outdoors.
if (!breakTime) {
Messages.showWarning("Time for a Break",
"You've reached the limit for auto naming of new sketches\n" +
"for the day. How about going for a walk instead?", null);
breakTime = true;
} else {
Messages.showWarning("Sunshine",
"No really, time for some fresh air for you.", null);
}
return;
}
newbieName = prefix + suffix + ((char) ('a' + index));
// Also sanitize the name since it might do strange things on
// non-English systems that don't use this sort of date format.
// http://code.google.com/p/processing/issues/detail?id=283
newbieName = Sketch.sanitizeName(newbieName);
newbieDir = new File(newbieParentDir, newbieName);
index++;
// Make sure it's not in the temp folder *and* it's not in the sketchbook
} while (newbieDir.exists() || new File(sketchbookFolder, newbieName).exists());
newbieDir = new File(untitledFolder, newbieName);

// Make the directory for the new sketch
newbieDir.mkdirs();
Expand Down Expand Up @@ -1223,6 +1174,72 @@ public void handleNew() {
}


String[] months = {
"jan", "feb", "mar", "apr", "may", "jun",
"jul", "aug", "sep", "oct", "nov", "dec"
};

public String generateNewSketchName() {
String prefix = Preferences.get("editor.untitled.prefix");
// Use a generic name like sketch_031008a, the date plus a char

String format = Preferences.get("editor.untitled.suffix");
String suffix = null;
if (format == null) {
Calendar cal = Calendar.getInstance();
int day = cal.get(Calendar.DAY_OF_MONTH); // 1..31
int month = cal.get(Calendar.MONTH); // 0..11
suffix = months[month] + PApplet.nf(day, 2);
} else {
//SimpleDateFormat formatter = new SimpleDateFormat("yyMMdd");
//SimpleDateFormat formatter = new SimpleDateFormat("MMMdd");
//String purty = formatter.format(new Date()).toLowerCase();
SimpleDateFormat formatter = new SimpleDateFormat(format);
suffix = formatter.format(new Date());
}

// Also sanitize the name since it might do strange things on
// non-English systems that don't use this sort of date format.
// http://code.google.com/p/processing/issues/detail?id=283
// Make sure it's not in the temp folder *and* it's not in the sketchbook
String namingScheme = Preferences.get("editor.untitled.default_sketch_naming");
if(namingScheme == null)
namingScheme = "friendly_name";
int index = 0;
String newbieName = null;
do {
if(namingScheme.equals("date")) {
newbieName = prefix + suffix;

// Convert to base 26, with a = 0, b = 1 ... z = 25
String letters = "";
for(int n = index++; n > 0; n /= 26)
letters = ((char) ('a' + (n % 26))) + letters;
if(letters.isEmpty())
letters = "a"; // Special case for index = 0.

newbieName += letters;
}
else if(namingScheme.equals("friendly_name"))
newbieName = FriendlyWords.generateProjectName();
else if(namingScheme.equals("friendly_date"))
newbieName = FriendlyWords.generateProjectName() + "_" + suffix;
else {
namingScheme = "friendly_name";
continue;
}

newbieName = Sketch.sanitizeName(newbieName);
} while (
newbieName == null ||
new File(untitledFolder, newbieName).exists() ||
new File(sketchbookFolder, newbieName).exists()
);

return newbieName;
}


/**
* Prompt for a sketch to open, and open it in a new window.
*/
Expand Down
Loading