src/Tools/jEdit/src/debugger_dockable.scala
changeset 75393 87ebf5a50283
parent 73987 fc363a3b690a
child 75809 1dd5d4f4b69e
equal deleted inserted replaced
75388:b3ca4a6ed74b 75393:87ebf5a50283
    24 import org.gjt.sp.jedit.{jEdit, View}
    24 import org.gjt.sp.jedit.{jEdit, View}
    25 import org.gjt.sp.jedit.menu.EnhancedMenuItem
    25 import org.gjt.sp.jedit.menu.EnhancedMenuItem
    26 import org.gjt.sp.jedit.textarea.JEditTextArea
    26 import org.gjt.sp.jedit.textarea.JEditTextArea
    27 
    27 
    28 
    28 
    29 object Debugger_Dockable
    29 object Debugger_Dockable {
    30 {
       
    31   /* breakpoints */
    30   /* breakpoints */
    32 
    31 
    33   def get_breakpoint(text_area: JEditTextArea, offset: Text.Offset): Option[(Command, Long)] =
    32   def get_breakpoint(text_area: JEditTextArea, offset: Text.Offset): Option[(Command, Long)] = {
    34   {
       
    35     GUI_Thread.require {}
    33     GUI_Thread.require {}
    36 
    34 
    37     Document_View.get(text_area) match {
    35     Document_View.get(text_area) match {
    38       case Some(doc_view) =>
    36       case Some(doc_view) =>
    39         val rendering = doc_view.get_rendering()
    37         val rendering = doc_view.get_rendering()
    53       List(new EnhancedMenuItem(context.getAction(name).getLabel, name, context))
    51       List(new EnhancedMenuItem(context.getAction(name).getLabel, name, context))
    54     }
    52     }
    55     else Nil
    53     else Nil
    56 }
    54 }
    57 
    55 
    58 class Debugger_Dockable(view: View, position: String) extends Dockable(view, position)
    56 class Debugger_Dockable(view: View, position: String) extends Dockable(view, position) {
    59 {
       
    60   GUI_Thread.require {}
    57   GUI_Thread.require {}
    61 
    58 
    62   private val debugger = PIDE.session.debugger
    59   private val debugger = PIDE.session.debugger
    63 
    60 
    64 
    61 
    73 
    70 
    74   val pretty_text_area = new Pretty_Text_Area(view)
    71   val pretty_text_area = new Pretty_Text_Area(view)
    75 
    72 
    76   override def detach_operation: Option[() => Unit] = pretty_text_area.detach_operation
    73   override def detach_operation: Option[() => Unit] = pretty_text_area.detach_operation
    77 
    74 
    78   private def handle_resize(): Unit =
    75   private def handle_resize(): Unit = {
    79   {
       
    80     GUI_Thread.require {}
    76     GUI_Thread.require {}
    81 
    77 
    82     pretty_text_area.resize(
    78     pretty_text_area.resize(
    83       Font_Info.main(PIDE.options.real("jedit_font_scale") * zoom.factor / 100))
    79       Font_Info.main(PIDE.options.real("jedit_font_scale") * zoom.factor / 100))
    84   }
    80   }
    85 
    81 
    86   private def handle_update(): Unit =
    82   private def handle_update(): Unit = {
    87   {
       
    88     GUI_Thread.require {}
    83     GUI_Thread.require {}
    89 
    84 
    90     val new_snapshot = PIDE.editor.current_node_snapshot(view).getOrElse(current_snapshot)
    85     val new_snapshot = PIDE.editor.current_node_snapshot(view).getOrElse(current_snapshot)
    91     val (new_threads, new_output) = debugger.status(tree_selection())
    86     val (new_threads, new_output) = debugger.status(tree_selection())
    92 
    87 
   120       case _ => None
   115       case _ => None
   121     }
   116     }
   122 
   117 
   123   def thread_selection(): Option[String] = tree_selection().map(_.thread_name)
   118   def thread_selection(): Option[String] = tree_selection().map(_.thread_name)
   124 
   119 
   125   private def update_tree(threads: Debugger.Threads): Unit =
   120   private def update_tree(threads: Debugger.Threads): Unit = {
   126   {
       
   127     val thread_contexts =
   121     val thread_contexts =
   128       (for ((a, b) <- threads.iterator)
   122       (for ((a, b) <- threads.iterator)
   129         yield Debugger.Context(a, b)).toList
   123         yield Debugger.Context(a, b)).toList
   130 
   124 
   131     val new_tree_selection =
   125     val new_tree_selection =
   161     }
   155     }
   162 
   156 
   163     tree.revalidate()
   157     tree.revalidate()
   164   }
   158   }
   165 
   159 
   166   def update_vals(): Unit =
   160   def update_vals(): Unit = {
   167   {
       
   168     tree_selection() match {
   161     tree_selection() match {
   169       case Some(c) if c.stack_state.isDefined =>
   162       case Some(c) if c.stack_state.isDefined =>
   170         debugger.print_vals(c, sml_button.selected, context_field.getText)
   163         debugger.print_vals(c, sml_button.selected, context_field.getText)
   171       case Some(c) =>
   164       case Some(c) =>
   172         debugger.clear_output(c.thread_name)
   165         debugger.clear_output(c.thread_name)
   174     }
   167     }
   175   }
   168   }
   176 
   169 
   177   tree.addTreeSelectionListener(
   170   tree.addTreeSelectionListener(
   178     new TreeSelectionListener {
   171     new TreeSelectionListener {
   179       override def valueChanged(e: TreeSelectionEvent): Unit =
   172       override def valueChanged(e: TreeSelectionEvent): Unit = {
   180       {
       
   181         update_focus()
   173         update_focus()
   182         update_vals()
   174         update_vals()
   183       }
   175       }
   184     })
   176     })
   185   tree.addMouseListener(
   177   tree.addMouseListener(
   186     new MouseAdapter {
   178     new MouseAdapter {
   187       override def mouseClicked(e: MouseEvent): Unit =
   179       override def mouseClicked(e: MouseEvent): Unit = {
   188       {
       
   189         val click = tree.getPathForLocation(e.getX, e.getY)
   180         val click = tree.getPathForLocation(e.getX, e.getY)
   190         if (click != null && e.getClickCount == 1)
   181         if (click != null && e.getClickCount == 1)
   191           update_focus()
   182           update_focus()
   192       }
   183       }
   193     })
   184     })
   228 
   219 
   229   private val context_label = new Label("Context:") {
   220   private val context_label = new Label("Context:") {
   230     tooltip = "Isabelle/ML context: type theory, Proof.context, Context.generic"
   221     tooltip = "Isabelle/ML context: type theory, Proof.context, Context.generic"
   231   }
   222   }
   232   private val context_field =
   223   private val context_field =
   233     new Completion_Popup.History_Text_Field("isabelle-debugger-context")
   224     new Completion_Popup.History_Text_Field("isabelle-debugger-context") {
   234     {
   225       override def processKeyEvent(evt: KeyEvent): Unit = {
   235       override def processKeyEvent(evt: KeyEvent): Unit =
       
   236       {
       
   237         if (evt.getID == KeyEvent.KEY_PRESSED && evt.getKeyCode == KeyEvent.VK_ENTER)
   226         if (evt.getID == KeyEvent.KEY_PRESSED && evt.getKeyCode == KeyEvent.VK_ENTER)
   238           eval_expression()
   227           eval_expression()
   239         super.processKeyEvent(evt)
   228         super.processKeyEvent(evt)
   240       }
   229       }
   241       setColumns(20)
   230       setColumns(20)
   245 
   234 
   246   private val expression_label = new Label("ML:") {
   235   private val expression_label = new Label("ML:") {
   247     tooltip = "Isabelle/ML or Standard ML expression"
   236     tooltip = "Isabelle/ML or Standard ML expression"
   248   }
   237   }
   249   private val expression_field =
   238   private val expression_field =
   250     new Completion_Popup.History_Text_Field("isabelle-debugger-expression")
   239     new Completion_Popup.History_Text_Field("isabelle-debugger-expression") {
   251     {
   240       override def processKeyEvent(evt: KeyEvent): Unit = {
   252       override def processKeyEvent(evt: KeyEvent): Unit =
       
   253       {
       
   254         if (evt.getID == KeyEvent.KEY_PRESSED && evt.getKeyCode == KeyEvent.VK_ENTER)
   241         if (evt.getID == KeyEvent.KEY_PRESSED && evt.getKeyCode == KeyEvent.VK_ENTER)
   255           eval_expression()
   242           eval_expression()
   256         super.processKeyEvent(evt)
   243         super.processKeyEvent(evt)
   257       }
   244       }
   258       { val max = getPreferredSize; max.width = Integer.MAX_VALUE; setMaximumSize(max) }
   245       { val max = getPreferredSize; max.width = Integer.MAX_VALUE; setMaximumSize(max) }
   264   private val eval_button = new Button("<html><b>Eval</b></html>") {
   251   private val eval_button = new Button("<html><b>Eval</b></html>") {
   265       tooltip = "Evaluate ML expression within optional context"
   252       tooltip = "Evaluate ML expression within optional context"
   266       reactions += { case ButtonClicked(_) => eval_expression() }
   253       reactions += { case ButtonClicked(_) => eval_expression() }
   267     }
   254     }
   268 
   255 
   269   private def eval_expression(): Unit =
   256   private def eval_expression(): Unit = {
   270   {
       
   271     context_field.addCurrentToHistory()
   257     context_field.addCurrentToHistory()
   272     expression_field.addCurrentToHistory()
   258     expression_field.addCurrentToHistory()
   273     tree_selection() match {
   259     tree_selection() match {
   274       case Some(c) if c.debug_index.isDefined =>
   260       case Some(c) if c.debug_index.isDefined =>
   275         debugger.eval(c, sml_button.selected, context_field.getText, expression_field.getText)
   261         debugger.eval(c, sml_button.selected, context_field.getText, expression_field.getText)
   301 
   287 
   302   addFocusListener(new FocusAdapter {
   288   addFocusListener(new FocusAdapter {
   303     override def focusGained(e: FocusEvent): Unit = update_focus()
   289     override def focusGained(e: FocusEvent): Unit = update_focus()
   304   })
   290   })
   305 
   291 
   306   private def update_focus(): Unit =
   292   private def update_focus(): Unit = {
   307   {
       
   308     for (c <- tree_selection()) {
   293     for (c <- tree_selection()) {
   309       debugger.set_focus(c)
   294       debugger.set_focus(c)
   310       for {
   295       for {
   311         pos <- c.debug_position
   296         pos <- c.debug_position
   312         link <- PIDE.editor.hyperlink_position(false, current_snapshot, pos)
   297         link <- PIDE.editor.hyperlink_position(false, current_snapshot, pos)
   338           break_button.selected = debugger.is_break()
   323           break_button.selected = debugger.is_break()
   339           handle_update()
   324           handle_update()
   340         }
   325         }
   341     }
   326     }
   342 
   327 
   343   override def init(): Unit =
   328   override def init(): Unit = {
   344   {
       
   345     PIDE.session.global_options += main
   329     PIDE.session.global_options += main
   346     PIDE.session.debugger_updates += main
   330     PIDE.session.debugger_updates += main
   347     debugger.init()
   331     debugger.init()
   348     handle_update()
   332     handle_update()
   349     jEdit.propertiesChanged()
   333     jEdit.propertiesChanged()
   350   }
   334   }
   351 
   335 
   352   override def exit(): Unit =
   336   override def exit(): Unit = {
   353   {
       
   354     PIDE.session.global_options -= main
   337     PIDE.session.global_options -= main
   355     PIDE.session.debugger_updates -= main
   338     PIDE.session.debugger_updates -= main
   356     delay_resize.revoke()
   339     delay_resize.revoke()
   357     debugger.exit()
   340     debugger.exit()
   358     jEdit.propertiesChanged()
   341     jEdit.propertiesChanged()