diff --git a/app/src/processing/app/ui/Editor.java b/app/src/processing/app/ui/Editor.java index 46d6605dcc..832be571b7 100644 --- a/app/src/processing/app/ui/Editor.java +++ b/app/src/processing/app/ui/Editor.java @@ -1193,7 +1193,10 @@ public void setUpdatesAvailable(int count) { /** - * Override this if you want a special menu for your particular 'mode'. + * Override this if you want a special menu for a Mode. + * You only get one menu, use it wisely! + * Note that this is called from the Editor constructor, + * so your Editor object may not be completely initialized yet. */ public JMenu buildModeMenu() { return null; diff --git a/java/src/processing/mode/java/JavaEditor.java b/java/src/processing/mode/java/JavaEditor.java index b62939096b..2e1e698975 100644 --- a/java/src/processing/mode/java/JavaEditor.java +++ b/java/src/processing/mode/java/JavaEditor.java @@ -75,7 +75,8 @@ public class JavaEditor extends Editor { protected LineHighlight currentLine; // where the debugger is suspended protected final String breakpointMarkerComment = " //<>//"; - protected JMenuItem inspectorItem; + JMenu modeMenu; +// protected JMenuItem inspectorItem; static final int ERROR_TAB_INDEX = 0; @@ -104,7 +105,9 @@ protected JavaEditor(Base base, String path, EditorState state, super(base, path, state, mode); jmode = (JavaMode) mode; + debugger = new Debugger(this); + debugger.populateMenu(modeMenu); // set breakpoints from marker comments for (LineID lineID : stripBreakpointComments()) { @@ -1385,8 +1388,7 @@ public boolean isDebuggerEnabled() { @Override public JMenu buildModeMenu() { - //return buildDebugMenu(); - return debugger.buildMenu(); + return modeMenu = new JMenu(Language.text("menu.debug")); } diff --git a/java/src/processing/mode/java/JavaToolbar.java b/java/src/processing/mode/java/JavaToolbar.java index 03f391baef..07da613aa6 100644 --- a/java/src/processing/mode/java/JavaToolbar.java +++ b/java/src/processing/mode/java/JavaToolbar.java @@ -37,24 +37,33 @@ public class JavaToolbar extends EditorToolbar { JavaEditor jeditor; -// boolean debug; // true if this is the expanded debug feller EditorButton stepButton; EditorButton continueButton; -// public JavaToolbar(Editor editor, boolean debug) { public JavaToolbar(Editor editor) { super(editor); -// this.debug = debug; jeditor = (JavaEditor) editor; } + /** + * Check if 'debugger' is available and enabled. + */ + private boolean isDebuggerArmed() { + // 'jeditor' not ready yet because this is called by super() + // 'debugger' also null during init + if (jeditor == null) { + return false; + } + return jeditor.isDebuggerEnabled(); + } + + @Override public List createButtons() { - // jeditor not ready yet because this is called by super() - final boolean debug = ((JavaEditor) editor).isDebuggerEnabled(); -// System.out.println("creating buttons in JavaToolbar, debug:" + debug); + final boolean debug = isDebuggerArmed(); + List outgoing = new ArrayList<>(); final String runText = debug ? @@ -130,10 +139,9 @@ public void actionPerformed(ActionEvent e) { } }; - if (((JavaEditor) editor).isDebuggerEnabled()) { + if (isDebuggerArmed()) { debugButton.setSelected(true); } -// debugButton.setRolloverLabel(label); box.add(debugButton); addGap(box); } diff --git a/java/src/processing/mode/java/debug/Debugger.java b/java/src/processing/mode/java/debug/Debugger.java index 6988ca185f..ee3868e189 100644 --- a/java/src/processing/mode/java/debug/Debugger.java +++ b/java/src/processing/mode/java/debug/Debugger.java @@ -117,12 +117,9 @@ public Debugger(JavaEditor editor) { /** * Creates the debug menu. Includes ActionListeners for the menu items. - * Intended for adding to the menu bar. - * - * @return The debug menu */ - public JMenu buildMenu() { - debugMenu = new JMenu(Language.text("menu.debug")); + public void populateMenu(JMenu modeMenu) { + debugMenu = modeMenu; JMenuItem item; debugItem = Toolkit.newJMenuItem(Language.text("menu.debug.enable"), 'D'); @@ -188,8 +185,6 @@ public void actionPerformed(ActionEvent e) { }); debugMenu.add(item); item.setEnabled(false); - - return debugMenu; } diff --git a/todo.txt b/todo.txt index 123bf9da98..8529ba82db 100755 --- a/todo.txt +++ b/todo.txt @@ -1,4 +1,6 @@ 1271 (4.0a2) +X break buildMenu() into populateMenu() method to delay Debugger init +X https://github.com/processing/processing4/issues/73 sam X Resolve rewrite of pixelDensity to settings in preproc