61208
|
1 |
/* Title: Tools/jEdit/src/state_dockable.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Dockable window for proof state output.
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle.jedit
|
|
8 |
|
|
9 |
|
|
10 |
import isabelle._
|
|
11 |
|
|
12 |
import scala.swing.{Button, CheckBox}
|
|
13 |
import scala.swing.event.ButtonClicked
|
|
14 |
|
|
15 |
import java.awt.BorderLayout
|
|
16 |
import java.awt.event.{ComponentEvent, ComponentAdapter}
|
|
17 |
|
|
18 |
import org.gjt.sp.jedit.View
|
|
19 |
|
|
20 |
|
|
21 |
class State_Dockable(view: View, position: String) extends Dockable(view, position)
|
|
22 |
{
|
|
23 |
GUI_Thread.require {}
|
|
24 |
|
|
25 |
|
|
26 |
/* text area */
|
|
27 |
|
|
28 |
val pretty_text_area = new Pretty_Text_Area(view)
|
|
29 |
set_content(pretty_text_area)
|
|
30 |
|
|
31 |
override def detach_operation = pretty_text_area.detach_operation
|
|
32 |
|
|
33 |
private val print_state =
|
|
34 |
new Query_Operation(PIDE.editor, view, "print_state", _ => (),
|
|
35 |
(snapshot, results, body) =>
|
|
36 |
pretty_text_area.update(snapshot, results, Pretty.separate(body)))
|
|
37 |
|
|
38 |
|
|
39 |
/* resize */
|
|
40 |
|
|
41 |
private val delay_resize =
|
|
42 |
GUI_Thread.delay_first(PIDE.options.seconds("editor_update_delay")) { handle_resize() }
|
|
43 |
|
|
44 |
addComponentListener(new ComponentAdapter {
|
|
45 |
override def componentResized(e: ComponentEvent) { delay_resize.invoke() }
|
|
46 |
override def componentShown(e: ComponentEvent) { delay_resize.invoke() }
|
|
47 |
})
|
|
48 |
|
|
49 |
private def handle_resize()
|
|
50 |
{
|
|
51 |
GUI_Thread.require {}
|
|
52 |
|
|
53 |
pretty_text_area.resize(
|
|
54 |
Font_Info.main(PIDE.options.real("jedit_font_scale") * zoom.factor / 100))
|
|
55 |
}
|
|
56 |
|
|
57 |
|
61211
|
58 |
/* update */
|
61210
|
59 |
|
61211
|
60 |
def update()
|
61210
|
61 |
{
|
|
62 |
GUI_Thread.require {}
|
|
63 |
|
61211
|
64 |
PIDE.document_model(view.getBuffer).map(_.snapshot()) match {
|
|
65 |
case Some(snapshot) =>
|
|
66 |
(PIDE.editor.current_command(view, snapshot), print_state.get_location) match {
|
|
67 |
case (Some(command1), Some(command2)) if command1.id == command2.id =>
|
|
68 |
case _ => print_state.apply_query(Nil)
|
|
69 |
}
|
|
70 |
case None =>
|
61210
|
71 |
}
|
|
72 |
}
|
|
73 |
|
|
74 |
|
61208
|
75 |
/* controls */
|
|
76 |
|
61211
|
77 |
private val update_button = new Button("Update") {
|
61208
|
78 |
tooltip = "Update display according to the command at cursor position"
|
|
79 |
reactions += { case ButtonClicked(_) => print_state.apply_query(Nil) }
|
|
80 |
}
|
|
81 |
|
61211
|
82 |
private val locate_button = new Button("Locate") {
|
61208
|
83 |
tooltip = "Locate printed command within source text"
|
|
84 |
reactions += { case ButtonClicked(_) => print_state.locate_query() }
|
|
85 |
}
|
|
86 |
|
|
87 |
private val zoom = new Font_Info.Zoom_Box { def changed = handle_resize() }
|
|
88 |
|
|
89 |
private val controls =
|
61219
|
90 |
new Wrap_Panel(Wrap_Panel.Alignment.Right)(update_button, locate_button,
|
61208
|
91 |
pretty_text_area.search_label, pretty_text_area.search_field, zoom)
|
|
92 |
add(controls.peer, BorderLayout.NORTH)
|
|
93 |
|
61211
|
94 |
override def focusOnDefaultComponent { update_button.requestFocus }
|
61208
|
95 |
|
|
96 |
|
|
97 |
/* main */
|
|
98 |
|
|
99 |
private val main =
|
|
100 |
Session.Consumer[Any](getClass.getName) {
|
|
101 |
case _: Session.Global_Options =>
|
|
102 |
GUI_Thread.later { handle_resize() }
|
|
103 |
}
|
|
104 |
|
|
105 |
override def init()
|
|
106 |
{
|
|
107 |
PIDE.session.global_options += main
|
|
108 |
handle_resize()
|
|
109 |
print_state.activate()
|
|
110 |
}
|
|
111 |
|
|
112 |
override def exit()
|
|
113 |
{
|
|
114 |
print_state.deactivate()
|
|
115 |
PIDE.session.global_options -= main
|
|
116 |
delay_resize.revoke()
|
|
117 |
}
|
|
118 |
}
|