Check if the sketch is modified and ask user to save changes. @return false if canceling the close/quit operation
()
| 1690 | * @return false if canceling the close/quit operation |
| 1691 | */ |
| 1692 | protected boolean checkModified() { |
| 1693 | if (!sketch.isModified()) |
| 1694 | return true; |
| 1695 | |
| 1696 | // As of Processing 1.0.10, this always happens immediately. |
| 1697 | // http://dev.processing.org/bugs/show_bug.cgi?id=1456 |
| 1698 | |
| 1699 | toFront(); |
| 1700 | |
| 1701 | String prompt = I18n.format(tr("Save changes to \"{0}\"? "), |
| 1702 | sketch.getName()); |
| 1703 | |
| 1704 | if (!OSUtils.hasMacOSStyleMenus()) { |
| 1705 | int result = |
| 1706 | JOptionPane.showConfirmDialog(this, prompt, tr("Close"), |
| 1707 | JOptionPane.YES_NO_CANCEL_OPTION, |
| 1708 | JOptionPane.QUESTION_MESSAGE); |
| 1709 | |
| 1710 | switch (result) { |
| 1711 | case JOptionPane.YES_OPTION: |
| 1712 | return handleSave(true); |
| 1713 | case JOptionPane.NO_OPTION: |
| 1714 | return true; // ok to continue |
| 1715 | case JOptionPane.CANCEL_OPTION: |
| 1716 | case JOptionPane.CLOSED_OPTION: // Escape key pressed |
| 1717 | return false; |
| 1718 | default: |
| 1719 | throw new IllegalStateException(); |
| 1720 | } |
| 1721 | |
| 1722 | } else { |
| 1723 | // This code is disabled unless Java 1.5 is being used on Mac OS X |
| 1724 | // because of a Java bug that prevents the initial value of the |
| 1725 | // dialog from being set properly (at least on my MacBook Pro). |
| 1726 | // The bug causes the "Don't Save" option to be the highlighted, |
| 1727 | // blinking, default. This sucks. But I'll tell you what doesn't |
| 1728 | // suck--workarounds for the Mac and Apple's snobby attitude about it! |
| 1729 | // I think it's nifty that they treat their developers like dirt. |
| 1730 | |
| 1731 | JOptionPane pane = |
| 1732 | new JOptionPane(tr("<html> " + |
| 1733 | "<head> <style type=\"text/css\">"+ |
| 1734 | "b { font: 13pt \"Lucida Grande\" }"+ |
| 1735 | "p { font: 11pt \"Lucida Grande\"; margin-top: 8px }"+ |
| 1736 | "</style> </head>" + |
| 1737 | "<b>Do you want to save changes to this sketch<BR>" + |
| 1738 | " before closing?</b>" + |
| 1739 | "<p>If you don't save, your changes will be lost."), |
| 1740 | JOptionPane.QUESTION_MESSAGE); |
| 1741 | |
| 1742 | String[] options = new String[] { |
| 1743 | tr("Save"), tr("Cancel"), tr("Don't Save") |
| 1744 | }; |
| 1745 | pane.setOptions(options); |
| 1746 | |
| 1747 | // highlight the safest option ala apple hig |
| 1748 | pane.setInitialValue(options[0]); |
| 1749 |
no test coverage detected