src/Tools/jEdit/src/jedit/document_model.scala
author wenzelm
Tue, 15 Dec 2009 20:44:59 +0100
changeset 34789 30528e68f774
parent 34788 3779c54a2d21
child 34808 e462572536e9
permissions -rw-r--r--
some explicit Swing_Thread guards;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34407
aad6834ba380 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     1
/*
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
     2
 * Document model connected to jEdit buffer
34407
aad6834ba380 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     3
 *
aad6834ba380 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     4
 * @author Fabian Immler, TU Munich
34447
wenzelm
parents: 34446
diff changeset
     5
 * @author Makarius
34407
aad6834ba380 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     6
 */
aad6834ba380 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     7
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
     8
package isabelle.jedit
34760
dc7f5e0d9d27 misc modernization of names;
wenzelm
parents: 34759
diff changeset
     9
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    10
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    11
import isabelle.proofdocument.{Change, Command, Edit, Insert, Remove, Proof_Document, Session}
34783
cb95d6bbf5f1 clarified BufferListener: use adapter, listen to contentInserted instead of preContentInserted;
wenzelm
parents: 34778
diff changeset
    12
34703
ff037c17332a minor tuning;
wenzelm
parents: 34696
diff changeset
    13
import scala.actors.Actor, Actor._
34693
3e995f100ad2 sealed Edit;
wenzelm
parents: 34685
diff changeset
    14
import scala.collection.mutable
34446
5c79f97ec1d1 superficial tuning;
wenzelm
parents: 34445
diff changeset
    15
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    16
import org.gjt.sp.jedit.Buffer
34783
cb95d6bbf5f1 clarified BufferListener: use adapter, listen to contentInserted instead of preContentInserted;
wenzelm
parents: 34778
diff changeset
    17
import org.gjt.sp.jedit.buffer.{BufferAdapter, BufferListener, JEditBuffer}
34649
70759ca6bb87 activation
immler@in.tum.de
parents: 34648
diff changeset
    18
import org.gjt.sp.jedit.syntax.{ModeProvider, SyntaxStyle}
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    19
34760
dc7f5e0d9d27 misc modernization of names;
wenzelm
parents: 34759
diff changeset
    20
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    21
object Document_Model
34588
e8ac8794971f superficial tuning;
wenzelm
parents: 34583
diff changeset
    22
{
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    23
  /* 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
    24
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    25
  private val key = "isabelle.document_model"
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    26
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    27
  def init(session: Session, buffer: Buffer): Document_Model =
34716
b8f2b44529fd tuned color (PG 4.0);
wenzelm
parents: 34712
diff changeset
    28
  {
34789
30528e68f774 some explicit Swing_Thread guards;
wenzelm
parents: 34788
diff changeset
    29
    Swing_Thread.assert()
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    30
    val model = new Document_Model(session, buffer)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    31
    buffer.setProperty(key, model)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    32
    model.activate()
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    33
    model
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
34788
3779c54a2d21 direct apply for Document_Model and Document_View;
wenzelm
parents: 34784
diff changeset
    36
  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
    37
  {
34789
30528e68f774 some explicit Swing_Thread guards;
wenzelm
parents: 34788
diff changeset
    38
    Swing_Thread.assert()
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    39
    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
    40
      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
    41
      case _ => None
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    42
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    43
  }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    44
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    45
  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
    46
  {
34789
30528e68f774 some explicit Swing_Thread guards;
wenzelm
parents: 34788
diff changeset
    47
    Swing_Thread.assert()
34788
3779c54a2d21 direct apply for Document_Model and Document_View;
wenzelm
parents: 34784
diff changeset
    48
    apply(buffer) match {
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    49
      case None => error("No document model for buffer: " + buffer)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    50
      case Some(model) =>
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    51
        model.deactivate()
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    52
        buffer.unsetProperty(key)
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34652
diff changeset
    53
    }
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    54
  }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    55
}
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    56
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    57
class Document_Model(val session: Session, val buffer: Buffer)
34588
e8ac8794971f superficial tuning;
wenzelm
parents: 34583
diff changeset
    58
{
34731
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    59
  /* changes vs. edits */
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    60
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34773
diff changeset
    61
  private val change_0 = new Change(Isabelle.session.document_0.id, None, Nil)  // FIXME !?
34731
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    62
  private var _changes = List(change_0)   // owned by Swing/AWT thread
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    63
  def changes = _changes
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    64
  private var current_change = change_0
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    65
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    66
  private val edits = new mutable.ListBuffer[Edit]   // owned by Swing thread
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    67
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    68
  private val edits_delay = Swing_Thread.delay_last(300) {
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    69
    if (!edits.isEmpty) {
34778
8eccd35e975e removed unused Session.prover_logic;
wenzelm
parents: 34777
diff changeset
    70
      val change = new Change(session.create_id(), Some(current_change), edits.toList)
34731
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    71
      _changes ::= change
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34773
diff changeset
    72
      session.input(change)
34731
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    73
      current_change = change
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    74
      edits.clear
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    75
    }
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    76
  }
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    77
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    78
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    79
  /* buffer listener */
34731
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    80
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    81
  private val buffer_listener: BufferListener = new BufferAdapter
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
    82
  {
34783
cb95d6bbf5f1 clarified BufferListener: use adapter, listen to contentInserted instead of preContentInserted;
wenzelm
parents: 34778
diff changeset
    83
    override def contentInserted(buffer: JEditBuffer,
34731
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    84
      start_line: Int, offset: Int, num_lines: Int, length: Int)
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    85
    {
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    86
      edits += Insert(offset, buffer.getText(offset, length))
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    87
      edits_delay()
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    88
    }
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    89
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    90
    override def preContentRemoved(buffer: JEditBuffer,
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    91
      start_line: Int, start: Int, num_lines: Int, removed_length: Int)
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    92
    {
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    93
      edits += Remove(start, buffer.getText(start, removed_length))
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    94
      edits_delay()
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    95
    }
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    96
  }
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    97
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    98
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
    99
  /* history of changes */
34660
e0561943bfc9 Change consisting of a list of Edits
immler@in.tum.de
parents: 34654
diff changeset
   100
34760
dc7f5e0d9d27 misc modernization of names;
wenzelm
parents: 34759
diff changeset
   101
  private def doc_or_pred(c: Change): Proof_Document =
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34773
diff changeset
   102
    session.document(c.id).getOrElse(doc_or_pred(c.parent.get))
34731
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
   103
34654
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   104
  def current_document() = doc_or_pred(current_change)
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   105
34731
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
   106
34654
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   107
  /* update to desired version */
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   108
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   109
  def set_version(goal: Change)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   110
  {
34654
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   111
    // changes in buffer must be ignored
34731
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
   112
    buffer.removeBufferListener(buffer_listener)
34654
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   113
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   114
    def apply(change: Change): Unit =
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   115
      change.edits.foreach {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   116
        case Insert(start, text) => buffer.insert(start, text)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   117
        case Remove(start, text) => buffer.remove(start, text.length)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   118
      }
34660
e0561943bfc9 Change consisting of a list of Edits
immler@in.tum.de
parents: 34654
diff changeset
   119
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   120
    def unapply(change: Change): Unit =
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   121
      change.edits.reverse.foreach {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   122
        case Insert(start, text) => buffer.remove(start, text.length)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   123
        case Remove(start, text) => buffer.insert(start, text)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   124
      }
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   125
34654
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   126
    // undo/redo changes
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   127
    val ancs_current = current_change.ancestors
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   128
    val ancs_goal = goal.ancestors
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   129
    val paired = ancs_current.reverse zip ancs_goal.reverse
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   130
    def last_common[A](xs: List[(A, A)]): Option[A] = {
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   131
      xs match {
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   132
        case (x, y) :: xs =>
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   133
          if (x == y)
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   134
            xs match {
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   135
              case (a, b) :: ys =>
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   136
                if (a == b) last_common(xs)
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   137
                else Some(x)
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   138
              case _ => Some(x)
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   139
            }
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   140
          else None
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   141
        case _ => None
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   142
      }
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   143
    }
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   144
    val common_anc = last_common(paired).get
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   145
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   146
    ancs_current.takeWhile(_ != common_anc) map unapply
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   147
    ancs_goal.takeWhile(_ != common_anc).reverse map apply
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   148
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   149
    current_change = goal
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   150
    // invoke repaint
34679
8be4cdbbe3a7 improved repainting
immler@in.tum.de
parents: 34673
diff changeset
   151
    buffer.propertiesChanged()
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   152
    // invalidate_all()  FIXME
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   153
    // overview.repaint()  FIXME
34654
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
   154
34703
ff037c17332a minor tuning;
wenzelm
parents: 34696
diff changeset
   155
    // track changes in buffer
34731
c0cb6bd10eec keep BufferListener and TextAreaExtension private;
wenzelm
parents: 34724
diff changeset
   156
    buffer.addBufferListener(buffer_listener)
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   157
  }
34446
5c79f97ec1d1 superficial tuning;
wenzelm
parents: 34445
diff changeset
   158
34693
3e995f100ad2 sealed Edit;
wenzelm
parents: 34685
diff changeset
   159
34680
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   160
  /* transforming offsets */
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   161
34760
dc7f5e0d9d27 misc modernization of names;
wenzelm
parents: 34759
diff changeset
   162
  private def changes_from(doc: Proof_Document): List[Edit] =
34718
39e3039645ae corrected order
immler@in.tum.de
parents: 34717
diff changeset
   163
    List.flatten(current_change.ancestors(_.id == doc.id).reverse.map(_.edits)) :::
39e3039645ae corrected order
immler@in.tum.de
parents: 34717
diff changeset
   164
      edits.toList
34680
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   165
34760
dc7f5e0d9d27 misc modernization of names;
wenzelm
parents: 34759
diff changeset
   166
  def from_current(doc: Proof_Document, offset: Int): Int =
34718
39e3039645ae corrected order
immler@in.tum.de
parents: 34717
diff changeset
   167
    (offset /: changes_from(doc).reverse) ((i, change) => change before i)
34680
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   168
34760
dc7f5e0d9d27 misc modernization of names;
wenzelm
parents: 34759
diff changeset
   169
  def to_current(doc: Proof_Document, offset: Int): Int =
34718
39e3039645ae corrected order
immler@in.tum.de
parents: 34717
diff changeset
   170
    (offset /: changes_from(doc)) ((i, change) => change after i)
34680
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   171
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   172
  def lines_of_command(cmd: Command): (Int, Int) =
34680
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   173
  {
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   174
    val document = current_document()
34681
74cc10b5ba51 fixed some issues with multiple active buffers
immler@in.tum.de
parents: 34680
diff changeset
   175
    (buffer.getLineOfOffset(to_current(document, cmd.start(document))),
74cc10b5ba51 fixed some issues with multiple active buffers
immler@in.tum.de
parents: 34680
diff changeset
   176
     buffer.getLineOfOffset(to_current(document, cmd.stop(document))))
34680
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   177
  }
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   178
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   179
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   180
  /* activation */
34680
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   181
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   182
  def activate()
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   183
  {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   184
    buffer.setTokenMarker(new Isabelle_Token_Marker(this))  // FIXME tune!?
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   185
    buffer.addBufferListener(buffer_listener)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   186
    buffer.propertiesChanged()
34680
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   187
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   188
    edits += Insert(0, buffer.getText(0, buffer.getLength))
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   189
    edits_delay()
34680
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   190
  }
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   191
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   192
  def deactivate()
34680
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   193
  {
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   194
    buffer.setTokenMarker(buffer.getMode.getTokenMarker)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34783
diff changeset
   195
    buffer.removeBufferListener(buffer_listener)
34680
1f1f6c95de64 clarified structure of TheoryView
immler@in.tum.de
parents: 34679
diff changeset
   196
  }
34447
wenzelm
parents: 34446
diff changeset
   197
}