author | wenzelm |
Tue, 31 Jan 2023 14:32:07 +0100 | |
changeset 77145 | de618831ffd9 |
parent 77144 | 42c3970e1ac1 |
child 77146 | eb114301c4df |
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 Status extends Enumeration { |
25 |
val WAITING = Value("waiting") |
|
26 |
val RUNNING = Value("running") |
|
27 |
val FINISHED = Value("finished") |
|
28 |
} |
|
29 |
||
30 |
object State { |
|
76681 | 31 |
def init(): State = State() |
76023 | 32 |
} |
33 |
||
34 |
sealed case class State( |
|
76606 | 35 |
progress: Progress = new Progress, |
76023 | 36 |
process: Future[Unit] = Future.value(()), |
76681 | 37 |
status: Status.Value = Status.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
|
38 |
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
|
39 |
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
|
40 |
output_more: XML.Body = Nil |
76681 | 41 |
) { |
42 |
def run(progress: Progress, process: Future[Unit]): State = |
|
43 |
copy(progress = progress, process = process, status = Status.RUNNING) |
|
44 |
||
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
|
45 |
def running(results: Command.Results, body: XML.Body): State = |
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
|
46 |
copy(status = Status.RUNNING, output_results = results, output_main = 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
|
47 |
|
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 |
def finish(output: XML.Body): State = |
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 |
copy(process = Future.value(()), status = Status.FINISHED, output_more = output) |
76718 | 50 |
|
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
|
51 |
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
|
52 |
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
|
53 |
(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
|
54 |
output_more |
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
|
55 |
|
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
|
56 |
def ok: Boolean = !output_body.exists(Protocol.is_error) |
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 |
|
76023 | 79 |
st.status match { |
80 |
case Document_Dockable.Status.WAITING => |
|
81 |
process_indicator.update("Waiting for PIDE document content ...", 5) |
|
82 |
case Document_Dockable.Status.RUNNING => |
|
83 |
process_indicator.update("Running document build process ...", 15) |
|
84 |
case Document_Dockable.Status.FINISHED => |
|
85 |
process_indicator.update(null, 0) |
|
86 |
} |
|
76034 | 87 |
} |
76023 | 88 |
|
76034 | 89 |
private def show_page(page: TabbedPane.Page): Unit = GUI_Thread.later { |
90 |
message_pane.selection.page = page |
|
76023 | 91 |
} |
92 |
||
93 |
||
94 |
/* text area with zoom/resize */ |
|
75816 | 95 |
|
96 |
override def detach_operation: Option[() => Unit] = pretty_text_area.detach_operation |
|
97 |
||
76021
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
98 |
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
|
99 |
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
|
100 |
|
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
101 |
private val delay_resize: Delay = |
76610 | 102 |
Delay.first(PIDE.session.update_delay, gui = true) { handle_resize() } |
76021
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 |
addComponentListener(new ComponentAdapter { |
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
105 |
override def componentResized(e: ComponentEvent): Unit = delay_resize.invoke() |
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
106 |
override def componentShown(e: ComponentEvent): Unit = delay_resize.invoke() |
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
107 |
}) |
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
108 |
|
76023 | 109 |
|
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
|
110 |
/* progress */ |
76023 | 111 |
|
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
|
112 |
class Log_Progress extends Program_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
|
113 |
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
|
114 |
|
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 |
override def detect_program(s: String): Option[String] = |
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 |
Document_Build.detect_running_script(s) |
76023 | 117 |
|
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
|
118 |
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
|
119 |
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
|
120 |
if (!stopped) { |
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 |
running_process(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
|
122 |
GUI_Thread.later { show_state() } |
76491 | 123 |
} |
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
|
124 |
} |
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
|
125 |
|
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
|
126 |
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
|
127 |
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
|
128 |
} |
76021
752425c69577
clarified component structure, concerning initialization order;
wenzelm
parents:
75853
diff
changeset
|
129 |
|
75816 | 130 |
|
131 |
/* document build process */ |
|
132 |
||
76491 | 133 |
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
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
} |
76491 | 138 |
|
76718 | 139 |
private def cancel_process(): Unit = |
140 |
current_state.change { st => st.process.cancel(); st } |
|
141 |
||
142 |
private def await_process(): Unit = |
|
143 |
current_state.guarded_access(st => if (st.process.is_finished) None else Some((), st)) |
|
144 |
||
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
|
145 |
private def running_process(progress: Log_Progress): Unit = { |
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
|
146 |
val (results, body) = progress.output() |
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
|
147 |
current_state.change(_.running(results, 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
|
148 |
} |
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
|
149 |
|
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
|
150 |
private def finish_process(output: XML.Body): Unit = |
76718 | 151 |
current_state.change(_.finish(output)) |
152 |
||
77145 | 153 |
private def run_process(body: Log_Progress => Unit): Boolean = { |
76718 | 154 |
val started = |
155 |
current_state.change_result { st => |
|
156 |
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
|
157 |
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
|
158 |
val progress = new Log_Progress |
76718 | 159 |
val process = |
160 |
Future.thread[Unit](name = "Document_Dockable.process") { |
|
161 |
await_process() |
|
162 |
body(progress) |
|
163 |
} |
|
164 |
(true, st.run(progress, process)) |
|
165 |
} |
|
166 |
else (false, st) |
|
167 |
} |
|
168 |
show_state() |
|
169 |
started |
|
170 |
} |
|
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76711
diff
changeset
|
171 |
|
76681 | 172 |
private def load_document(session: String): Boolean = { |
76718 | 173 |
val options = PIDE.options.value |
77145 | 174 |
run_process { _ => |
76718 | 175 |
try { |
176 |
val session_background = |
|
177 |
Document_Build.session_background( |
|
178 |
options, session, dirs = JEdit_Sessions.session_dirs) |
|
179 |
PIDE.editor.document_setup(Some(session_background)) |
|
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76711
diff
changeset
|
180 |
|
76718 | 181 |
finish_process(Nil) |
182 |
GUI_Thread.later { |
|
76725
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
183 |
refresh_theories() |
76718 | 184 |
show_state() |
76996 | 185 |
show_page(input_page) |
76718 | 186 |
} |
187 |
} |
|
188 |
catch { |
|
189 |
case exn: Throwable if !Exn.is_interrupt(exn) => |
|
190 |
finish_process(List(Protocol.error_message(Exn.print(exn)))) |
|
191 |
GUI_Thread.later { |
|
192 |
show_state() |
|
193 |
show_page(output_page) |
|
76681 | 194 |
} |
195 |
} |
|
196 |
} |
|
197 |
} |
|
198 |
||
76732 | 199 |
private def document_build( |
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
200 |
document_session: Document_Editor.Session, |
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
|
201 |
progress: Log_Progress |
76732 | 202 |
): Unit = { |
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
203 |
val session_background = document_session.get_background |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
204 |
val snapshot = document_session.get_snapshot |
77022 | 205 |
val session_context = JEdit_Sessions.open_session_context(document_snapshot = Some(snapshot)) |
76732 | 206 |
try { |
207 |
val context = |
|
208 |
Document_Build.context(session_context, |
|
209 |
document_session = Some(session_background.base), |
|
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
210 |
document_selection = document_session.selection, |
76732 | 211 |
progress = 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
|
212 |
|
76732 | 213 |
Isabelle_System.make_directory(Document_Editor.document_output_dir()) |
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
214 |
val doc = context.build_document(document_session.get_variant, verbose = true) |
76732 | 215 |
|
216 |
File.write(Document_Editor.document_output().log, doc.log) |
|
217 |
Bytes.write(Document_Editor.document_output().pdf, doc.pdf) |
|
218 |
Document_Editor.view_document() |
|
219 |
} |
|
220 |
finally { session_context.close() } |
|
221 |
} |
|
222 |
||
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
223 |
private def document_build_attempt(): Boolean = { |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
224 |
val document_session = PIDE.editor.document_session() |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
225 |
if (document_session.is_vacuous) true |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
226 |
else if (document_session.is_pending) false |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
227 |
else { |
77145 | 228 |
run_process { progress => |
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
229 |
show_page(output_page) |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
230 |
val result = Exn.capture { document_build(document_session, progress) } |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
231 |
val msgs = |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
232 |
result match { |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
233 |
case Exn.Res(_) => |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
234 |
List(Protocol.writeln_message("OK")) |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
235 |
case Exn.Exn(exn: Document_Build.Build_Error) => |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
236 |
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
|
237 |
case Exn.Exn(exn) => |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
238 |
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
|
239 |
} |
76732 | 240 |
|
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
241 |
progress.stop_program() |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
242 |
running_process(progress) |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
243 |
finish_process(Pretty.separate(msgs)) |
76732 | 244 |
|
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
245 |
show_state() |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
246 |
show_page(if (Exn.is_interrupt_exn(result)) input_page else output_page) |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
247 |
} |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
248 |
true |
76023 | 249 |
} |
250 |
} |
|
251 |
||
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
252 |
private lazy val delay_build: Delay = |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
253 |
Delay.first(PIDE.session.output_delay, gui = true) { |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
254 |
if (!document_build_attempt()) delay_build.invoke() |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
255 |
} |
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
256 |
|
75816 | 257 |
|
258 |
/* controls */ |
|
259 |
||
76681 | 260 |
private val document_session = |
261 |
JEdit_Sessions.document_selector(PIDE.options, standalone = true) |
|
262 |
||
76602 | 263 |
private lazy val delay_load: Delay = |
76610 | 264 |
Delay.last(PIDE.session.load_delay, gui = true) { |
76681 | 265 |
for (session <- document_session.selection_value) { |
266 |
if (!load_document(session)) delay_load.invoke() |
|
267 |
} |
|
76602 | 268 |
} |
269 |
||
270 |
document_session.reactions += { case SelectionChanged(_) => delay_load.invoke() } |
|
271 |
||
76726 | 272 |
private val load_button = |
273 |
new GUI.Button("Load") { |
|
274 |
tooltip = "Load document theories" |
|
275 |
override def clicked(): Unit = PIDE.editor.document_select_all(set = true) |
|
276 |
} |
|
277 |
||
75853 | 278 |
private val build_button = |
279 |
new GUI.Button("<html><b>Build</b></html>") { |
|
75816 | 280 |
tooltip = "Build document" |
77144
42c3970e1ac1
clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents:
77142
diff
changeset
|
281 |
override def clicked(): Unit = delay_build.invoke() |
76023 | 282 |
} |
283 |
||
284 |
private val cancel_button = |
|
285 |
new GUI.Button("Cancel") { |
|
286 |
tooltip = "Cancel build process" |
|
76718 | 287 |
override def clicked(): Unit = cancel_process() |
76023 | 288 |
} |
289 |
||
290 |
private val view_button = |
|
291 |
new GUI.Button("View") { |
|
292 |
tooltip = "View document" |
|
76606 | 293 |
override def clicked(): Unit = Document_Editor.view_document() |
75816 | 294 |
} |
295 |
||
296 |
private val controls = |
|
76726 | 297 |
Wrap_Panel(List(document_session, process_indicator.component, load_button, |
298 |
build_button, view_button, cancel_button)) |
|
75816 | 299 |
|
300 |
add(controls.peer, BorderLayout.NORTH) |
|
301 |
||
302 |
override def focusOnDefaultComponent(): Unit = build_button.requestFocus() |
|
303 |
||
304 |
||
76023 | 305 |
/* message pane with pages */ |
306 |
||
76726 | 307 |
private val reset_button = |
308 |
new GUI.Button("Reset") { |
|
309 |
tooltip = "Deselect document theories" |
|
76720 | 310 |
override def clicked(): Unit = PIDE.editor.document_select_all(set = false) |
311 |
} |
|
312 |
||
76726 | 313 |
private val purge_button = new GUI.Button("Purge") { |
314 |
tooltip = "Remove theories that are no longer required" |
|
315 |
override def clicked(): Unit = PIDE.editor.purge() |
|
316 |
} |
|
317 |
||
76720 | 318 |
private val theories_controls = |
76726 | 319 |
Wrap_Panel(List(reset_button, purge_button)) |
76720 | 320 |
|
76602 | 321 |
private val theories = new Theories_Status(view, document = true) |
77008 | 322 |
private val theories_pane = new ScrollPane(theories.gui) |
76567 | 323 |
|
76725
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
324 |
private def refresh_theories(): Unit = { |
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
325 |
val domain = PIDE.editor.document_theories().toSet |
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
326 |
theories.update(domain = Some(domain), trim = true, force = true) |
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
327 |
theories.refresh() |
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
328 |
} |
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
329 |
|
76996 | 330 |
private val input_page = |
331 |
new TabbedPane.Page("Input", new BorderPanel { |
|
76720 | 332 |
layout(theories_controls) = BorderPanel.Position.North |
77008 | 333 |
layout(theories_pane) = BorderPanel.Position.Center |
76567 | 334 |
}, "Selection and status of document theories") |
335 |
||
76023 | 336 |
private val output_controls = |
337 |
Wrap_Panel(List(pretty_text_area.search_label, pretty_text_area.search_field, zoom)) |
|
338 |
||
339 |
private val output_page = |
|
340 |
new TabbedPane.Page("Output", new BorderPanel { |
|
341 |
layout(output_controls) = BorderPanel.Position.North |
|
342 |
layout(Component.wrap(pretty_text_area)) = BorderPanel.Position.Center |
|
76996 | 343 |
}, "Results from document build process") |
76023 | 344 |
|
76996 | 345 |
message_pane.pages ++= List(input_page, output_page) |
76023 | 346 |
|
347 |
set_content(message_pane) |
|
348 |
||
349 |
||
75816 | 350 |
/* main */ |
351 |
||
352 |
private val main = |
|
76567 | 353 |
Session.Consumer[Any](getClass.getName) { |
75816 | 354 |
case _: Session.Global_Options => |
76567 | 355 |
GUI_Thread.later { |
76578
06b001094ddb
more uniform session selectors, with persistent options;
wenzelm
parents:
76577
diff
changeset
|
356 |
document_session.load() |
76567 | 357 |
handle_resize() |
76725
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
358 |
refresh_theories() |
76567 | 359 |
} |
360 |
case changed: Session.Commands_Changed => |
|
361 |
GUI_Thread.later { |
|
76719 | 362 |
val domain = PIDE.editor.document_theories().filter(changed.nodes).toSet |
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76711
diff
changeset
|
363 |
if (domain.nonEmpty) theories.update(domain = Some(domain)) |
76567 | 364 |
} |
75816 | 365 |
} |
366 |
||
367 |
override def init(): Unit = { |
|
76701 | 368 |
PIDE.editor.document_init(dockable) |
76491 | 369 |
init_state() |
75816 | 370 |
PIDE.session.global_options += main |
76567 | 371 |
PIDE.session.commands_changed += main |
75816 | 372 |
handle_resize() |
76602 | 373 |
delay_load.invoke() |
75816 | 374 |
} |
375 |
||
376 |
override def exit(): Unit = { |
|
377 |
PIDE.session.global_options -= main |
|
76567 | 378 |
PIDE.session.commands_changed -= main |
75816 | 379 |
delay_resize.revoke() |
76701 | 380 |
PIDE.editor.document_exit(dockable) |
75816 | 381 |
} |
382 |
} |