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 java.awt.BorderLayout
|
|
13 |
import java.awt.event.{ComponentEvent, ComponentAdapter}
|
|
14 |
|
|
15 |
import org.gjt.sp.jedit.View
|
|
16 |
|
|
17 |
|
75393
|
18 |
class State_Dockable(view: View, position: String) extends Dockable(view, position) {
|
61208
|
19 |
GUI_Thread.require {}
|
|
20 |
|
|
21 |
|
|
22 |
/* text area */
|
|
23 |
|
|
24 |
val pretty_text_area = new Pretty_Text_Area(view)
|
|
25 |
set_content(pretty_text_area)
|
|
26 |
|
71601
|
27 |
override def detach_operation: Option[() => Unit] = pretty_text_area.detach_operation
|
61208
|
28 |
|
|
29 |
private val print_state =
|
66082
|
30 |
new Query_Operation(PIDE.editor, view, "print_state", _ => (),
|
61208
|
31 |
(snapshot, results, body) =>
|
|
32 |
pretty_text_area.update(snapshot, results, Pretty.separate(body)))
|
|
33 |
|
|
34 |
|
|
35 |
/* resize */
|
|
36 |
|
|
37 |
private val delay_resize =
|
71704
|
38 |
Delay.first(PIDE.options.seconds("editor_update_delay"), gui = true) { handle_resize() }
|
61208
|
39 |
|
|
40 |
addComponentListener(new ComponentAdapter {
|
73340
|
41 |
override def componentResized(e: ComponentEvent): Unit = delay_resize.invoke()
|
|
42 |
override def componentShown(e: ComponentEvent): Unit = delay_resize.invoke()
|
61208
|
43 |
})
|
|
44 |
|
75812
|
45 |
private def handle_resize(): Unit =
|
75839
|
46 |
GUI_Thread.require { pretty_text_area.zoom(zoom) }
|
61208
|
47 |
|
|
48 |
|
61211
|
49 |
/* update */
|
61210
|
50 |
|
61801
|
51 |
def update_request(): Unit =
|
|
52 |
GUI_Thread.require { print_state.apply_query(Nil) }
|
61720
|
53 |
|
75393
|
54 |
def update(): Unit = {
|
61210
|
55 |
GUI_Thread.require {}
|
|
56 |
|
66091
|
57 |
PIDE.editor.current_node_snapshot(view) match {
|
61211
|
58 |
case Some(snapshot) =>
|
66082
|
59 |
(PIDE.editor.current_command(view, snapshot), print_state.get_location) match {
|
61211
|
60 |
case (Some(command1), Some(command2)) if command1.id == command2.id =>
|
61801
|
61 |
case _ => update_request()
|
61211
|
62 |
}
|
|
63 |
case None =>
|
61210
|
64 |
}
|
|
65 |
}
|
|
66 |
|
|
67 |
|
61801
|
68 |
/* auto update */
|
|
69 |
|
|
70 |
private var auto_update_enabled = true
|
|
71 |
|
|
72 |
private def auto_update(): Unit =
|
|
73 |
GUI_Thread.require { if (auto_update_enabled) update() }
|
|
74 |
|
|
75 |
|
61208
|
76 |
/* controls */
|
|
77 |
|
75852
|
78 |
private val auto_update_button = new GUI.Bool("Auto update", init = auto_update_enabled) {
|
61720
|
79 |
tooltip = "Indicate automatic update following cursor movement"
|
75852
|
80 |
override def clicked(state: Boolean): Unit = {
|
|
81 |
auto_update_enabled = state
|
|
82 |
auto_update()
|
|
83 |
}
|
61720
|
84 |
}
|
|
85 |
|
75853
|
86 |
private val update_button = new GUI.Button("<html><b>Update</b></html>") {
|
61208
|
87 |
tooltip = "Update display according to the command at cursor position"
|
75853
|
88 |
override def clicked(): Unit = update_request()
|
61208
|
89 |
}
|
|
90 |
|
75853
|
91 |
private val locate_button = new GUI.Button("Locate") {
|
61208
|
92 |
tooltip = "Locate printed command within source text"
|
75853
|
93 |
override def clicked(): Unit = print_state.locate_query()
|
61208
|
94 |
}
|
|
95 |
|
75839
|
96 |
private val zoom = new Font_Info.Zoom { override def changed(): Unit = handle_resize() }
|
61208
|
97 |
|
|
98 |
private val controls =
|
66205
|
99 |
Wrap_Panel(
|
|
100 |
List(auto_update_button, update_button,
|
66206
|
101 |
locate_button, pretty_text_area.search_label, pretty_text_area.search_field, zoom))
|
66205
|
102 |
|
61208
|
103 |
add(controls.peer, BorderLayout.NORTH)
|
|
104 |
|
|
105 |
|
|
106 |
/* main */
|
|
107 |
|
|
108 |
private val main =
|
|
109 |
Session.Consumer[Any](getClass.getName) {
|
|
110 |
case _: Session.Global_Options =>
|
|
111 |
GUI_Thread.later { handle_resize() }
|
61720
|
112 |
|
|
113 |
case changed: Session.Commands_Changed =>
|
61801
|
114 |
if (changed.assignment) GUI_Thread.later { auto_update() }
|
61720
|
115 |
|
|
116 |
case Session.Caret_Focus =>
|
61801
|
117 |
GUI_Thread.later { auto_update() }
|
61208
|
118 |
}
|
|
119 |
|
75393
|
120 |
override def init(): Unit = {
|
61208
|
121 |
PIDE.session.global_options += main
|
61720
|
122 |
PIDE.session.commands_changed += main
|
|
123 |
PIDE.session.caret_focus += main
|
61208
|
124 |
handle_resize()
|
|
125 |
print_state.activate()
|
61801
|
126 |
auto_update()
|
61208
|
127 |
}
|
|
128 |
|
75393
|
129 |
override def exit(): Unit = {
|
61208
|
130 |
print_state.deactivate()
|
61720
|
131 |
PIDE.session.caret_focus -= main
|
61208
|
132 |
PIDE.session.global_options -= main
|
61720
|
133 |
PIDE.session.commands_changed -= main
|
61208
|
134 |
delay_resize.revoke()
|
|
135 |
}
|
|
136 |
}
|