Skip to content

Commit

Permalink
clean up debugger init by delaying some calls until ready (fixes #73)
Browse files Browse the repository at this point in the history
  • Loading branch information
benfry committed Apr 25, 2020
1 parent 7962204 commit 200afc4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
5 changes: 4 additions & 1 deletion app/src/processing/app/ui/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions java/src/processing/mode/java/JavaEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -1385,8 +1388,7 @@ public boolean isDebuggerEnabled() {

@Override
public JMenu buildModeMenu() {
//return buildDebugMenu();
return debugger.buildMenu();
return modeMenu = new JMenu(Language.text("menu.debug"));
}


Expand Down
24 changes: 16 additions & 8 deletions java/src/processing/mode/java/JavaToolbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<EditorButton> 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<EditorButton> outgoing = new ArrayList<>();

final String runText = debug ?
Expand Down Expand Up @@ -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);
}
Expand Down
9 changes: 2 additions & 7 deletions java/src/processing/mode/java/debug/Debugger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -188,8 +185,6 @@ public void actionPerformed(ActionEvent e) {
});
debugMenu.add(item);
item.setEnabled(false);

return debugMenu;
}


Expand Down
2 changes: 2 additions & 0 deletions todo.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 200afc4

Please sign in to comment.