src/Pure/PIDE/document_editor.scala
author wenzelm
Mon, 16 Jan 2023 20:08:15 +0100
changeset 76994 7c23db6b857b
parent 76739 cb72b5996520
child 77144 42c3970e1ac1
permissions -rw-r--r--
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup; more Document_Build.running_script, but display it as "Running XYZ";
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
76606
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/PIDE/document_editor.scala
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
     3
76730
1b8dd8c0492f tuned comments;
wenzelm
parents: 76716
diff changeset
     4
Central resources and configuration for interactive document preparation.
76606
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
     5
*/
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
     6
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
     7
package isabelle
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
     8
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
     9
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    10
object Document_Editor {
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    11
  /* document output */
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    12
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    13
  def document_name: String = "document"
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    14
  def document_output_dir(): Path = Path.explode("$ISABELLE_HOME_USER/document_output")
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    15
  def document_output(): Path = document_output_dir() + Path.basic(document_name)
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    16
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    17
  def view_document(): Unit = {
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    18
    val path = document_output().pdf
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    19
    if (path.is_file) Isabelle_System.pdf_viewer(path)
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    20
  }
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    21
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    22
76730
1b8dd8c0492f tuned comments;
wenzelm
parents: 76716
diff changeset
    23
  /* configuration state */
76609
cc9ddf373bd2 maintain global state of document editor views, notably for is_active operation;
wenzelm
parents: 76606
diff changeset
    24
cc9ddf373bd2 maintain global state of document editor views, notably for is_active operation;
wenzelm
parents: 76606
diff changeset
    25
  sealed case class State(
76678
f34b923ff2c9 clarified signature;
wenzelm
parents: 76610
diff changeset
    26
    session_background: Option[Sessions.Background] = None,
76715
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    27
    selection: Set[Document.Node.Name] = Set.empty,
76609
cc9ddf373bd2 maintain global state of document editor views, notably for is_active operation;
wenzelm
parents: 76606
diff changeset
    28
    views: Set[AnyRef] = Set.empty,
cc9ddf373bd2 maintain global state of document editor views, notably for is_active operation;
wenzelm
parents: 76606
diff changeset
    29
  ) {
76678
f34b923ff2c9 clarified signature;
wenzelm
parents: 76610
diff changeset
    30
    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: 76606
diff changeset
    31
76715
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    32
    def all_document_theories: List[Document.Node.Name] =
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    33
      session_background match {
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    34
        case Some(background) => background.base.all_document_theories
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    35
        case None => Nil
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    36
      }
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    37
76716
a7602257a825 clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents: 76715
diff changeset
    38
    def active_document_theories: List[Document.Node.Name] =
a7602257a825 clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents: 76715
diff changeset
    39
      if (is_active) all_document_theories else Nil
a7602257a825 clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents: 76715
diff changeset
    40
76715
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    41
    def select(
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    42
      names: Iterable[Document.Node.Name],
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    43
      set: Boolean = false,
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    44
      toggle: Boolean = false
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    45
    ): State = {
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    46
      copy(selection =
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    47
        names.foldLeft(selection) {
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    48
          case (sel, name) =>
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    49
            val b = if (toggle) !selection(name) else set
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    50
            if (b) sel + name else sel - name
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    51
        })
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    52
    }
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
    53
76609
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
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    57
}