66098
|
1 |
/* Title: Tools/VSCode/src/state_panel.scala
|
66096
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Show proof state.
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle.vscode
|
|
8 |
|
|
9 |
|
|
10 |
import isabelle._
|
|
11 |
|
|
12 |
|
66098
|
13 |
object State_Panel
|
66096
|
14 |
{
|
|
15 |
private val make_id = Counter.make()
|
66098
|
16 |
private val instances = Synchronized(Map.empty[Counter.ID, State_Panel])
|
66096
|
17 |
|
|
18 |
def init(server: Server)
|
|
19 |
{
|
66098
|
20 |
val instance = new State_Panel(server)
|
66096
|
21 |
instances.change(_ + (instance.id -> instance))
|
|
22 |
instance.init()
|
|
23 |
}
|
|
24 |
|
|
25 |
def exit(id: Counter.ID)
|
|
26 |
{
|
|
27 |
instances.change(map =>
|
|
28 |
map.get(id) match {
|
|
29 |
case None => map
|
|
30 |
case Some(instance) => instance.exit(); map - id
|
|
31 |
})
|
|
32 |
}
|
|
33 |
|
|
34 |
def locate(id: Counter.ID): Unit =
|
|
35 |
instances.value.get(id).foreach(state =>
|
|
36 |
state.server.editor.send_dispatcher(state.locate()))
|
|
37 |
|
|
38 |
def update(id: Counter.ID): Unit =
|
|
39 |
instances.value.get(id).foreach(state =>
|
|
40 |
state.server.editor.send_dispatcher(state.update()))
|
|
41 |
}
|
|
42 |
|
|
43 |
|
66098
|
44 |
class State_Panel private(val server: Server)
|
66096
|
45 |
{
|
|
46 |
/* output */
|
|
47 |
|
66098
|
48 |
val id: Counter.ID = State_Panel.make_id()
|
66096
|
49 |
|
|
50 |
private def output(content: String): Unit =
|
|
51 |
server.channel.write(Protocol.State_Output(id, content))
|
|
52 |
|
|
53 |
|
|
54 |
/* query operation */
|
|
55 |
|
|
56 |
private val print_state =
|
|
57 |
new Query_Operation(server.editor, (), "print_state", _ => (),
|
|
58 |
(snapshot, results, body) =>
|
|
59 |
{
|
|
60 |
val text = server.resources.output_pretty_message(Pretty.separate(body))
|
|
61 |
val content =
|
|
62 |
HTML.output_document(
|
|
63 |
List(HTML.style(HTML.fonts_css()),
|
|
64 |
HTML.style_file(Url.print_file(HTML.isabelle_css.file))),
|
|
65 |
List(
|
|
66 |
HTML.chapter("Proof state"),
|
|
67 |
HTML.source(text)),
|
|
68 |
css = "")
|
|
69 |
output(content)
|
|
70 |
})
|
|
71 |
|
|
72 |
def locate() { print_state.locate_query() }
|
|
73 |
|
|
74 |
def update()
|
|
75 |
{
|
|
76 |
server.editor.current_node_snapshot(()) match {
|
|
77 |
case Some(snapshot) =>
|
|
78 |
(server.editor.current_command((), snapshot), print_state.get_location) match {
|
|
79 |
case (Some(command1), Some(command2)) if command1.id == command2.id =>
|
|
80 |
case _ => print_state.apply_query(Nil)
|
|
81 |
}
|
|
82 |
case None =>
|
|
83 |
}
|
|
84 |
}
|
|
85 |
|
|
86 |
|
|
87 |
/* auto update */
|
|
88 |
|
|
89 |
private val auto_update_enabled = Synchronized(true)
|
|
90 |
|
|
91 |
def set_auto_update(b: Boolean) { auto_update_enabled.change(_ => b); if (b) update() }
|
|
92 |
|
66099
|
93 |
def auto_update() { if (auto_update_enabled.value) update() }
|
66096
|
94 |
|
|
95 |
|
|
96 |
/* main */
|
|
97 |
|
|
98 |
private val main =
|
|
99 |
Session.Consumer[Any](getClass.getName) {
|
66099
|
100 |
case changed: Session.Commands_Changed =>
|
|
101 |
if (changed.assignment) auto_update()
|
|
102 |
|
|
103 |
case Session.Caret_Focus =>
|
|
104 |
auto_update()
|
66096
|
105 |
}
|
|
106 |
|
|
107 |
def init()
|
|
108 |
{
|
|
109 |
server.session.commands_changed += main
|
|
110 |
server.session.caret_focus += main
|
|
111 |
server.editor.send_wait_dispatcher { print_state.activate() }
|
|
112 |
server.editor.send_dispatcher { auto_update() }
|
|
113 |
}
|
|
114 |
|
|
115 |
def exit()
|
|
116 |
{
|
|
117 |
server.editor.send_wait_dispatcher { print_state.deactivate() }
|
|
118 |
server.session.commands_changed -= main
|
|
119 |
server.session.caret_focus -= main
|
|
120 |
}
|
|
121 |
}
|