author | wenzelm |
Thu, 08 Dec 2022 22:11:36 +0100 | |
changeset 76609 | cc9ddf373bd2 |
parent 76606 | 3558388330f8 |
child 76610 | 6e2383488a55 |
permissions | -rw-r--r-- |
76606 | 1 |
/* Title: Pure/PIDE/document_editor.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Central resources for interactive document preparation. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
10 |
object Document_Editor { |
|
11 |
/* document output */ |
|
12 |
||
13 |
def document_name: String = "document" |
|
14 |
def document_output_dir(): Path = Path.explode("$ISABELLE_HOME_USER/document_output") |
|
15 |
def document_output(): Path = document_output_dir() + Path.basic(document_name) |
|
16 |
||
17 |
def view_document(): Unit = { |
|
18 |
val path = document_output().pdf |
|
19 |
if (path.is_file) Isabelle_System.pdf_viewer(path) |
|
20 |
} |
|
21 |
||
22 |
||
23 |
/* progress */ |
|
24 |
||
25 |
class Log_Progress(session: Session) extends Progress { |
|
26 |
def show(text: String): Unit = {} |
|
27 |
||
28 |
private val syslog = session.make_syslog() |
|
29 |
||
30 |
private def update(text: String = syslog.content()): Unit = show(text) |
|
31 |
private val delay = |
|
32 |
Delay.first(session.session_options.seconds("editor_update_delay"), gui = true) { update() } |
|
33 |
||
34 |
override def echo(msg: String): Unit = { syslog += msg; delay.invoke() } |
|
35 |
||
36 |
def load(): Unit = GUI_Thread.require { |
|
37 |
val path = document_output().log |
|
38 |
val text = if (path.is_file) File.read(path) else "" |
|
39 |
GUI_Thread.later { delay.revoke(); update(text) } |
|
40 |
} |
|
41 |
||
42 |
GUI_Thread.later { update() } |
|
43 |
} |
|
76609
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
76606
diff
changeset
|
44 |
|
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
76606
diff
changeset
|
45 |
|
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
76606
diff
changeset
|
46 |
/* global state */ |
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
76606
diff
changeset
|
47 |
|
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
76606
diff
changeset
|
48 |
sealed case class State( |
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
76606
diff
changeset
|
49 |
session_info: Option[Sessions.Info] = None, |
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
76606
diff
changeset
|
50 |
views: Set[AnyRef] = Set.empty, |
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
76606
diff
changeset
|
51 |
) { |
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
76606
diff
changeset
|
52 |
def is_active: Boolean = session_info.isDefined && views.nonEmpty |
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
76606
diff
changeset
|
53 |
|
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
76606
diff
changeset
|
54 |
def register_view(id: AnyRef): State = copy(views = views + id) |
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
76606
diff
changeset
|
55 |
def unregister_view(id: AnyRef): State = copy(views = views - id) |
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
76606
diff
changeset
|
56 |
} |
76606 | 57 |
} |