author | wenzelm |
Thu, 29 Jun 2017 11:36:25 +0200 | |
changeset 66211 | 100c9c997e2b |
parent 66206 | 2d2082db735a |
child 66212 | f41396c15bb1 |
permissions | -rw-r--r-- |
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())) |
|
66211 | 41 |
|
42 |
def auto_update(id: Counter.ID, enabled: Boolean): Unit = |
|
43 |
instances.value.get(id).foreach(state => |
|
44 |
state.server.editor.send_dispatcher(state.auto_update(Some(enabled)))) |
|
66096 | 45 |
} |
46 |
||
47 |
||
66098 | 48 |
class State_Panel private(val server: Server) |
66096 | 49 |
{ |
50 |
/* output */ |
|
51 |
||
66098 | 52 |
val id: Counter.ID = State_Panel.make_id() |
66096 | 53 |
|
54 |
private def output(content: String): Unit = |
|
55 |
server.channel.write(Protocol.State_Output(id, content)) |
|
56 |
||
57 |
||
58 |
/* query operation */ |
|
59 |
||
60 |
private val print_state = |
|
61 |
new Query_Operation(server.editor, (), "print_state", _ => (), |
|
62 |
(snapshot, results, body) => |
|
63 |
{ |
|
64 |
val text = server.resources.output_pretty_message(Pretty.separate(body)) |
|
65 |
val content = |
|
66 |
HTML.output_document( |
|
67 |
List(HTML.style(HTML.fonts_css()), |
|
66211 | 68 |
HTML.style_file(Url.print_file(HTML.isabelle_css.file)), |
69 |
HTML.script(controls_script)), |
|
66201
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
70 |
List(controls, HTML.source(text)), |
66096 | 71 |
css = "") |
72 |
output(content) |
|
73 |
}) |
|
74 |
||
75 |
def locate() { print_state.locate_query() } |
|
76 |
||
77 |
def update() |
|
78 |
{ |
|
79 |
server.editor.current_node_snapshot(()) match { |
|
80 |
case Some(snapshot) => |
|
81 |
(server.editor.current_command((), snapshot), print_state.get_location) match { |
|
82 |
case (Some(command1), Some(command2)) if command1.id == command2.id => |
|
83 |
case _ => print_state.apply_query(Nil) |
|
84 |
} |
|
85 |
case None => |
|
86 |
} |
|
87 |
} |
|
88 |
||
89 |
||
90 |
/* auto update */ |
|
91 |
||
92 |
private val auto_update_enabled = Synchronized(true) |
|
93 |
||
66211 | 94 |
def auto_update(set: Option[Boolean] = None) |
95 |
{ |
|
96 |
val enabled = |
|
97 |
auto_update_enabled.guarded_access(a => |
|
98 |
set match { |
|
99 |
case None => Some((a, a)) |
|
100 |
case Some(b) => Some((b, b)) |
|
101 |
}) |
|
102 |
if (enabled) update() |
|
103 |
} |
|
66096 | 104 |
|
105 |
||
66201
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
106 |
/* controls */ |
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
107 |
|
66211 | 108 |
private def controls_script = |
109 |
VSCode_JavaScript.invoke_command + |
|
110 |
""" |
|
111 |
function invoke_auto_update(enabled) |
|
112 |
{ invoke_command("_isabelle.state-auto-update", [""" + id + """, enabled]) } |
|
113 |
||
114 |
function invoke_update() { invoke_command("_isabelle.state-update", [""" + id + """]) } |
|
115 |
||
116 |
function invoke_locate() { invoke_command("_isabelle.state-locate", [""" + id + """]) } |
|
117 |
""" |
|
66201
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
118 |
|
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
119 |
private def auto_update_button: XML.Elem = |
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
120 |
HTML.GUI.checkbox(HTML.text("Auto update"), |
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
121 |
name = "auto_update", |
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
122 |
tooltip = "Indicate automatic update following cursor movement", |
66211 | 123 |
selected = auto_update_enabled.value, |
124 |
script = "invoke_auto_update(this.checked)") |
|
66201
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
125 |
|
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
126 |
private def update_button: XML.Elem = |
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
127 |
HTML.GUI.button(List(HTML.bold(HTML.text("Update"))), |
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
128 |
name = "update", |
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
129 |
tooltip = "Update display according to the command at cursor position", |
66211 | 130 |
script = "invoke_update()") |
66201
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
131 |
|
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
132 |
private def locate_button: XML.Elem = |
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
133 |
HTML.GUI.button(HTML.text("Locate"), |
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
134 |
name = "locate", |
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
135 |
tooltip = "Locate printed command within source text", |
66211 | 136 |
script = "invoke_locate()") |
66201
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
137 |
|
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
138 |
private val controls: XML.Elem = |
66211 | 139 |
HTML.Wrap_Panel(List(auto_update_button, update_button, locate_button)) |
66201
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
140 |
|
d8f2c745f572
GUI controls similar to Tools/jEdit/src/state_dockable.scala;
wenzelm
parents:
66099
diff
changeset
|
141 |
|
66096 | 142 |
/* main */ |
143 |
||
144 |
private val main = |
|
145 |
Session.Consumer[Any](getClass.getName) { |
|
66099 | 146 |
case changed: Session.Commands_Changed => |
147 |
if (changed.assignment) auto_update() |
|
148 |
||
149 |
case Session.Caret_Focus => |
|
150 |
auto_update() |
|
66096 | 151 |
} |
152 |
||
153 |
def init() |
|
154 |
{ |
|
155 |
server.session.commands_changed += main |
|
156 |
server.session.caret_focus += main |
|
157 |
server.editor.send_wait_dispatcher { print_state.activate() } |
|
158 |
server.editor.send_dispatcher { auto_update() } |
|
159 |
} |
|
160 |
||
161 |
def exit() |
|
162 |
{ |
|
163 |
server.editor.send_wait_dispatcher { print_state.deactivate() } |
|
164 |
server.session.commands_changed -= main |
|
165 |
server.session.caret_focus -= main |
|
166 |
} |
|
167 |
} |