@@ -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 ();
0 commit comments