src/Tools/jEdit/src/document_model.scala
author wenzelm
Wed, 28 Dec 2016 16:50:14 +0100
changeset 64680 7f87c1aa0ffa
parent 64673 b5965890e54d
child 64799 c0c648911f1a
permissions -rw-r--r--
tuned;
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
55778
e1fd8780f997 tuned comment;
wenzelm
parents: 55435
diff changeset
     5
Document model connected to jEdit buffer (node in theory graph or
e1fd8780f997 tuned comment;
wenzelm
parents: 55435
diff changeset
     6
auxiliary file).
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
34693
3e995f100ad2 sealed Edit;
wenzelm
parents: 34685
diff changeset
    14
import scala.collection.mutable
59736
5c1a0069b9d3 tight span for theory header, which is relevant for error positions (including semantic completion);
wenzelm
parents: 59715
diff changeset
    15
import scala.util.parsing.input.CharSequenceReader
34446
5c79f97ec1d1 superficial tuning;
wenzelm
parents: 34445
diff changeset
    16
59077
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
    17
import org.gjt.sp.jedit.jEdit
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    18
import org.gjt.sp.jedit.Buffer
61192
98eba31c51f8 tuned signature;
wenzelm
parents: 60933
diff changeset
    19
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
    20
34760
dc7f5e0d9d27 misc modernization of names;
wenzelm
parents: 34759
diff changeset
    21
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    22
object Document_Model
34588
e8ac8794971f superficial tuning;
wenzelm
parents: 34583
diff changeset
    23
{
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    24
  /* document model of buffer */
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    25
50565
b00ea974613c tuned property name;
wenzelm
parents: 50363
diff changeset
    26
  private val key = "PIDE.document_model"
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    27
34788
3779c54a2d21 direct apply for Document_Model and Document_View;
wenzelm
parents: 34784
diff changeset
    28
  def apply(buffer: Buffer): Option[Document_Model] =
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    29
  {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    30
    buffer.getProperty(key) match {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    31
      case model: Document_Model => Some(model)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    32
      case _ => None
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    33
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    34
  }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    35
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    36
  def exit(buffer: Buffer)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    37
  {
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57610
diff changeset
    38
    GUI_Thread.require {}
34788
3779c54a2d21 direct apply for Document_Model and Document_View;
wenzelm
parents: 34784
diff changeset
    39
    apply(buffer) match {
39636
610dc743932c permissive exit;
wenzelm
parents: 39179
diff changeset
    40
      case None =>
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    41
      case Some(model) =>
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    42
        model.deactivate()
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    43
        buffer.unsetProperty(key)
47058
34761733526c refined init_model: allow change of buffer name as caused by "Save as", for example;
wenzelm
parents: 46920
diff changeset
    44
        buffer.propertiesChanged
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34652
diff changeset
    45
    }
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    46
  }
43397
dba359c0ae3b more robust init;
wenzelm
parents: 43394
diff changeset
    47
59077
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
    48
  def init(session: Session, buffer: Buffer, node_name: Document.Node.Name,
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
    49
    old_model: Option[Document_Model]): Document_Model =
43397
dba359c0ae3b more robust init;
wenzelm
parents: 43394
diff changeset
    50
  {
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57610
diff changeset
    51
    GUI_Thread.require {}
59077
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
    52
60274
c2837a39da01 more conservative Document_Model.init: avoid Document.Node.Clear due to change of token marker (e.g. due to change of jEdit mode properties);
wenzelm
parents: 60272
diff changeset
    53
    val model =
c2837a39da01 more conservative Document_Model.init: avoid Document.Node.Clear due to change of token marker (e.g. due to change of jEdit mode properties);
wenzelm
parents: 60272
diff changeset
    54
      old_model match {
c2837a39da01 more conservative Document_Model.init: avoid Document.Node.Clear due to change of token marker (e.g. due to change of jEdit mode properties);
wenzelm
parents: 60272
diff changeset
    55
        case Some(old) if old.node_name == node_name => old
c2837a39da01 more conservative Document_Model.init: avoid Document.Node.Clear due to change of token marker (e.g. due to change of jEdit mode properties);
wenzelm
parents: 60272
diff changeset
    56
        case _ =>
c2837a39da01 more conservative Document_Model.init: avoid Document.Node.Clear due to change of token marker (e.g. due to change of jEdit mode properties);
wenzelm
parents: 60272
diff changeset
    57
          apply(buffer).map(_.deactivate)
c2837a39da01 more conservative Document_Model.init: avoid Document.Node.Clear due to change of token marker (e.g. due to change of jEdit mode properties);
wenzelm
parents: 60272
diff changeset
    58
          val model = new Document_Model(session, buffer, node_name)
c2837a39da01 more conservative Document_Model.init: avoid Document.Node.Clear due to change of token marker (e.g. due to change of jEdit mode properties);
wenzelm
parents: 60272
diff changeset
    59
          buffer.setProperty(key, model)
c2837a39da01 more conservative Document_Model.init: avoid Document.Node.Clear due to change of token marker (e.g. due to change of jEdit mode properties);
wenzelm
parents: 60272
diff changeset
    60
          model.activate()
c2837a39da01 more conservative Document_Model.init: avoid Document.Node.Clear due to change of token marker (e.g. due to change of jEdit mode properties);
wenzelm
parents: 60272
diff changeset
    61
          buffer.propertiesChanged
c2837a39da01 more conservative Document_Model.init: avoid Document.Node.Clear due to change of token marker (e.g. due to change of jEdit mode properties);
wenzelm
parents: 60272
diff changeset
    62
          model
c2837a39da01 more conservative Document_Model.init: avoid Document.Node.Clear due to change of token marker (e.g. due to change of jEdit mode properties);
wenzelm
parents: 60272
diff changeset
    63
      }
c2837a39da01 more conservative Document_Model.init: avoid Document.Node.Clear due to change of token marker (e.g. due to change of jEdit mode properties);
wenzelm
parents: 60272
diff changeset
    64
    model.init_token_marker
c2837a39da01 more conservative Document_Model.init: avoid Document.Node.Clear due to change of token marker (e.g. due to change of jEdit mode properties);
wenzelm
parents: 60272
diff changeset
    65
    model
43397
dba359c0ae3b more robust init;
wenzelm
parents: 43394
diff changeset
    66
  }
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    67
}
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    68
38151
2837c952ca31 explicit Change.Snapshot and Document.Node;
wenzelm
parents: 38150
diff changeset
    69
52973
d5f7fa1498b7 tuned signature;
wenzelm
parents: 52887
diff changeset
    70
class Document_Model(val session: Session, val buffer: Buffer, val node_name: Document.Node.Name)
34588
e8ac8794971f superficial tuning;
wenzelm
parents: 34583
diff changeset
    71
{
64680
wenzelm
parents: 64673
diff changeset
    72
  override def toString: String = node_name.toString
wenzelm
parents: 64673
diff changeset
    73
wenzelm
parents: 64673
diff changeset
    74
44385
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44379
diff changeset
    75
  /* header */
38222
dac5fa0ac971 replaced individual Document_Model history by all-inclusive one in Session;
wenzelm
parents: 38158
diff changeset
    76
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
    77
  def is_theory: Boolean = node_name.is_theory
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
    78
48707
ba531af91148 simplified Document.Node.Header -- internalized errors;
wenzelm
parents: 47393
diff changeset
    79
  def node_header(): Document.Node.Header =
46920
5f44c8bea84e more explicit indication of swing thread context;
wenzelm
parents: 46750
diff changeset
    80
  {
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57610
diff changeset
    81
    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
    82
64673
b5965890e54d more uniform treatment of file name vs. theory name and special header;
wenzelm
parents: 63446
diff changeset
    83
    PIDE.resources.special_header(node_name) getOrElse
b5965890e54d more uniform treatment of file name vs. theory name and special header;
wenzelm
parents: 63446
diff changeset
    84
    {
b5965890e54d more uniform treatment of file name vs. theory name and special header;
wenzelm
parents: 63446
diff changeset
    85
      if (is_theory) {
63022
785a59235a15 more IDE support for Isabelle/Pure bootstrap;
wenzelm
parents: 62932
diff changeset
    86
        JEdit_Lib.buffer_lock(buffer) {
785a59235a15 more IDE support for Isabelle/Pure bootstrap;
wenzelm
parents: 62932
diff changeset
    87
          Token_Markup.line_token_iterator(
785a59235a15 more IDE support for Isabelle/Pure bootstrap;
wenzelm
parents: 62932
diff changeset
    88
            Thy_Header.bootstrap_syntax, buffer, 0, buffer.getLineCount).collectFirst(
785a59235a15 more IDE support for Isabelle/Pure bootstrap;
wenzelm
parents: 62932
diff changeset
    89
              {
63446
19162a9ef7e3 tunes signature;
wenzelm
parents: 63022
diff changeset
    90
                case Text.Info(range, tok) if tok.is_command(Thy_Header.THEORY) => range.start
63022
785a59235a15 more IDE support for Isabelle/Pure bootstrap;
wenzelm
parents: 62932
diff changeset
    91
              })
785a59235a15 more IDE support for Isabelle/Pure bootstrap;
wenzelm
parents: 62932
diff changeset
    92
            match {
785a59235a15 more IDE support for Isabelle/Pure bootstrap;
wenzelm
parents: 62932
diff changeset
    93
              case Some(offset) =>
785a59235a15 more IDE support for Isabelle/Pure bootstrap;
wenzelm
parents: 62932
diff changeset
    94
                val length = buffer.getLength - offset
785a59235a15 more IDE support for Isabelle/Pure bootstrap;
wenzelm
parents: 62932
diff changeset
    95
                PIDE.resources.check_thy_reader("", node_name,
785a59235a15 more IDE support for Isabelle/Pure bootstrap;
wenzelm
parents: 62932
diff changeset
    96
                  new CharSequenceReader(buffer.getSegment(offset, length)), Token.Pos.command)
64673
b5965890e54d more uniform treatment of file name vs. theory name and special header;
wenzelm
parents: 63446
diff changeset
    97
              case None =>
b5965890e54d more uniform treatment of file name vs. theory name and special header;
wenzelm
parents: 63446
diff changeset
    98
                Document.Node.no_header
63022
785a59235a15 more IDE support for Isabelle/Pure bootstrap;
wenzelm
parents: 62932
diff changeset
    99
            }
785a59235a15 more IDE support for Isabelle/Pure bootstrap;
wenzelm
parents: 62932
diff changeset
   100
        }
46748
8f3ae4d04a2d refined node_header -- more direct buffer access (again);
wenzelm
parents: 46740
diff changeset
   101
      }
64673
b5965890e54d more uniform treatment of file name vs. theory name and special header;
wenzelm
parents: 63446
diff changeset
   102
      else Document.Node.no_header
46748
8f3ae4d04a2d refined node_header -- more direct buffer access (again);
wenzelm
parents: 46740
diff changeset
   103
    }
46920
5f44c8bea84e more explicit indication of swing thread context;
wenzelm
parents: 46750
diff changeset
   104
  }
44385
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44379
diff changeset
   105
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44379
diff changeset
   106
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44379
diff changeset
   107
  /* perspective */
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44379
diff changeset
   108
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57610
diff changeset
   109
  // 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
   110
  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
   111
  def node_required: Boolean = _node_required
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   112
  def node_required_=(b: Boolean)
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   113
  {
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57610
diff changeset
   114
    GUI_Thread.require {}
54531
8330faaeebd5 restrict node_required status and Theories panel to actual theories;
wenzelm
parents: 54530
diff changeset
   115
    if (_node_required != b && is_theory) {
52816
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   116
      _node_required = b
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   117
      PIDE.options_changed()
52974
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
   118
      PIDE.editor.flush()
52816
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   119
    }
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   120
  }
52808
143f225e50f5 allow explicit indication of required node: full eval, no prints;
wenzelm
parents: 52807
diff changeset
   121
61728
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   122
  def node_perspective(hidden: Boolean, doc_blobs: Document.Blobs): (Boolean, Document.Node.Perspective_Text) =
44385
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44379
diff changeset
   123
  {
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57610
diff changeset
   124
    GUI_Thread.require {}
52759
a20631db9c8a support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents: 50565
diff changeset
   125
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
   126
    if (Isabelle.continuous_checking && is_theory) {
54325
2c4155003352 clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents: 52977
diff changeset
   127
      val snapshot = this.snapshot()
54530
2c1440f70028 ranges of thy_load commands count as visible within perspective;
wenzelm
parents: 54521
diff changeset
   128
2c1440f70028 ranges of thy_load commands count as visible within perspective;
wenzelm
parents: 54521
diff changeset
   129
      val document_view_ranges =
57883
d50aeb916a4b tuned -- eliminated redundant check (see 1f77110c94ef);
wenzelm
parents: 57621
diff changeset
   130
        for {
d50aeb916a4b tuned -- eliminated redundant check (see 1f77110c94ef);
wenzelm
parents: 57621
diff changeset
   131
          doc_view <- PIDE.document_views(buffer)
d50aeb916a4b tuned -- eliminated redundant check (see 1f77110c94ef);
wenzelm
parents: 57621
diff changeset
   132
          range <- doc_view.perspective(snapshot).ranges
d50aeb916a4b tuned -- eliminated redundant check (see 1f77110c94ef);
wenzelm
parents: 57621
diff changeset
   133
        } yield range
54530
2c1440f70028 ranges of thy_load commands count as visible within perspective;
wenzelm
parents: 54521
diff changeset
   134
56314
9a513737a0b2 tuned signature;
wenzelm
parents: 56208
diff changeset
   135
      val load_ranges =
54530
2c1440f70028 ranges of thy_load commands count as visible within perspective;
wenzelm
parents: 54521
diff changeset
   136
        for {
56314
9a513737a0b2 tuned signature;
wenzelm
parents: 56208
diff changeset
   137
          cmd <- snapshot.node.load_commands
54530
2c1440f70028 ranges of thy_load commands count as visible within perspective;
wenzelm
parents: 54521
diff changeset
   138
          blob_name <- cmd.blobs_names
56457
eea4bbe15745 tuned signature -- prefer static type Document.Node.Name;
wenzelm
parents: 56335
diff changeset
   139
          blob_buffer <- JEdit_Lib.jedit_buffer(blob_name)
59319
wenzelm
parents: 59080
diff changeset
   140
          if JEdit_Lib.jedit_text_areas(blob_buffer).nonEmpty
54530
2c1440f70028 ranges of thy_load commands count as visible within perspective;
wenzelm
parents: 54521
diff changeset
   141
          start <- snapshot.node.command_start(cmd)
2c1440f70028 ranges of thy_load commands count as visible within perspective;
wenzelm
parents: 54521
diff changeset
   142
          range = snapshot.convert(cmd.proper_range + start)
2c1440f70028 ranges of thy_load commands count as visible within perspective;
wenzelm
parents: 54521
diff changeset
   143
        } yield range
2c1440f70028 ranges of thy_load commands count as visible within perspective;
wenzelm
parents: 54521
diff changeset
   144
56314
9a513737a0b2 tuned signature;
wenzelm
parents: 56208
diff changeset
   145
      val reparse = snapshot.node.load_commands.exists(_.blobs_changed(doc_blobs))
55781
b3a4207fb9a6 proper update of text perspective for nodes with changed blobs, which is important to refresh the corresponding command perspective (otherwise it might refer to invalid thy_load commands and cause full execution of the node by the prover);
wenzelm
parents: 55778
diff changeset
   146
b3a4207fb9a6 proper update of text perspective for nodes with changed blobs, which is important to refresh the corresponding command perspective (otherwise it might refer to invalid thy_load commands and cause full execution of the node by the prover);
wenzelm
parents: 55778
diff changeset
   147
      (reparse,
b3a4207fb9a6 proper update of text perspective for nodes with changed blobs, which is important to refresh the corresponding command perspective (otherwise it might refer to invalid thy_load commands and cause full execution of the node by the prover);
wenzelm
parents: 55778
diff changeset
   148
        Document.Node.Perspective(node_required,
61728
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   149
          Text.Perspective(if (hidden) Nil else document_view_ranges ::: load_ranges),
55781
b3a4207fb9a6 proper update of text perspective for nodes with changed blobs, which is important to refresh the corresponding command perspective (otherwise it might refer to invalid thy_load commands and cause full execution of the node by the prover);
wenzelm
parents: 55778
diff changeset
   150
          PIDE.editor.node_overlays(node_name)))
52849
199e9fa5a5c2 maintain overlays within node perspective;
wenzelm
parents: 52816
diff changeset
   151
    }
57615
df1b3452d71c more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents: 57612
diff changeset
   152
    else (false, Document.Node.no_perspective_text)
44385
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44379
diff changeset
   153
  }
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44379
diff changeset
   154
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44379
diff changeset
   155
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
   156
  /* 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
   157
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57610
diff changeset
   158
  private var _blob: Option[(Bytes, Symbol.Text_Chunk)] = None  // owned by GUI thread
54511
1fd24c96ce9b caching of blob;
wenzelm
parents: 54509
diff changeset
   159
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57610
diff changeset
   160
  private def reset_blob(): Unit = GUI_Thread.require { _blob = None }
54511
1fd24c96ce9b caching of blob;
wenzelm
parents: 54509
diff changeset
   161
55783
da0513d95155 more formal Document.Blobs;
wenzelm
parents: 55781
diff changeset
   162
  def get_blob(): Option[Document.Blob] =
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57610
diff changeset
   163
    GUI_Thread.require {
55783
da0513d95155 more formal Document.Blobs;
wenzelm
parents: 55781
diff changeset
   164
      if (is_theory) None
da0513d95155 more formal Document.Blobs;
wenzelm
parents: 55781
diff changeset
   165
      else {
56473
5b5c750e9763 simplified Text.Chunk -- eliminated ooddities;
wenzelm
parents: 56469
diff changeset
   166
        val (bytes, chunk) =
55783
da0513d95155 more formal Document.Blobs;
wenzelm
parents: 55781
diff changeset
   167
          _blob match {
da0513d95155 more formal Document.Blobs;
wenzelm
parents: 55781
diff changeset
   168
            case Some(x) => x
da0513d95155 more formal Document.Blobs;
wenzelm
parents: 55781
diff changeset
   169
            case None =>
56208
06cc31dff138 clarifed module name;
wenzelm
parents: 55791
diff changeset
   170
              val bytes = PIDE.resources.file_content(buffer)
56746
d37a5d09a277 tuned signature;
wenzelm
parents: 56662
diff changeset
   171
              val chunk = Symbol.Text_Chunk(buffer.getSegment(0, buffer.getLength))
56473
5b5c750e9763 simplified Text.Chunk -- eliminated ooddities;
wenzelm
parents: 56469
diff changeset
   172
              _blob = Some((bytes, chunk))
5b5c750e9763 simplified Text.Chunk -- eliminated ooddities;
wenzelm
parents: 56469
diff changeset
   173
              (bytes, chunk)
55783
da0513d95155 more formal Document.Blobs;
wenzelm
parents: 55781
diff changeset
   174
          }
da0513d95155 more formal Document.Blobs;
wenzelm
parents: 55781
diff changeset
   175
        val changed = pending_edits.is_pending()
56473
5b5c750e9763 simplified Text.Chunk -- eliminated ooddities;
wenzelm
parents: 56469
diff changeset
   176
        Some(Document.Blob(bytes, chunk, changed))
54511
1fd24c96ce9b caching of blob;
wenzelm
parents: 54509
diff changeset
   177
      }
1fd24c96ce9b caching of blob;
wenzelm
parents: 54509
diff changeset
   178
    }
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
   179
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
   180
58543
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   181
  /* bibtex entries */
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   182
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   183
  private var _bibtex: Option[List[(String, Text.Offset)]] = None  // owned by GUI thread
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   184
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   185
  private def reset_bibtex(): Unit = GUI_Thread.require { _bibtex = None }
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   186
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   187
  def bibtex_entries(): List[(String, Text.Offset)] =
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   188
    GUI_Thread.require {
58546
72e2b2a609c4 clarified modules;
wenzelm
parents: 58543
diff changeset
   189
      if (Bibtex_JEdit.check(buffer)) {
58543
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   190
        _bibtex match {
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   191
          case Some(entries) => entries
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   192
          case None =>
58547
6080615b8b96 clarified modules;
wenzelm
parents: 58546
diff changeset
   193
            val entries = Bibtex_JEdit.parse_buffer_entries(buffer)
58543
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   194
            _bibtex = Some(entries)
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   195
            entries
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   196
        }
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   197
      }
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   198
      else Nil
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   199
    }
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   200
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   201
50363
2f8dc9e65401 tuned signature in accordance to document operations;
wenzelm
parents: 50344
diff changeset
   202
  /* edits */
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
   203
54461
6c360a6ade0e centralized management of pending buffer edits;
wenzelm
parents: 54441
diff changeset
   204
  def node_edits(
56335
8953d4cc060a store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents: 56314
diff changeset
   205
      clear: Boolean,
8953d4cc060a store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents: 56314
diff changeset
   206
      text_edits: List[Text.Edit],
8953d4cc060a store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents: 56314
diff changeset
   207
      perspective: Document.Node.Perspective_Text): List[Document.Edit_Text] =
57621
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   208
  {
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   209
    val edits: List[Document.Edit_Text] =
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   210
      get_blob() match {
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   211
        case None =>
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   212
          val header_edit = session.header_edit(node_name, node_header())
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   213
          if (clear)
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   214
            List(header_edit,
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   215
              node_name -> Document.Node.Clear(),
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   216
              node_name -> Document.Node.Edits(text_edits),
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   217
              node_name -> perspective)
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   218
          else
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   219
            List(header_edit,
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   220
              node_name -> Document.Node.Edits(text_edits),
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   221
              node_name -> perspective)
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   222
        case Some(blob) =>
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   223
          List(node_name -> Document.Node.Blob(blob),
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   224
            node_name -> Document.Node.Edits(text_edits))
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   225
      }
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   226
    edits.filterNot(_._2.is_void)
caa37976801f more frugal edits;
wenzelm
parents: 57615
diff changeset
   227
  }
50363
2f8dc9e65401 tuned signature in accordance to document operations;
wenzelm
parents: 50344
diff changeset
   228
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
   229
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
   230
  /* pending edits */
43648
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43644
diff changeset
   231
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
   232
  private object pending_edits
38224
809578d7f6af more explicit model of pending text edits;
wenzelm
parents: 38223
diff changeset
   233
  {
54461
6c360a6ade0e centralized management of pending buffer edits;
wenzelm
parents: 54441
diff changeset
   234
    private var pending_clear = false
38425
e467db701d78 moved Text_Edit to Text.Edit;
wenzelm
parents: 38417
diff changeset
   235
    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
   236
    private var last_perspective = Document.Node.no_perspective_text
44438
0fc38897248a early filtering of unchanged perspective;
wenzelm
parents: 44436
diff changeset
   237
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
   238
    def is_pending(): Boolean = synchronized { pending_clear || pending.nonEmpty }
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
   239
    def snapshot(): List[Text.Edit] = synchronized { pending.toList }
38224
809578d7f6af more explicit model of pending text edits;
wenzelm
parents: 38223
diff changeset
   240
61728
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   241
    def flushed_edits(hidden: Boolean, doc_blobs: Document.Blobs): List[Document.Edit_Text] =
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   242
      synchronized {
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   243
        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
   244
61728
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   245
        val clear = pending_clear
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   246
        val edits = snapshot()
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   247
        val (reparse, perspective) = node_perspective(hidden, doc_blobs)
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   248
        if (clear || reparse || edits.nonEmpty || last_perspective != perspective) {
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   249
          pending_clear = false
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   250
          pending.clear
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   251
          last_perspective = perspective
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   252
          node_edits(clear, edits, perspective)
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   253
        }
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   254
        else Nil
43648
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43644
diff changeset
   255
      }
38224
809578d7f6af more explicit model of pending text edits;
wenzelm
parents: 38223
diff changeset
   256
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
   257
    def edit(clear: Boolean, e: Text.Edit): Unit = synchronized
38224
809578d7f6af more explicit model of pending text edits;
wenzelm
parents: 38223
diff changeset
   258
    {
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
   259
      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
   260
54511
1fd24c96ce9b caching of blob;
wenzelm
parents: 54509
diff changeset
   261
      reset_blob()
58543
9c1389befa56 maintain Document_Model.bibtex_entries;
wenzelm
parents: 57883
diff changeset
   262
      reset_bibtex()
54511
1fd24c96ce9b caching of blob;
wenzelm
parents: 54509
diff changeset
   263
61538
bf4969660913 avoid highlighted area getting "stuck" after edit;
wenzelm
parents: 61192
diff changeset
   264
      for (doc_view <- PIDE.document_views(buffer))
bf4969660913 avoid highlighted area getting "stuck" after edit;
wenzelm
parents: 61192
diff changeset
   265
        doc_view.rich_text_area.active_reset()
bf4969660913 avoid highlighted area getting "stuck" after edit;
wenzelm
parents: 61192
diff changeset
   266
54461
6c360a6ade0e centralized management of pending buffer edits;
wenzelm
parents: 54441
diff changeset
   267
      if (clear) {
6c360a6ade0e centralized management of pending buffer edits;
wenzelm
parents: 54441
diff changeset
   268
        pending_clear = true
6c360a6ade0e centralized management of pending buffer edits;
wenzelm
parents: 54441
diff changeset
   269
        pending.clear
6c360a6ade0e centralized management of pending buffer edits;
wenzelm
parents: 54441
diff changeset
   270
      }
6c360a6ade0e centralized management of pending buffer edits;
wenzelm
parents: 54441
diff changeset
   271
      pending += e
6c360a6ade0e centralized management of pending buffer edits;
wenzelm
parents: 54441
diff changeset
   272
      PIDE.editor.invoke()
44436
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44385
diff changeset
   273
    }
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44385
diff changeset
   274
  }
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44385
diff changeset
   275
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
   276
  def is_stable(): Boolean = !pending_edits.is_pending();
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
   277
54464
wenzelm
parents: 54461
diff changeset
   278
  def snapshot(): Document.Snapshot =
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
   279
    session.snapshot(node_name, pending_edits.snapshot())
34731
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
   280
61728
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   281
  def flushed_edits(hidden: Boolean, doc_blobs: Document.Blobs): List[Document.Edit_Text] =
5f5ff1eab407 double flush to ensure persistent "state" output is reset;
wenzelm
parents: 61538
diff changeset
   282
    pending_edits.flushed_edits(hidden, doc_blobs)
34828
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   283
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   284
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   285
  /* buffer listener */
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   286
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   287
  private val buffer_listener: BufferListener = new BufferAdapter
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   288
  {
40478
4bae781b8f7c replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents: 40474
diff changeset
   289
    override def bufferLoaded(buffer: JEditBuffer)
4bae781b8f7c replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents: 40474
diff changeset
   290
    {
55791
5821b1937fa5 clarified init_models: simultaneous initialization of all document models, before flushing edits by regular means (via PIDE.editor.invoke) -- important for consolidated doc_blobs when determining initial edits;
wenzelm
parents: 55785
diff changeset
   291
      pending_edits.edit(true, Text.Edit.insert(0, JEdit_Lib.buffer_text(buffer)))
40478
4bae781b8f7c replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents: 40474
diff changeset
   292
    }
4bae781b8f7c replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents: 40474
diff changeset
   293
34828
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   294
    override def contentInserted(buffer: JEditBuffer,
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   295
      start_line: Int, offset: Int, num_lines: Int, length: Int)
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   296
    {
40478
4bae781b8f7c replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents: 40474
diff changeset
   297
      if (!buffer.isLoading)
54461
6c360a6ade0e centralized management of pending buffer edits;
wenzelm
parents: 54441
diff changeset
   298
        pending_edits.edit(false, Text.Edit.insert(offset, buffer.getText(offset, length)))
34828
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   299
    }
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   300
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   301
    override def preContentRemoved(buffer: JEditBuffer,
38426
2858ec7b6dd8 specific types Text.Offset and Text.Range;
wenzelm
parents: 38425
diff changeset
   302
      start_line: Int, offset: Int, num_lines: Int, removed_length: Int)
34828
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   303
    {
40478
4bae781b8f7c replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents: 40474
diff changeset
   304
      if (!buffer.isLoading)
54461
6c360a6ade0e centralized management of pending buffer edits;
wenzelm
parents: 54441
diff changeset
   305
        pending_edits.edit(false, Text.Edit.remove(offset, buffer.getText(offset, removed_length)))
34828
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   306
    }
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   307
  }
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   308
c2308b317244 misc tuning;
wenzelm
parents: 34827
diff changeset
   309
59078
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   310
  /* syntax */
37557
1ae272fd4082 refresh Isabelle token marker after buffer properties changed, e.g. when fold mode is switched;
wenzelm
parents: 37555
diff changeset
   311
59078
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   312
  def syntax_changed()
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   313
  {
61192
98eba31c51f8 tuned signature;
wenzelm
parents: 60933
diff changeset
   314
    JEdit_Lib.buffer_line_manager(buffer).setFirstInvalidLineContext(0)
59080
611914621edb added Untyped.method convenience (for *this* class only);
wenzelm
parents: 59079
diff changeset
   315
    for (text_area <- JEdit_Lib.jedit_text_areas(buffer))
611914621edb added Untyped.method convenience (for *this* class only);
wenzelm
parents: 59079
diff changeset
   316
      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
   317
        invoke(text_area)
62246
d9410066dbd5 more thorough syntax_changed: new commands need require new folds;
wenzelm
parents: 61728
diff changeset
   318
    buffer.invalidateCachedFoldLevels
59078
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   319
  }
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   320
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   321
  private def init_token_marker()
59077
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
   322
  {
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
   323
    Isabelle.buffer_token_marker(buffer) match {
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
   324
      case Some(marker) if marker != buffer.getTokenMarker =>
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
   325
        buffer.setTokenMarker(marker)
59078
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   326
        syntax_changed()
59077
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
   327
      case _ =>
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
   328
    }
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
   329
  }
7e0d3da6e6d8 node-specific syntax, with base_syntax as default;
wenzelm
parents: 59076
diff changeset
   330
59078
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   331
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   332
  /* activation */
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   333
43512
270ce5ff2086 clarified init/exit procedure;
wenzelm
parents: 43452
diff changeset
   334
  private def activate()
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   335
  {
55791
5821b1937fa5 clarified init_models: simultaneous initialization of all document models, before flushing edits by regular means (via PIDE.editor.invoke) -- important for consolidated doc_blobs when determining initial edits;
wenzelm
parents: 55785
diff changeset
   336
    pending_edits.edit(true, Text.Edit.insert(0, JEdit_Lib.buffer_text(buffer)))
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   337
    buffer.addBufferListener(buffer_listener)
59078
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   338
    init_token_marker()
34680
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   339
  }
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   340
43512
270ce5ff2086 clarified init/exit procedure;
wenzelm
parents: 43452
diff changeset
   341
  private def deactivate()
34680
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   342
  {
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   343
    buffer.removeBufferListener(buffer_listener)
59078
cf255dc2b48f more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents: 59077
diff changeset
   344
    init_token_marker()
34680
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   345
  }
34447
wenzelm
parents: 34446
diff changeset
   346
}