author | wenzelm |
Sun, 05 Feb 2023 14:59:50 +0100 | |
changeset 77195 | e312c7fa3bad |
parent 77194 | 7438d516ab4f |
child 77196 | 3d709d300d0f |
permissions | -rw-r--r-- |
75816 | 1 |
/* Title: Tools/jEdit/src/document_dockable.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Dockable window for document build support. |
|
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 |
||
76023 | 15 |
import scala.swing.{ScrollPane, TextArea, Label, TabbedPane, BorderPanel, Component} |
76602 | 16 |
import scala.swing.event.SelectionChanged |
76023 | 17 |
|
75816 | 18 |
import org.gjt.sp.jedit.{jEdit, View} |
19 |
||
20 |
||
76023 | 21 |
object Document_Dockable { |
76491 | 22 |
/* state */ |
23 |
||
76023 | 24 |
object State { |
76681 | 25 |
def init(): State = State() |
76023 | 26 |
} |
27 |
||
28 |
sealed case class State( |
|
77146 | 29 |
pending: Boolean = false, |
76023 | 30 |
process: Future[Unit] = Future.value(()), |
77146 | 31 |
progress: Progress = new Progress, |
76994
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
32 |
output_results: Command.Results = Command.Results.empty, |
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
33 |
output_main: XML.Body = Nil, |
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
34 |
output_more: XML.Body = Nil |
76681 | 35 |
) { |
77146 | 36 |
def running: Boolean = !process.is_finished |
76681 | 37 |
|
77147 | 38 |
def run(process: Future[Unit], progress: Progress, reset_pending: Boolean): State = |
39 |
copy(process = process, progress = progress, pending = if (reset_pending) false else pending) |
|
77146 | 40 |
|
41 |
def output(results: Command.Results, body: XML.Body): State = |
|
77152
4c9296390f20
more accurate output: avoid output_main from last run;
wenzelm
parents:
77151
diff
changeset
|
42 |
copy(output_results = results, output_main = body, output_more = Nil) |
76994
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
43 |
|
77152
4c9296390f20
more accurate output: avoid output_main from last run;
wenzelm
parents:
77151
diff
changeset
|
44 |
def finish(body: XML.Body): State = |
4c9296390f20
more accurate output: avoid output_main from last run;
wenzelm
parents:
77151
diff
changeset
|
45 |
copy(process = Future.value(()), output_more = body) |
76718 | 46 |
|
76994
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
47 |
def output_body: XML.Body = |
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
48 |
output_main ::: |
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
49 |
(if (output_main.nonEmpty && output_more.nonEmpty) Pretty.Separator else Nil) ::: |
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
50 |
output_more |
77157
c0633a0da53e
clarified GUI events: reset everything on session context switch;
wenzelm
parents:
77156
diff
changeset
|
51 |
|
c0633a0da53e
clarified GUI events: reset everything on session context switch;
wenzelm
parents:
77156
diff
changeset
|
52 |
def reset(): State = { |
c0633a0da53e
clarified GUI events: reset everything on session context switch;
wenzelm
parents:
77156
diff
changeset
|
53 |
process.cancel() |
c0633a0da53e
clarified GUI events: reset everything on session context switch;
wenzelm
parents:
77156
diff
changeset
|
54 |
progress.stop() |
c0633a0da53e
clarified GUI events: reset everything on session context switch;
wenzelm
parents:
77156
diff
changeset
|
55 |
State.init() |
c0633a0da53e
clarified GUI events: reset everything on session context switch;
wenzelm
parents:
77156
diff
changeset
|
56 |
} |
76681 | 57 |
} |
76023 | 58 |
} |
59 |
||
75816 | 60 |
class Document_Dockable(view: View, position: String) extends Dockable(view, position) { |
76609
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
76606
diff
changeset
|
61 |
dockable => |
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
76606
diff
changeset
|
62 |
|
75816 | 63 |
GUI_Thread.require {} |
64 |
||
65 |
||
76023 | 66 |
/* component state -- owned by GUI thread */ |
67 |
||
76681 | 68 |
private val current_state = Synchronized(Document_Dockable.State.init()) |
76023 | 69 |
|
70 |
private val process_indicator = new Process_Indicator |
|
71 |
private val pretty_text_area = new Pretty_Text_Area(view) |
|
72 |
private val message_pane = new TabbedPane |
|
73 |
||
76034 | 74 |
private def show_state(): Unit = GUI_Thread.later { |
76023 | 75 |
val st = current_state.value |
76 |
||
76994
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
77 |
pretty_text_area.update(Document.Snapshot.init, st.output_results, st.output_body) |
75816 | 78 |
|
77146 | 79 |
if (st.running) process_indicator.update("Running document build process ...", 15) |
80 |
else if (st.pending) process_indicator.update("Waiting for pending document content ...", 5) |
|
81 |
else process_indicator.update(null, 0) |
|
76034 | 82 |
} |
76023 | 83 |
|
76034 | 84 |
private def show_page(page: TabbedPane.Page): Unit = GUI_Thread.later { |
77156
e3a7d3668629
clarified GUI events: ensure fresh output when switching pages;
wenzelm
parents:
77155
diff
changeset
|
85 |
show_state() |
76034 | 86 |
message_pane.selection.page = page |
76023 | 87 |
} |
88 |
||
89 |
||
90 |
/* text area with zoom/resize */ |
|
75816 | 91 |
|
92 |
override def detach_operation: Option[() => Unit] = pretty_text_area.detach_operation |
|
93 |
||
76021
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
94 |
private val zoom = new Font_Info.Zoom { override def changed(): Unit = handle_resize() } |
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
95 |
private def handle_resize(): Unit = GUI_Thread.require { pretty_text_area.zoom(zoom) } |
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
96 |
|
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
97 |
private val delay_resize: Delay = |
76610 | 98 |
Delay.first(PIDE.session.update_delay, gui = true) { handle_resize() } |
76021
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
99 |
|
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
100 |
addComponentListener(new ComponentAdapter { |
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
101 |
override def componentResized(e: ComponentEvent): Unit = delay_resize.invoke() |
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
102 |
override def componentShown(e: ComponentEvent): Unit = delay_resize.invoke() |
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
103 |
}) |
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
104 |
|
76023 | 105 |
|
76994
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
106 |
/* progress */ |
76023 | 107 |
|
77174 | 108 |
class Log_Progress extends Program_Progress(default_title = "build") { |
76994
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
109 |
progress => |
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
110 |
|
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
111 |
override def detect_program(s: String): Option[String] = |
77173
f1063cdb0093
clarified terminology of inlined "PROGRAM START" messages;
wenzelm
parents:
77170
diff
changeset
|
112 |
Document_Build.detect_program_start(s) |
76023 | 113 |
|
76994
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
114 |
private val delay: Delay = |
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
115 |
Delay.first(PIDE.session.output_delay) { |
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
116 |
if (!stopped) { |
77146 | 117 |
output_process(progress) |
77156
e3a7d3668629
clarified GUI events: ensure fresh output when switching pages;
wenzelm
parents:
77155
diff
changeset
|
118 |
show_state() |
76491 | 119 |
} |
76994
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
120 |
} |
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
121 |
|
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
122 |
override def echo(msg: String): Unit = { super.echo(msg); delay.invoke() } |
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
123 |
override def stop_program(): Unit = { super.stop_program(); delay.invoke() } |
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
124 |
} |
76021
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
125 |
|
75816 | 126 |
|
127 |
/* document build process */ |
|
128 |
||
76491 | 129 |
private def init_state(): Unit = |
76994
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
130 |
current_state.change { st => |
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
131 |
st.progress.stop() |
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
132 |
Document_Dockable.State(progress = new Log_Progress) |
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
133 |
} |
76491 | 134 |
|
76718 | 135 |
private def cancel_process(): Unit = |
136 |
current_state.change { st => st.process.cancel(); st } |
|
137 |
||
138 |
private def await_process(): Unit = |
|
139 |
current_state.guarded_access(st => if (st.process.is_finished) None else Some((), st)) |
|
140 |
||
77146 | 141 |
private def output_process(progress: Log_Progress): Unit = { |
76994
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
142 |
val (results, body) = progress.output() |
77146 | 143 |
current_state.change(_.output(results, body)) |
76994
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
144 |
} |
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
145 |
|
77147 | 146 |
private def pending_process(): Unit = |
147 |
current_state.change { st => |
|
148 |
if (st.pending) st |
|
77149
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
149 |
else { |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
150 |
delay_auto_build.revoke() |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
151 |
delay_build.invoke() |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
152 |
st.copy(pending = true) |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
153 |
} |
77147 | 154 |
} |
155 |
||
76994
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
156 |
private def finish_process(output: XML.Body): Unit = |
77147 | 157 |
current_state.change { st => |
77149
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
158 |
if (st.pending) { |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
159 |
delay_auto_build.revoke() |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
160 |
delay_build.invoke() |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
161 |
} |
77147 | 162 |
st.finish(output) |
163 |
} |
|
76718 | 164 |
|
77147 | 165 |
private def run_process(reset_pending: Boolean = false)(body: Log_Progress => Unit): Boolean = { |
76718 | 166 |
val started = |
167 |
current_state.change_result { st => |
|
168 |
if (st.process.is_finished) { |
|
76994
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
169 |
st.progress.stop() |
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76769
diff
changeset
|
170 |
val progress = new Log_Progress |
76718 | 171 |
val process = |
172 |
Future.thread[Unit](name = "Document_Dockable.process") { |
|
173 |
await_process() |
|
174 |
body(progress) |
|
175 |
} |
|
77147 | 176 |
(true, st.run(process, progress, reset_pending)) |
76718 | 177 |
} |
178 |
else (false, st) |
|
179 |
} |
|
180 |
show_state() |
|
181 |
started |
|
182 |
} |
|
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76711
diff
changeset
|
183 |
|
76681 | 184 |
private def load_document(session: String): Boolean = { |
76718 | 185 |
val options = PIDE.options.value |
77147 | 186 |
run_process() { _ => |
76718 | 187 |
try { |
188 |
val session_background = |
|
189 |
Document_Build.session_background( |
|
190 |
options, session, dirs = JEdit_Sessions.session_dirs) |
|
191 |
PIDE.editor.document_setup(Some(session_background)) |
|
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76711
diff
changeset
|
192 |
|
76718 | 193 |
finish_process(Nil) |
194 |
GUI_Thread.later { |
|
76725
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
195 |
refresh_theories() |
76996 | 196 |
show_page(input_page) |
76718 | 197 |
} |
198 |
} |
|
199 |
catch { |
|
200 |
case exn: Throwable if !Exn.is_interrupt(exn) => |
|
201 |
finish_process(List(Protocol.error_message(Exn.print(exn)))) |
|
77156
e3a7d3668629
clarified GUI events: ensure fresh output when switching pages;
wenzelm
parents:
77155
diff
changeset
|
202 |
show_page(output_page) |
76681 | 203 |
} |
204 |
} |
|
205 |
} |
|
206 |
||
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
207 |
private def document_build_attempt(): Boolean = { |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
208 |
val document_session = PIDE.editor.document_session() |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
209 |
if (document_session.is_vacuous) true |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
210 |
else if (document_session.is_pending) false |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
211 |
else { |
77147 | 212 |
run_process(reset_pending = true) { progress => |
77153
0bb95bcf804e
more accurate output: avoid output_body from last run;
wenzelm
parents:
77152
diff
changeset
|
213 |
output_process(progress) |
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
214 |
show_page(output_page) |
77153
0bb95bcf804e
more accurate output: avoid output_body from last run;
wenzelm
parents:
77152
diff
changeset
|
215 |
|
77194 | 216 |
val result = Exn.capture { |
217 |
val snapshot = document_session.get_snapshot |
|
218 |
using(JEdit_Sessions.open_session_context(document_snapshot = Some(snapshot))) { |
|
77195 | 219 |
session_context => Document_Editor.build(session_context, document_session, progress) |
77194 | 220 |
} |
221 |
} |
|
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
222 |
val msgs = |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
223 |
result match { |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
224 |
case Exn.Res(_) => |
77188 | 225 |
List(Protocol.writeln_message("DONE")) |
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
226 |
case Exn.Exn(exn: Document_Build.Build_Error) => |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
227 |
exn.log_errors.map(s => Protocol.error_message(YXML.parse_body(s))) |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
228 |
case Exn.Exn(exn) => |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
229 |
List(Protocol.error_message(YXML.parse_body(Exn.print(exn)))) |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
230 |
} |
76732 | 231 |
|
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
232 |
progress.stop_program() |
77146 | 233 |
output_process(progress) |
77152
4c9296390f20
more accurate output: avoid output_main from last run;
wenzelm
parents:
77151
diff
changeset
|
234 |
progress.stop() |
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
235 |
finish_process(Pretty.separate(msgs)) |
76732 | 236 |
|
77155
6840013a791a
clarified GUI: avoid odd jumping pages on "Cancel";
wenzelm
parents:
77154
diff
changeset
|
237 |
show_page(output_page) |
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
238 |
} |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
239 |
true |
76023 | 240 |
} |
241 |
} |
|
242 |
||
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
243 |
private lazy val delay_build: Delay = |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
244 |
Delay.first(PIDE.session.output_delay, gui = true) { |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
245 |
if (!document_build_attempt()) delay_build.invoke() |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
246 |
} |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
247 |
|
77149
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
248 |
private lazy val delay_auto_build: Delay = |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
249 |
Delay.last(PIDE.session.document_delay, gui = true) { |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
250 |
pending_process() |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
251 |
} |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
252 |
|
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
253 |
private def document_pending() = current_state.value.pending |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
254 |
|
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
255 |
private val document_auto = new JEdit_Options.Bool_Access("editor_document_auto") |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
256 |
|
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
257 |
|
75816 | 258 |
|
259 |
/* controls */ |
|
260 |
||
76681 | 261 |
private val document_session = |
262 |
JEdit_Sessions.document_selector(PIDE.options, standalone = true) |
|
263 |
||
76602 | 264 |
private lazy val delay_load: Delay = |
76610 | 265 |
Delay.last(PIDE.session.load_delay, gui = true) { |
76681 | 266 |
for (session <- document_session.selection_value) { |
77157
c0633a0da53e
clarified GUI events: reset everything on session context switch;
wenzelm
parents:
77156
diff
changeset
|
267 |
current_state.change(_.reset()) |
76681 | 268 |
if (!load_document(session)) delay_load.invoke() |
77154 | 269 |
else if (document_auto()) delay_auto_build.invoke() |
76681 | 270 |
} |
76602 | 271 |
} |
272 |
||
77154 | 273 |
document_session.reactions += { |
274 |
case SelectionChanged(_) => |
|
275 |
delay_load.invoke() |
|
276 |
delay_build.revoke() |
|
77157
c0633a0da53e
clarified GUI events: reset everything on session context switch;
wenzelm
parents:
77156
diff
changeset
|
277 |
delay_auto_build.revoke() |
77154 | 278 |
} |
76602 | 279 |
|
77149
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
280 |
private val auto_build_button = |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
281 |
new JEdit_Options.Bool_GUI(document_auto, "Auto") { |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
282 |
tooltip = Word.capitalize(document_auto.description) |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
283 |
override def clicked(state: Boolean): Unit = { |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
284 |
super.clicked(state) |
77160 | 285 |
|
77149
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
286 |
if (state) delay_auto_build.invoke() |
77160 | 287 |
else delay_auto_build.revoke() |
77149
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
288 |
} |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
289 |
} |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
290 |
|
75853 | 291 |
private val build_button = |
292 |
new GUI.Button("<html><b>Build</b></html>") { |
|
75816 | 293 |
tooltip = "Build document" |
77147 | 294 |
override def clicked(): Unit = pending_process() |
76023 | 295 |
} |
296 |
||
297 |
private val view_button = |
|
298 |
new GUI.Button("View") { |
|
299 |
tooltip = "View document" |
|
76606 | 300 |
override def clicked(): Unit = Document_Editor.view_document() |
75816 | 301 |
} |
302 |
||
303 |
private val controls = |
|
77159 | 304 |
Wrap_Panel(List(document_session, process_indicator.component, |
77170 | 305 |
auto_build_button, build_button, view_button)) |
75816 | 306 |
|
307 |
add(controls.peer, BorderLayout.NORTH) |
|
308 |
||
309 |
override def focusOnDefaultComponent(): Unit = build_button.requestFocus() |
|
310 |
||
311 |
||
76023 | 312 |
/* message pane with pages */ |
313 |
||
77159 | 314 |
private val all_button = |
315 |
new GUI.Button("All") { |
|
316 |
tooltip = "Select all document theories" |
|
317 |
override def clicked(): Unit = PIDE.editor.document_select_all(set = true) |
|
318 |
} |
|
319 |
||
320 |
private val none_button = |
|
321 |
new GUI.Button("None") { |
|
322 |
tooltip = "Deselect all document theories" |
|
76720 | 323 |
override def clicked(): Unit = PIDE.editor.document_select_all(set = false) |
324 |
} |
|
325 |
||
76726 | 326 |
private val purge_button = new GUI.Button("Purge") { |
327 |
tooltip = "Remove theories that are no longer required" |
|
328 |
override def clicked(): Unit = PIDE.editor.purge() |
|
329 |
} |
|
330 |
||
77159 | 331 |
private val input_controls = |
332 |
Wrap_Panel(List(all_button, none_button, purge_button)) |
|
76720 | 333 |
|
76602 | 334 |
private val theories = new Theories_Status(view, document = true) |
77008 | 335 |
private val theories_pane = new ScrollPane(theories.gui) |
76567 | 336 |
|
76725
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
337 |
private def refresh_theories(): Unit = { |
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
338 |
val domain = PIDE.editor.document_theories().toSet |
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
339 |
theories.update(domain = Some(domain), trim = true, force = true) |
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
340 |
theories.refresh() |
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
341 |
} |
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
342 |
|
76996 | 343 |
private val input_page = |
344 |
new TabbedPane.Page("Input", new BorderPanel { |
|
77159 | 345 |
layout(input_controls) = BorderPanel.Position.North |
77008 | 346 |
layout(theories_pane) = BorderPanel.Position.Center |
76567 | 347 |
}, "Selection and status of document theories") |
348 |
||
77170 | 349 |
|
350 |
private val cancel_button = |
|
351 |
new GUI.Button("Cancel") { |
|
352 |
tooltip = "Cancel build process" |
|
353 |
override def clicked(): Unit = cancel_process() |
|
354 |
} |
|
355 |
||
356 |
private val output_controls = Wrap_Panel(List(cancel_button, zoom)) |
|
76023 | 357 |
|
358 |
private val output_page = |
|
359 |
new TabbedPane.Page("Output", new BorderPanel { |
|
360 |
layout(output_controls) = BorderPanel.Position.North |
|
361 |
layout(Component.wrap(pretty_text_area)) = BorderPanel.Position.Center |
|
76996 | 362 |
}, "Results from document build process") |
76023 | 363 |
|
76996 | 364 |
message_pane.pages ++= List(input_page, output_page) |
76023 | 365 |
|
366 |
set_content(message_pane) |
|
367 |
||
368 |
||
75816 | 369 |
/* main */ |
370 |
||
371 |
private val main = |
|
76567 | 372 |
Session.Consumer[Any](getClass.getName) { |
75816 | 373 |
case _: Session.Global_Options => |
76567 | 374 |
GUI_Thread.later { |
76578
06b001094ddb
more uniform session selectors, with persistent options;
wenzelm
parents:
76577
diff
changeset
|
375 |
document_session.load() |
76567 | 376 |
handle_resize() |
76725
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
377 |
refresh_theories() |
76567 | 378 |
} |
379 |
case changed: Session.Commands_Changed => |
|
380 |
GUI_Thread.later { |
|
76719 | 381 |
val domain = PIDE.editor.document_theories().filter(changed.nodes).toSet |
77150 | 382 |
if (domain.nonEmpty) { |
383 |
theories.update(domain = Some(domain)) |
|
77149
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
384 |
|
77150 | 385 |
val pending = document_pending() |
386 |
val auto = document_auto() |
|
387 |
if ((pending || auto) && PIDE.editor.document_session().is_ready) { |
|
77149
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
388 |
if (pending) { |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
389 |
delay_auto_build.revoke() |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
390 |
delay_build.invoke() |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
391 |
} |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
392 |
else if (auto) { |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
393 |
delay_auto_build.invoke() |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
394 |
} |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
395 |
} |
77147 | 396 |
} |
76567 | 397 |
} |
75816 | 398 |
} |
399 |
||
400 |
override def init(): Unit = { |
|
76701 | 401 |
PIDE.editor.document_init(dockable) |
76491 | 402 |
init_state() |
75816 | 403 |
PIDE.session.global_options += main |
76567 | 404 |
PIDE.session.commands_changed += main |
75816 | 405 |
handle_resize() |
76602 | 406 |
delay_load.invoke() |
75816 | 407 |
} |
408 |
||
409 |
override def exit(): Unit = { |
|
410 |
PIDE.session.global_options -= main |
|
76567 | 411 |
PIDE.session.commands_changed -= main |
75816 | 412 |
delay_resize.revoke() |
76701 | 413 |
PIDE.editor.document_exit(dockable) |
75816 | 414 |
} |
415 |
} |