| author | wenzelm | 
| Sun, 18 Dec 2022 15:49:37 +0100 | |
| changeset 76678 | f34b923ff2c9 | 
| parent 76610 | 6e2383488a55 | 
| child 76715 | bf5ff407f32f | 
| 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) | |
| 76610 | 31 |     private val delay = Delay.first(session.update_delay, gui = true) { update() }
 | 
| 76606 | 32 | |
| 33 |     override def echo(msg: String): Unit = { syslog += msg; delay.invoke() }
 | |
| 34 | ||
| 35 |     def load(): Unit = GUI_Thread.require {
 | |
| 36 | val path = document_output().log | |
| 37 | val text = if (path.is_file) File.read(path) else "" | |
| 38 |       GUI_Thread.later { delay.revoke(); update(text) }
 | |
| 39 | } | |
| 40 | ||
| 41 |     GUI_Thread.later { update() }
 | |
| 42 | } | |
| 76609 
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
 wenzelm parents: 
76606diff
changeset | 43 | |
| 
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
 wenzelm parents: 
76606diff
changeset | 44 | |
| 
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
 wenzelm parents: 
76606diff
changeset | 45 | /* global state */ | 
| 
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
 wenzelm parents: 
76606diff
changeset | 46 | |
| 
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
 wenzelm parents: 
76606diff
changeset | 47 | sealed case class State( | 
| 76678 | 48 | session_background: Option[Sessions.Background] = None, | 
| 76609 
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
 wenzelm parents: 
76606diff
changeset | 49 | views: Set[AnyRef] = Set.empty, | 
| 
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
 wenzelm parents: 
76606diff
changeset | 50 |   ) {
 | 
| 76678 | 51 | def is_active: Boolean = session_background.isDefined && views.nonEmpty | 
| 76609 
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
 wenzelm parents: 
76606diff
changeset | 52 | |
| 
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
 wenzelm parents: 
76606diff
changeset | 53 | 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: 
76606diff
changeset | 54 | 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: 
76606diff
changeset | 55 | } | 
| 76606 | 56 | } |