Displays a JDialog prompting the user to save when the user hits run/present/etc.
()
| 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> There are unsaved" |
| 1278 | + " changes in your sketch.<br />" |
| 1279 | + " 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); |
no test coverage detected