MCPcopy Index your code
hub / github.com/benfry/processing4 / checkModified

Method checkModified

app/src/processing/app/ui/Editor.java:2009–2076  ·  view source on GitHub ↗

Check if the sketch is modified and ask user to save changes. @return false if canceling the close/quit operation

()

Source from the content-addressed store, hash-verified

2007 * @return false if canceling the close/quit operation
2008 */
2009 @SuppressWarnings({"BooleanMethodIsAlwaysInverted", "RedundantIfStatement"})
2010 public boolean checkModified() {
2011 if (!sketch.isModified()) return true;
2012
2013 // As of Processing 1.0.10, this always happens immediately.
2014 // https://download.processing.org/bugzilla/1456.html
2015
2016 // With Java 7u40 on OS X, need to bring the window forward.
2017 toFront();
2018
2019 if (!Platform.isMacOS()) {
2020 String prompt =
2021 Language.interpolate("close.unsaved_changes", sketch.getName());
2022 int result =
2023 JOptionPane.showConfirmDialog(this, prompt,
2024 Language.text("menu.file.close"),
2025 JOptionPane.YES_NO_CANCEL_OPTION,
2026 JOptionPane.QUESTION_MESSAGE);
2027
2028 if (result == JOptionPane.YES_OPTION) {
2029 return handleSave(true);
2030
2031 } else if (result == JOptionPane.NO_OPTION) {
2032 return true; // ok to continue
2033
2034 } else if (result == JOptionPane.CANCEL_OPTION ||
2035 result == JOptionPane.CLOSED_OPTION) {
2036 return false;
2037
2038 } else {
2039 throw new IllegalStateException();
2040 }
2041
2042 } else {
2043 String tier1 = Language.interpolate("save.title", sketch.getName());
2044 String tier2 = Language.text("save.hint");
2045 JOptionPane pane =
2046 new JOptionPane(Toolkit.formatMessage(tier1, tier2), JOptionPane.QUESTION_MESSAGE);
2047
2048 String[] options = new String[] {
2049 Language.text("save.btn.save"),
2050 Language.text("prompt.cancel"),
2051 Language.text("save.btn.dont_save")
2052 };
2053 pane.setOptions(options);
2054
2055 // highlight the safest option ala apple hig
2056 pane.setInitialValue(options[0]);
2057
2058 // On macOS, setting the destructive property places
2059 // this option away from the others at the left-hand side.
2060 pane.putClientProperty("Quaqua.OptionPane.destructiveOption", 2);
2061
2062 JDialog dialog = pane.createDialog(this, null);
2063 dialog.setVisible(true);
2064
2065 Object result = pane.getValue();
2066 if (result == options[0]) { // save (and close/quit)

Callers 2

handleCloseMethod · 0.80
handleQuitEachMethod · 0.80

Calls 9

isMacOSMethod · 0.95
interpolateMethod · 0.95
textMethod · 0.95
handleSaveMethod · 0.95
formatMessageMethod · 0.95
getValueMethod · 0.80
setVisibleMethod · 0.65
isModifiedMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected