mirror of
https://github.com/processing/processing4.git
synced 2026-02-11 17:40:48 +01:00
fix loophole with untitled sketches and mode changes
This commit is contained in:
@@ -602,32 +602,37 @@ public class Base {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The call has already checked to make sure this sketch is not modified,
|
||||
* now change the mode.
|
||||
*/
|
||||
protected void changeMode(Mode mode) {
|
||||
if (activeEditor.getMode() != mode) {
|
||||
Sketch sketch = activeEditor.getSketch();
|
||||
nextMode = mode;
|
||||
|
||||
// If the current editor contains file extensions that the new mode can handle, then
|
||||
// write a sketch.properties file with the new mode specified, and reopen.
|
||||
boolean newModeCanHandleCurrentSource = true;
|
||||
for (final SketchCode code: sketch.getCode()) {
|
||||
if (!mode.validExtension(code.getExtension())) {
|
||||
newModeCanHandleCurrentSource = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (newModeCanHandleCurrentSource) {
|
||||
final File props = new File(sketch.getCodeFolder(), "sketch.properties");
|
||||
saveModeSettings(props, nextMode);
|
||||
|
||||
if (sketch.isUntitled()) {
|
||||
// If no changes have been made, just close and start fresh.
|
||||
// (Otherwise the editor would lose its 'untitled' status.)
|
||||
handleClose(activeEditor, true);
|
||||
handleOpen(sketch.getMainFilePath());
|
||||
} else {
|
||||
// If you're changing modes, and there's nothing in the current sketch, you probably
|
||||
// don't intend to keep the old, wrong-mode editor around.
|
||||
if (sketch.isUntitled()) {
|
||||
handleClose(activeEditor, true);
|
||||
}
|
||||
handleNew();
|
||||
|
||||
} else {
|
||||
// If the current editor contains file extensions that the new mode can handle, then
|
||||
// write a sketch.properties file with the new mode specified, and reopen.
|
||||
boolean newModeCanHandleCurrentSource = true;
|
||||
for (final SketchCode code: sketch.getCode()) {
|
||||
if (!mode.validExtension(code.getExtension())) {
|
||||
newModeCanHandleCurrentSource = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (newModeCanHandleCurrentSource) {
|
||||
final File props = new File(sketch.getCodeFolder(), "sketch.properties");
|
||||
saveModeSettings(props, nextMode);
|
||||
handleClose(activeEditor, true);
|
||||
handleOpen(sketch.getMainFilePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
2
todo.txt
2
todo.txt
@@ -42,7 +42,7 @@ X https://github.com/processing/processing/issues/2194
|
||||
X remove default menu bar hack when 7u60 arrives
|
||||
X http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8022667
|
||||
X when renaming a tab, include the previous name to be edited
|
||||
_ changing the mode on an untitled, unmodified sketch removes untitled status
|
||||
X changing the mode on an untitled, unmodified sketch removes untitled status
|
||||
|
||||
gsoc
|
||||
X clear status messages in the Contribution Manager
|
||||
|
||||
Reference in New Issue
Block a user