Displays a JDialog prompting the user to save when the user hits run/present/etc.
()
| 1861 | * run/present/etc. |
| 1862 | */ |
| 1863 | protected void autoSave() { |
| 1864 | if (!JavaMode.autoSaveEnabled) { |
| 1865 | return; |
| 1866 | } |
| 1867 | |
| 1868 | try { |
| 1869 | if (sketch.isModified() && !sketch.isUntitled()) { |
| 1870 | if (JavaMode.autoSavePromptEnabled) { |
| 1871 | final JDialog autoSaveDialog = |
| 1872 | new JDialog(base.getActiveEditor(), getSketch().getName(), true); |
| 1873 | Container container = autoSaveDialog.getContentPane(); |
| 1874 | |
| 1875 | JPanel panelMain = new JPanel(); |
| 1876 | panelMain.setBorder(BorderFactory.createEmptyBorder(4, 0, 2, 2)); |
| 1877 | panelMain.setLayout(new BoxLayout(panelMain, BoxLayout.PAGE_AXIS)); |
| 1878 | |
| 1879 | JPanel panelLabel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| 1880 | JLabel label = new JLabel("<html><body> There are unsaved" |
| 1881 | + " changes in your sketch.<br />" |
| 1882 | + " Do you want to save it before" |
| 1883 | + " running? </body></html>"); |
| 1884 | label.setFont(new Font(label.getFont().getName(), |
| 1885 | Font.PLAIN, label.getFont().getSize() + 1)); |
| 1886 | panelLabel.add(label); |
| 1887 | panelMain.add(panelLabel); |
| 1888 | final JCheckBox dontRedisplay = new JCheckBox("Remember this decision"); |
| 1889 | JPanel panelButtons = new JPanel(new FlowLayout(FlowLayout.CENTER, 8, 2)); |
| 1890 | |
| 1891 | JButton btnRunSave = new JButton("Save and Run"); |
| 1892 | btnRunSave.addActionListener(new ActionListener() { |
| 1893 | @Override |
| 1894 | public void actionPerformed(ActionEvent e) { |
| 1895 | handleSave(true); |
| 1896 | if (dontRedisplay.isSelected()) { |
| 1897 | JavaMode.autoSavePromptEnabled = !dontRedisplay.isSelected(); |
| 1898 | JavaMode.defaultAutoSaveEnabled = true; |
| 1899 | jmode.savePreferences(); |
| 1900 | } |
| 1901 | autoSaveDialog.dispose(); |
| 1902 | } |
| 1903 | }); |
| 1904 | panelButtons.add(btnRunSave); |
| 1905 | |
| 1906 | JButton btnRunNoSave = new JButton("Run, Don't Save"); |
| 1907 | btnRunNoSave.addActionListener(new ActionListener() { |
| 1908 | @Override |
| 1909 | public void actionPerformed(ActionEvent e) { |
| 1910 | if (dontRedisplay.isSelected()) { |
| 1911 | JavaMode.autoSavePromptEnabled = !dontRedisplay.isSelected(); |
| 1912 | JavaMode.defaultAutoSaveEnabled = false; |
| 1913 | jmode.savePreferences(); |
| 1914 | } |
| 1915 | autoSaveDialog.dispose(); |
| 1916 | } |
| 1917 | }); |
| 1918 | panelButtons.add(btnRunNoSave); |
| 1919 | panelMain.add(panelButtons); |
| 1920 |
no test coverage detected