| author | wenzelm | 
| Wed, 21 Dec 2022 15:34:33 +0100 | |
| changeset 76732 | 0ba6f360d38a | 
| parent 76730 | 1b8dd8c0492f | 
| child 76739 | cb72b5996520 | 
| permissions | -rw-r--r-- | 
| 76606 | 1 | /* Title: Pure/PIDE/document_editor.scala | 
| 2 | Author: Makarius | |
| 3 | ||
| 76730 | 4 | Central resources and configuration for interactive document preparation. | 
| 76606 | 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 | ||
| 76732 | 35 |     def finish(text: String): Unit = GUI_Thread.require {
 | 
| 36 | delay.revoke() | |
| 37 | update(text) | |
| 76606 | 38 | } | 
| 39 | ||
| 40 |     GUI_Thread.later { update() }
 | |
| 41 | } | |
| 76609 
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
 wenzelm parents: 
76606diff
changeset | 42 | |
| 
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
 wenzelm parents: 
76606diff
changeset | 43 | |
| 76730 | 44 | /* configuration state */ | 
| 76609 
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
 wenzelm parents: 
76606diff
changeset | 45 | |
| 
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
 wenzelm parents: 
76606diff
changeset | 46 | sealed case class State( | 
| 76678 | 47 | session_background: Option[Sessions.Background] = None, | 
| 76715 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 48 | selection: Set[Document.Node.Name] = Set.empty, | 
| 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 | |
| 76715 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 53 | def is_required(name: Document.Node.Name): Boolean = | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 54 | is_active && selection.contains(name) && all_document_theories.contains(name) | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 55 | |
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 56 | def required: List[Document.Node.Name] = | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 57 | if (is_active) all_document_theories.filter(selection) else Nil | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 58 | |
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 59 | def all_document_theories: List[Document.Node.Name] = | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 60 |       session_background match {
 | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 61 | case Some(background) => background.base.all_document_theories | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 62 | case None => Nil | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 63 | } | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 64 | |
| 76716 
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
 wenzelm parents: 
76715diff
changeset | 65 | def active_document_theories: List[Document.Node.Name] = | 
| 
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
 wenzelm parents: 
76715diff
changeset | 66 | if (is_active) all_document_theories else Nil | 
| 
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
 wenzelm parents: 
76715diff
changeset | 67 | |
| 76715 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 68 | def select( | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 69 | names: Iterable[Document.Node.Name], | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 70 | set: Boolean = false, | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 71 | toggle: Boolean = false | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 72 |     ): State = {
 | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 73 | copy(selection = | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 74 |         names.foldLeft(selection) {
 | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 75 | case (sel, name) => | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 76 | val b = if (toggle) !selection(name) else set | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 77 | if (b) sel + name else sel - name | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 78 | }) | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 79 | } | 
| 
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
 wenzelm parents: 
76678diff
changeset | 80 | |
| 76609 
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
 wenzelm parents: 
76606diff
changeset | 81 | 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 | 82 | 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 | 83 | } | 
| 76606 | 84 | } |