60749
|
1 |
/* Title: Tools/jEdit/src/debugger_dockable.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Dockable window for Isabelle/ML debugger.
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle.jedit
|
|
8 |
|
|
9 |
|
|
10 |
import isabelle._
|
|
11 |
|
|
12 |
import java.awt.BorderLayout
|
60832
|
13 |
import java.awt.event.{ComponentEvent, ComponentAdapter, KeyEvent}
|
|
14 |
|
|
15 |
import scala.swing.{Button, Label, Component}
|
|
16 |
import scala.swing.event.ButtonClicked
|
60749
|
17 |
|
|
18 |
import org.gjt.sp.jedit.View
|
|
19 |
|
|
20 |
|
|
21 |
class Debugger_Dockable(view: View, position: String) extends Dockable(view, position)
|
|
22 |
{
|
|
23 |
GUI_Thread.require {}
|
|
24 |
|
|
25 |
|
|
26 |
/* component state -- owned by GUI thread */
|
|
27 |
|
|
28 |
private var current_snapshot = Document.Snapshot.init
|
|
29 |
private var current_output: List[XML.Tree] = Nil
|
|
30 |
|
|
31 |
|
60832
|
32 |
/* common GUI components */
|
|
33 |
|
|
34 |
private val context_label = new Label("Context:") { tooltip = "Isabelle/ML context (optional)" }
|
|
35 |
private val context_field =
|
|
36 |
new Completion_Popup.History_Text_Field("isabelle-debugger-context")
|
|
37 |
{
|
|
38 |
setColumns(20)
|
|
39 |
setToolTipText(context_label.tooltip)
|
|
40 |
setFont(GUI.imitate_font(getFont, Font_Info.main_family(), 1.2))
|
|
41 |
}
|
|
42 |
|
|
43 |
private val expression_label = new Label("ML:") { tooltip = "Isabelle/ML expression" }
|
|
44 |
private val expression_field =
|
|
45 |
new Completion_Popup.History_Text_Field("isabelle-debugger-expression")
|
|
46 |
{
|
|
47 |
override def processKeyEvent(evt: KeyEvent)
|
|
48 |
{
|
|
49 |
if (evt.getID == KeyEvent.KEY_PRESSED && evt.getKeyCode == KeyEvent.VK_ENTER)
|
|
50 |
eval_expression()
|
|
51 |
super.processKeyEvent(evt)
|
|
52 |
}
|
|
53 |
{ val max = getPreferredSize; max.width = Integer.MAX_VALUE; setMaximumSize(max) }
|
|
54 |
setColumns(40)
|
|
55 |
setToolTipText(expression_label.tooltip)
|
|
56 |
setFont(GUI.imitate_font(getFont, Font_Info.main_family(), 1.2))
|
|
57 |
}
|
|
58 |
|
|
59 |
private val eval_button = new Button("<html><b>Eval</b></html>") {
|
|
60 |
tooltip = "Evaluate Isabelle/ML expression within optional context"
|
|
61 |
reactions += { case ButtonClicked(_) => eval_expression() }
|
|
62 |
}
|
|
63 |
|
|
64 |
private def eval_expression()
|
|
65 |
{
|
|
66 |
// FIXME
|
|
67 |
Output.writeln("eval context = " + quote(context_field.getText) + " expression = " +
|
|
68 |
quote(expression_field.getText))
|
|
69 |
}
|
|
70 |
|
|
71 |
private val zoom = new Font_Info.Zoom_Box { def changed = handle_resize() }
|
|
72 |
|
|
73 |
|
60749
|
74 |
/* pretty text area */
|
|
75 |
|
|
76 |
val pretty_text_area = new Pretty_Text_Area(view)
|
|
77 |
set_content(pretty_text_area)
|
|
78 |
|
|
79 |
override def detach_operation = pretty_text_area.detach_operation
|
|
80 |
|
|
81 |
|
|
82 |
private def handle_resize()
|
|
83 |
{
|
|
84 |
GUI_Thread.require {}
|
|
85 |
|
|
86 |
pretty_text_area.resize(
|
|
87 |
Font_Info.main(PIDE.options.real("jedit_font_scale") * zoom.factor / 100))
|
|
88 |
}
|
|
89 |
|
|
90 |
private def handle_update()
|
|
91 |
{
|
|
92 |
GUI_Thread.require {}
|
|
93 |
|
|
94 |
val new_snapshot = PIDE.editor.current_node_snapshot(view).getOrElse(current_snapshot)
|
60834
|
95 |
val new_output = // FIXME select by thread name
|
|
96 |
(for ((_, results) <- Debugger.current_state.output; (_, tree) <- results.iterator)
|
|
97 |
yield tree).toList
|
60749
|
98 |
|
|
99 |
if (new_output != current_output)
|
|
100 |
pretty_text_area.update(new_snapshot, Command.Results.empty, Pretty.separate(new_output))
|
|
101 |
|
|
102 |
current_snapshot = new_snapshot
|
|
103 |
current_output = new_output
|
|
104 |
}
|
|
105 |
|
|
106 |
|
|
107 |
/* main */
|
|
108 |
|
|
109 |
private val main =
|
|
110 |
Session.Consumer[Any](getClass.getName) {
|
|
111 |
case _: Session.Global_Options =>
|
|
112 |
GUI_Thread.later { handle_resize() }
|
|
113 |
|
|
114 |
case Debugger.Event =>
|
|
115 |
GUI_Thread.later { handle_update() }
|
|
116 |
}
|
|
117 |
|
|
118 |
override def init()
|
|
119 |
{
|
|
120 |
PIDE.session.global_options += main
|
|
121 |
PIDE.session.debugger_events += main
|
|
122 |
handle_update()
|
|
123 |
}
|
|
124 |
|
|
125 |
override def exit()
|
|
126 |
{
|
|
127 |
PIDE.session.global_options -= main
|
|
128 |
PIDE.session.debugger_events -= main
|
|
129 |
delay_resize.revoke()
|
|
130 |
}
|
|
131 |
|
|
132 |
|
|
133 |
/* resize */
|
|
134 |
|
|
135 |
private val delay_resize =
|
|
136 |
GUI_Thread.delay_first(PIDE.options.seconds("editor_update_delay")) { handle_resize() }
|
|
137 |
|
|
138 |
addComponentListener(new ComponentAdapter {
|
|
139 |
override def componentResized(e: ComponentEvent) { delay_resize.invoke() }
|
60750
|
140 |
override def componentShown(e: ComponentEvent) { delay_resize.invoke() }
|
60749
|
141 |
})
|
|
142 |
|
|
143 |
|
|
144 |
/* controls */
|
|
145 |
|
|
146 |
private val controls =
|
|
147 |
new Wrap_Panel(Wrap_Panel.Alignment.Right)(
|
60832
|
148 |
context_label, Component.wrap(context_field),
|
|
149 |
expression_label, Component.wrap(expression_field), eval_button,
|
60749
|
150 |
pretty_text_area.search_label, pretty_text_area.search_field, zoom)
|
|
151 |
add(controls.peer, BorderLayout.NORTH)
|
|
152 |
}
|