From c02d3585f6df2d2c0fc846370a9c30ad161ee167 Mon Sep 17 00:00:00 2001 From: joelmoniz Date: Mon, 2 Jun 2014 23:49:55 +0530 Subject: [PATCH 1/6] Basic fnctionality of autosave before running TODO: Add preferences Improve UI --- .../mode/experimental/DebugEditor.java | 80 ++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/pdex/src/processing/mode/experimental/DebugEditor.java b/pdex/src/processing/mode/experimental/DebugEditor.java index 3e4041e70..7ab11b682 100755 --- a/pdex/src/processing/mode/experimental/DebugEditor.java +++ b/pdex/src/processing/mode/experimental/DebugEditor.java @@ -48,6 +48,7 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; +import javax.swing.SwingWorker; import javax.swing.border.EtchedBorder; import javax.swing.table.TableModel; import javax.swing.text.Document; @@ -921,7 +922,7 @@ public class DebugEditor extends JavaEditor implements ActionListener { vi.setTitle(getSketch().getName()); } // if file location has changed, update autosaver - autosaver.reloadAutosaveDir(); +// autosaver.reloadAutosaveDir(); return saved; } @@ -1071,6 +1072,83 @@ public class DebugEditor extends JavaEditor implements ActionListener { return ta; } + /** + * Grab current contents of the sketch window, advance the console, stop any + * other running sketches, auto-save the user's code... not in that order. + */ + @Override + public void prepareRun() { + super.prepareRun(); + try { + if (sketch.isUntitled()) { + if (handleSave(true)) + statusTimedNotice("Saved. Running...", 5); + else + statusTimedNotice("Save Canceled. Running anyway...", 5); + } + else if (sketch.isModified())// TODO: Fix ugly UI + // TODO: Add to preferences + { + Object[] options = { "Save", "Continue Without Saving" }; + int op = JOptionPane + .showOptionDialog( + new Frame(), + "There are unsaved changes in your sketch. Save before proceeding?", + this.getSketch().getName(), JOptionPane.YES_NO_OPTION, + JOptionPane.PLAIN_MESSAGE, null, options, options[0]); + if (op == JOptionPane.YES_OPTION) { + if (handleSave(true)) + statusTimedNotice("Saved. Running...", 5); + } + else + if (op == JOptionPane.NO_OPTION) + statusTimedNotice("Not saved. Running...", 5); + } + } catch (Exception e) { + // show the error as a message in the window + statusError(e); + } + } + + /** + * Shows a notice message in the editor status bar for a certain duration of + * time. + * + * @param msg + * @param secs + */ + public void statusTimedNotice(final String msg, final int secs) { +// EventQueue.invokeLater(new Runnable() { +// +// @Override +// public void run() { +// statusNotice(msg); +// try { +// Thread.sleep(secs * 1000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// statusEmpty(); +// +// } +// }); + SwingWorker s = new SwingWorker() { + + @Override + protected Void doInBackground() throws Exception { + statusNotice(msg); + try { + Thread.sleep(secs * 1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + statusEmpty(); + return null; + } + }; + s.execute(); + } + /** * Access variable inspector window. * From 95755e940456d0bf48ef4df4e4d07bb8aa93d06c Mon Sep 17 00:00:00 2001 From: joelmoniz Date: Wed, 4 Jun 2014 20:19:42 +0530 Subject: [PATCH 2/6] Added untitledAutoSave, autoSave to preferences --- .../mode/experimental/DebugEditor.java | 19 ++++--------------- .../mode/experimental/ExperimentalMode.java | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/pdex/src/processing/mode/experimental/DebugEditor.java b/pdex/src/processing/mode/experimental/DebugEditor.java index 7ab11b682..51e7341d1 100755 --- a/pdex/src/processing/mode/experimental/DebugEditor.java +++ b/pdex/src/processing/mode/experimental/DebugEditor.java @@ -1079,8 +1079,11 @@ public class DebugEditor extends JavaEditor implements ActionListener { @Override public void prepareRun() { super.prepareRun(); + if (!ExperimentalMode.autoSaveEnabled) + return; + try { - if (sketch.isUntitled()) { + if (sketch.isUntitled() && ExperimentalMode.untitledAutoSaveEnabled) { if (handleSave(true)) statusTimedNotice("Saved. Running...", 5); else @@ -1118,20 +1121,6 @@ public class DebugEditor extends JavaEditor implements ActionListener { * @param secs */ public void statusTimedNotice(final String msg, final int secs) { -// EventQueue.invokeLater(new Runnable() { -// -// @Override -// public void run() { -// statusNotice(msg); -// try { -// Thread.sleep(secs * 1000); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } -// statusEmpty(); -// -// } -// }); SwingWorker s = new SwingWorker() { @Override diff --git a/pdex/src/processing/mode/experimental/ExperimentalMode.java b/pdex/src/processing/mode/experimental/ExperimentalMode.java index 5b04896d3..b90b5a519 100755 --- a/pdex/src/processing/mode/experimental/ExperimentalMode.java +++ b/pdex/src/processing/mode/experimental/ExperimentalMode.java @@ -127,13 +127,15 @@ public class ExperimentalMode extends JavaMode { } volatile public static boolean errorCheckEnabled = true, warningsEnabled = true, - codeCompletionsEnabled = true, debugOutputEnabled = false, errorLogsEnabled = false; + codeCompletionsEnabled = true, debugOutputEnabled = false, errorLogsEnabled = false, + untitledAutoSaveEnabled = false, autoSaveEnabled = true; public static int autoSaveInterval = 3; //in minutes public static final String prefErrorCheck = "pdex.errorCheckEnabled", prefWarnings = "pdex.warningsEnabled", prefCodeCompletionEnabled = "pdex.ccEnabled", - prefDebugOP = "pdex.dbgOutput", prefErrorLogs = "pdex.writeErrorLogs", prefAutoSaveInterval = "pdex.autoSaveInterval"; + prefDebugOP = "pdex.dbgOutput", prefErrorLogs = "pdex.writeErrorLogs", prefAutoSaveInterval = "pdex.autoSaveInterval", + prefUntitledAutoSave = "pdex.autoSave.untitledAutoSaveEnabled", prefAutoSave = "pdex.autoSaveEnabled"; public void loadPreferences(){ log("Load PDEX prefs"); @@ -144,6 +146,8 @@ public class ExperimentalMode extends JavaMode { DEBUG = Preferences.getBoolean(prefDebugOP); errorLogsEnabled = Preferences.getBoolean(prefErrorLogs); autoSaveInterval = Preferences.getInteger(prefAutoSaveInterval); + untitledAutoSaveEnabled = Preferences.getBoolean(prefUntitledAutoSave); + autoSaveEnabled = Preferences.getBoolean(prefAutoSave); } public void savePreferences(){ @@ -154,6 +158,8 @@ public class ExperimentalMode extends JavaMode { Preferences.setBoolean(prefDebugOP, DEBUG); Preferences.setBoolean(prefErrorLogs,errorLogsEnabled); Preferences.setInteger(prefAutoSaveInterval,autoSaveInterval); + Preferences.setBoolean(prefUntitledAutoSave,untitledAutoSaveEnabled); + Preferences.setBoolean(prefAutoSave,autoSaveEnabled); } public void ensurePrefsExist(){ @@ -169,6 +175,10 @@ public class ExperimentalMode extends JavaMode { Preferences.setBoolean(prefErrorLogs,errorLogsEnabled); if(Preferences.get(prefAutoSaveInterval) == null) Preferences.setInteger(prefAutoSaveInterval,autoSaveInterval); + if(Preferences.get(prefUntitledAutoSave) == null) + Preferences.setBoolean(prefUntitledAutoSave,untitledAutoSaveEnabled); + if(Preferences.get(prefAutoSave) == null) + Preferences.setBoolean(prefAutoSave,autoSaveEnabled); } From 63e6f1b912cd0cd35785100fbafe975800d00478 Mon Sep 17 00:00:00 2001 From: joelmoniz Date: Wed, 4 Jun 2014 22:10:40 +0530 Subject: [PATCH 3/6] Commenting out untitledAutoSave --- .../processing/mode/experimental/DebugEditor.java | 15 ++++++++------- .../mode/experimental/ExperimentalMode.java | 12 ++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/pdex/src/processing/mode/experimental/DebugEditor.java b/pdex/src/processing/mode/experimental/DebugEditor.java index 51e7341d1..5ac4a9811 100755 --- a/pdex/src/processing/mode/experimental/DebugEditor.java +++ b/pdex/src/processing/mode/experimental/DebugEditor.java @@ -1083,13 +1083,14 @@ public class DebugEditor extends JavaEditor implements ActionListener { return; try { - if (sketch.isUntitled() && ExperimentalMode.untitledAutoSaveEnabled) { - if (handleSave(true)) - statusTimedNotice("Saved. Running...", 5); - else - statusTimedNotice("Save Canceled. Running anyway...", 5); - } - else if (sketch.isModified())// TODO: Fix ugly UI +// if (sketch.isUntitled() && ExperimentalMode.untitledAutoSaveEnabled) { +// if (handleSave(true)) +// statusTimedNotice("Saved. Running...", 5); +// else +// statusTimedNotice("Save Canceled. Running anyway...", 5); +// } +// else + if (sketch.isModified() && !sketch.isUntitled())// TODO: Fix ugly UI // TODO: Add to preferences { Object[] options = { "Save", "Continue Without Saving" }; diff --git a/pdex/src/processing/mode/experimental/ExperimentalMode.java b/pdex/src/processing/mode/experimental/ExperimentalMode.java index b90b5a519..29941ad87 100755 --- a/pdex/src/processing/mode/experimental/ExperimentalMode.java +++ b/pdex/src/processing/mode/experimental/ExperimentalMode.java @@ -128,14 +128,14 @@ public class ExperimentalMode extends JavaMode { volatile public static boolean errorCheckEnabled = true, warningsEnabled = true, codeCompletionsEnabled = true, debugOutputEnabled = false, errorLogsEnabled = false, - untitledAutoSaveEnabled = false, autoSaveEnabled = true; + autoSaveEnabled = true; //,untitledAutoSaveEnabled; public static int autoSaveInterval = 3; //in minutes public static final String prefErrorCheck = "pdex.errorCheckEnabled", prefWarnings = "pdex.warningsEnabled", prefCodeCompletionEnabled = "pdex.ccEnabled", prefDebugOP = "pdex.dbgOutput", prefErrorLogs = "pdex.writeErrorLogs", prefAutoSaveInterval = "pdex.autoSaveInterval", - prefUntitledAutoSave = "pdex.autoSave.untitledAutoSaveEnabled", prefAutoSave = "pdex.autoSaveEnabled"; + prefAutoSave = "pdex.autoSaveEnabled"; //prefUntitledAutoSave = "pdex.autoSave.untitledAutoSaveEnabled" public void loadPreferences(){ log("Load PDEX prefs"); @@ -146,7 +146,7 @@ public class ExperimentalMode extends JavaMode { DEBUG = Preferences.getBoolean(prefDebugOP); errorLogsEnabled = Preferences.getBoolean(prefErrorLogs); autoSaveInterval = Preferences.getInteger(prefAutoSaveInterval); - untitledAutoSaveEnabled = Preferences.getBoolean(prefUntitledAutoSave); +// untitledAutoSaveEnabled = Preferences.getBoolean(prefUntitledAutoSave); autoSaveEnabled = Preferences.getBoolean(prefAutoSave); } @@ -158,7 +158,7 @@ public class ExperimentalMode extends JavaMode { Preferences.setBoolean(prefDebugOP, DEBUG); Preferences.setBoolean(prefErrorLogs,errorLogsEnabled); Preferences.setInteger(prefAutoSaveInterval,autoSaveInterval); - Preferences.setBoolean(prefUntitledAutoSave,untitledAutoSaveEnabled); +// Preferences.setBoolean(prefUntitledAutoSave,untitledAutoSaveEnabled); Preferences.setBoolean(prefAutoSave,autoSaveEnabled); } @@ -175,8 +175,8 @@ public class ExperimentalMode extends JavaMode { Preferences.setBoolean(prefErrorLogs,errorLogsEnabled); if(Preferences.get(prefAutoSaveInterval) == null) Preferences.setInteger(prefAutoSaveInterval,autoSaveInterval); - if(Preferences.get(prefUntitledAutoSave) == null) - Preferences.setBoolean(prefUntitledAutoSave,untitledAutoSaveEnabled); +// if(Preferences.get(prefUntitledAutoSave) == null) +// Preferences.setBoolean(prefUntitledAutoSave,untitledAutoSaveEnabled); if(Preferences.get(prefAutoSave) == null) Preferences.setBoolean(prefAutoSave,autoSaveEnabled); } From ea275b845bf4b53832506404a49072dc7ab11bef Mon Sep 17 00:00:00 2001 From: joelmoniz Date: Sun, 8 Jun 2014 12:31:10 +0530 Subject: [PATCH 4/6] Done with adding autoSave to PDE X --- .../mode/experimental/DebugEditor.java | 140 +++++++++++++----- .../mode/experimental/ExperimentalMode.java | 14 +- 2 files changed, 117 insertions(+), 37 deletions(-) diff --git a/pdex/src/processing/mode/experimental/DebugEditor.java b/pdex/src/processing/mode/experimental/DebugEditor.java index 5ac4a9811..640589460 100755 --- a/pdex/src/processing/mode/experimental/DebugEditor.java +++ b/pdex/src/processing/mode/experimental/DebugEditor.java @@ -22,7 +22,10 @@ import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Color; import java.awt.Component; +import java.awt.Container; import java.awt.EventQueue; +import java.awt.FlowLayout; +import java.awt.Font; import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -40,8 +43,14 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.BorderFactory; import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JCheckBox; import javax.swing.JCheckBoxMenuItem; +import javax.swing.JDialog; +import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JOptionPane; @@ -49,6 +58,7 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; +import javax.swing.border.Border; import javax.swing.border.EtchedBorder; import javax.swing.table.TableModel; import javax.swing.text.Document; @@ -59,6 +69,7 @@ import processing.app.Base; import processing.app.EditorState; import processing.app.EditorToolbar; import processing.app.Mode; +import processing.app.Preferences; import processing.app.Sketch; import processing.app.SketchCode; import processing.app.Toolkit; @@ -922,7 +933,7 @@ public class DebugEditor extends JavaEditor implements ActionListener { vi.setTitle(getSketch().getName()); } // if file location has changed, update autosaver -// autosaver.reloadAutosaveDir(); + autosaver.reloadAutosaveDir(); return saved; } @@ -1080,36 +1091,95 @@ public class DebugEditor extends JavaEditor implements ActionListener { public void prepareRun() { super.prepareRun(); if (!ExperimentalMode.autoSaveEnabled) - return; - + return; + try { -// if (sketch.isUntitled() && ExperimentalMode.untitledAutoSaveEnabled) { -// if (handleSave(true)) -// statusTimedNotice("Saved. Running...", 5); -// else -// statusTimedNotice("Save Canceled. Running anyway...", 5); -// } -// else - if (sketch.isModified() && !sketch.isUntitled())// TODO: Fix ugly UI - // TODO: Add to preferences - { - Object[] options = { "Save", "Continue Without Saving" }; - int op = JOptionPane - .showOptionDialog( - new Frame(), - "There are unsaved changes in your sketch. Save before proceeding?", - this.getSketch().getName(), JOptionPane.YES_NO_OPTION, - JOptionPane.PLAIN_MESSAGE, null, options, options[0]); - if (op == JOptionPane.YES_OPTION) { - if (handleSave(true)) - statusTimedNotice("Saved. Running...", 5); - } - else - if (op == JOptionPane.NO_OPTION) - statusTimedNotice("Not saved. Running...", 5); + // if (sketch.isUntitled() && + // ExperimentalMode.untitledAutoSaveEnabled) { + // if (handleSave(true)) + // statusTimedNotice("Saved. Running...", 5); + // else + // statusTimedNotice("Save Canceled. Running anyway...", 5); + // } + // else + if (sketch.isModified() && !sketch.isUntitled()) { + if (ExperimentalMode.autoSavePromptEnabled) { + final JDialog autoSaveDialog = new JDialog( + base.getActiveEditor(), this.getSketch().getName(), + true); + Container container = autoSaveDialog.getContentPane(); + + JPanel panel = new JPanel(); + panel.setBorder(BorderFactory.createEmptyBorder(4, 0, 2, 2)); + panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); + + JPanel panel1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + JLabel label = new JLabel( + " There are unsaved" + + " changes in your sketch.
" + + "    Do you want to save it before" + + " running? "); + label.setFont(new Font(label.getFont().getName(), + Font.PLAIN, label.getFont().getSize() + 1)); + panel1.add(label); + panel.add(panel1); + final JCheckBox dontRedisplay = new JCheckBox( + "Remember this decision"); + + panel1 = new JPanel(new FlowLayout( + FlowLayout.CENTER, 8, 2)); + JButton button = new JButton("Save and Run"); + button.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (handleSave(true)) + statusTimedNotice("Saved. Running...", 5); + if (dontRedisplay.isSelected()) { + ExperimentalMode.autoSavePromptEnabled = !dontRedisplay + .isSelected(); + ExperimentalMode.defaultAutoSaveEnabled = true; + dmode.savePreferences(); + } + autoSaveDialog.dispose(); + } + }); + panel1.add(button); + button = new JButton("Run, Don't Save"); + button.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + statusTimedNotice("Not saved. Running...", 5); + if (dontRedisplay.isSelected()) { + ExperimentalMode.autoSavePromptEnabled = !dontRedisplay + .isSelected(); + ExperimentalMode.defaultAutoSaveEnabled = false; + dmode.savePreferences(); + } + autoSaveDialog.dispose(); + } + }); + panel1.add(button); + panel.add(panel1); + + panel1 = new JPanel(); + panel1.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); + panel1.add(dontRedisplay); + panel.add(panel1); + + container.add(panel); + + autoSaveDialog.setResizable(false); + autoSaveDialog.pack(); + autoSaveDialog + .setLocationRelativeTo(base.getActiveEditor()); + autoSaveDialog.setVisible(true); + + } else if (ExperimentalMode.defaultAutoSaveEnabled) + handleSave(true); } } catch (Exception e) { - // show the error as a message in the window statusError(e); } } @@ -1126,13 +1196,13 @@ public class DebugEditor extends JavaEditor implements ActionListener { @Override protected Void doInBackground() throws Exception { - statusNotice(msg); - try { - Thread.sleep(secs * 1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - statusEmpty(); + statusNotice(msg); + try { + Thread.sleep(secs * 1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + statusEmpty(); return null; } }; diff --git a/pdex/src/processing/mode/experimental/ExperimentalMode.java b/pdex/src/processing/mode/experimental/ExperimentalMode.java index 29941ad87..26cb99f56 100755 --- a/pdex/src/processing/mode/experimental/ExperimentalMode.java +++ b/pdex/src/processing/mode/experimental/ExperimentalMode.java @@ -128,14 +128,16 @@ public class ExperimentalMode extends JavaMode { volatile public static boolean errorCheckEnabled = true, warningsEnabled = true, codeCompletionsEnabled = true, debugOutputEnabled = false, errorLogsEnabled = false, - autoSaveEnabled = true; //,untitledAutoSaveEnabled; + autoSaveEnabled = true, autoSavePromptEnabled = true, + defaultAutoSaveEnabled = true; // ,untitledAutoSaveEnabled; public static int autoSaveInterval = 3; //in minutes public static final String prefErrorCheck = "pdex.errorCheckEnabled", prefWarnings = "pdex.warningsEnabled", prefCodeCompletionEnabled = "pdex.ccEnabled", prefDebugOP = "pdex.dbgOutput", prefErrorLogs = "pdex.writeErrorLogs", prefAutoSaveInterval = "pdex.autoSaveInterval", - prefAutoSave = "pdex.autoSaveEnabled"; //prefUntitledAutoSave = "pdex.autoSave.untitledAutoSaveEnabled" + prefAutoSave = "pdex.autoSave.autoSaveEnabled", // prefUntitledAutoSave = "pdex.autoSave.untitledAutoSaveEnabled", + prefAutoSavePrompt = "pdex.autoSave.promptDisplay", prefDefaultAutoSave = "pdex.autoSave.autoSaveByDefault"; public void loadPreferences(){ log("Load PDEX prefs"); @@ -148,6 +150,8 @@ public class ExperimentalMode extends JavaMode { autoSaveInterval = Preferences.getInteger(prefAutoSaveInterval); // untitledAutoSaveEnabled = Preferences.getBoolean(prefUntitledAutoSave); autoSaveEnabled = Preferences.getBoolean(prefAutoSave); + autoSavePromptEnabled = Preferences.getBoolean(prefAutoSavePrompt); + defaultAutoSaveEnabled = Preferences.getBoolean(prefDefaultAutoSave); } public void savePreferences(){ @@ -160,6 +164,8 @@ public class ExperimentalMode extends JavaMode { Preferences.setInteger(prefAutoSaveInterval,autoSaveInterval); // Preferences.setBoolean(prefUntitledAutoSave,untitledAutoSaveEnabled); Preferences.setBoolean(prefAutoSave,autoSaveEnabled); + Preferences.setBoolean(prefAutoSavePrompt, autoSavePromptEnabled); + Preferences.setBoolean(prefDefaultAutoSave, defaultAutoSaveEnabled); } public void ensurePrefsExist(){ @@ -179,6 +185,10 @@ public class ExperimentalMode extends JavaMode { // Preferences.setBoolean(prefUntitledAutoSave,untitledAutoSaveEnabled); if(Preferences.get(prefAutoSave) == null) Preferences.setBoolean(prefAutoSave,autoSaveEnabled); + if(Preferences.get(prefAutoSavePrompt) == null) + Preferences.setBoolean(prefAutoSavePrompt,autoSavePromptEnabled); + if(Preferences.get(prefDefaultAutoSave) == null) + Preferences.setBoolean(prefDefaultAutoSave,defaultAutoSaveEnabled); } From 9351cf287909854f1af8a64591dfbda3376b61c0 Mon Sep 17 00:00:00 2001 From: Joel Moniz Date: Tue, 10 Jun 2014 23:44:10 +0530 Subject: [PATCH 5/6] Polishing up autosave implementation --- .../mode/experimental/DebugEditor.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/pdex/src/processing/mode/experimental/DebugEditor.java b/pdex/src/processing/mode/experimental/DebugEditor.java index 62c6db78e..05bd0256f 100755 --- a/pdex/src/processing/mode/experimental/DebugEditor.java +++ b/pdex/src/processing/mode/experimental/DebugEditor.java @@ -1085,13 +1085,24 @@ public class DebugEditor extends JavaEditor implements ActionListener { return ta; } + private boolean wasSaved; + /** * Grab current contents of the sketch window, advance the console, stop any * other running sketches, auto-save the user's code... not in that order. */ @Override public void prepareRun() { + wasSaved = false; + autoSave(); super.prepareRun(); + if (wasSaved) + statusTimedNotice("Saved. Running...", 5); + else + statusTimedNotice("Not saved. Running...", 5); + } + + protected void autoSave() { if (!ExperimentalMode.autoSaveEnabled) return; @@ -1128,15 +1139,14 @@ public class DebugEditor extends JavaEditor implements ActionListener { final JCheckBox dontRedisplay = new JCheckBox( "Remember this decision"); - panel1 = new JPanel(new FlowLayout( - FlowLayout.CENTER, 8, 2)); + panel1 = new JPanel(new FlowLayout(FlowLayout.CENTER, 8, 2)); JButton button = new JButton("Save and Run"); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (handleSave(true)) - statusTimedNotice("Saved. Running...", 5); + wasSaved = true; if (dontRedisplay.isSelected()) { ExperimentalMode.autoSavePromptEnabled = !dontRedisplay .isSelected(); @@ -1152,7 +1162,6 @@ public class DebugEditor extends JavaEditor implements ActionListener { @Override public void actionPerformed(ActionEvent e) { - statusTimedNotice("Not saved. Running...", 5); if (dontRedisplay.isSelected()) { ExperimentalMode.autoSavePromptEnabled = !dontRedisplay .isSelected(); @@ -1179,11 +1188,13 @@ public class DebugEditor extends JavaEditor implements ActionListener { autoSaveDialog.setVisible(true); } else if (ExperimentalMode.defaultAutoSaveEnabled) - handleSave(true); + if (handleSave(true)) + wasSaved = true; } } catch (Exception e) { statusError(e); } + } /** From a4761e9e0977c533d96ebde73497aea61ad2885d Mon Sep 17 00:00:00 2001 From: Joel Moniz Date: Wed, 11 Jun 2014 00:59:18 +0530 Subject: [PATCH 6/6] More changes to auto-save Removing status notices --- .../mode/experimental/DebugEditor.java | 88 +++++++------------ 1 file changed, 32 insertions(+), 56 deletions(-) diff --git a/pdex/src/processing/mode/experimental/DebugEditor.java b/pdex/src/processing/mode/experimental/DebugEditor.java index 05bd0256f..7fa971325 100755 --- a/pdex/src/processing/mode/experimental/DebugEditor.java +++ b/pdex/src/processing/mode/experimental/DebugEditor.java @@ -1085,23 +1085,21 @@ public class DebugEditor extends JavaEditor implements ActionListener { return ta; } - private boolean wasSaved; - + /** * Grab current contents of the sketch window, advance the console, stop any * other running sketches, auto-save the user's code... not in that order. */ @Override public void prepareRun() { - wasSaved = false; autoSave(); super.prepareRun(); - if (wasSaved) - statusTimedNotice("Saved. Running...", 5); - else - statusTimedNotice("Not saved. Running...", 5); } + /** + * Displays a JDialog prompting the user to save when the user hits + * run/present/etc. + */ protected void autoSave() { if (!ExperimentalMode.autoSaveEnabled) return; @@ -1122,11 +1120,14 @@ public class DebugEditor extends JavaEditor implements ActionListener { true); Container container = autoSaveDialog.getContentPane(); - JPanel panel = new JPanel(); - panel.setBorder(BorderFactory.createEmptyBorder(4, 0, 2, 2)); - panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); + JPanel panelMain = new JPanel(); + panelMain.setBorder(BorderFactory.createEmptyBorder(4, 0, + 2, 2)); + panelMain.setLayout(new BoxLayout(panelMain, + BoxLayout.PAGE_AXIS)); - JPanel panel1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + JPanel panelLabel = new JPanel(new FlowLayout( + FlowLayout.LEFT)); JLabel label = new JLabel( " There are unsaved" + " changes in your sketch.
" @@ -1134,19 +1135,19 @@ public class DebugEditor extends JavaEditor implements ActionListener { + " running? "); label.setFont(new Font(label.getFont().getName(), Font.PLAIN, label.getFont().getSize() + 1)); - panel1.add(label); - panel.add(panel1); + panelLabel.add(label); + panelMain.add(panelLabel); final JCheckBox dontRedisplay = new JCheckBox( "Remember this decision"); - panel1 = new JPanel(new FlowLayout(FlowLayout.CENTER, 8, 2)); - JButton button = new JButton("Save and Run"); - button.addActionListener(new ActionListener() { + JPanel panelButtons = new JPanel(new FlowLayout( + FlowLayout.CENTER, 8, 2)); + JButton btnRunSave = new JButton("Save and Run"); + btnRunSave.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - if (handleSave(true)) - wasSaved = true; + handleSave(true); if (dontRedisplay.isSelected()) { ExperimentalMode.autoSavePromptEnabled = !dontRedisplay .isSelected(); @@ -1156,9 +1157,9 @@ public class DebugEditor extends JavaEditor implements ActionListener { autoSaveDialog.dispose(); } }); - panel1.add(button); - button = new JButton("Run, Don't Save"); - button.addActionListener(new ActionListener() { + panelButtons.add(btnRunSave); + JButton btnRunNoSave = new JButton("Run, Don't Save"); + btnRunNoSave.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -1171,15 +1172,16 @@ public class DebugEditor extends JavaEditor implements ActionListener { autoSaveDialog.dispose(); } }); - panel1.add(button); - panel.add(panel1); + panelButtons.add(btnRunNoSave); + panelMain.add(panelButtons); - panel1 = new JPanel(); - panel1.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); - panel1.add(dontRedisplay); - panel.add(panel1); + JPanel panelCheck = new JPanel(); + panelCheck + .setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); + panelCheck.add(dontRedisplay); + panelMain.add(panelCheck); - container.add(panel); + container.add(panelMain); autoSaveDialog.setResizable(false); autoSaveDialog.pack(); @@ -1188,39 +1190,13 @@ public class DebugEditor extends JavaEditor implements ActionListener { autoSaveDialog.setVisible(true); } else if (ExperimentalMode.defaultAutoSaveEnabled) - if (handleSave(true)) - wasSaved = true; + handleSave(true); } } catch (Exception e) { statusError(e); } - } - - /** - * Shows a notice message in the editor status bar for a certain duration of - * time. - * - * @param msg - * @param secs - */ - public void statusTimedNotice(final String msg, final int secs) { - SwingWorker s = new SwingWorker() { - - @Override - protected Void doInBackground() throws Exception { - statusNotice(msg); - try { - Thread.sleep(secs * 1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - statusEmpty(); - return null; - } - }; - s.execute(); - } + } /** * Access variable inspector window.