From ecee836ad128b446c6aa5232d4d8f926fdb1652b Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Mon, 18 May 2015 11:09:07 -0400 Subject: [PATCH] debugger reworking --- java/src/processing/mode/java/Debugger.java | 118 +++++++++--------- java/src/processing/mode/java/JavaEditor.java | 41 +++++- .../mode/java/VariableInspector.java | 14 ++- todo.txt | 25 ++-- 4 files changed, 122 insertions(+), 76 deletions(-) diff --git a/java/src/processing/mode/java/Debugger.java b/java/src/processing/mode/java/Debugger.java index e4d24afae..8cf79d9a2 100644 --- a/java/src/processing/mode/java/Debugger.java +++ b/java/src/processing/mode/java/Debugger.java @@ -317,49 +317,49 @@ public class Debugger implements VMEventListener { } - /** Print the current stack trace. */ - public synchronized void printStackTrace() { - if (isStarted()) { - printStackTrace(currentThread); - } - } - - - /** - * Print local variables. Outputs type, name and value of each variable. - */ - public synchronized void printLocals() { - if (isStarted()) { - printLocalVariables(currentThread); - } - } - - - /** - * Print fields of current {@code this}-object. - * Outputs type, name and value of each field. - */ - public synchronized void printThis() { - if (isStarted()) { - printThis(currentThread); - } - } - - - /** - * Print a source code snippet of the current location. - */ - public synchronized void printSource() { - if (isStarted()) { - printSourceLocation(currentThread); - } - } +// /** Print the current stack trace. */ +// public synchronized void printStackTrace() { +// if (isStarted()) { +// printStackTrace(currentThread); +// } +// } +// +// +// /** +// * Print local variables. Outputs type, name and value of each variable. +// */ +// public synchronized void printLocals() { +// if (isStarted()) { +// printLocalVariables(currentThread); +// } +// } +// +// +// /** +// * Print fields of current {@code this}-object. +// * Outputs type, name and value of each field. +// */ +// public synchronized void printThis() { +// if (isStarted()) { +// printThis(currentThread); +// } +// } +// +// +// /** +// * Print a source code snippet of the current location. +// */ +// public synchronized void printSource() { +// if (isStarted()) { +// printSourceLocation(currentThread); +// } +// } /** * Set a breakpoint on the current line. */ - public synchronized void setBreakpoint() { + synchronized void setBreakpoint() { setBreakpoint(editor.getCurrentLineID()); } @@ -369,12 +369,12 @@ public class Debugger implements VMEventListener { * @param lineIdx the line index (0-based) of the current tab to set the * breakpoint on */ - public synchronized void setBreakpoint(int lineIdx) { + synchronized void setBreakpoint(int lineIdx) { setBreakpoint(editor.getLineIDInCurrentTab(lineIdx)); } - public synchronized void setBreakpoint(LineID line) { + synchronized void setBreakpoint(LineID line) { // do nothing if we are kinda busy if (isStarted() && !isPaused()) { return; @@ -391,7 +391,7 @@ public class Debugger implements VMEventListener { /** * Remove a breakpoint from the current line (if set). */ - public synchronized void removeBreakpoint() { + synchronized void removeBreakpoint() { removeBreakpoint(editor.getCurrentLineID().lineIdx()); } @@ -402,7 +402,7 @@ public class Debugger implements VMEventListener { * @param lineIdx the line index (0-based) in the current tab to remove the * breakpoint from */ - protected void removeBreakpoint(int lineIdx) { + void removeBreakpoint(int lineIdx) { // do nothing if we are kinda busy if (isBusy()) { return; @@ -418,7 +418,7 @@ public class Debugger implements VMEventListener { /** Remove all breakpoints. */ - public synchronized void clearBreakpoints() { + synchronized void clearBreakpoints() { //TODO: handle busy-ness correctly if (isBusy()) { log(Level.WARNING, "busy"); @@ -436,7 +436,7 @@ public class Debugger implements VMEventListener { * Clear breakpoints in a specific tab. * @param tabFilename the tab's file name */ - public synchronized void clearBreakpoints(String tabFilename) { + synchronized void clearBreakpoints(String tabFilename) { //TODO: handle busy-ness correctly if (isBusy()) { log(Level.WARNING, "busy"); @@ -460,7 +460,7 @@ public class Debugger implements VMEventListener { * @return the breakpoint, or null if no breakpoint is set on the specified * line. */ - protected LineBreakpoint breakpointOnLine(LineID line) { + LineBreakpoint breakpointOnLine(LineID line) { for (LineBreakpoint bp : breakpoints) { if (bp.isOnLine(line)) { return bp; @@ -471,7 +471,7 @@ public class Debugger implements VMEventListener { /** Toggle a breakpoint on the current line. */ - public synchronized void toggleBreakpoint() { + synchronized void toggleBreakpoint() { toggleBreakpoint(editor.getCurrentLineID().lineIdx()); } @@ -480,7 +480,7 @@ public class Debugger implements VMEventListener { * Toggle a breakpoint on a line in the current tab. * @param lineIdx the line index (0-based) in the current tab */ - public synchronized void toggleBreakpoint(int lineIdx) { + synchronized void toggleBreakpoint(int lineIdx) { LineID line = editor.getLineIDInCurrentTab(lineIdx); if (!hasBreakpoint(line)) { setBreakpoint(line.lineIdx()); @@ -501,17 +501,17 @@ public class Debugger implements VMEventListener { } - /** Print a list of currently set breakpoints. */ - public synchronized void listBreakpoints() { - if (breakpoints.isEmpty()) { - System.out.println("no breakpoints"); - } else { - System.out.println("line breakpoints:"); - for (LineBreakpoint bp : breakpoints) { - System.out.println(bp); - } - } - } +// /** Print a list of currently set breakpoints. */ +// public synchronized void listBreakpoints() { +// if (breakpoints.isEmpty()) { +// System.out.println("no breakpoints"); +// } else { +// System.out.println("line breakpoints:"); +// for (LineBreakpoint bp : breakpoints) { +// System.out.println(bp); +// } +// } +// } /** @@ -519,7 +519,7 @@ public class Debugger implements VMEventListener { * @param tabFilename the tab's file name * @return the list of breakpoints in the given tab */ - public synchronized List getBreakpoints(String tabFilename) { + synchronized List getBreakpoints(String tabFilename) { List list = new ArrayList(); for (LineBreakpoint bp : breakpoints) { if (bp.lineID().fileName().equals(tabFilename)) { diff --git a/java/src/processing/mode/java/JavaEditor.java b/java/src/processing/mode/java/JavaEditor.java index 2c5999e45..6a27670d3 100644 --- a/java/src/processing/mode/java/JavaEditor.java +++ b/java/src/processing/mode/java/JavaEditor.java @@ -1450,6 +1450,7 @@ public class JavaEditor extends Editor { } }); debugMenu.add(item); + item.setEnabled(false); // item = new JMenuItem(Language.text("menu.debug.stop")); // item.addActionListener(new ActionListener() { @@ -1467,6 +1468,7 @@ public class JavaEditor extends Editor { } }); debugMenu.add(item); + item.setEnabled(false); item = Toolkit.newJMenuItemShift(Language.text("menu.debug.step_into"), KeyEvent.VK_J); item.addActionListener(new ActionListener() { @@ -1475,6 +1477,7 @@ public class JavaEditor extends Editor { } }); debugMenu.add(item); + item.setEnabled(false); item = Toolkit.newJMenuItemAlt(Language.text("menu.debug.step_out"), KeyEvent.VK_J); item.addActionListener(new ActionListener() { @@ -1483,11 +1486,12 @@ public class JavaEditor extends Editor { } }); debugMenu.add(item); + item.setEnabled(false); debugMenu.addSeparator(); item = - Toolkit.newJMenuItem(Language.text("menu.debug.toggle_breakpoint"), KeyEvent.VK_B); + Toolkit.newJMenuItem(Language.text("menu.debug.toggle_breakpoint"), 'B'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Logger.getLogger(JavaEditor.class.getName()).log(Level.INFO, "Invoked 'Toggle Breakpoint' menu item"); @@ -1495,7 +1499,18 @@ public class JavaEditor extends Editor { } }); debugMenu.add(item); + item.setEnabled(false); + item = Toolkit.newJMenuItem(Language.text("menu.debug.variable_inspector"), 'Y'); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + toggleVariableInspector(); + } + }); + debugMenu.add(item); + item.setEnabled(false); + + /* item = new JMenuItem(Language.text("menu.debug.list_breakpoints")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -1506,7 +1521,9 @@ public class JavaEditor extends Editor { debugMenu.add(item); debugMenu.addSeparator(); + */ + /* item = new JMenuItem(Language.text("menu.debug.print_stack_trace")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -1553,6 +1570,7 @@ public class JavaEditor extends Editor { debugMenu.add(item); debugMenu.addSeparator(); + */ // item = Toolkit.newJMenuItem(Language.text("menu.debug.toggle_variable_inspector"), KeyEvent.VK_I); // item.addActionListener(new ActionListener() { @@ -1563,6 +1581,7 @@ public class JavaEditor extends Editor { // }); // debugMenu.add(item); + /* item = Toolkit.newJMenuItem(Language.text("menu.debug.show_sketch_outline"), KeyEvent.VK_L); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -1580,6 +1599,7 @@ public class JavaEditor extends Editor { } }); debugMenu.add(item); + */ return debugMenu; } @@ -2133,6 +2153,10 @@ public class JavaEditor extends Editor { public void updateDebugToggle() { final boolean enabled = isDebuggerEnabled(); rebuildToolbar(); + + if (!enabled && inspector.isVisible()) { + toggleVariableInspector(); + } /* if (enabled) { inspector.setFocusableWindowState(false); // to not get focus when set visible @@ -2150,11 +2174,22 @@ public class JavaEditor extends Editor { } + public void toggleVariableInspector() { + if (inspector.isVisible()) { + inspector.setVisible(false); + } else { +// inspector.setFocusableWindowState(false); // to not get focus when set visible + inspector.setVisible(true); +// inspector.setFocusableWindowState(true); // allow to get focus again + } + } + + // public void showVariableInspector() { // tray.setVisible(true); // } -// -// + + // /** // * Set visibility of the variable inspector window. // * @param visible true to set the variable inspector visible, diff --git a/java/src/processing/mode/java/VariableInspector.java b/java/src/processing/mode/java/VariableInspector.java index 18ac9b513..d604c6482 100644 --- a/java/src/processing/mode/java/VariableInspector.java +++ b/java/src/processing/mode/java/VariableInspector.java @@ -47,7 +47,7 @@ import processing.app.Mode; import processing.mode.java.debug.VariableNode; -public class VariableInspector extends JFrame { +public class VariableInspector extends JDialog { static public final int GAP = 13; EditorButton continueButton; @@ -95,8 +95,17 @@ public class VariableInspector extends JFrame { public VariableInspector(final JavaEditor editor) { - super("Inspector"); + // As a JDialog, the menu bar comes from the Editor + super(editor, "Inspector"); this.editor = editor; + + // Use the small toolbar style (at least on OS X) + // https://developer.apple.com/library/mac/technotes/tn2007/tn2196.html#WINDOWS + getRootPane().putClientProperty("Window.style", "small"); + + // When clicking this window, keep the focus on the Editor window + setFocusableWindowState(false); + //setUndecorated(true); //editor.addComponentListener(new EditorFollower()); @@ -111,7 +120,6 @@ public class VariableInspector extends JFrame { // editor.getY() + VERTICAL_OFFSET); setLocationRelativeTo(editor); - /* bgColor = mode.getColor("buttons.bgcolor"); statusFont = mode.getFont("buttons.status.font"); diff --git a/todo.txt b/todo.txt index 9fa0d6515..a6a154ae5 100644 --- a/todo.txt +++ b/todo.txt @@ -2,25 +2,28 @@ pdex/debugger X remove "Experimental Mode: Yikes!" messages +o NullPointerException in initiateToolTip() +X https://github.com/processing/processing/issues/3286 +X can no longer reproduce - -in a8, but unconfirmed -_ "step" not working properly -_ https://github.com/processing/processing/issues/3266 +in alpha 8 (but not confirmed in time) +X "step" not working properly +X https://github.com/processing/processing/issues/3266 _ Cmd-click behavior on function/variable is firing when cmd-click not pressed _ https://github.com/processing/processing/issues/3242 pdex -_ NullPointerException in initiateToolTip() -_ https://github.com/processing/processing/issues/3286 -_ get rid of the debugger 'pane', just have that be the old window +_ name of toggle debug and variable inspector +_ Enable Debugger (with or without a checkbox) +_ "show inspector" "hide inspector" "variable inspector" (with a check) +X get rid of the debugger 'pane', just have that be the old window o show debug window when running, hide when stopped o can we animate the show/hide for the debug box? -_ large window places the debugger window offscreen -_ https://github.com/processing/processing/issues/3091 -_ almost all of the debugger menu needs to disappear -_ https://github.com/processing/processing/issues/3267 +X large window places the debugger window offscreen +X https://github.com/processing/processing/issues/3091 +X almost all of the debugger menu needs to disappear +X https://github.com/processing/processing/issues/3267 _ everything below toggle breakpoint, plus show/hide inspector _ debugger button should show/hide toolbar buttons for step/continue _ fix hasJavaTabs() function