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

Method autoSave

java/src/processing/mode/java/JavaEditor.java:1260–1334  ·  view source on GitHub ↗

Displays a JDialog prompting the user to save when the user hits run/present/etc.

()

Source from the content-addressed store, hash-verified

1258 * run/present/etc.
1259 */
1260 protected void autoSave() {
1261 if (!JavaMode.autoSaveEnabled) {
1262 return;
1263 }
1264
1265 try {
1266 if (sketch.isModified() && !sketch.isUntitled()) {
1267 if (JavaMode.autoSavePromptEnabled) {
1268 final JDialog autoSaveDialog =
1269 new JDialog(base.getActiveEditor(), getSketch().getName(), true);
1270 Container container = autoSaveDialog.getContentPane();
1271
1272 JPanel panelMain = new JPanel();
1273 panelMain.setBorder(BorderFactory.createEmptyBorder(4, 0, 2, 2));
1274 panelMain.setLayout(new BoxLayout(panelMain, BoxLayout.PAGE_AXIS));
1275
1276 JPanel panelLabel = new JPanel(new FlowLayout(FlowLayout.LEFT));
1277 JLabel label = new JLabel("<html><body>&nbsp;There are unsaved"
1278 + " changes in your sketch.<br />"
1279 + "&nbsp;&nbsp;&nbsp; Do you want to save it before"
1280 + " running? </body></html>");
1281 label.setFont(new Font(
1282 label.getFont().getName(),
1283 Font.PLAIN,
1284 Toolkit.zoom(label.getFont().getSize() + 1)
1285 ));
1286 panelLabel.add(label);
1287 panelMain.add(panelLabel);
1288 final JCheckBox dontRedisplay = new JCheckBox("Remember this decision");
1289 JPanel panelButtons = new JPanel(new FlowLayout(FlowLayout.CENTER, 8, 2));
1290
1291 JButton btnRunSave = new JButton("Save and Run");
1292 btnRunSave.addActionListener(e -> {
1293 handleSave(true);
1294 if (dontRedisplay.isSelected()) {
1295 JavaMode.autoSavePromptEnabled = !dontRedisplay.isSelected();
1296 JavaMode.defaultAutoSaveEnabled = true;
1297 jmode.savePreferences();
1298 }
1299 autoSaveDialog.dispose();
1300 });
1301 panelButtons.add(btnRunSave);
1302
1303 JButton btnRunNoSave = new JButton("Run, Don't Save");
1304 btnRunNoSave.addActionListener(e -> {
1305 if (dontRedisplay.isSelected()) {
1306 JavaMode.autoSavePromptEnabled = !dontRedisplay.isSelected();
1307 JavaMode.defaultAutoSaveEnabled = false;
1308 jmode.savePreferences();
1309 }
1310 autoSaveDialog.dispose();
1311 });
1312 panelButtons.add(btnRunNoSave);
1313 panelMain.add(panelButtons);
1314
1315 JPanel panelCheck = new JPanel();
1316 panelCheck.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
1317 panelCheck.add(dontRedisplay);

Callers 2

handleTweakMethod · 0.95
prepareRunMethod · 0.95

Calls 15

zoomMethod · 0.95
handleSaveMethod · 0.95
statusErrorMethod · 0.95
isUntitledMethod · 0.80
getActiveEditorMethod · 0.80
getSketchMethod · 0.80
getSizeMethod · 0.80
savePreferencesMethod · 0.80
setResizableMethod · 0.65
setVisibleMethod · 0.65
isModifiedMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected