Skip to content

Commit 497a2c4

Browse files
committed
Show warning message if mode cannot be changed
If selected mode cannot handle current source, show warning dialog and reselect old (current) mode.
1 parent a6a9b5c commit 497a2c4

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

app/src/processing/app/Base.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,8 +885,9 @@ public Mode getNextMode() {
885885
/**
886886
* The call has already checked to make sure this sketch is not modified,
887887
* now change the mode.
888+
* @return true if mode is changed.
888889
*/
889-
public void changeMode(Mode mode) {
890+
public boolean changeMode(Mode mode) {
890891
Mode oldMode = activeEditor.getMode();
891892
if (oldMode != mode) {
892893
Sketch sketch = activeEditor.getSketch();
@@ -908,7 +909,9 @@ public void changeMode(Mode mode) {
908909
break;
909910
}
910911
}
911-
if (newModeCanHandleCurrentSource) {
912+
if (!newModeCanHandleCurrentSource) {
913+
return false;
914+
} else {
912915
final File props = new File(sketch.getCodeFolder(), "sketch.properties");
913916
saveModeSettings(props, nextMode);
914917
handleClose(activeEditor, true);
@@ -918,10 +921,12 @@ public void changeMode(Mode mode) {
918921
// re-open the sketch using the mode we were in before
919922
saveModeSettings(props, oldMode);
920923
handleOpen(sketch.getMainFilePath());
924+
return false;
921925
}
922926
}
923927
}
924928
}
929+
return true;
925930
}
926931

927932

app/src/processing/app/ui/Editor.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -505,22 +505,15 @@ public void rebuildModePopup() {
505505
item.addActionListener(new ActionListener() {
506506
public void actionPerformed(ActionEvent e) {
507507
if (!sketch.isModified()) {
508-
base.changeMode(m);
508+
if (!base.changeMode(m)) {
509+
reselectMode();
510+
Messages.showWarning(Language.text("warn.cannot_change_mode.title"),
511+
Language.interpolate("warn.cannot_change_mode.body", m));
512+
}
509513
} else {
514+
reselectMode();
510515
Messages.showWarning("Save",
511516
"Please save the sketch before changing the mode.");
512-
513-
// Re-select the old checkbox, because it was automatically
514-
// updated by Java, even though the Mode could not be changed.
515-
// https://github.com/processing/processing/issues/2615
516-
for (Component c : getModePopup().getComponents()) {
517-
if (c instanceof JRadioButtonMenuItem) {
518-
if (((JRadioButtonMenuItem)c).getText() == mode.getTitle()) {
519-
((JRadioButtonMenuItem)c).setSelected(true);
520-
break;
521-
}
522-
}
523-
}
524517
}
525518
}
526519
});
@@ -543,6 +536,19 @@ public void actionPerformed(ActionEvent e) {
543536
Toolkit.setMenuMnemsInside(modePopup);
544537
}
545538

539+
// Re-select the old checkbox, because it was automatically
540+
// updated by Java, even though the Mode could not be changed.
541+
// https://github.com/processing/processing/issues/2615
542+
private void reselectMode() {
543+
for (Component c : getModePopup().getComponents()) {
544+
if (c instanceof JRadioButtonMenuItem) {
545+
if (((JRadioButtonMenuItem)c).getText() == mode.getTitle()) {
546+
((JRadioButtonMenuItem)c).setSelected(true);
547+
break;
548+
}
549+
}
550+
}
551+
}
546552

547553
public JPopupMenu getModePopup() {
548554
return modePopup.getPopupMenu();

build/shared/lib/languages/PDE.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@ contrib.import.errors.link = Error: The library %s has a strange looking downloa
529529
warn.delete = Delete
530530
warn.delete.sketch = Are you sure you want to delete this sketch?
531531
warn.delete.file = Are you sure you want to delete "%s"?
532+
warn.cannot_change_mode.title = Cannot change mode
533+
warn.cannot_change_mode.body = Cannot change mode,\nbecause "%s" mode is not compatible with current mode.
532534

533535

534536
# ---------------------------------------

build/shared/lib/languages/PDE_ja.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,8 @@ contrib.import.errors.link = Error: The library %s has a strange looking downloa
528528
warn.delete = Delete
529529
warn.delete.sketch = Are you sure you want to delete this sketch?
530530
warn.delete.file = Are you sure you want to delete "%s"?
531+
warn.cannot_change_mode.title = モード変更失敗
532+
warn.cannot_change_mode.body = 互換性がないため、"%s"モードに切り替えられません。
531533

532534

533535
# ---------------------------------------

0 commit comments

Comments
 (0)