Check if the sketch is modified and ask user to save changes. @return false if canceling the close/quit operation
()
| 2420 | * @return false if canceling the close/quit operation |
| 2421 | */ |
| 2422 | public boolean checkModified() { |
| 2423 | if (!sketch.isModified()) return true; |
| 2424 | |
| 2425 | // As of Processing 1.0.10, this always happens immediately. |
| 2426 | // http://dev.processing.org/bugs/show_bug.cgi?id=1456 |
| 2427 | |
| 2428 | // With Java 7u40 on OS X, need to bring the window forward. |
| 2429 | toFront(); |
| 2430 | |
| 2431 | if (!Platform.isMacOS()) { |
| 2432 | String prompt = |
| 2433 | Language.interpolate("close.unsaved_changes", sketch.getName()); |
| 2434 | int result = |
| 2435 | JOptionPane.showConfirmDialog(this, prompt, |
| 2436 | Language.text("menu.file.close"), |
| 2437 | JOptionPane.YES_NO_CANCEL_OPTION, |
| 2438 | JOptionPane.QUESTION_MESSAGE); |
| 2439 | |
| 2440 | if (result == JOptionPane.YES_OPTION) { |
| 2441 | return handleSave(true); |
| 2442 | |
| 2443 | } else if (result == JOptionPane.NO_OPTION) { |
| 2444 | return true; // ok to continue |
| 2445 | |
| 2446 | } else if (result == JOptionPane.CANCEL_OPTION || |
| 2447 | result == JOptionPane.CLOSED_OPTION) { |
| 2448 | return false; |
| 2449 | |
| 2450 | } else { |
| 2451 | throw new IllegalStateException(); |
| 2452 | } |
| 2453 | |
| 2454 | } else { |
| 2455 | // This code is disabled unless Java 1.5 is being used on Mac OS X |
| 2456 | // because of a Java bug that prevents the initial value of the |
| 2457 | // dialog from being set properly (at least on my MacBook Pro). |
| 2458 | // The bug causes the "Don't Save" option to be the highlighted, |
| 2459 | // blinking, default. This sucks. But I'll tell you what doesn't |
| 2460 | // suck--workarounds for the Mac and Apple's snobby attitude about it! |
| 2461 | // I think it's nifty that they treat their developers like dirt. |
| 2462 | |
| 2463 | // Pane formatting adapted from the quaqua guide |
| 2464 | // http://www.randelshofer.ch/quaqua/guide/joptionpane.html |
| 2465 | JOptionPane pane = |
| 2466 | new JOptionPane("<html> " + |
| 2467 | "<head> <style type=\"text/css\">"+ |
| 2468 | "b { font: 13pt \"Lucida Grande\" }"+ |
| 2469 | "p { font: 11pt \"Lucida Grande\"; margin-top: 8px }"+ |
| 2470 | "</style> </head>" + |
| 2471 | "<b>" + Language.interpolate("save.title", sketch.getName()) + "</b>" + |
| 2472 | "<p>" + Language.text("save.hint") + "</p>", |
| 2473 | JOptionPane.QUESTION_MESSAGE); |
| 2474 | |
| 2475 | String[] options = new String[] { |
| 2476 | Language.text("save.btn.save"), |
| 2477 | Language.text("prompt.cancel"), |
| 2478 | Language.text("save.btn.dont_save") |
| 2479 | }; |
no test coverage detected