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 =
|
66082
|
34 |
new Query_Operation(PIDE.editor, view, "print_state", _ => (),
|
61208
|
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 |
|
61801
|
60 |
def update_request(): Unit =
|
|
61 |
GUI_Thread.require { print_state.apply_query(Nil) }
|
61720
|
62 |
|
61211
|
63 |
def update()
|
61210
|
64 |
{
|
|
65 |
GUI_Thread.require {}
|
|
66 |
|
64813
|
67 |
Document_Model.get(view.getBuffer).map(_.snapshot()) match {
|
61211
|
68 |
case Some(snapshot) =>
|
66082
|
69 |
(PIDE.editor.current_command(view, snapshot), print_state.get_location) match {
|
61211
|
70 |
case (Some(command1), Some(command2)) if command1.id == command2.id =>
|
61801
|
71 |
case _ => update_request()
|
61211
|
72 |
}
|
|
73 |
case None =>
|
61210
|
74 |
}
|
|
75 |
}
|
|
76 |
|
|
77 |
|
61801
|
78 |
/* auto update */
|
|
79 |
|
|
80 |
private var auto_update_enabled = true
|
|
81 |
|
|
82 |
private def auto_update(): Unit =
|
|
83 |
GUI_Thread.require { if (auto_update_enabled) update() }
|
|
84 |
|
|
85 |
|
61208
|
86 |
/* controls */
|
|
87 |
|
61720
|
88 |
private val auto_update_button = new CheckBox("Auto update") {
|
|
89 |
tooltip = "Indicate automatic update following cursor movement"
|
61801
|
90 |
reactions += { case ButtonClicked(_) => auto_update_enabled = this.selected; auto_update() }
|
|
91 |
selected = auto_update_enabled
|
61720
|
92 |
}
|
|
93 |
|
61220
|
94 |
private val update_button = new Button("<html><b>Update</b></html>") {
|
61208
|
95 |
tooltip = "Update display according to the command at cursor position"
|
61801
|
96 |
reactions += { case ButtonClicked(_) => update_request() }
|
61208
|
97 |
}
|
|
98 |
|
61211
|
99 |
private val locate_button = new Button("Locate") {
|
61208
|
100 |
tooltip = "Locate printed command within source text"
|
|
101 |
reactions += { case ButtonClicked(_) => print_state.locate_query() }
|
|
102 |
}
|
|
103 |
|
|
104 |
private val zoom = new Font_Info.Zoom_Box { def changed = handle_resize() }
|
|
105 |
|
|
106 |
private val controls =
|
61720
|
107 |
new Wrap_Panel(Wrap_Panel.Alignment.Right)(auto_update_button, update_button,
|
|
108 |
locate_button, pretty_text_area.search_label, pretty_text_area.search_field, zoom)
|
61208
|
109 |
add(controls.peer, BorderLayout.NORTH)
|
|
110 |
|
|
111 |
|
|
112 |
/* main */
|
|
113 |
|
|
114 |
private val main =
|
|
115 |
Session.Consumer[Any](getClass.getName) {
|
|
116 |
case _: Session.Global_Options =>
|
|
117 |
GUI_Thread.later { handle_resize() }
|
61720
|
118 |
|
|
119 |
case changed: Session.Commands_Changed =>
|
61801
|
120 |
if (changed.assignment) GUI_Thread.later { auto_update() }
|
61720
|
121 |
|
|
122 |
case Session.Caret_Focus =>
|
61801
|
123 |
GUI_Thread.later { auto_update() }
|
61208
|
124 |
}
|
|
125 |
|
|
126 |
override def init()
|
|
127 |
{
|
|
128 |
PIDE.session.global_options += main
|
61720
|
129 |
PIDE.session.commands_changed += main
|
|
130 |
PIDE.session.caret_focus += main
|
61208
|
131 |
handle_resize()
|
|
132 |
print_state.activate()
|
61801
|
133 |
auto_update()
|
61208
|
134 |
}
|
|
135 |
|
|
136 |
override def exit()
|
|
137 |
{
|
|
138 |
print_state.deactivate()
|
61720
|
139 |
PIDE.session.caret_focus -= main
|
61208
|
140 |
PIDE.session.global_options -= main
|
61720
|
141 |
PIDE.session.commands_changed -= main
|
61208
|
142 |
delay_resize.revoke()
|
|
143 |
}
|
|
144 |
}
|