| author | wenzelm |
| Mon, 27 Oct 2025 15:36:47 +0100 | |
| changeset 83419 | 0ac8a8a3793b |
| parent 83412 | b1a472adb667 |
| child 83431 | b41b4fa1ac6f |
| permissions | -rw-r--r-- |
| 52981 | 1 |
/* Title: Pure/PIDE/query_operation.scala |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
3 |
|
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
4 |
One-shot query operations via asynchronous print functions and temporary |
|
52932
eb7d7c0034b5
removed command location is considered finished, and its overlay removed eventually;
wenzelm
parents:
52931
diff
changeset
|
5 |
document overlays. |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
6 |
*/ |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
7 |
|
| 52981 | 8 |
package isabelle |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
9 |
|
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
10 |
|
| 75393 | 11 |
object Query_Operation {
|
| 78595 | 12 |
enum Status { case waiting, running, finished }
|
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
13 |
|
| 75393 | 14 |
object State {
|
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
15 |
val empty: State = State() |
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
16 |
|
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
17 |
def make(command: Command, query: List[String]): State = |
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
18 |
State(instance = Document_ID.make().toString, |
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
19 |
location = Some(command), |
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
20 |
query = query, |
| 78595 | 21 |
status = Status.waiting) |
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
22 |
} |
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
23 |
|
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
24 |
sealed case class State( |
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
25 |
instance: String = Document_ID.none.toString, |
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
26 |
location: Option[Command] = None, |
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
27 |
query: List[String] = Nil, |
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
28 |
update_pending: Boolean = false, |
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
29 |
output: List[XML.Tree] = Nil, |
| 78595 | 30 |
status: Status = Status.finished, |
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
31 |
exec_id: Document_ID.Exec = Document_ID.none) |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
32 |
} |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
33 |
|
| 52980 | 34 |
class Query_Operation[Editor_Context]( |
35 |
editor: Editor[Editor_Context], |
|
36 |
editor_context: Editor_Context, |
|
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
37 |
operation_name: String, |
| 78595 | 38 |
consume_status: Query_Operation.Status => Unit, |
|
83419
0ac8a8a3793b
clarified signature: prefer explicit type Editor.Output;
wenzelm
parents:
83412
diff
changeset
|
39 |
consume_output: Editor.Output => Unit |
| 75393 | 40 |
) {
|
|
61206
d5aeb401111a
more specific name to reduce danger of clash with direct uses of plain Command.print_function;
wenzelm
parents:
60893
diff
changeset
|
41 |
private val print_function = operation_name + "_query" |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
42 |
|
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
43 |
|
| 66094 | 44 |
/* implicit state -- owned by editor thread */ |
| 52874 | 45 |
|
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
46 |
private val current_state = Synchronized(Query_Operation.State.empty) |
| 61210 | 47 |
|
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
48 |
def get_location: Option[Command] = current_state.value.location |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
49 |
|
| 75393 | 50 |
private def remove_overlay(): Unit = {
|
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
51 |
val state = current_state.value |
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
52 |
for (command <- state.location) {
|
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
53 |
editor.remove_overlay(command, print_function, state.instance :: state.query) |
|
54310
6ddeb83eb67a
clarified remove_overlay: always flush in order to make sure that apply_query can make a fresh start with the same arguments (see also 6e69f9ca8f1c) -- NB: print functions are idempotent;
wenzelm
parents:
53872
diff
changeset
|
54 |
} |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
55 |
} |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
56 |
|
| 52877 | 57 |
|
58 |
/* content update */ |
|
59 |
||
| 75393 | 60 |
private def content_update(): Unit = {
|
| 66094 | 61 |
editor.require_dispatcher {}
|
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
62 |
|
| 52876 | 63 |
|
64 |
/* snapshot */ |
|
65 |
||
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
66 |
val state0 = current_state.value |
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
67 |
|
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
68 |
val (snapshot, command_results, results, removed) = |
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
69 |
state0.location match {
|
| 52876 | 70 |
case Some(cmd) => |
| 52974 | 71 |
val snapshot = editor.node_snapshot(cmd.node_name) |
| 65195 | 72 |
val command_results = snapshot.command_results(cmd) |
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
73 |
val results = |
| 83411 | 74 |
List.from( |
75 |
for {
|
|
| 83412 | 76 |
case (_, elem@XML.Elem(Markup(Markup.RESULT, props@Markup.Instance(instance)), _)) |
77 |
<- command_results.iterator |
|
78 |
if instance == state0.instance |
|
| 83411 | 79 |
} yield elem) |
| 72823 | 80 |
val removed = !snapshot.get_node(cmd.node_name).commands.contains(cmd) |
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
81 |
(snapshot, command_results, results, removed) |
| 52876 | 82 |
case None => |
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
83 |
(Document.Snapshot.init, Command.Results.empty, Nil, true) |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
84 |
} |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
85 |
|
| 52876 | 86 |
|
87 |
||
|
54640
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
88 |
/* resolve sendback: static command id */ |
|
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
89 |
|
| 75393 | 90 |
def resolve_sendback(body: XML.Body): XML.Body = {
|
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
91 |
state0.location match {
|
|
54640
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
92 |
case None => body |
|
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
93 |
case Some(command) => |
|
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
94 |
def resolve(body: XML.Body): XML.Body = |
|
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
95 |
body map {
|
|
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
96 |
case XML.Wrapped_Elem(m, b1, b2) => XML.Wrapped_Elem(m, resolve(b1), resolve(b2)) |
|
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
97 |
case XML.Elem(Markup(Markup.SENDBACK, props), b) => |
|
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
98 |
val props1 = |
|
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
99 |
props.map({
|
| 63805 | 100 |
case (Markup.ID, Value.Long(id)) if id == state0.exec_id => |
101 |
(Markup.ID, Value.Long(command.id)) |
|
|
54640
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
102 |
case p => p |
|
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
103 |
}) |
|
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
104 |
XML.Elem(Markup(Markup.SENDBACK, props1), resolve(b)) |
|
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
105 |
case XML.Elem(m, b) => XML.Elem(m, resolve(b)) |
|
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
106 |
case t => t |
|
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
107 |
} |
|
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
108 |
resolve(body) |
|
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
109 |
} |
|
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
110 |
} |
|
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
111 |
|
|
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
112 |
|
| 52876 | 113 |
/* output */ |
114 |
||
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
115 |
val new_output = |
| 52876 | 116 |
for {
|
| 78592 | 117 |
case XML.Elem(_, List(XML.Elem(markup, body))) <- results |
| 52876 | 118 |
if Markup.messages.contains(markup.name) |
|
54640
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54327
diff
changeset
|
119 |
body1 = resolve_sendback(body) |
| 76680 | 120 |
} yield Protocol.make_message(body1, markup.name, props = markup.properties) |
| 52876 | 121 |
|
122 |
||
123 |
/* status */ |
|
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
124 |
|
| 78595 | 125 |
def get_status(name: String, status: Query_Operation.Status): Option[Query_Operation.Status] = |
|
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52890
diff
changeset
|
126 |
results.collectFirst({ case XML.Elem(_, List(elem: XML.Elem)) if elem.name == name => status })
|
| 52876 | 127 |
|
128 |
val new_status = |
|
| 78595 | 129 |
if (removed) Query_Operation.Status.finished |
|
52932
eb7d7c0034b5
removed command location is considered finished, and its overlay removed eventually;
wenzelm
parents:
52931
diff
changeset
|
130 |
else |
| 78595 | 131 |
get_status(Markup.FINISHED, Query_Operation.Status.finished) orElse |
132 |
get_status(Markup.RUNNING, Query_Operation.Status.running) getOrElse |
|
133 |
Query_Operation.Status.waiting |
|
| 52876 | 134 |
|
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
135 |
|
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
136 |
/* state update */ |
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
137 |
|
| 78595 | 138 |
if (new_status == Query_Operation.Status.running) |
|
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52890
diff
changeset
|
139 |
results.collectFirst( |
|
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52890
diff
changeset
|
140 |
{
|
|
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52890
diff
changeset
|
141 |
case XML.Elem(Markup(_, Position.Id(id)), List(elem: XML.Elem)) |
|
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52890
diff
changeset
|
142 |
if elem.name == Markup.RUNNING => id |
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
143 |
}).foreach(id => current_state.change(_.copy(exec_id = id))) |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
144 |
|
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
145 |
if (state0.output != new_output || state0.status != new_status) {
|
| 83411 | 146 |
if (snapshot.is_outdated) {
|
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
147 |
current_state.change(_.copy(update_pending = true)) |
| 83411 | 148 |
} |
| 52876 | 149 |
else {
|
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
150 |
current_state.change(_.copy(update_pending = false)) |
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
151 |
if (state0.output != new_output && !removed) {
|
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
152 |
current_state.change(_.copy(output = new_output)) |
|
83419
0ac8a8a3793b
clarified signature: prefer explicit type Editor.Output;
wenzelm
parents:
83412
diff
changeset
|
153 |
consume_output( |
|
0ac8a8a3793b
clarified signature: prefer explicit type Editor.Output;
wenzelm
parents:
83412
diff
changeset
|
154 |
Editor.Output(snapshot = snapshot, results = command_results, messages = new_output)) |
| 52877 | 155 |
} |
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
156 |
if (state0.status != new_status) {
|
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
157 |
current_state.change(_.copy(status = new_status)) |
| 52935 | 158 |
consume_status(new_status) |
| 78595 | 159 |
if (new_status == Query_Operation.Status.finished) |
| 52877 | 160 |
remove_overlay() |
161 |
} |
|
| 52876 | 162 |
} |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
163 |
} |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
164 |
} |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
165 |
|
| 52877 | 166 |
|
|
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52890
diff
changeset
|
167 |
/* query operations */ |
|
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52890
diff
changeset
|
168 |
|
|
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52890
diff
changeset
|
169 |
def cancel_query(): Unit = |
| 66094 | 170 |
editor.require_dispatcher { editor.session.cancel_exec(current_state.value.exec_id) }
|
| 52877 | 171 |
|
| 75393 | 172 |
def apply_query(query: List[String]): Unit = {
|
|
83365
675ec7e6b233
avoid somewhat adhoc change to query_operation.scala (see also 486e094b676c);
wenzelm
parents:
83363
diff
changeset
|
173 |
editor.require_dispatcher {}
|
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
174 |
|
|
83365
675ec7e6b233
avoid somewhat adhoc change to query_operation.scala (see also 486e094b676c);
wenzelm
parents:
83363
diff
changeset
|
175 |
editor.current_node_snapshot(editor_context) match {
|
|
675ec7e6b233
avoid somewhat adhoc change to query_operation.scala (see also 486e094b676c);
wenzelm
parents:
83363
diff
changeset
|
176 |
case Some(snapshot) => |
|
675ec7e6b233
avoid somewhat adhoc change to query_operation.scala (see also 486e094b676c);
wenzelm
parents:
83363
diff
changeset
|
177 |
remove_overlay() |
|
675ec7e6b233
avoid somewhat adhoc change to query_operation.scala (see also 486e094b676c);
wenzelm
parents:
83363
diff
changeset
|
178 |
current_state.change(_ => Query_Operation.State.empty) |
|
83419
0ac8a8a3793b
clarified signature: prefer explicit type Editor.Output;
wenzelm
parents:
83412
diff
changeset
|
179 |
consume_output(Editor.Output.init) |
|
66108
8b433b6f302f
more permissive: avoid situations where query is silently ignored;
wenzelm
parents:
66094
diff
changeset
|
180 |
|
|
8b433b6f302f
more permissive: avoid situations where query is silently ignored;
wenzelm
parents:
66094
diff
changeset
|
181 |
editor.current_command(editor_context, snapshot) match {
|
|
8b433b6f302f
more permissive: avoid situations where query is silently ignored;
wenzelm
parents:
66094
diff
changeset
|
182 |
case Some(command) => |
|
8b433b6f302f
more permissive: avoid situations where query is silently ignored;
wenzelm
parents:
66094
diff
changeset
|
183 |
val state = Query_Operation.State.make(command, query) |
|
8b433b6f302f
more permissive: avoid situations where query is silently ignored;
wenzelm
parents:
66094
diff
changeset
|
184 |
current_state.change(_ => state) |
|
8b433b6f302f
more permissive: avoid situations where query is silently ignored;
wenzelm
parents:
66094
diff
changeset
|
185 |
editor.insert_overlay(command, print_function, state.instance :: query) |
|
8b433b6f302f
more permissive: avoid situations where query is silently ignored;
wenzelm
parents:
66094
diff
changeset
|
186 |
case None => |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
187 |
} |
|
66108
8b433b6f302f
more permissive: avoid situations where query is silently ignored;
wenzelm
parents:
66094
diff
changeset
|
188 |
|
|
83365
675ec7e6b233
avoid somewhat adhoc change to query_operation.scala (see also 486e094b676c);
wenzelm
parents:
83363
diff
changeset
|
189 |
consume_status(current_state.value.status) |
|
675ec7e6b233
avoid somewhat adhoc change to query_operation.scala (see also 486e094b676c);
wenzelm
parents:
83363
diff
changeset
|
190 |
editor.flush() |
|
675ec7e6b233
avoid somewhat adhoc change to query_operation.scala (see also 486e094b676c);
wenzelm
parents:
83363
diff
changeset
|
191 |
case None => |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
192 |
} |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
193 |
} |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
194 |
|
| 75393 | 195 |
def locate_query(): Unit = {
|
| 66094 | 196 |
editor.require_dispatcher {}
|
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
197 |
|
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
198 |
val state = current_state.value |
| 52980 | 199 |
for {
|
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
200 |
command <- state.location |
| 52980 | 201 |
snapshot = editor.node_snapshot(command.node_name) |
| 64664 | 202 |
link <- editor.hyperlink_command(true, snapshot, command.id) |
| 52980 | 203 |
} link.follow(editor_context) |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
204 |
} |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
205 |
|
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
206 |
|
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
207 |
/* main */ |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
208 |
|
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
209 |
private val main = |
|
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
210 |
Session.Consumer[Session.Commands_Changed](getClass.getName) {
|
|
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
211 |
case changed => |
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
212 |
val state = current_state.value |
|
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
213 |
state.location match {
|
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
214 |
case Some(command) |
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
215 |
if state.update_pending || |
| 78595 | 216 |
(state.status != Query_Operation.Status.finished && |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
217 |
changed.commands.contains(command)) => |
| 66094 | 218 |
editor.send_dispatcher { content_update() }
|
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
219 |
case _ => |
|
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
220 |
} |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
221 |
} |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
222 |
|
| 75393 | 223 |
def activate(): Unit = {
|
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
224 |
editor.session.commands_changed += main |
| 53840 | 225 |
} |
| 53000 | 226 |
|
| 75393 | 227 |
def deactivate(): Unit = {
|
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
228 |
editor.session.commands_changed -= main |
| 53000 | 229 |
remove_overlay() |
|
61545
57000ac6291f
clarified Query_Operation.State, with separate instance to avoid extra flush (see also 6ddeb83eb67a);
wenzelm
parents:
61210
diff
changeset
|
230 |
current_state.change(_ => Query_Operation.State.empty) |
|
83419
0ac8a8a3793b
clarified signature: prefer explicit type Editor.Output;
wenzelm
parents:
83412
diff
changeset
|
231 |
consume_output(Editor.Output.init) |
| 78595 | 232 |
consume_status(Query_Operation.Status.finished) |
| 53000 | 233 |
} |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
diff
changeset
|
234 |
} |