author | wenzelm |
Thu, 07 Nov 2024 13:22:59 +0100 | |
changeset 81387 | c677755779f5 |
parent 80480 | 972f7a4cdc0e |
child 81392 | 92aa6f7b470c |
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 |
||
81387
c677755779f5
more uniform pretty_text_area.zoom via its zoom_component;
wenzelm
parents:
80480
diff
changeset
|
94 |
private def handle_resize(): Unit = pretty_text_area.zoom() |
76021
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
95 |
|
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
96 |
private val delay_resize: Delay = |
76610 | 97 |
Delay.first(PIDE.session.update_delay, gui = true) { handle_resize() } |
76021
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
98 |
|
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
99 |
addComponentListener(new ComponentAdapter { |
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
100 |
override def componentResized(e: ComponentEvent): Unit = delay_resize.invoke() |
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
101 |
override def componentShown(e: ComponentEvent): Unit = delay_resize.invoke() |
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
102 |
}) |
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
103 |
|
76023 | 104 |
|
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
|
105 |
/* progress */ |
76023 | 106 |
|
77174 | 107 |
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
|
108 |
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
|
109 |
|
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 |
override def detect_program(s: String): Option[String] = |
77173
f1063cdb0093
clarified terminology of inlined "PROGRAM START" messages;
wenzelm
parents:
77170
diff
changeset
|
111 |
Document_Build.detect_program_start(s) |
76023 | 112 |
|
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
|
113 |
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
|
114 |
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
|
115 |
if (!stopped) { |
77146 | 116 |
output_process(progress) |
77156
e3a7d3668629
clarified GUI events: ensure fresh output when switching pages;
wenzelm
parents:
77155
diff
changeset
|
117 |
show_state() |
76491 | 118 |
} |
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
|
119 |
} |
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 |
|
77509
3bc49507bae5
clarified treatment of "verbose" messages, e.g. Progress.theory();
wenzelm
parents:
77502
diff
changeset
|
121 |
override def output(message: Progress.Message): Unit = { super.output(message); delay.invoke() } |
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
|
122 |
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
|
123 |
} |
76021
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
124 |
|
75816 | 125 |
|
126 |
/* document build process */ |
|
127 |
||
76491 | 128 |
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
|
129 |
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
|
130 |
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
|
131 |
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
|
132 |
} |
76491 | 133 |
|
76718 | 134 |
private def cancel_process(): Unit = |
135 |
current_state.change { st => st.process.cancel(); st } |
|
136 |
||
137 |
private def await_process(): Unit = |
|
138 |
current_state.guarded_access(st => if (st.process.is_finished) None else Some((), st)) |
|
139 |
||
77146 | 140 |
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
|
141 |
val (results, body) = progress.output() |
77146 | 142 |
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
|
143 |
} |
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 |
|
77147 | 145 |
private def pending_process(): Unit = |
146 |
current_state.change { st => |
|
147 |
if (st.pending) st |
|
77149
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
148 |
else { |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
149 |
delay_auto_build.revoke() |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
150 |
delay_build.invoke() |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
151 |
st.copy(pending = true) |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
152 |
} |
77147 | 153 |
} |
154 |
||
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
|
155 |
private def finish_process(output: XML.Body): Unit = |
77147 | 156 |
current_state.change { st => |
77149
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
157 |
if (st.pending) { |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
158 |
delay_auto_build.revoke() |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
159 |
delay_build.invoke() |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
160 |
} |
77147 | 161 |
st.finish(output) |
162 |
} |
|
76718 | 163 |
|
77147 | 164 |
private def run_process(reset_pending: Boolean = false)(body: Log_Progress => Unit): Boolean = { |
76718 | 165 |
val started = |
166 |
current_state.change_result { st => |
|
167 |
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
|
168 |
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
|
169 |
val progress = new Log_Progress |
76718 | 170 |
val process = |
171 |
Future.thread[Unit](name = "Document_Dockable.process") { |
|
172 |
await_process() |
|
173 |
body(progress) |
|
174 |
} |
|
77147 | 175 |
(true, st.run(process, progress, reset_pending)) |
76718 | 176 |
} |
177 |
else (false, st) |
|
178 |
} |
|
179 |
show_state() |
|
180 |
started |
|
181 |
} |
|
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76711
diff
changeset
|
182 |
|
76681 | 183 |
private def load_document(session: String): Boolean = { |
76718 | 184 |
val options = PIDE.options.value |
77147 | 185 |
run_process() { _ => |
76718 | 186 |
try { |
187 |
val session_background = |
|
188 |
Document_Build.session_background( |
|
189 |
options, session, dirs = JEdit_Sessions.session_dirs) |
|
190 |
PIDE.editor.document_setup(Some(session_background)) |
|
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76711
diff
changeset
|
191 |
|
76718 | 192 |
finish_process(Nil) |
193 |
GUI_Thread.later { |
|
76725
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
194 |
refresh_theories() |
76996 | 195 |
show_page(input_page) |
76718 | 196 |
} |
197 |
} |
|
198 |
catch { |
|
199 |
case exn: Throwable if !Exn.is_interrupt(exn) => |
|
200 |
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
|
201 |
show_page(output_page) |
76681 | 202 |
} |
203 |
} |
|
204 |
} |
|
205 |
||
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
206 |
private def document_build_attempt(): Boolean = { |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
207 |
val document_session = PIDE.editor.document_session() |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
208 |
if (document_session.is_vacuous) true |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
209 |
else if (document_session.is_pending) false |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
210 |
else { |
77147 | 211 |
run_process(reset_pending = true) { progress => |
77153
0bb95bcf804e
more accurate output: avoid output_body from last run;
wenzelm
parents:
77152
diff
changeset
|
212 |
output_process(progress) |
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
213 |
show_page(output_page) |
77153
0bb95bcf804e
more accurate output: avoid output_body from last run;
wenzelm
parents:
77152
diff
changeset
|
214 |
|
77194 | 215 |
val result = Exn.capture { |
216 |
val snapshot = document_session.get_snapshot |
|
77196 | 217 |
using(JEdit_Sessions.open_session_context(document_snapshot = Some(snapshot)))( |
218 |
Document_Editor.build(_, document_session, progress)) |
|
77194 | 219 |
} |
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
220 |
val msgs = |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
221 |
result match { |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
222 |
case Exn.Res(_) => |
77188 | 223 |
List(Protocol.writeln_message("DONE")) |
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
224 |
case Exn.Exn(exn: Document_Build.Build_Error) => |
80480
972f7a4cdc0e
clarified YXML.Source: more direct support for String and Bytes, instead of CharSequence;
wenzelm
parents:
78614
diff
changeset
|
225 |
exn.log_errors.map(s => Protocol.error_message(YXML.parse_body(YXML.Source(s)))) |
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
226 |
case Exn.Exn(exn) => |
80480
972f7a4cdc0e
clarified YXML.Source: more direct support for String and Bytes, instead of CharSequence;
wenzelm
parents:
78614
diff
changeset
|
227 |
List(Protocol.error_message(YXML.parse_body(YXML.Source(Exn.print(exn))))) |
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
228 |
} |
76732 | 229 |
|
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
230 |
progress.stop_program() |
77146 | 231 |
output_process(progress) |
77152
4c9296390f20
more accurate output: avoid output_main from last run;
wenzelm
parents:
77151
diff
changeset
|
232 |
progress.stop() |
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
233 |
finish_process(Pretty.separate(msgs)) |
76732 | 234 |
|
77155
6840013a791a
clarified GUI: avoid odd jumping pages on "Cancel";
wenzelm
parents:
77154
diff
changeset
|
235 |
show_page(output_page) |
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
236 |
} |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
237 |
true |
76023 | 238 |
} |
239 |
} |
|
240 |
||
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
241 |
private lazy val delay_build: Delay = |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
242 |
Delay.first(PIDE.session.output_delay, gui = true) { |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
243 |
if (!document_build_attempt()) delay_build.invoke() |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
244 |
} |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
245 |
|
77149
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
246 |
private lazy val delay_auto_build: Delay = |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
247 |
Delay.last(PIDE.session.document_delay, gui = true) { |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
248 |
pending_process() |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
249 |
} |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
250 |
|
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
251 |
private def document_pending() = current_state.value.pending |
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 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
|
254 |
|
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
255 |
|
75816 | 256 |
|
257 |
/* controls */ |
|
258 |
||
76681 | 259 |
private val document_session = |
260 |
JEdit_Sessions.document_selector(PIDE.options, standalone = true) |
|
261 |
||
76602 | 262 |
private lazy val delay_load: Delay = |
76610 | 263 |
Delay.last(PIDE.session.load_delay, gui = true) { |
76681 | 264 |
for (session <- document_session.selection_value) { |
77157
c0633a0da53e
clarified GUI events: reset everything on session context switch;
wenzelm
parents:
77156
diff
changeset
|
265 |
current_state.change(_.reset()) |
76681 | 266 |
if (!load_document(session)) delay_load.invoke() |
77154 | 267 |
else if (document_auto()) delay_auto_build.invoke() |
76681 | 268 |
} |
76602 | 269 |
} |
270 |
||
77154 | 271 |
document_session.reactions += { |
272 |
case SelectionChanged(_) => |
|
273 |
delay_load.invoke() |
|
274 |
delay_build.revoke() |
|
77157
c0633a0da53e
clarified GUI events: reset everything on session context switch;
wenzelm
parents:
77156
diff
changeset
|
275 |
delay_auto_build.revoke() |
77154 | 276 |
} |
76602 | 277 |
|
77149
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
278 |
private val auto_build_button = |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
279 |
new JEdit_Options.Bool_GUI(document_auto, "Auto") { |
78614 | 280 |
tooltip = Word.capitalized(document_auto.description) |
77149
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
281 |
override def clicked(state: Boolean): Unit = { |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
282 |
super.clicked(state) |
77160 | 283 |
|
77149
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
284 |
if (state) delay_auto_build.invoke() |
77160 | 285 |
else delay_auto_build.revoke() |
77149
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
286 |
} |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
287 |
} |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
288 |
|
75853 | 289 |
private val build_button = |
290 |
new GUI.Button("<html><b>Build</b></html>") { |
|
75816 | 291 |
tooltip = "Build document" |
77147 | 292 |
override def clicked(): Unit = pending_process() |
76023 | 293 |
} |
294 |
||
295 |
private val view_button = |
|
296 |
new GUI.Button("View") { |
|
297 |
tooltip = "View document" |
|
76606 | 298 |
override def clicked(): Unit = Document_Editor.view_document() |
75816 | 299 |
} |
300 |
||
301 |
private val controls = |
|
77159 | 302 |
Wrap_Panel(List(document_session, process_indicator.component, |
77170 | 303 |
auto_build_button, build_button, view_button)) |
75816 | 304 |
|
305 |
add(controls.peer, BorderLayout.NORTH) |
|
306 |
||
307 |
override def focusOnDefaultComponent(): Unit = build_button.requestFocus() |
|
308 |
||
309 |
||
76023 | 310 |
/* message pane with pages */ |
311 |
||
77159 | 312 |
private val all_button = |
313 |
new GUI.Button("All") { |
|
314 |
tooltip = "Select all document theories" |
|
315 |
override def clicked(): Unit = PIDE.editor.document_select_all(set = true) |
|
316 |
} |
|
317 |
||
318 |
private val none_button = |
|
319 |
new GUI.Button("None") { |
|
320 |
tooltip = "Deselect all document theories" |
|
76720 | 321 |
override def clicked(): Unit = PIDE.editor.document_select_all(set = false) |
322 |
} |
|
323 |
||
76726 | 324 |
private val purge_button = new GUI.Button("Purge") { |
325 |
tooltip = "Remove theories that are no longer required" |
|
326 |
override def clicked(): Unit = PIDE.editor.purge() |
|
327 |
} |
|
328 |
||
77159 | 329 |
private val input_controls = |
330 |
Wrap_Panel(List(all_button, none_button, purge_button)) |
|
76720 | 331 |
|
76602 | 332 |
private val theories = new Theories_Status(view, document = true) |
77008 | 333 |
private val theories_pane = new ScrollPane(theories.gui) |
76567 | 334 |
|
76725
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
335 |
private def refresh_theories(): Unit = { |
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
336 |
val domain = PIDE.editor.document_theories().toSet |
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
337 |
theories.update(domain = Some(domain), trim = true, force = true) |
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
338 |
theories.refresh() |
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
339 |
} |
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
340 |
|
76996 | 341 |
private val input_page = |
342 |
new TabbedPane.Page("Input", new BorderPanel { |
|
77159 | 343 |
layout(input_controls) = BorderPanel.Position.North |
77008 | 344 |
layout(theories_pane) = BorderPanel.Position.Center |
76567 | 345 |
}, "Selection and status of document theories") |
346 |
||
77170 | 347 |
|
348 |
private val cancel_button = |
|
349 |
new GUI.Button("Cancel") { |
|
350 |
tooltip = "Cancel build process" |
|
351 |
override def clicked(): Unit = cancel_process() |
|
352 |
} |
|
353 |
||
81387
c677755779f5
more uniform pretty_text_area.zoom via its zoom_component;
wenzelm
parents:
80480
diff
changeset
|
354 |
private val output_controls = Wrap_Panel(List(cancel_button, pretty_text_area.zoom_component)) |
76023 | 355 |
|
356 |
private val output_page = |
|
357 |
new TabbedPane.Page("Output", new BorderPanel { |
|
358 |
layout(output_controls) = BorderPanel.Position.North |
|
359 |
layout(Component.wrap(pretty_text_area)) = BorderPanel.Position.Center |
|
76996 | 360 |
}, "Results from document build process") |
76023 | 361 |
|
76996 | 362 |
message_pane.pages ++= List(input_page, output_page) |
76023 | 363 |
|
364 |
set_content(message_pane) |
|
365 |
||
366 |
||
75816 | 367 |
/* main */ |
368 |
||
369 |
private val main = |
|
76567 | 370 |
Session.Consumer[Any](getClass.getName) { |
75816 | 371 |
case _: Session.Global_Options => |
76567 | 372 |
GUI_Thread.later { |
76578
06b001094ddb
more uniform session selectors, with persistent options;
wenzelm
parents:
76577
diff
changeset
|
373 |
document_session.load() |
76567 | 374 |
handle_resize() |
76725
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
375 |
refresh_theories() |
76567 | 376 |
} |
377 |
case changed: Session.Commands_Changed => |
|
378 |
GUI_Thread.later { |
|
76719 | 379 |
val domain = PIDE.editor.document_theories().filter(changed.nodes).toSet |
77150 | 380 |
if (domain.nonEmpty) { |
381 |
theories.update(domain = Some(domain)) |
|
77149
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
382 |
|
77150 | 383 |
val pending = document_pending() |
384 |
val auto = document_auto() |
|
385 |
if ((pending || auto) && PIDE.editor.document_session().is_ready) { |
|
77149
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
386 |
if (pending) { |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
387 |
delay_auto_build.revoke() |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
388 |
delay_build.invoke() |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
389 |
} |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
390 |
else if (auto) { |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
391 |
delay_auto_build.invoke() |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
392 |
} |
3991a35cd740
automatically build document when selected theories are finished;
wenzelm
parents:
77147
diff
changeset
|
393 |
} |
77147 | 394 |
} |
76567 | 395 |
} |
75816 | 396 |
} |
397 |
||
398 |
override def init(): Unit = { |
|
76701 | 399 |
PIDE.editor.document_init(dockable) |
76491 | 400 |
init_state() |
75816 | 401 |
PIDE.session.global_options += main |
76567 | 402 |
PIDE.session.commands_changed += main |
75816 | 403 |
handle_resize() |
76602 | 404 |
delay_load.invoke() |
75816 | 405 |
} |
406 |
||
407 |
override def exit(): Unit = { |
|
408 |
PIDE.session.global_options -= main |
|
76567 | 409 |
PIDE.session.commands_changed -= main |
75816 | 410 |
delay_resize.revoke() |
76701 | 411 |
PIDE.editor.document_exit(dockable) |
75816 | 412 |
} |
413 |
} |