src/Tools/jEdit/src/debugger_dockable.scala
author wenzelm
Mon, 10 Aug 2015 20:22:49 +0200
changeset 60880 fa958e24ff24
parent 60878 1f0d2bbcf38b
child 60883 8eb8640d7300
permissions -rw-r--r--
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
60749
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
     1
/*  Title:      Tools/jEdit/src/debugger_dockable.scala
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
     3
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
     4
Dockable window for Isabelle/ML debugger.
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
     5
*/
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
     6
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
     7
package isabelle.jedit
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
     8
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
     9
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
    10
import isabelle._
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
    11
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    12
import java.awt.{BorderLayout, Dimension}
60875
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
    13
import java.awt.event.{ComponentEvent, ComponentAdapter, KeyEvent, MouseEvent, MouseAdapter,
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
    14
  FocusAdapter, FocusEvent}
60878
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    15
import javax.swing.{JTree, JScrollPane, JMenuItem}
60850
d5d776c8a7e2 proper dynamic update;
wenzelm
parents: 60849
diff changeset
    16
import javax.swing.tree.{DefaultMutableTreeNode, DefaultTreeModel, TreeSelectionModel}
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    17
import javax.swing.event.{TreeSelectionEvent, TreeSelectionListener}
60832
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
    18
60857
4c18d8e4fe14 clarified debugger loop;
wenzelm
parents: 60856
diff changeset
    19
import scala.swing.{Button, Label, Component, SplitPane, Orientation, CheckBox}
60832
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
    20
import scala.swing.event.ButtonClicked
60749
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
    21
60875
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
    22
import org.gjt.sp.jedit.{jEdit, View}
60878
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    23
import org.gjt.sp.jedit.menu.EnhancedMenuItem
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    24
import org.gjt.sp.jedit.textarea.JEditTextArea
60749
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
    25
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
    26
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    27
object Debugger_Dockable
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    28
{
60878
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    29
  /* state entries */
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    30
60851
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
    31
  sealed case class Thread_Entry(thread_name: String, debug_states: List[Debugger.Debug_State])
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    32
  {
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    33
    override def toString: String = thread_name
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    34
  }
60851
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
    35
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
    36
  sealed case class Stack_Entry(debug_state: Debugger.Debug_State, index: Int)
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
    37
  {
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
    38
    override def toString: String = debug_state.function
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
    39
  }
60878
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    40
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    41
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    42
  /* breakpoints */
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    43
60880
fa958e24ff24 set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents: 60878
diff changeset
    44
  def toggle_breakpoint(command: Command, breakpoint: Long)
60878
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    45
  {
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    46
    GUI_Thread.require {}
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    47
60880
fa958e24ff24 set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents: 60878
diff changeset
    48
    Debugger.toggle_breakpoint(command, breakpoint)
60878
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    49
    jEdit.propertiesChanged()
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    50
  }
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    51
60880
fa958e24ff24 set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents: 60878
diff changeset
    52
  def get_breakpoint(text_area: JEditTextArea, offset: Text.Offset): Option[(Command, Long)] =
60878
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    53
  {
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    54
    GUI_Thread.require {}
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    55
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    56
    PIDE.document_view(text_area) match {
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    57
      case Some(doc_view) =>
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    58
        val rendering = doc_view.get_rendering()
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    59
        val range = JEdit_Lib.point_range(text_area.getBuffer, offset)
60880
fa958e24ff24 set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents: 60878
diff changeset
    60
        rendering.breakpoint(range)
60878
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    61
      case None => None
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    62
    }
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    63
  }
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    64
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    65
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    66
  /* context menu */
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    67
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    68
  def context_menu(text_area: JEditTextArea, offset: Text.Offset): List[JMenuItem] =
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    69
    if (get_breakpoint(text_area, offset).isDefined) {
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    70
      val context = jEdit.getActionContext()
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    71
      val name = "isabelle.toggle-breakpoint"
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    72
      List(new EnhancedMenuItem(context.getAction(name).getLabel, name, context))
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    73
    }
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
    74
    else Nil
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    75
}
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    76
60749
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
    77
class Debugger_Dockable(view: View, position: String) extends Dockable(view, position)
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
    78
{
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
    79
  GUI_Thread.require {}
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
    80
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
    81
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
    82
  /* component state -- owned by GUI thread */
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
    83
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
    84
  private var current_snapshot = Document.Snapshot.init
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    85
  private var current_threads: Map[String, List[Debugger.Debug_State]] = Map.empty
60749
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
    86
  private var current_output: List[XML.Tree] = Nil
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
    87
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
    88
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    89
  /* pretty text area */
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    90
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    91
  val pretty_text_area = new Pretty_Text_Area(view)
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    92
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    93
  override def detach_operation = pretty_text_area.detach_operation
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    94
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    95
  private def handle_resize()
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    96
  {
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    97
    GUI_Thread.require {}
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    98
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
    99
    pretty_text_area.resize(
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   100
      Font_Info.main(PIDE.options.real("jedit_font_scale") * zoom.factor / 100))
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   101
  }
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   102
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   103
  private def handle_update()
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   104
  {
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   105
    GUI_Thread.require {}
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   106
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   107
    val new_state = Debugger.current_state()
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   108
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   109
    val new_snapshot = PIDE.editor.current_node_snapshot(view).getOrElse(current_snapshot)
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   110
    val new_threads = new_state.threads
60851
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   111
    val new_output =
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   112
    {
60859
933737bacac7 expand all rows for robustness and simplicity;
wenzelm
parents: 60857
diff changeset
   113
      val current_thread_selection = thread_selection()
60851
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   114
      (for {
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   115
        (thread_name, results) <- new_state.output
60859
933737bacac7 expand all rows for robustness and simplicity;
wenzelm
parents: 60857
diff changeset
   116
        if current_thread_selection.isEmpty || current_thread_selection.get == thread_name
60851
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   117
        (_, tree) <- results.iterator
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   118
      } yield tree).toList
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   119
    }
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   120
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   121
    if (new_threads != current_threads) {
60851
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   122
      val thread_entries =
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   123
        (for ((a, b) <- new_threads.iterator)
60851
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   124
          yield Debugger_Dockable.Thread_Entry(a, b)).toList.sortBy(_.thread_name)
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   125
      update_tree(thread_entries)
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   126
    }
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   127
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   128
    if (new_output != current_output)
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   129
      pretty_text_area.update(new_snapshot, Command.Results.empty, Pretty.separate(new_output))
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   130
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   131
    current_snapshot = new_snapshot
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   132
    current_threads = new_threads
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   133
    current_output = new_output
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   134
  }
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   135
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   136
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   137
  /* tree view */
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   138
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   139
  private val root = new DefaultMutableTreeNode("Threads")
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   140
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   141
  val tree = new JTree(root)
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   142
  tree.setRowHeight(0)
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   143
  tree.getSelectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION)
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   144
60854
8f45dd297357 more controls;
wenzelm
parents: 60851
diff changeset
   145
  def tree_selection(): Option[(Debugger_Dockable.Thread_Entry, Option[Int])] =
60851
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   146
    tree.getSelectionPath match {
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   147
      case null => None
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   148
      case path =>
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   149
        path.getPath.toList.map(n => n.asInstanceOf[DefaultMutableTreeNode].getUserObject) match {
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   150
          case List(_, t: Debugger_Dockable.Thread_Entry) =>
60854
8f45dd297357 more controls;
wenzelm
parents: 60851
diff changeset
   151
            Some((t, None))
60851
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   152
          case List(_, t: Debugger_Dockable.Thread_Entry, s: Debugger_Dockable.Stack_Entry) =>
60854
8f45dd297357 more controls;
wenzelm
parents: 60851
diff changeset
   153
            Some((t, Some(s.index)))
60851
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   154
          case _ => None
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   155
        }
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   156
    }
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   157
60859
933737bacac7 expand all rows for robustness and simplicity;
wenzelm
parents: 60857
diff changeset
   158
  def thread_selection(): Option[String] = tree_selection().map(sel => sel._1.thread_name)
933737bacac7 expand all rows for robustness and simplicity;
wenzelm
parents: 60857
diff changeset
   159
60875
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   160
  def focus_selection(): Option[Position.T] =
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   161
    tree_selection() match {
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   162
      case Some((t, opt_index)) =>
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   163
        val i = opt_index getOrElse 0
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   164
        if (i < t.debug_states.length) Some(t.debug_states(i).pos) else None
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   165
      case _ => None
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   166
    }
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   167
60851
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   168
  private def update_tree(thread_entries: List[Debugger_Dockable.Thread_Entry])
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   169
  {
60860
e78bdf06d33c approximate old selection after update;
wenzelm
parents: 60859
diff changeset
   170
    val old_thread_selection = thread_selection()
e78bdf06d33c approximate old selection after update;
wenzelm
parents: 60859
diff changeset
   171
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   172
    tree.clearSelection
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   173
    root.removeAllChildren
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   174
60859
933737bacac7 expand all rows for robustness and simplicity;
wenzelm
parents: 60857
diff changeset
   175
    for (thread_entry <- thread_entries) {
933737bacac7 expand all rows for robustness and simplicity;
wenzelm
parents: 60857
diff changeset
   176
      val thread_node = new DefaultMutableTreeNode(thread_entry)
60851
35932863b114 support for tree selection;
wenzelm
parents: 60850
diff changeset
   177
      for ((debug_state, i) <- thread_entry.debug_states.zipWithIndex) {
60859
933737bacac7 expand all rows for robustness and simplicity;
wenzelm
parents: 60857
diff changeset
   178
        val stack_node =
933737bacac7 expand all rows for robustness and simplicity;
wenzelm
parents: 60857
diff changeset
   179
          new DefaultMutableTreeNode(Debugger_Dockable.Stack_Entry(debug_state, i))
933737bacac7 expand all rows for robustness and simplicity;
wenzelm
parents: 60857
diff changeset
   180
        thread_node.add(stack_node)
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   181
      }
60859
933737bacac7 expand all rows for robustness and simplicity;
wenzelm
parents: 60857
diff changeset
   182
      root.add(thread_node)
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   183
    }
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   184
60859
933737bacac7 expand all rows for robustness and simplicity;
wenzelm
parents: 60857
diff changeset
   185
    tree.getModel.asInstanceOf[DefaultTreeModel].reload(root)
60860
e78bdf06d33c approximate old selection after update;
wenzelm
parents: 60859
diff changeset
   186
e78bdf06d33c approximate old selection after update;
wenzelm
parents: 60859
diff changeset
   187
    old_thread_selection match {
e78bdf06d33c approximate old selection after update;
wenzelm
parents: 60859
diff changeset
   188
      case Some(thread_name) if thread_entries.exists(t => t.thread_name == thread_name) =>
e78bdf06d33c approximate old selection after update;
wenzelm
parents: 60859
diff changeset
   189
        val i =
e78bdf06d33c approximate old selection after update;
wenzelm
parents: 60859
diff changeset
   190
          (for (t <- thread_entries.iterator.takeWhile(t => t.thread_name != thread_name))
e78bdf06d33c approximate old selection after update;
wenzelm
parents: 60859
diff changeset
   191
            yield 1 + t.debug_states.length).sum
e78bdf06d33c approximate old selection after update;
wenzelm
parents: 60859
diff changeset
   192
        tree.addSelectionRow(i + 1)
e78bdf06d33c approximate old selection after update;
wenzelm
parents: 60859
diff changeset
   193
      case _ =>
e78bdf06d33c approximate old selection after update;
wenzelm
parents: 60859
diff changeset
   194
    }
60859
933737bacac7 expand all rows for robustness and simplicity;
wenzelm
parents: 60857
diff changeset
   195
    for (i <- 0 until tree.getRowCount) tree.expandRow(i)
60860
e78bdf06d33c approximate old selection after update;
wenzelm
parents: 60859
diff changeset
   196
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   197
    tree.revalidate()
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   198
  }
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   199
60875
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   200
  tree.addTreeSelectionListener(
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   201
    new TreeSelectionListener {
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   202
      override def valueChanged(e: TreeSelectionEvent) { update_focus(focus_selection()) }
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   203
    })
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   204
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   205
  tree.addMouseListener(new MouseAdapter {
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   206
    override def mouseClicked(e: MouseEvent)
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   207
    {
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   208
      val click = tree.getPathForLocation(e.getX, e.getY)
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   209
      if (click != null && e.getClickCount == 1) {
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   210
        (click.getLastPathComponent, tree.getLastSelectedPathComponent) match {
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   211
          case (node: DefaultMutableTreeNode, node1: DefaultMutableTreeNode) if node == node1 =>
60875
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   212
            handle_update()
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   213
          case _ =>
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   214
        }
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   215
      }
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   216
    }
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   217
  })
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   218
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   219
  val tree_view = new JScrollPane(tree)
60849
wenzelm
parents: 60848
diff changeset
   220
  tree_view.setMinimumSize(new Dimension(200, 50))
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   221
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   222
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   223
  /* controls */
60832
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   224
60862
097afdd8a2fd eval ML context;
wenzelm
parents: 60861
diff changeset
   225
  private val context_label = new Label("Context:") {
097afdd8a2fd eval ML context;
wenzelm
parents: 60861
diff changeset
   226
    tooltip = "Isabelle/ML context: type theory, Proof.context, Context.generic"
097afdd8a2fd eval ML context;
wenzelm
parents: 60861
diff changeset
   227
  }
60832
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   228
  private val context_field =
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   229
    new Completion_Popup.History_Text_Field("isabelle-debugger-context")
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   230
    {
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   231
      setColumns(20)
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   232
      setToolTipText(context_label.tooltip)
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   233
      setFont(GUI.imitate_font(getFont, Font_Info.main_family(), 1.2))
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   234
    }
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   235
60862
097afdd8a2fd eval ML context;
wenzelm
parents: 60861
diff changeset
   236
  private val expression_label = new Label("ML:") {
097afdd8a2fd eval ML context;
wenzelm
parents: 60861
diff changeset
   237
    tooltip = "Isabelle/ML or Standard ML expression"
097afdd8a2fd eval ML context;
wenzelm
parents: 60861
diff changeset
   238
  }
60832
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   239
  private val expression_field =
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   240
    new Completion_Popup.History_Text_Field("isabelle-debugger-expression")
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   241
    {
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   242
      override def processKeyEvent(evt: KeyEvent)
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   243
      {
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   244
        if (evt.getID == KeyEvent.KEY_PRESSED && evt.getKeyCode == KeyEvent.VK_ENTER)
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   245
          eval_expression()
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   246
        super.processKeyEvent(evt)
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   247
      }
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   248
      { val max = getPreferredSize; max.width = Integer.MAX_VALUE; setMaximumSize(max) }
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   249
      setColumns(40)
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   250
      setToolTipText(expression_label.tooltip)
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   251
      setFont(GUI.imitate_font(getFont, Font_Info.main_family(), 1.2))
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   252
    }
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   253
60857
4c18d8e4fe14 clarified debugger loop;
wenzelm
parents: 60856
diff changeset
   254
  private val sml_button = new CheckBox("SML") {
4c18d8e4fe14 clarified debugger loop;
wenzelm
parents: 60856
diff changeset
   255
    tooltip = "Official Standard ML instead of Isabelle/ML"
4c18d8e4fe14 clarified debugger loop;
wenzelm
parents: 60856
diff changeset
   256
    selected = false
4c18d8e4fe14 clarified debugger loop;
wenzelm
parents: 60856
diff changeset
   257
  }
4c18d8e4fe14 clarified debugger loop;
wenzelm
parents: 60856
diff changeset
   258
60832
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   259
  private val eval_button = new Button("<html><b>Eval</b></html>") {
60862
097afdd8a2fd eval ML context;
wenzelm
parents: 60861
diff changeset
   260
      tooltip = "Evaluate ML expression within optional context"
60832
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   261
      reactions += { case ButtonClicked(_) => eval_expression() }
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   262
    }
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   263
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   264
  private def eval_expression()
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   265
  {
60861
fa77faa87d5f maintain history more often;
wenzelm
parents: 60860
diff changeset
   266
    context_field.addCurrentToHistory()
fa77faa87d5f maintain history more often;
wenzelm
parents: 60860
diff changeset
   267
    expression_field.addCurrentToHistory()
60856
eb21ae05ec43 clarified thread state;
wenzelm
parents: 60854
diff changeset
   268
    tree_selection() match {
60857
4c18d8e4fe14 clarified debugger loop;
wenzelm
parents: 60856
diff changeset
   269
      case Some((t, opt_index)) if t.debug_states.nonEmpty =>
4c18d8e4fe14 clarified debugger loop;
wenzelm
parents: 60856
diff changeset
   270
        Debugger.eval(t.thread_name, opt_index getOrElse 0,
4c18d8e4fe14 clarified debugger loop;
wenzelm
parents: 60856
diff changeset
   271
          sml_button.selected, context_field.getText, expression_field.getText)
60856
eb21ae05ec43 clarified thread state;
wenzelm
parents: 60854
diff changeset
   272
      case _ =>
eb21ae05ec43 clarified thread state;
wenzelm
parents: 60854
diff changeset
   273
    }
60832
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   274
  }
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   275
60869
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   276
  private val step_button = new Button("Step") {
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   277
    tooltip = "Single-step in depth-first order"
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   278
    reactions += { case ButtonClicked(_) => thread_selection().map(Debugger.step(_)) }
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   279
  }
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   280
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   281
  private val step_over_button = new Button("Step over") {
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   282
    tooltip = "Single-step within this function"
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   283
    reactions += { case ButtonClicked(_) => thread_selection().map(Debugger.step_over(_)) }
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   284
  }
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   285
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   286
  private val step_out_button = new Button("Step out") {
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   287
    tooltip = "Single-step outside this function"
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   288
    reactions += { case ButtonClicked(_) => thread_selection().map(Debugger.step_out(_)) }
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   289
  }
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   290
60854
8f45dd297357 more controls;
wenzelm
parents: 60851
diff changeset
   291
  private val continue_button = new Button("Continue") {
60869
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   292
    tooltip = "Continue program on current thread, until next breakpoint"
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   293
    reactions += { case ButtonClicked(_) => thread_selection().map(Debugger.continue(_)) }
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   294
  }
60854
8f45dd297357 more controls;
wenzelm
parents: 60851
diff changeset
   295
8f45dd297357 more controls;
wenzelm
parents: 60851
diff changeset
   296
  private val cancel_button = new Button("Cancel") {
60869
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   297
    tooltip = "Interrupt program on current thread"
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   298
    reactions += { case ButtonClicked(_) => thread_selection().map(Debugger.cancel(_)) }
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   299
  }
60854
8f45dd297357 more controls;
wenzelm
parents: 60851
diff changeset
   300
60845
c4cb46e3cdd1 more controls;
wenzelm
parents: 60842
diff changeset
   301
  private val debugger_active =
c4cb46e3cdd1 more controls;
wenzelm
parents: 60842
diff changeset
   302
    new JEdit_Options.Check_Box("ML_debugger_active", "Active", "Enable debugger at run-time")
c4cb46e3cdd1 more controls;
wenzelm
parents: 60842
diff changeset
   303
c4cb46e3cdd1 more controls;
wenzelm
parents: 60842
diff changeset
   304
  private val debugger_stepping =
c4cb46e3cdd1 more controls;
wenzelm
parents: 60842
diff changeset
   305
    new JEdit_Options.Check_Box("ML_debugger_stepping", "Stepping", "Enable single-step mode")
c4cb46e3cdd1 more controls;
wenzelm
parents: 60842
diff changeset
   306
60832
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   307
  private val zoom = new Font_Info.Zoom_Box { def changed = handle_resize() }
1cdc63224ed3 more GUI components;
wenzelm
parents: 60750
diff changeset
   308
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   309
  private val controls =
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   310
    new Wrap_Panel(Wrap_Panel.Alignment.Right)(
60869
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   311
      step_button, step_over_button, step_out_button, continue_button, cancel_button,
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   312
      context_label, Component.wrap(context_field),
60857
4c18d8e4fe14 clarified debugger loop;
wenzelm
parents: 60856
diff changeset
   313
      expression_label, Component.wrap(expression_field),
60869
878e32cf3131 more single stepping;
wenzelm
parents: 60862
diff changeset
   314
      sml_button, eval_button,
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   315
      pretty_text_area.search_label, pretty_text_area.search_field,
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   316
      debugger_stepping, debugger_active, zoom)
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   317
  add(controls.peer, BorderLayout.NORTH)
60749
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   318
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   319
60875
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   320
  /* focus */
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   321
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   322
  override def focusOnDefaultComponent { eval_button.requestFocus }
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   323
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   324
  addFocusListener(new FocusAdapter {
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   325
    override def focusGained(e: FocusEvent) { update_focus(focus_selection()) }
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   326
    override def focusLost(e: FocusEvent) { update_focus(None) }
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   327
  })
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   328
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   329
  private def update_focus(focus: Option[Position.T])
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   330
  {
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   331
    if (Debugger.focus(focus) && focus.isDefined)
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   332
      PIDE.editor.hyperlink_position(current_snapshot, focus.get).foreach(_.follow(view))
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   333
  }
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   334
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   335
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   336
  /* main panel */
60749
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   337
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   338
  val main_panel = new SplitPane(Orientation.Vertical) {
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   339
    oneTouchExpandable = true
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   340
    leftComponent = Component.wrap(tree_view)
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   341
    rightComponent = Component.wrap(pretty_text_area)
60749
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   342
  }
60848
7ec20b1c8dc9 more GUI components;
wenzelm
parents: 60845
diff changeset
   343
  set_content(main_panel)
60749
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   344
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   345
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   346
  /* main */
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   347
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   348
  private val main =
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   349
    Session.Consumer[Any](getClass.getName) {
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   350
      case _: Session.Global_Options =>
60835
6512bb0b1ff4 clarified management of (single) session;
wenzelm
parents: 60834
diff changeset
   351
        Debugger.init(PIDE.session)
60845
c4cb46e3cdd1 more controls;
wenzelm
parents: 60842
diff changeset
   352
        GUI_Thread.later {
c4cb46e3cdd1 more controls;
wenzelm
parents: 60842
diff changeset
   353
          debugger_active.load()
c4cb46e3cdd1 more controls;
wenzelm
parents: 60842
diff changeset
   354
          debugger_stepping.load()
c4cb46e3cdd1 more controls;
wenzelm
parents: 60842
diff changeset
   355
          handle_resize()
c4cb46e3cdd1 more controls;
wenzelm
parents: 60842
diff changeset
   356
        }
60749
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   357
60835
6512bb0b1ff4 clarified management of (single) session;
wenzelm
parents: 60834
diff changeset
   358
      case _: Debugger.Update =>
60749
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   359
        GUI_Thread.later { handle_update() }
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   360
    }
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   361
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   362
  override def init()
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   363
  {
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   364
    PIDE.session.global_options += main
60835
6512bb0b1ff4 clarified management of (single) session;
wenzelm
parents: 60834
diff changeset
   365
    PIDE.session.debugger_updates += main
6512bb0b1ff4 clarified management of (single) session;
wenzelm
parents: 60834
diff changeset
   366
    Debugger.init(PIDE.session)
60876
52edced9cce5 rendering for debugger/breakpoint active state;
wenzelm
parents: 60875
diff changeset
   367
    Debugger.inc_active()
60749
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   368
    handle_update()
60876
52edced9cce5 rendering for debugger/breakpoint active state;
wenzelm
parents: 60875
diff changeset
   369
    jEdit.propertiesChanged()
60749
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   370
  }
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   371
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   372
  override def exit()
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   373
  {
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   374
    PIDE.session.global_options -= main
60835
6512bb0b1ff4 clarified management of (single) session;
wenzelm
parents: 60834
diff changeset
   375
    PIDE.session.debugger_updates -= main
60749
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   376
    delay_resize.revoke()
60875
ee23c1d21ac3 follow debugger focus;
wenzelm
parents: 60869
diff changeset
   377
    update_focus(None)
60876
52edced9cce5 rendering for debugger/breakpoint active state;
wenzelm
parents: 60875
diff changeset
   378
    Debugger.dec_active()
52edced9cce5 rendering for debugger/breakpoint active state;
wenzelm
parents: 60875
diff changeset
   379
    jEdit.propertiesChanged()
60749
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   380
  }
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   381
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   382
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   383
  /* resize */
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   384
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   385
  private val delay_resize =
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   386
    GUI_Thread.delay_first(PIDE.options.seconds("editor_update_delay")) { handle_resize() }
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   387
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   388
  addComponentListener(new ComponentAdapter {
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   389
    override def componentResized(e: ComponentEvent) { delay_resize.invoke() }
60750
7694aa52ad56 more uniform ComponentAdapter;
wenzelm
parents: 60749
diff changeset
   390
    override def componentShown(e: ComponentEvent) { delay_resize.invoke() }
60749
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   391
  })
f727b99faaf7 skeleton for interactive debugger;
wenzelm
parents:
diff changeset
   392
}