mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
instead of denying Mode changes, just open a new Editor window (resolves #189)
This commit is contained in:
@@ -940,9 +940,7 @@ public class Base {
|
||||
|
||||
|
||||
/**
|
||||
* The call has already checked to make sure this sketch is not modified,
|
||||
* now change the mode.
|
||||
* @return true if mode is changed.
|
||||
* @return true if mode is changed within this window (false if new window)
|
||||
*/
|
||||
public boolean changeMode(Mode mode) {
|
||||
Mode oldMode = activeEditor.getMode();
|
||||
@@ -950,25 +948,22 @@ public class Base {
|
||||
Sketch sketch = activeEditor.getSketch();
|
||||
nextMode = mode;
|
||||
|
||||
if (sketch.isUntitled()) {
|
||||
if (sketch.isModified()) {
|
||||
handleNew(); // don't bother with error messages, just switch
|
||||
return false;
|
||||
|
||||
} else if (sketch.isUntitled()) {
|
||||
// The current sketch is empty, just close and start fresh.
|
||||
// (Otherwise the editor would lose its 'untitled' status.)
|
||||
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) {
|
||||
return false;
|
||||
} else {
|
||||
// If the current sketch contains file extensions that the new mode
|
||||
// can handle, then write a sketch.properties file with the new mode
|
||||
// specified, and reopen. (Really only useful for Java <-> Android)
|
||||
//if (isCompatible(sketch, mode)) {
|
||||
if (mode.canEdit(sketch)) {
|
||||
final File props = new File(sketch.getCodeFolder(), "sketch.properties");
|
||||
saveModeSettings(props, nextMode);
|
||||
handleClose(activeEditor, true);
|
||||
@@ -980,11 +975,27 @@ public class Base {
|
||||
handleOpen(sketch.getMainFilePath());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
handleNew(); // create a new window with the new Mode
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Against all (or at least most) odds, we were able to reassign the Mode
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
private boolean isCompatible(Sketch sketch, Mode mode) {
|
||||
for (final SketchCode code : sketch.getCode()) {
|
||||
if (!mode.validExtension(code.getExtension())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
private static class ModeInfo {
|
||||
|
||||
@@ -949,6 +949,17 @@ public abstract class Mode {
|
||||
return validExtension(f.getName().substring(dot + 1));
|
||||
}
|
||||
|
||||
|
||||
public boolean canEdit(Sketch sketch) {
|
||||
for (final SketchCode code : sketch.getCode()) {
|
||||
if (!validExtension(code.getExtension())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check this extension (no dots, please) against the list of valid
|
||||
* extensions.
|
||||
|
||||
@@ -529,6 +529,7 @@ public abstract class Editor extends JFrame implements RunnerListener {
|
||||
for (final Mode m : base.getModeList()) {
|
||||
JRadioButtonMenuItem item = new JRadioButtonMenuItem(m.getTitle());
|
||||
item.addActionListener(e -> {
|
||||
/*
|
||||
if (!sketch.isModified()) {
|
||||
if (!base.changeMode(m)) {
|
||||
reselectMode();
|
||||
@@ -540,6 +541,14 @@ public abstract class Editor extends JFrame implements RunnerListener {
|
||||
Messages.showWarning("Save",
|
||||
"Please save the sketch before changing the mode.");
|
||||
}
|
||||
*/
|
||||
//if (sketch.isModified() || !base.changeMode(m)) {
|
||||
if (!base.changeMode(m)) {
|
||||
// Returns false if unable to change the mode in this window
|
||||
// (which will open a new window with the new Mode), in which case
|
||||
// re-select the menu item b/c Java changes it automatically.
|
||||
reselectMode();
|
||||
}
|
||||
});
|
||||
modePopup.add(item);
|
||||
modeGroup.add(item);
|
||||
|
||||
@@ -17,6 +17,10 @@ X set args for JavaFX and OpenGL for the mouse and key events
|
||||
X make sure that everything is set properly, also for keys
|
||||
X move ISSUE_TEMPLATE to .github subfolder
|
||||
X https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/manually-creating-a-single-issue-template-for-your-repository
|
||||
o ability to switch mode in p5 w/o saving/closing/etc
|
||||
X trying to save the user from themselves here is just messier than needed
|
||||
X opt to open a new editor window rather than weird error messages
|
||||
X https://github.com/processing/processing4/issues/189
|
||||
|
||||
readme
|
||||
X was fixed in the source for 4.0a5, but may not have been included in the dist
|
||||
@@ -170,9 +174,6 @@ _ better for git, etc
|
||||
_ single file thing is long gone
|
||||
_ introduce the idea of 'scraps' (ala gist) that are just single page blobs
|
||||
_ launch/psk files/import from web editor (more details below)
|
||||
_ ability to switch mode in p5 w/o saving/closing/etc
|
||||
_ trying to save the user from themselves here is just messier than needed
|
||||
_ https://github.com/processing/processing4/issues/189
|
||||
_ cleaning up the temp file handling
|
||||
_ 'show sketch folder' weird when in temp folder
|
||||
_ ask to save first (sketch has not been saved yet)
|
||||
|
||||
Reference in New Issue
Block a user