src/Tools/jEdit/src/document_model.scala
author wenzelm
Sat, 30 Jul 2022 13:44:26 +0200
changeset 75728 3f64fdf75082
parent 75394 42267c650205
child 75847 93436389db1c
permissions -rw-r--r--
clarified signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43282
5d294220ca43 moved sources -- eliminated Netbeans artifact of jedit package directory;
wenzelm
parents: 40851
diff changeset
     1
/*  Title:      Tools/jEdit/src/document_model.scala
36760
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     2
    Author:     Fabian Immler, TU Munich
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     3
    Author:     Makarius
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     4
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
     5
Document model connected to jEdit buffer or external file: content of theory
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
     6
node or auxiliary file (blob).
36760
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     7
*/
34407
aad6834ba380 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     8
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
     9
package isabelle.jedit
34760
dc7f5e0d9d27 misc modernization of names;
wenzelm
parents: 34759
diff changeset
    10
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    11
36015
6111de7c916a adapted to Scala 2.8.0 Beta 1;
wenzelm
parents: 34871
diff changeset
    12
import isabelle._
6111de7c916a adapted to Scala 2.8.0 Beta 1;
wenzelm
parents: 34871
diff changeset
    13
64858
e31cf6eaecb8 update File_Model based on file-system events;
wenzelm
parents: 64836
diff changeset
    14
import java.io.{File => JFile}
e31cf6eaecb8 update File_Model based on file-system events;
wenzelm
parents: 64836
diff changeset
    15
34693
3e995f100ad2 sealed Edit;
wenzelm
parents: 34685
diff changeset
    16
import scala.collection.mutable
66019
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
    17
import scala.annotation.tailrec
34446
5c79f97ec1d1 superficial tuning;
wenzelm
parents: 34445
diff changeset
    18
72960
wenzelm
parents: 72959
diff changeset
    19
import org.gjt.sp.jedit.View
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    20
import org.gjt.sp.jedit.Buffer
61192
98eba31c51f8 tuned signature;
wenzelm
parents: 60933
diff changeset
    21
import org.gjt.sp.jedit.buffer.{BufferAdapter, BufferListener, JEditBuffer}
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    22
34760
dc7f5e0d9d27 misc modernization of names;
wenzelm
parents: 34759
diff changeset
    23
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
    24
object Document_Model {
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    25
  /* document models */
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    26
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    27
  sealed case class State(
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    28
    models: Map[Document.Node.Name, Document_Model] = Map.empty,
66101
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66082
diff changeset
    29
    buffer_models: Map[JEditBuffer, Buffer_Model] = Map.empty,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
    30
    overlays: Document.Overlays = Document.Overlays.empty
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
    31
  ) {
64868
6212d3c396b0 tuned signature;
wenzelm
parents: 64867
diff changeset
    32
    def file_models_iterator: Iterator[(Document.Node.Name, File_Model)] =
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    33
      for {
64868
6212d3c396b0 tuned signature;
wenzelm
parents: 64867
diff changeset
    34
        (node_name, model) <- models.iterator
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    35
        if model.isInstanceOf[File_Model]
64868
6212d3c396b0 tuned signature;
wenzelm
parents: 64867
diff changeset
    36
      } yield (node_name, model.asInstanceOf[File_Model])
64813
7283f41d05ab manage buffer models as explicit global state;
wenzelm
parents: 64799
diff changeset
    37
68476
1be1b7620a42 tuned signature -- facilitate testing;
wenzelm
parents: 67934
diff changeset
    38
    def document_blobs: Document.Blobs =
1be1b7620a42 tuned signature -- facilitate testing;
wenzelm
parents: 67934
diff changeset
    39
      Document.Blobs(
1be1b7620a42 tuned signature -- facilitate testing;
wenzelm
parents: 67934
diff changeset
    40
        (for {
1be1b7620a42 tuned signature -- facilitate testing;
wenzelm
parents: 67934
diff changeset
    41
          (node_name, model) <- models.iterator
1be1b7620a42 tuned signature -- facilitate testing;
wenzelm
parents: 67934
diff changeset
    42
          blob <- model.get_blob
1be1b7620a42 tuned signature -- facilitate testing;
wenzelm
parents: 67934
diff changeset
    43
        } yield (node_name -> blob)).toMap)
1be1b7620a42 tuned signature -- facilitate testing;
wenzelm
parents: 67934
diff changeset
    44
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
    45
    def open_buffer(
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
    46
      session: Session,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
    47
      node_name: Document.Node.Name,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
    48
      buffer: Buffer
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
    49
    ) : (Buffer_Model, State) = {
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    50
      val old_model =
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    51
        models.get(node_name) match {
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    52
          case Some(file_model: File_Model) => Some(file_model)
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    53
          case Some(buffer_model: Buffer_Model) => Some(buffer_model.exit())
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    54
          case _ => None
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    55
        }
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    56
      val buffer_model = Buffer_Model(session, node_name, buffer).init(old_model)
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    57
      (buffer_model,
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    58
        copy(models = models + (node_name -> buffer_model),
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    59
          buffer_models = buffer_models + (buffer -> buffer_model)))
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    60
    }
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    61
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
    62
    def close_buffer(buffer: JEditBuffer): State = {
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    63
      buffer_models.get(buffer) match {
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    64
        case None => this
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    65
        case Some(buffer_model) =>
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    66
          val file_model = buffer_model.exit()
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    67
          copy(models = models + (file_model.node_name -> file_model),
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    68
            buffer_models = buffer_models - buffer)
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    69
      }
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    70
    }
64835
fd1efd6dd385 resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents: 64832
diff changeset
    71
fd1efd6dd385 resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents: 64832
diff changeset
    72
    def provide_file(session: Session, node_name: Document.Node.Name, text: String): State =
fd1efd6dd385 resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents: 64832
diff changeset
    73
      if (models.isDefinedAt(node_name)) this
fd1efd6dd385 resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents: 64832
diff changeset
    74
      else {
fd1efd6dd385 resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents: 64832
diff changeset
    75
        val edit = Text.Edit.insert(0, text)
64863
wenzelm
parents: 64858
diff changeset
    76
        val model = File_Model.init(session, node_name, text, pending_edits = List(edit))
64835
fd1efd6dd385 resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents: 64832
diff changeset
    77
        copy(models = models + (node_name -> model))
fd1efd6dd385 resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents: 64832
diff changeset
    78
      }
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    79
  }
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    80
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    81
  private val state = Synchronized(State())  // owned by GUI thread
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    82
73999
6b213c0115f5 clarified global state: allow to deactivate main plugin;
wenzelm
parents: 73702
diff changeset
    83
  def reset(): Unit = state.change(_ => State())
6b213c0115f5 clarified global state: allow to deactivate main plugin;
wenzelm
parents: 73702
diff changeset
    84
64835
fd1efd6dd385 resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents: 64832
diff changeset
    85
  def get_models(): Map[Document.Node.Name, Document_Model] = state.value.models
71601
97ccf48c2f0c misc tuning based on hints by IntelliJ IDEA;
wenzelm
parents: 69255
diff changeset
    86
  def get(name: Document.Node.Name): Option[Document_Model] = get_models().get(name)
64835
fd1efd6dd385 resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents: 64832
diff changeset
    87
  def get(buffer: JEditBuffer): Option[Buffer_Model] = state.value.buffer_models.get(buffer)
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    88
68476
1be1b7620a42 tuned signature -- facilitate testing;
wenzelm
parents: 67934
diff changeset
    89
  def document_blobs(): Document.Blobs = state.value.document_blobs
1be1b7620a42 tuned signature -- facilitate testing;
wenzelm
parents: 67934
diff changeset
    90
66152
18e1aba549f6 tuned signature;
wenzelm
parents: 66150
diff changeset
    91
18e1aba549f6 tuned signature;
wenzelm
parents: 66150
diff changeset
    92
  /* bibtex */
18e1aba549f6 tuned signature;
wenzelm
parents: 66150
diff changeset
    93
64831
4792ee012e94 tuned signature;
wenzelm
parents: 64829
diff changeset
    94
  def bibtex_entries_iterator(): Iterator[Text.Info[(String, Document_Model)]] =
66150
c2e19b9e1398 tuned signature;
wenzelm
parents: 66114
diff changeset
    95
    Bibtex.entries_iterator(state.value.models)
64829
07f209e957bc refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents: 64828
diff changeset
    96
66152
18e1aba549f6 tuned signature;
wenzelm
parents: 66150
diff changeset
    97
  def bibtex_completion(history: Completion.History, rendering: Rendering, caret: Text.Offset)
18e1aba549f6 tuned signature;
wenzelm
parents: 66150
diff changeset
    98
      : Option[Completion.Result] =
18e1aba549f6 tuned signature;
wenzelm
parents: 66150
diff changeset
    99
    Bibtex.completion(history, rendering, caret, state.value.models)
18e1aba549f6 tuned signature;
wenzelm
parents: 66150
diff changeset
   100
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   101
66101
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66082
diff changeset
   102
  /* overlays */
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66082
diff changeset
   103
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66082
diff changeset
   104
  def node_overlays(name: Document.Node.Name): Document.Node.Overlays =
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66082
diff changeset
   105
    state.value.overlays(name)
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66082
diff changeset
   106
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66082
diff changeset
   107
  def insert_overlay(command: Command, fn: String, args: List[String]): Unit =
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66082
diff changeset
   108
    state.change(st => st.copy(overlays = st.overlays.insert(command, fn, args)))
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66082
diff changeset
   109
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66082
diff changeset
   110
  def remove_overlay(command: Command, fn: String, args: List[String]): Unit =
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66082
diff changeset
   111
    state.change(st => st.copy(overlays = st.overlays.remove(command, fn, args)))
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66082
diff changeset
   112
0f0f294e314f maintain overlays within main state of document models;
wenzelm
parents: 66082
diff changeset
   113
64858
e31cf6eaecb8 update File_Model based on file-system events;
wenzelm
parents: 64836
diff changeset
   114
  /* sync external files */
e31cf6eaecb8 update File_Model based on file-system events;
wenzelm
parents: 64836
diff changeset
   115
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   116
  def sync_files(changed_files: Set[JFile]): Boolean = {
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   117
    state.change_result { st =>
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   118
      val changed_models =
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   119
        (for {
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   120
          (node_name, model) <- st.file_models_iterator
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   121
          file <- model.file if changed_files(file)
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   122
          text <- PIDE.resources.read_file_content(node_name)
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   123
          if model.content.text != text
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   124
        } yield {
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   125
          val content = Document_Model.File_Content(text)
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   126
          val edits = Text.Edit.replace(0, model.content.text, text)
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   127
          (node_name, model.copy(content = content, pending_edits = model.pending_edits ::: edits))
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   128
        }).toList
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   129
      if (changed_models.isEmpty) (false, st)
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   130
      else (true, st.copy(models = changed_models.foldLeft(st.models)(_ + _)))
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   131
    }
64858
e31cf6eaecb8 update File_Model based on file-system events;
wenzelm
parents: 64836
diff changeset
   132
  }
e31cf6eaecb8 update File_Model based on file-system events;
wenzelm
parents: 64836
diff changeset
   133
e31cf6eaecb8 update File_Model based on file-system events;
wenzelm
parents: 64836
diff changeset
   134
64836
wenzelm
parents: 64835
diff changeset
   135
  /* syntax */
wenzelm
parents: 64835
diff changeset
   136
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   137
  def syntax_changed(names: List[Document.Node.Name]): Unit = {
64836
wenzelm
parents: 64835
diff changeset
   138
    GUI_Thread.require {}
wenzelm
parents: 64835
diff changeset
   139
wenzelm
parents: 64835
diff changeset
   140
    val models = state.value.models
wenzelm
parents: 64835
diff changeset
   141
    for (name <- names.iterator; model <- models.get(name)) {
wenzelm
parents: 64835
diff changeset
   142
      model match { case buffer_model: Buffer_Model => buffer_model.syntax_changed() case _ => }
wenzelm
parents: 64835
diff changeset
   143
    }
wenzelm
parents: 64835
diff changeset
   144
  }
wenzelm
parents: 64835
diff changeset
   145
wenzelm
parents: 64835
diff changeset
   146
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   147
  /* init and exit */
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   148
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   149
  def init(session: Session, node_name: Document.Node.Name, buffer: Buffer): Buffer_Model = {
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   150
    GUI_Thread.require {}
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   151
    state.change_result(st =>
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   152
      st.buffer_models.get(buffer) match {
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   153
        case Some(buffer_model) if buffer_model.node_name == node_name =>
72960
wenzelm
parents: 72959
diff changeset
   154
          buffer_model.init_token_marker()
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   155
          (buffer_model, st)
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   156
        case _ =>
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   157
          val res = st.close_buffer(buffer).open_buffer(session, node_name, buffer)
72960
wenzelm
parents: 72959
diff changeset
   158
          buffer.propertiesChanged()
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   159
          res
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   160
      })
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   161
  }
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   162
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   163
  def exit(buffer: Buffer): Unit = {
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57610
diff changeset
   164
    GUI_Thread.require {}
64813
7283f41d05ab manage buffer models as explicit global state;
wenzelm
parents: 64799
diff changeset
   165
    state.change(st =>
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   166
      if (st.buffer_models.isDefinedAt(buffer)) {
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   167
        val res = st.close_buffer(buffer)
72960
wenzelm
parents: 72959
diff changeset
   168
        buffer.propertiesChanged()
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   169
        res
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   170
      }
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   171
      else st)
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   172
  }
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   173
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   174
  def provide_files(session: Session, files: List[(Document.Node.Name, String)]): Unit = {
64835
fd1efd6dd385 resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents: 64832
diff changeset
   175
    GUI_Thread.require {}
fd1efd6dd385 resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents: 64832
diff changeset
   176
    state.change(st =>
73358
78aa7846e91f tuned --- fewer warnings;
wenzelm
parents: 73340
diff changeset
   177
      files.foldLeft(st) {
78aa7846e91f tuned --- fewer warnings;
wenzelm
parents: 73340
diff changeset
   178
        case (st1, (node_name, text)) => st1.provide_file(session, node_name, text)
78aa7846e91f tuned --- fewer warnings;
wenzelm
parents: 73340
diff changeset
   179
      })
64835
fd1efd6dd385 resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents: 64832
diff changeset
   180
  }
fd1efd6dd385 resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents: 64832
diff changeset
   181
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   182
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   183
  /* required nodes */
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   184
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   185
  def required_nodes(): Set[Document.Node.Name] =
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   186
    (for {
64868
6212d3c396b0 tuned signature;
wenzelm
parents: 64867
diff changeset
   187
      (node_name, model) <- state.value.models.iterator
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   188
      if model.node_required
64868
6212d3c396b0 tuned signature;
wenzelm
parents: 64867
diff changeset
   189
    } yield node_name).toSet
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   190
73340
0ffcad1f6130 tuned --- fewer warnings;
wenzelm
parents: 73055
diff changeset
   191
  def node_required(
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   192
    name: Document.Node.Name,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   193
    toggle: Boolean = false,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   194
    set: Boolean = false
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   195
  ) : Unit = {
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   196
    GUI_Thread.require {}
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   197
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   198
    val changed =
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   199
      state.change_result(st =>
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   200
        st.models.get(name) match {
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   201
          case None => (false, st)
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   202
          case Some(model) =>
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   203
            val required = if (toggle) !model.node_required else set
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   204
            model match {
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   205
              case model1: File_Model if required != model1.node_required =>
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   206
                (true, st.copy(models = st.models + (name -> model1.copy(node_required = required))))
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   207
              case model1: Buffer_Model if required != model1.node_required =>
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   208
                model1.set_node_required(required); (true, st)
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   209
              case _ => (false, st)
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   210
            }
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   211
        })
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   212
    if (changed) {
65243
ba5ce07e06a7 proper plugin access;
wenzelm
parents: 65196
diff changeset
   213
      PIDE.plugin.options_changed()
66082
2d12a730a380 clarified modules;
wenzelm
parents: 66040
diff changeset
   214
      PIDE.editor.flush()
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   215
    }
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   216
  }
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   217
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   218
  def view_node_required(view: View, toggle: Boolean = false, set: Boolean = false): Unit =
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   219
    Document_Model.get(view.getBuffer).foreach(model =>
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   220
      node_required(model.node_name, toggle = toggle, set = set))
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   221
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   222
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   223
  /* flushed edits */
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   224
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   225
  def flush_edits(hidden: Boolean, purge: Boolean): (Document.Blobs, List[Document.Edit_Text]) = {
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   226
    GUI_Thread.require {}
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   227
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   228
    state.change_result { st =>
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   229
      val doc_blobs = st.document_blobs
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   230
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   231
      val buffer_edits =
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   232
        (for {
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   233
          (_, model) <- st.buffer_models.iterator
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   234
          edit <- model.flush_edits(doc_blobs, hidden).iterator
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   235
        } yield edit).toList
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   236
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   237
      val file_edits =
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   238
        (for {
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   239
          (node_name, model) <- st.file_models_iterator
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   240
          (edits, model1) <- model.flush_edits(doc_blobs, hidden)
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   241
        } yield (edits, node_name -> model1)).toList
64867
e7220f4de11f support "purge" operation on document model;
wenzelm
parents: 64864
diff changeset
   242
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   243
      val model_edits = buffer_edits ::: file_edits.flatMap(_._1)
64867
e7220f4de11f support "purge" operation on document model;
wenzelm
parents: 64864
diff changeset
   244
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   245
      val purge_edits =
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   246
        if (purge) {
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   247
          val purged =
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   248
            (for ((node_name, model) <- st.file_models_iterator)
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   249
             yield (node_name -> model.purge_edits(doc_blobs))).toList
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   250
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   251
          val imports = {
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   252
            val open_nodes =
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   253
              (for ((_, model) <- st.buffer_models.iterator) yield model.node_name).toList
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   254
            val touched_nodes = model_edits.map(_._1)
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   255
            val pending_nodes = for ((node_name, None) <- purged) yield node_name
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   256
            (open_nodes ::: touched_nodes ::: pending_nodes).map((_, Position.none))
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   257
          }
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   258
          val retain = PIDE.resources.dependencies(imports).theories.toSet
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   259
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   260
          for ((node_name, Some(edits)) <- purged if !retain(node_name); edit <- edits)
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   261
            yield edit
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   262
        }
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   263
        else Nil
64867
e7220f4de11f support "purge" operation on document model;
wenzelm
parents: 64864
diff changeset
   264
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   265
      val st1 = st.copy(models = st.models ++ file_edits.map(_._2) -- purge_edits.map(_._1))
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   266
      PIDE.plugin.file_watcher.purge(
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   267
        (for {
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   268
          (_, model) <- st1.file_models_iterator
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   269
          file <- model.file
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   270
        } yield file.getParentFile).toSet)
64867
e7220f4de11f support "purge" operation on document model;
wenzelm
parents: 64864
diff changeset
   271
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   272
      ((doc_blobs, model_edits ::: purge_edits), st1)
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   273
    }
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   274
  }
43397
dba359c0ae3b more robust init;
wenzelm
parents: 43394
diff changeset
   275
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   276
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   277
  /* file content */
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   278
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   279
  sealed case class File_Content(text: String) {
64835
fd1efd6dd385 resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents: 64832
diff changeset
   280
    lazy val bytes: Bytes = Bytes(Symbol.encode(text))
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   281
    lazy val chunk: Symbol.Text_Chunk = Symbol.Text_Chunk(text)
64831
4792ee012e94 tuned signature;
wenzelm
parents: 64829
diff changeset
   282
    lazy val bibtex_entries: List[Text.Info[String]] =
66150
c2e19b9e1398 tuned signature;
wenzelm
parents: 66114
diff changeset
   283
      try { Bibtex.entries(text) }
67288
aa9d28034945 avoid spurious noise: Prover IDE is meant to check for errors;
wenzelm
parents: 67265
diff changeset
   284
      catch { case ERROR(_) => Nil }
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   285
  }
66019
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
   286
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
   287
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
   288
  /* HTTP preview */
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
   289
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   290
  def open_preview(view: View, plain_text: Boolean): Unit = {
66019
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
   291
    Document_Model.get(view.getBuffer) match {
67246
4cedf44f2af1 isabelle.preview presents auxiliary text files as well;
wenzelm
parents: 67244
diff changeset
   292
      case Some(model) =>
75148
90678a1929a3 clarified signature;
wenzelm
parents: 75146
diff changeset
   293
        val url = Preview_Service.server_url(plain_text, model.node_name)
67246
4cedf44f2af1 isabelle.preview presents auxiliary text files as well;
wenzelm
parents: 67244
diff changeset
   294
        PIDE.editor.hyperlink_url(url).follow(view)
66036
b6396880b644 clarified;
wenzelm
parents: 66019
diff changeset
   295
      case _ =>
66019
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
   296
    }
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
   297
  }
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
   298
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   299
  object Preview_Service extends HTTP.Service("preview") {
75148
90678a1929a3 clarified signature;
wenzelm
parents: 75146
diff changeset
   300
    service =>
90678a1929a3 clarified signature;
wenzelm
parents: 75146
diff changeset
   301
90678a1929a3 clarified signature;
wenzelm
parents: 75146
diff changeset
   302
    private val plain_text_prefix = "plain_text="
90678a1929a3 clarified signature;
wenzelm
parents: 75146
diff changeset
   303
90678a1929a3 clarified signature;
wenzelm
parents: 75146
diff changeset
   304
    def server_url(plain_text: Boolean, node_name: Document.Node.Name): String =
90678a1929a3 clarified signature;
wenzelm
parents: 75146
diff changeset
   305
      PIDE.plugin.http_server.url + "/" + service.name + "?" +
90678a1929a3 clarified signature;
wenzelm
parents: 75146
diff changeset
   306
        (if (plain_text) plain_text_prefix else "") + Url.encode(node_name.node)
90678a1929a3 clarified signature;
wenzelm
parents: 75146
diff changeset
   307
75113
a7a489ea4661 clarified signature;
wenzelm
parents: 75112
diff changeset
   308
    def apply(request: HTTP.Request): Option[HTTP.Response] =
75107
7c0217c8b8a5 clarified signature;
wenzelm
parents: 75105
diff changeset
   309
      for {
75112
899e70a9af83 tuned signature;
wenzelm
parents: 75108
diff changeset
   310
        query <- request.decode_query
75107
7c0217c8b8a5 clarified signature;
wenzelm
parents: 75105
diff changeset
   311
        name = Library.perhaps_unprefix(plain_text_prefix, query)
7c0217c8b8a5 clarified signature;
wenzelm
parents: 75105
diff changeset
   312
        model <- get(PIDE.resources.node_name(name))
7c0217c8b8a5 clarified signature;
wenzelm
parents: 75105
diff changeset
   313
      }
7c0217c8b8a5 clarified signature;
wenzelm
parents: 75105
diff changeset
   314
      yield {
7c0217c8b8a5 clarified signature;
wenzelm
parents: 75105
diff changeset
   315
        val snapshot = model.await_stable_snapshot()
7c0217c8b8a5 clarified signature;
wenzelm
parents: 75105
diff changeset
   316
        val html_context =
7c0217c8b8a5 clarified signature;
wenzelm
parents: 75105
diff changeset
   317
          new Presentation.HTML_Context {
75728
3f64fdf75082 clarified signature;
wenzelm
parents: 75394
diff changeset
   318
            override def nodes: Presentation.Nodes = Presentation.Nodes.empty
75107
7c0217c8b8a5 clarified signature;
wenzelm
parents: 75105
diff changeset
   319
            override def root_dir: Path = Path.current
7c0217c8b8a5 clarified signature;
wenzelm
parents: 75105
diff changeset
   320
            override def theory_session(name: Document.Node.Name): Sessions.Info =
7c0217c8b8a5 clarified signature;
wenzelm
parents: 75105
diff changeset
   321
              PIDE.resources.sessions_structure(
7c0217c8b8a5 clarified signature;
wenzelm
parents: 75105
diff changeset
   322
                PIDE.resources.session_base.theory_qualifier(name))
7c0217c8b8a5 clarified signature;
wenzelm
parents: 75105
diff changeset
   323
          }
7c0217c8b8a5 clarified signature;
wenzelm
parents: 75105
diff changeset
   324
        val document =
7c0217c8b8a5 clarified signature;
wenzelm
parents: 75105
diff changeset
   325
          Presentation.html_document(
7c0217c8b8a5 clarified signature;
wenzelm
parents: 75105
diff changeset
   326
            snapshot, html_context, Presentation.elements2,
7c0217c8b8a5 clarified signature;
wenzelm
parents: 75105
diff changeset
   327
            plain_text = query.startsWith(plain_text_prefix),
75146
1ef43607aef2 clarified signature;
wenzelm
parents: 75145
diff changeset
   328
            fonts_css = HTML.fonts_css_dir(HTTP.url_path(request.server_name)))
75107
7c0217c8b8a5 clarified signature;
wenzelm
parents: 75105
diff changeset
   329
        HTTP.Response.html(document.content)
75113
a7a489ea4661 clarified signature;
wenzelm
parents: 75112
diff changeset
   330
      }
a7a489ea4661 clarified signature;
wenzelm
parents: 75112
diff changeset
   331
  }
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   332
}
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   333
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   334
sealed abstract class Document_Model extends Document.Model {
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   335
  /* perspective */
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   336
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   337
  def document_view_ranges(snapshot: Document.Snapshot): List[Text.Range] = Nil
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   338
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   339
  def node_perspective(
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   340
    doc_blobs: Document.Blobs,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   341
    hidden: Boolean
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   342
  ): (Boolean, Document.Node.Perspective_Text) = {
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57610
diff changeset
   343
    GUI_Thread.require {}
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   344
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   345
    if (Isabelle.continuous_checking && is_theory) {
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   346
      val snapshot = this.snapshot()
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   347
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   348
      val reparse = snapshot.node.load_commands_changed(doc_blobs)
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   349
      val perspective =
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   350
        if (hidden) Text.Perspective.empty
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   351
        else {
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   352
          val view_ranges = document_view_ranges(snapshot)
71601
97ccf48c2f0c misc tuning based on hints by IntelliJ IDEA;
wenzelm
parents: 69255
diff changeset
   353
          val load_ranges = snapshot.commands_loading_ranges(PIDE.editor.visible_node)
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   354
          Text.Perspective(view_ranges ::: load_ranges)
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   355
        }
66082
2d12a730a380 clarified modules;
wenzelm
parents: 66040
diff changeset
   356
      val overlays = PIDE.editor.node_overlays(node_name)
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   357
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   358
      (reparse, Document.Node.Perspective(node_required, perspective, overlays))
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   359
    }
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   360
    else (false, Document.Node.no_perspective_text)
43397
dba359c0ae3b more robust init;
wenzelm
parents: 43394
diff changeset
   361
  }
66019
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
   362
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
   363
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
   364
  /* snapshot */
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
   365
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   366
  @tailrec final def await_stable_snapshot(): Document.Snapshot = {
66019
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
   367
    val snapshot = this.snapshot()
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
   368
    if (snapshot.is_outdated) {
73702
7202e12cb324 tuned signature --- following hints by IntelliJ IDEA;
wenzelm
parents: 73518
diff changeset
   369
      PIDE.options.seconds("editor_output_delay").sleep()
66019
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
   370
      await_stable_snapshot()
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
   371
    }
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
   372
    else snapshot
69b5ef78fb07 HTML preview via builtin HTTP server;
wenzelm
parents: 65469
diff changeset
   373
  }
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   374
}
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   375
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   376
object File_Model {
66114
c137a9f038a6 clarified signature;
wenzelm
parents: 66101
diff changeset
   377
  def empty(session: Session): File_Model =
c137a9f038a6 clarified signature;
wenzelm
parents: 66101
diff changeset
   378
    File_Model(session, Document.Node.Name.empty, None, Document_Model.File_Content(""),
c137a9f038a6 clarified signature;
wenzelm
parents: 66101
diff changeset
   379
      false, Document.Node.no_perspective_text, Nil)
c137a9f038a6 clarified signature;
wenzelm
parents: 66101
diff changeset
   380
64863
wenzelm
parents: 64858
diff changeset
   381
  def init(session: Session,
wenzelm
parents: 64858
diff changeset
   382
    node_name: Document.Node.Name,
wenzelm
parents: 64858
diff changeset
   383
    text: String,
wenzelm
parents: 64858
diff changeset
   384
    node_required: Boolean = false,
wenzelm
parents: 64858
diff changeset
   385
    last_perspective: Document.Node.Perspective_Text = Document.Node.no_perspective_text,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   386
    pending_edits: List[Text.Edit] = Nil
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   387
  ): File_Model = {
65469
78ace4a14975 more explicit jEdit file operations;
wenzelm
parents: 65359
diff changeset
   388
    val file = JEdit_Lib.check_file(node_name.node)
65245
e955b33f432c proper plugin access;
wenzelm
parents: 65243
diff changeset
   389
    file.foreach(PIDE.plugin.file_watcher.register_parent(_))
64863
wenzelm
parents: 64858
diff changeset
   390
64864
eec7ffef0be6 accomodate very big file_models and changed_files;
wenzelm
parents: 64863
diff changeset
   391
    val content = Document_Model.File_Content(text)
71733
6c470c918aad more general support for isabelle_scala_service;
wenzelm
parents: 71684
diff changeset
   392
    val node_required1 = node_required || File_Format.registry.is_theory(node_name)
67291
1bd9a0142d7a bibtex theory is always required and thus eventually consolidated;
wenzelm
parents: 67288
diff changeset
   393
    File_Model(session, node_name, file, content, node_required1, last_perspective, pending_edits)
64863
wenzelm
parents: 64858
diff changeset
   394
  }
wenzelm
parents: 64858
diff changeset
   395
}
wenzelm
parents: 64858
diff changeset
   396
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   397
case class File_Model(
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   398
  session: Session,
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   399
  node_name: Document.Node.Name,
64864
eec7ffef0be6 accomodate very big file_models and changed_files;
wenzelm
parents: 64863
diff changeset
   400
  file: Option[JFile],
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   401
  content: Document_Model.File_Content,
64863
wenzelm
parents: 64858
diff changeset
   402
  node_required: Boolean,
wenzelm
parents: 64858
diff changeset
   403
  last_perspective: Document.Node.Perspective_Text,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   404
  pending_edits: List[Text.Edit]
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   405
) extends Document_Model {
66114
c137a9f038a6 clarified signature;
wenzelm
parents: 66101
diff changeset
   406
  /* text */
c137a9f038a6 clarified signature;
wenzelm
parents: 66101
diff changeset
   407
67014
e6a695d6a6b2 tuned signature;
wenzelm
parents: 66959
diff changeset
   408
  def get_text(range: Text.Range): Option[String] =
66114
c137a9f038a6 clarified signature;
wenzelm
parents: 66101
diff changeset
   409
    range.try_substring(content.text)
c137a9f038a6 clarified signature;
wenzelm
parents: 66101
diff changeset
   410
c137a9f038a6 clarified signature;
wenzelm
parents: 66101
diff changeset
   411
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   412
  /* header */
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   413
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   414
  def node_header: Document.Node.Header =
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   415
    PIDE.resources.special_header(node_name) getOrElse
72772
a9ef39041114 clarified signature;
wenzelm
parents: 72652
diff changeset
   416
      PIDE.resources.check_thy(node_name, Scan.char_reader(content.text), strict = false)
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   417
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   418
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   419
  /* content */
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   420
64829
07f209e957bc refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents: 64828
diff changeset
   421
  def node_position(offset: Text.Offset): Line.Node_Position =
07f209e957bc refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents: 64828
diff changeset
   422
    Line.Node_Position(node_name.node,
65196
e8760a98db78 discontinued pointless Text.Length: Javascript and Java agree in old-fashioned UTF-16;
wenzelm
parents: 65132
diff changeset
   423
      Line.Position.zero.advance(content.text.substring(0, offset)))
64829
07f209e957bc refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents: 64828
diff changeset
   424
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   425
  def get_blob: Option[Document.Blob] =
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   426
    if (is_theory) None
67265
f32287c95432 store full blob source for the sake of markup_to_XML;
wenzelm
parents: 67262
diff changeset
   427
    else Some(Document.Blob(content.bytes, content.text, content.chunk, pending_edits.nonEmpty))
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   428
64831
4792ee012e94 tuned signature;
wenzelm
parents: 64829
diff changeset
   429
  def bibtex_entries: List[Text.Info[String]] =
69255
800b1ce96fce more general support for Isabelle/PIDE file formats -- less hardwired Bibtex operations;
wenzelm
parents: 68476
diff changeset
   430
    if (Bibtex.is_bibtex(node_name.node)) content.bibtex_entries else Nil
64680
wenzelm
parents: 64673
diff changeset
   431
wenzelm
parents: 64673
diff changeset
   432
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   433
  /* edits */
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   434
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   435
  def update_text(text: String): Option[File_Model] =
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   436
    Text.Edit.replace(0, content.text, text) match {
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   437
      case Nil => None
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   438
      case edits =>
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   439
        val content1 = Document_Model.File_Content(text)
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   440
        val pending_edits1 = pending_edits ::: edits
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   441
        Some(copy(content = content1, pending_edits = pending_edits1))
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   442
    }
38222
dac5fa0ac971 replaced individual Document_Model history by all-inclusive one in Session;
wenzelm
parents: 38158
diff changeset
   443
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   444
  def flush_edits(
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   445
    doc_blobs: Document.Blobs,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   446
    hidden: Boolean
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   447
  ) : Option[(List[Document.Edit_Text], File_Model)] = {
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   448
    val (reparse, perspective) = node_perspective(doc_blobs, hidden)
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   449
    if (reparse || pending_edits.nonEmpty || last_perspective != perspective) {
64867
e7220f4de11f support "purge" operation on document model;
wenzelm
parents: 64864
diff changeset
   450
      val edits = node_edits(node_header, pending_edits, perspective)
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   451
      Some((edits, copy(last_perspective = perspective, pending_edits = Nil)))
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   452
    }
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   453
    else None
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   454
  }
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   455
64867
e7220f4de11f support "purge" operation on document model;
wenzelm
parents: 64864
diff changeset
   456
  def purge_edits(doc_blobs: Document.Blobs): Option[List[Document.Edit_Text]] =
67310
506acf60d6b1 proper purge of auxiliary bibtex theory;
wenzelm
parents: 67308
diff changeset
   457
    if (pending_edits.nonEmpty ||
71733
6c470c918aad more general support for isabelle_scala_service;
wenzelm
parents: 71684
diff changeset
   458
        !File_Format.registry.is_theory(node_name) &&
67310
506acf60d6b1 proper purge of auxiliary bibtex theory;
wenzelm
parents: 67308
diff changeset
   459
          (node_required || !Document.Node.is_no_perspective_text(last_perspective))) None
64867
e7220f4de11f support "purge" operation on document model;
wenzelm
parents: 64864
diff changeset
   460
    else {
e7220f4de11f support "purge" operation on document model;
wenzelm
parents: 64864
diff changeset
   461
      val text_edits = List(Text.Edit.remove(0, content.text))
e7220f4de11f support "purge" operation on document model;
wenzelm
parents: 64864
diff changeset
   462
      Some(node_edits(Document.Node.no_header, text_edits, Document.Node.no_perspective_text))
e7220f4de11f support "purge" operation on document model;
wenzelm
parents: 64864
diff changeset
   463
    }
e7220f4de11f support "purge" operation on document model;
wenzelm
parents: 64864
diff changeset
   464
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   465
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   466
  /* snapshot */
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   467
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   468
  def is_stable: Boolean = pending_edits.isEmpty
64818
67a0a563d2b3 clarified buffer events: exit model while loading;
wenzelm
parents: 64817
diff changeset
   469
  def snapshot(): Document.Snapshot = session.snapshot(node_name, pending_edits)
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   470
}
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   471
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   472
case class Buffer_Model(session: Session, node_name: Document.Node.Name, buffer: Buffer)
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   473
extends Document_Model {
66114
c137a9f038a6 clarified signature;
wenzelm
parents: 66101
diff changeset
   474
  /* text */
c137a9f038a6 clarified signature;
wenzelm
parents: 66101
diff changeset
   475
67014
e6a695d6a6b2 tuned signature;
wenzelm
parents: 66959
diff changeset
   476
  def get_text(range: Text.Range): Option[String] =
e6a695d6a6b2 tuned signature;
wenzelm
parents: 66959
diff changeset
   477
    JEdit_Lib.get_text(buffer, range)
66114
c137a9f038a6 clarified signature;
wenzelm
parents: 66101
diff changeset
   478
c137a9f038a6 clarified signature;
wenzelm
parents: 66101
diff changeset
   479
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   480
  /* header */
54509
1f77110c94ef maintain document model for all files, with document view for theory only, and special blob for non-theory files;
wenzelm
parents: 54464
diff changeset
   481
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   482
  def node_header(): Document.Node.Header = {
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57610
diff changeset
   483
    GUI_Thread.require {}
54509
1f77110c94ef maintain document model for all files, with document view for theory only, and special blob for non-theory files;
wenzelm
parents: 54464
diff changeset
   484
64673
b5965890e54d more uniform treatment of file name vs. theory name and special header;
wenzelm
parents: 63446
diff changeset
   485
    PIDE.resources.special_header(node_name) getOrElse
64826
c97296294f6d clarified check_thy_reader: check node_name here;
wenzelm
parents: 64825
diff changeset
   486
      JEdit_Lib.buffer_lock(buffer) {
72772
a9ef39041114 clarified signature;
wenzelm
parents: 72652
diff changeset
   487
        PIDE.resources.check_thy(node_name, JEdit_Lib.buffer_reader(buffer), strict = false)
46748
8f3ae4d04a2d refined node_header -- more direct buffer access (again);
wenzelm
parents: 46740
diff changeset
   488
      }
46920
5f44c8bea84e more explicit indication of swing thread context;
wenzelm
parents: 46750
diff changeset
   489
  }
44385
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44379
diff changeset
   490
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44379
diff changeset
   491
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44379
diff changeset
   492
  /* perspective */
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44379
diff changeset
   493
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57610
diff changeset
   494
  // owned by GUI thread
52816
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   495
  private var _node_required = false
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   496
  def node_required: Boolean = _node_required
73340
0ffcad1f6130 tuned --- fewer warnings;
wenzelm
parents: 73055
diff changeset
   497
  def set_node_required(b: Boolean): Unit = GUI_Thread.require { _node_required = b }
52808
143f225e50f5 allow explicit indication of required node: full eval, no prints;
wenzelm
parents: 52807
diff changeset
   498
64883
e89f5ef32aa2 tuned signature;
wenzelm
parents: 64868
diff changeset
   499
  def document_view_iterator: Iterator[Document_View] =
e89f5ef32aa2 tuned signature;
wenzelm
parents: 64868
diff changeset
   500
    for {
e89f5ef32aa2 tuned signature;
wenzelm
parents: 64868
diff changeset
   501
      text_area <- JEdit_Lib.jedit_text_areas(buffer)
e89f5ef32aa2 tuned signature;
wenzelm
parents: 64868
diff changeset
   502
      doc_view <- Document_View.get(text_area)
e89f5ef32aa2 tuned signature;
wenzelm
parents: 64868
diff changeset
   503
    } yield doc_view
e89f5ef32aa2 tuned signature;
wenzelm
parents: 64868
diff changeset
   504
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   505
  override def document_view_ranges(snapshot: Document.Snapshot): List[Text.Range] = {
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57610
diff changeset
   506
    GUI_Thread.require {}
52759
a20631db9c8a support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents: 50565
diff changeset
   507
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   508
    (for {
64883
e89f5ef32aa2 tuned signature;
wenzelm
parents: 64868
diff changeset
   509
      doc_view <- document_view_iterator
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   510
      range <- doc_view.perspective(snapshot).ranges.iterator
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   511
    } yield range).toList
44385
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44379
diff changeset
   512
  }
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44379
diff changeset
   513
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44379
diff changeset
   514
54509
1f77110c94ef maintain document model for all files, with document view for theory only, and special blob for non-theory files;
wenzelm
parents: 54464
diff changeset
   515
  /* blob */
1f77110c94ef maintain document model for all files, with document view for theory only, and special blob for non-theory files;
wenzelm
parents: 54464
diff changeset
   516
64885
205274ca16ee tuned whitespace;
wenzelm
parents: 64883
diff changeset
   517
  // owned by GUI thread
67265
f32287c95432 store full blob source for the sake of markup_to_XML;
wenzelm
parents: 67262
diff changeset
   518
  private var _blob: Option[(Bytes, String, Symbol.Text_Chunk)] = None
54511
1fd24c96ce9b caching of blob;
wenzelm
parents: 54509
diff changeset
   519
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57610
diff changeset
   520
  private def reset_blob(): Unit = GUI_Thread.require { _blob = None }
54511
1fd24c96ce9b caching of blob;
wenzelm
parents: 54509
diff changeset
   521
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   522
  def get_blob: Option[Document.Blob] =
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57610
diff changeset
   523
    GUI_Thread.require {
55783
da0513d95155 more formal Document.Blobs;
wenzelm
parents: 55781
diff changeset
   524
      if (is_theory) None
da0513d95155 more formal Document.Blobs;
wenzelm
parents: 55781
diff changeset
   525
      else {
67265
f32287c95432 store full blob source for the sake of markup_to_XML;
wenzelm
parents: 67262
diff changeset
   526
        val (bytes, text, chunk) =
55783
da0513d95155 more formal Document.Blobs;
wenzelm
parents: 55781
diff changeset
   527
          _blob match {
da0513d95155 more formal Document.Blobs;
wenzelm
parents: 55781
diff changeset
   528
            case Some(x) => x
da0513d95155 more formal Document.Blobs;
wenzelm
parents: 55781
diff changeset
   529
            case None =>
64835
fd1efd6dd385 resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents: 64832
diff changeset
   530
              val bytes = PIDE.resources.make_file_content(buffer)
67265
f32287c95432 store full blob source for the sake of markup_to_XML;
wenzelm
parents: 67262
diff changeset
   531
              val text = buffer.getText(0, buffer.getLength)
f32287c95432 store full blob source for the sake of markup_to_XML;
wenzelm
parents: 67262
diff changeset
   532
              val chunk = Symbol.Text_Chunk(text)
f32287c95432 store full blob source for the sake of markup_to_XML;
wenzelm
parents: 67262
diff changeset
   533
              val x = (bytes, text, chunk)
f32287c95432 store full blob source for the sake of markup_to_XML;
wenzelm
parents: 67262
diff changeset
   534
              _blob = Some(x)
f32287c95432 store full blob source for the sake of markup_to_XML;
wenzelm
parents: 67262
diff changeset
   535
              x
55783
da0513d95155 more formal Document.Blobs;
wenzelm
parents: 55781
diff changeset
   536
          }
64818
67a0a563d2b3 clarified buffer events: exit model while loading;
wenzelm
parents: 64817
diff changeset
   537
        val changed = pending_edits.nonEmpty
67265
f32287c95432 store full blob source for the sake of markup_to_XML;
wenzelm
parents: 67262
diff changeset
   538
        Some(Document.Blob(bytes, text, chunk, changed))
54511
1fd24c96ce9b caching of blob;
wenzelm
parents: 54509
diff changeset
   539
      }
1fd24c96ce9b caching of blob;
wenzelm
parents: 54509
diff changeset
   540
    }
54509
1f77110c94ef maintain document model for all files, with document view for theory only, and special blob for non-theory files;
wenzelm
parents: 54464
diff changeset
   541
1f77110c94ef maintain document model for all files, with document view for theory only, and special blob for non-theory files;
wenzelm
parents: 54464
diff changeset
   542
58543
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   543
  /* bibtex entries */
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   544
64885
205274ca16ee tuned whitespace;
wenzelm
parents: 64883
diff changeset
   545
  // owned by GUI thread
205274ca16ee tuned whitespace;
wenzelm
parents: 64883
diff changeset
   546
  private var _bibtex_entries: Option[List[Text.Info[String]]] = None
58543
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   547
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   548
  private def reset_bibtex_entries(): Unit = GUI_Thread.require { _bibtex_entries = None }
58543
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   549
64831
4792ee012e94 tuned signature;
wenzelm
parents: 64829
diff changeset
   550
  def bibtex_entries: List[Text.Info[String]] =
58543
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   551
    GUI_Thread.require {
69255
800b1ce96fce more general support for Isabelle/PIDE file formats -- less hardwired Bibtex operations;
wenzelm
parents: 68476
diff changeset
   552
      if (Bibtex.is_bibtex(node_name.node)) {
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   553
        _bibtex_entries match {
58543
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   554
          case Some(entries) => entries
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   555
          case None =>
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   556
            val text = JEdit_Lib.buffer_text(buffer)
64828
e837f6bf653c clarified modules;
wenzelm
parents: 64827
diff changeset
   557
            val entries =
66150
c2e19b9e1398 tuned signature;
wenzelm
parents: 66114
diff changeset
   558
              try { Bibtex.entries(text) }
64828
e837f6bf653c clarified modules;
wenzelm
parents: 64827
diff changeset
   559
              catch { case ERROR(msg) => Output.warning(msg); Nil }
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   560
            _bibtex_entries = Some(entries)
58543
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   561
            entries
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   562
        }
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   563
      }
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   564
      else Nil
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   565
    }
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   566
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   567
50344
608265769ce0 emit bulk edits on initialization of multiple buffers, which greatly improves performance when starting big sessions (e.g. JinjaThreads);
wenzelm
parents: 50207
diff changeset
   568
  /* pending edits */
43648
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43644
diff changeset
   569
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   570
  private object pending_edits {
38425
e467db701d78 moved Text_Edit to Text.Edit;
wenzelm
parents: 38417
diff changeset
   571
    private val pending = new mutable.ListBuffer[Text.Edit]
57615
df1b3452d71c more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents: 57612
diff changeset
   572
    private var last_perspective = Document.Node.no_perspective_text
44438
0fc38897248a early filtering of unchanged perspective;
wenzelm
parents: 44436
diff changeset
   573
64818
67a0a563d2b3 clarified buffer events: exit model while loading;
wenzelm
parents: 64817
diff changeset
   574
    def nonEmpty: Boolean = synchronized { pending.nonEmpty }
67a0a563d2b3 clarified buffer events: exit model while loading;
wenzelm
parents: 64817
diff changeset
   575
    def get_edits: List[Text.Edit] = synchronized { pending.toList }
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   576
    def get_last_perspective: Document.Node.Perspective_Text = synchronized { last_perspective }
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   577
    def set_last_perspective(perspective: Document.Node.Perspective_Text): Unit =
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   578
      synchronized { last_perspective = perspective }
38224
809578d7f6af more explicit model of pending text edits;
wenzelm
parents: 38223
diff changeset
   579
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   580
    def flush_edits(doc_blobs: Document.Blobs, hidden: Boolean): List[Document.Edit_Text] =
61728
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   581
      synchronized {
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   582
        GUI_Thread.require {}
60272
4f72b00d9952 no GUI_Thread for SideKick parsers (in contrast to 4c8205fe3644), to avoid danger of deadlock due to nested context switch;
wenzelm
parents: 59737
diff changeset
   583
64818
67a0a563d2b3 clarified buffer events: exit model while loading;
wenzelm
parents: 64817
diff changeset
   584
        val edits = get_edits
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   585
        val (reparse, perspective) = node_perspective(doc_blobs, hidden)
64818
67a0a563d2b3 clarified buffer events: exit model while loading;
wenzelm
parents: 64817
diff changeset
   586
        if (reparse || edits.nonEmpty || last_perspective != perspective) {
73367
77ef8bef0593 clarified signature --- fewer warnings;
wenzelm
parents: 73358
diff changeset
   587
          pending.clear()
61728
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   588
          last_perspective = perspective
71601
97ccf48c2f0c misc tuning based on hints by IntelliJ IDEA;
wenzelm
parents: 69255
diff changeset
   589
          node_edits(node_header(), edits, perspective)
61728
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   590
        }
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   591
        else Nil
43648
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43644
diff changeset
   592
      }
38224
809578d7f6af more explicit model of pending text edits;
wenzelm
parents: 38223
diff changeset
   593
75380
2cb2606ce075 tuned: avoid problems with scala3;
wenzelm
parents: 75148
diff changeset
   594
    def edit(edits: List[Text.Edit]): Unit = synchronized {
60272
4f72b00d9952 no GUI_Thread for SideKick parsers (in contrast to 4c8205fe3644), to avoid danger of deadlock due to nested context switch;
wenzelm
parents: 59737
diff changeset
   595
      GUI_Thread.require {}
4f72b00d9952 no GUI_Thread for SideKick parsers (in contrast to 4c8205fe3644), to avoid danger of deadlock due to nested context switch;
wenzelm
parents: 59737
diff changeset
   596
54511
1fd24c96ce9b caching of blob;
wenzelm
parents: 54509
diff changeset
   597
      reset_blob()
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   598
      reset_bibtex_entries()
54511
1fd24c96ce9b caching of blob;
wenzelm
parents: 54509
diff changeset
   599
64883
e89f5ef32aa2 tuned signature;
wenzelm
parents: 64868
diff changeset
   600
      for (doc_view <- document_view_iterator)
61538
bf4969660913 avoid highlighted area getting "stuck" after edit;
wenzelm
parents: 61192
diff changeset
   601
        doc_view.rich_text_area.active_reset()
bf4969660913 avoid highlighted area getting "stuck" after edit;
wenzelm
parents: 61192
diff changeset
   602
64818
67a0a563d2b3 clarified buffer events: exit model while loading;
wenzelm
parents: 64817
diff changeset
   603
      pending ++= edits
66082
2d12a730a380 clarified modules;
wenzelm
parents: 66040
diff changeset
   604
      PIDE.editor.invoke()
44436
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44385
diff changeset
   605
    }
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44385
diff changeset
   606
  }
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44385
diff changeset
   607
64835
fd1efd6dd385 resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents: 64832
diff changeset
   608
  def is_stable: Boolean = !pending_edits.nonEmpty
64818
67a0a563d2b3 clarified buffer events: exit model while loading;
wenzelm
parents: 64817
diff changeset
   609
  def snapshot(): Document.Snapshot = session.snapshot(node_name, pending_edits.get_edits)
60933
6d03e05ef041 more robust access to stable tip version: take all pending edits into account, don't assume model for current buffer;
wenzelm
parents: 60274
diff changeset
   610
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   611
  def flush_edits(doc_blobs: Document.Blobs, hidden: Boolean): List[Document.Edit_Text] =
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   612
    pending_edits.flush_edits(doc_blobs, hidden)
34828
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   613
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   614
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   615
  /* buffer listener */
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   616
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   617
  private val buffer_listener: BufferListener = new BufferAdapter {
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   618
    override def contentInserted(
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   619
      buffer: JEditBuffer,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   620
      start_line: Int,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   621
      offset: Int,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   622
      num_lines: Int,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   623
      length: Int
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   624
    ): Unit = {
64818
67a0a563d2b3 clarified buffer events: exit model while loading;
wenzelm
parents: 64817
diff changeset
   625
      pending_edits.edit(List(Text.Edit.insert(offset, buffer.getText(offset, length))))
34828
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   626
    }
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   627
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   628
    override def preContentRemoved(
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   629
      buffer: JEditBuffer,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   630
      start_line: Int,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   631
      offset: Int,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   632
      num_lines: Int,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   633
      removed_length: Int
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   634
    ): Unit = {
64818
67a0a563d2b3 clarified buffer events: exit model while loading;
wenzelm
parents: 64817
diff changeset
   635
      pending_edits.edit(List(Text.Edit.remove(offset, buffer.getText(offset, removed_length))))
34828
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   636
    }
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   637
  }
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   638
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   639
59078
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   640
  /* syntax */
37557
1ae272fd4082 refresh Isabelle token marker after buffer properties changed, e.g. when fold mode is switched;
wenzelm
parents: 37555
diff changeset
   641
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   642
  def syntax_changed(): Unit = {
61192
98eba31c51f8 tuned signature;
wenzelm
parents: 60933
diff changeset
   643
    JEdit_Lib.buffer_line_manager(buffer).setFirstInvalidLineContext(0)
59080
611914621edb added Untyped.method convenience (for *this* class only);
wenzelm
parents: 59079
diff changeset
   644
    for (text_area <- JEdit_Lib.jedit_text_areas(buffer))
611914621edb added Untyped.method convenience (for *this* class only);
wenzelm
parents: 59079
diff changeset
   645
      Untyped.method(Class.forName("org.gjt.sp.jedit.textarea.TextArea"), "foldStructureChanged").
611914621edb added Untyped.method convenience (for *this* class only);
wenzelm
parents: 59079
diff changeset
   646
        invoke(text_area)
72960
wenzelm
parents: 72959
diff changeset
   647
    buffer.invalidateCachedFoldLevels()
59078
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   648
  }
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   649
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   650
  def init_token_marker(): Unit = {
59077
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
   651
    Isabelle.buffer_token_marker(buffer) match {
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
   652
      case Some(marker) if marker != buffer.getTokenMarker =>
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
   653
        buffer.setTokenMarker(marker)
59078
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   654
        syntax_changed()
59077
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
   655
      case _ =>
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
   656
    }
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
   657
  }
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
   658
59078
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   659
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   660
  /* init */
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   661
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   662
  def init(old_model: Option[File_Model]): Buffer_Model = {
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   663
    GUI_Thread.require {}
59078
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   664
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   665
    old_model match {
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   666
      case None =>
64818
67a0a563d2b3 clarified buffer events: exit model while loading;
wenzelm
parents: 64817
diff changeset
   667
        pending_edits.edit(List(Text.Edit.insert(0, JEdit_Lib.buffer_text(buffer))))
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   668
      case Some(file_model) =>
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   669
        set_node_required(file_model.node_required)
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   670
        pending_edits.set_last_perspective(file_model.last_perspective)
64818
67a0a563d2b3 clarified buffer events: exit model while loading;
wenzelm
parents: 64817
diff changeset
   671
        pending_edits.edit(
67a0a563d2b3 clarified buffer events: exit model while loading;
wenzelm
parents: 64817
diff changeset
   672
          file_model.pending_edits :::
67a0a563d2b3 clarified buffer events: exit model while loading;
wenzelm
parents: 64817
diff changeset
   673
            Text.Edit.replace(0, file_model.content.text, JEdit_Lib.buffer_text(buffer)))
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   674
    }
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   675
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   676
    buffer.addBufferListener(buffer_listener)
59078
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   677
    init_token_marker()
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   678
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   679
    this
34680
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   680
  }
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   681
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   682
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   683
  /* exit */
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   684
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75380
diff changeset
   685
  def exit(): File_Model = {
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   686
    GUI_Thread.require {}
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   687
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   688
    buffer.removeBufferListener(buffer_listener)
59078
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   689
    init_token_marker()
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   690
64863
wenzelm
parents: 64858
diff changeset
   691
    File_Model.init(session, node_name, JEdit_Lib.buffer_text(buffer), node_required,
wenzelm
parents: 64858
diff changeset
   692
      pending_edits.get_last_perspective, pending_edits.get_edits)
34680
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   693
  }
34447
wenzelm
parents: 34446
diff changeset
   694
}