src/Tools/jEdit/src/document_view.scala
author wenzelm
Wed Mar 14 15:37:51 2012 +0100 (2012-03-14)
changeset 46920 5f44c8bea84e
parent 46918 1752164d916b
child 46997 395b7277ed76
permissions -rw-r--r--
more explicit indication of swing thread context;
wenzelm@43282
     1
/*  Title:      Tools/jEdit/src/document_view.scala
wenzelm@36760
     2
    Author:     Fabian Immler, TU Munich
wenzelm@36760
     3
    Author:     Makarius
wenzelm@36760
     4
wenzelm@36760
     5
Document view connected to jEdit text area.
wenzelm@36760
     6
*/
wenzelm@34408
     7
immler@34403
     8
package isabelle.jedit
immler@34403
     9
wenzelm@34760
    10
wenzelm@36015
    11
import isabelle._
wenzelm@36015
    12
wenzelm@44379
    13
import scala.collection.mutable
wenzelm@45460
    14
import scala.collection.immutable.SortedMap
wenzelm@34784
    15
import scala.actors.Actor._
wenzelm@34784
    16
wenzelm@43520
    17
import java.lang.System
wenzelm@45744
    18
import java.text.BreakIterator
wenzelm@46572
    19
import java.awt.{Color, Graphics2D, Point}
wenzelm@46572
    20
import java.awt.event.{MouseMotionAdapter, MouseEvent,
wenzelm@39741
    21
  FocusAdapter, FocusEvent, WindowEvent, WindowAdapter}
wenzelm@46572
    22
import javax.swing.{Popup, PopupFactory, SwingUtilities, BorderFactory}
wenzelm@34784
    23
import javax.swing.event.{CaretListener, CaretEvent}
wenzelm@34734
    24
wenzelm@43404
    25
import org.gjt.sp.util.Log
wenzelm@43404
    26
wenzelm@42839
    27
import org.gjt.sp.jedit.{jEdit, OperatingSystem, Debug}
wenzelm@34709
    28
import org.gjt.sp.jedit.gui.RolloverButton
wenzelm@39176
    29
import org.gjt.sp.jedit.options.GutterOptionPane
wenzelm@44436
    30
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea, TextAreaExtension, TextAreaPainter,
wenzelm@44436
    31
  ScrollListener}
wenzelm@43369
    32
import org.gjt.sp.jedit.syntax.{SyntaxStyle}
wenzelm@34784
    33
wenzelm@34784
    34
wenzelm@34784
    35
object Document_View
wenzelm@34784
    36
{
wenzelm@34784
    37
  /* document view of text area */
wenzelm@34784
    38
wenzelm@34784
    39
  private val key = new Object
wenzelm@34784
    40
wenzelm@39741
    41
  def apply(text_area: JEditTextArea): Option[Document_View] =
wenzelm@34784
    42
  {
wenzelm@38223
    43
    Swing_Thread.require()
wenzelm@34784
    44
    text_area.getClientProperty(key) match {
wenzelm@34784
    45
      case doc_view: Document_View => Some(doc_view)
wenzelm@34784
    46
      case _ => None
wenzelm@34784
    47
    }
wenzelm@34784
    48
  }
wenzelm@34784
    49
wenzelm@39741
    50
  def exit(text_area: JEditTextArea)
wenzelm@34784
    51
  {
wenzelm@38223
    52
    Swing_Thread.require()
wenzelm@34788
    53
    apply(text_area) match {
wenzelm@39636
    54
      case None =>
wenzelm@34784
    55
      case Some(doc_view) =>
wenzelm@34784
    56
        doc_view.deactivate()
wenzelm@34784
    57
        text_area.putClientProperty(key, null)
wenzelm@34784
    58
    }
wenzelm@34784
    59
  }
wenzelm@43397
    60
wenzelm@43397
    61
  def init(model: Document_Model, text_area: JEditTextArea): Document_View =
wenzelm@43397
    62
  {
wenzelm@43397
    63
    exit(text_area)
wenzelm@43397
    64
    val doc_view = new Document_View(model, text_area)
wenzelm@43397
    65
    text_area.putClientProperty(key, doc_view)
wenzelm@43397
    66
    doc_view.activate()
wenzelm@43397
    67
    doc_view
wenzelm@43397
    68
  }
wenzelm@34784
    69
}
immler@34403
    70
wenzelm@34733
    71
wenzelm@43376
    72
class Document_View(val model: Document_Model, val text_area: JEditTextArea)
immler@34654
    73
{
wenzelm@34784
    74
  private val session = model.session
wenzelm@34784
    75
immler@34403
    76
wenzelm@43419
    77
  /* robust extension body */
wenzelm@43404
    78
wenzelm@43404
    79
  def robust_body[A](default: A)(body: => A): A =
wenzelm@43417
    80
  {
wenzelm@43417
    81
    try {
wenzelm@43417
    82
      Swing_Thread.require()
wenzelm@43417
    83
      if (model.buffer == text_area.getBuffer) body
wenzelm@43417
    84
      else {
wenzelm@43650
    85
        Log.log(Log.ERROR, this, ERROR("Inconsistent document model"))
wenzelm@43417
    86
        default
wenzelm@43404
    87
      }
wenzelm@43404
    88
    }
wenzelm@43417
    89
    catch { case t: Throwable => Log.log(Log.ERROR, this, t); default }
wenzelm@43417
    90
  }
wenzelm@43404
    91
wenzelm@43404
    92
wenzelm@44378
    93
  /* visible text range */
wenzelm@38881
    94
wenzelm@46815
    95
  // NB: TextArea.getScreenLineEndOffset of last line is beyond Buffer.getLength
wenzelm@38881
    96
  def proper_line_range(start: Text.Offset, end: Text.Offset): Text.Range =
wenzelm@46812
    97
    Text.Range(start, end min model.buffer.getLength)
wenzelm@38881
    98
wenzelm@46583
    99
  def visible_range(): Option[Text.Range] =
wenzelm@38881
   100
  {
wenzelm@46583
   101
    val n = text_area.getVisibleLines
wenzelm@46583
   102
    if (n > 0) {
wenzelm@46583
   103
      val start = text_area.getScreenLineStartOffset(0)
wenzelm@46583
   104
      val raw_end = text_area.getScreenLineEndOffset(n - 1)
wenzelm@46583
   105
      Some(proper_line_range(start, if (raw_end >= 0) raw_end else model.buffer.getLength))
wenzelm@46583
   106
    }
wenzelm@46583
   107
    else None
wenzelm@38881
   108
  }
wenzelm@38881
   109
wenzelm@44378
   110
  def invalidate_range(range: Text.Range)
wenzelm@39132
   111
  {
wenzelm@39132
   112
    text_area.invalidateLineRange(
wenzelm@39132
   113
      model.buffer.getLineOfOffset(range.start),
wenzelm@39132
   114
      model.buffer.getLineOfOffset(range.stop))
wenzelm@39132
   115
  }
wenzelm@39132
   116
wenzelm@38881
   117
wenzelm@44379
   118
  /* perspective */
wenzelm@44379
   119
wenzelm@44379
   120
  def perspective(): Text.Perspective =
wenzelm@44379
   121
  {
wenzelm@44379
   122
    Swing_Thread.require()
wenzelm@44776
   123
    val buffer_range = model.buffer_range()
wenzelm@44473
   124
    Text.Perspective(
wenzelm@44379
   125
      for {
wenzelm@44379
   126
        i <- 0 until text_area.getVisibleLines
wenzelm@44379
   127
        val start = text_area.getScreenLineStartOffset(i)
wenzelm@44379
   128
        val stop = text_area.getScreenLineEndOffset(i)
wenzelm@44379
   129
        if start >= 0 && stop >= 0
wenzelm@44583
   130
        val range <- buffer_range.try_restrict(Text.Range(start, stop))
wenzelm@44583
   131
        if !range.is_singularity
wenzelm@44379
   132
      }
wenzelm@44583
   133
      yield range)
wenzelm@44379
   134
  }
wenzelm@44379
   135
wenzelm@44437
   136
  private def update_perspective = new TextAreaExtension
wenzelm@44437
   137
  {
wenzelm@44437
   138
    override def paintScreenLineRange(gfx: Graphics2D,
wenzelm@44437
   139
      first_line: Int, last_line: Int, physical_lines: Array[Int],
wenzelm@44437
   140
      start: Array[Int], end: Array[Int], y: Int, line_height: Int)
wenzelm@44437
   141
    {
wenzelm@44437
   142
      model.update_perspective()
wenzelm@44437
   143
    }
wenzelm@44437
   144
  }
wenzelm@44437
   145
wenzelm@44379
   146
wenzelm@43419
   147
  /* snapshot */
wenzelm@43419
   148
wenzelm@43419
   149
  // owned by Swing thread
wenzelm@43419
   150
  @volatile private var was_outdated = false
wenzelm@43419
   151
  @volatile private var was_updated = false
wenzelm@43419
   152
wenzelm@43419
   153
  def update_snapshot(): Document.Snapshot =
wenzelm@43419
   154
  {
wenzelm@43419
   155
    Swing_Thread.require()
wenzelm@43419
   156
    val snapshot = model.snapshot()
wenzelm@43419
   157
    was_updated = was_outdated && !snapshot.is_outdated
wenzelm@43419
   158
    was_outdated = was_outdated || snapshot.is_outdated
wenzelm@43419
   159
    snapshot
wenzelm@43419
   160
  }
wenzelm@43419
   161
wenzelm@43419
   162
  def flush_snapshot(): (Boolean, Document.Snapshot) =
wenzelm@43419
   163
  {
wenzelm@43419
   164
    Swing_Thread.require()
wenzelm@43419
   165
    val snapshot = update_snapshot()
wenzelm@43419
   166
    val updated = was_updated
wenzelm@43419
   167
    if (updated) { was_outdated = false; was_updated = false }
wenzelm@43419
   168
    (updated, snapshot)
wenzelm@43419
   169
  }
wenzelm@43419
   170
wenzelm@43419
   171
wenzelm@39740
   172
  /* HTML popups */
wenzelm@39740
   173
wenzelm@39740
   174
  private var html_popup: Option[Popup] = None
wenzelm@34834
   175
wenzelm@39740
   176
  private def exit_popup() { html_popup.map(_.hide) }
wenzelm@38881
   177
wenzelm@39740
   178
  private val html_panel =
wenzelm@43661
   179
    new HTML_Panel(Isabelle.font_family(), scala.math.round(Isabelle.font_size()))
wenzelm@39741
   180
  html_panel.setBorder(BorderFactory.createLineBorder(Color.black))
wenzelm@38884
   181
wenzelm@39740
   182
  private def html_panel_resize()
wenzelm@39740
   183
  {
wenzelm@39740
   184
    Swing_Thread.now {
wenzelm@39740
   185
      html_panel.resize(Isabelle.font_family(), scala.math.round(Isabelle.font_size()))
wenzelm@39740
   186
    }
wenzelm@39740
   187
  }
wenzelm@38884
   188
wenzelm@39740
   189
  private def init_popup(snapshot: Document.Snapshot, x: Int, y: Int)
wenzelm@39740
   190
  {
wenzelm@39740
   191
    exit_popup()
wenzelm@40154
   192
/* FIXME broken
wenzelm@39740
   193
    val offset = text_area.xyToOffset(x, y)
wenzelm@39740
   194
    val p = new Point(x, y); SwingUtilities.convertPointToScreen(p, text_area.getPainter)
wenzelm@34784
   195
wenzelm@39740
   196
    // FIXME snapshot.cumulate
wenzelm@45665
   197
    snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Rendering.popup) match {
wenzelm@39740
   198
      case Text.Info(_, Some(msg)) #:: _ =>
wenzelm@39740
   199
        val popup = PopupFactory.getSharedInstance().getPopup(text_area, html_panel, p.x, p.y + 60)
wenzelm@39740
   200
        html_panel.render_sync(List(msg))
wenzelm@39742
   201
        Thread.sleep(10)  // FIXME !?
wenzelm@39740
   202
        popup.show
wenzelm@39740
   203
        html_popup = Some(popup)
wenzelm@39740
   204
      case _ =>
immler@34403
   205
    }
wenzelm@40154
   206
*/
immler@34678
   207
  }
immler@34403
   208
immler@34403
   209
wenzelm@39131
   210
  /* subexpression highlighting */
wenzelm@39131
   211
wenzelm@46205
   212
  @volatile private var _highlight_range: Option[Text.Info[Color]] = None
wenzelm@46205
   213
  def highlight_range(): Option[Text.Info[Color]] = _highlight_range
wenzelm@39740
   214
wenzelm@40338
   215
  private var control: Boolean = false
wenzelm@40338
   216
wenzelm@39740
   217
  private def exit_control()
wenzelm@39740
   218
  {
wenzelm@39740
   219
    exit_popup()
wenzelm@43381
   220
    _highlight_range = None
wenzelm@39740
   221
  }
wenzelm@39740
   222
wenzelm@39131
   223
  private val focus_listener = new FocusAdapter {
wenzelm@39742
   224
    override def focusLost(e: FocusEvent) {
wenzelm@43381
   225
      _highlight_range = None // FIXME exit_control !?
wenzelm@39742
   226
    }
wenzelm@39131
   227
  }
wenzelm@39131
   228
wenzelm@39741
   229
  private val window_listener = new WindowAdapter {
wenzelm@39741
   230
    override def windowIconified(e: WindowEvent) { exit_control() }
wenzelm@39742
   231
    override def windowDeactivated(e: WindowEvent) { exit_control() }
wenzelm@39741
   232
  }
wenzelm@39741
   233
wenzelm@39131
   234
  private val mouse_motion_listener = new MouseMotionAdapter {
wenzelm@39131
   235
    override def mouseMoved(e: MouseEvent) {
wenzelm@46920
   236
      Swing_Thread.assert()
wenzelm@46920
   237
wenzelm@40338
   238
      control = if (OperatingSystem.isMacOS()) e.isMetaDown else e.isControlDown
wenzelm@39740
   239
      val x = e.getX()
wenzelm@39740
   240
      val y = e.getY()
wenzelm@39740
   241
wenzelm@39740
   242
      if (!model.buffer.isLoaded) exit_control()
wenzelm@39132
   243
      else
wenzelm@46920
   244
        Isabelle.buffer_lock(model.buffer) {
wenzelm@43419
   245
          val snapshot = update_snapshot()
wenzelm@39740
   246
wenzelm@39740
   247
          if (control) init_popup(snapshot, x, y)
wenzelm@39740
   248
wenzelm@46205
   249
          for (Text.Info(range, _) <- _highlight_range) invalidate_range(range)
wenzelm@46205
   250
          _highlight_range =
wenzelm@46205
   251
            if (control) {
wenzelm@46205
   252
              val offset = text_area.xyToOffset(x, y)
wenzelm@46205
   253
              Isabelle_Rendering.subexp(snapshot, Text.Range(offset, offset + 1))
wenzelm@46205
   254
            }
wenzelm@46205
   255
            else None
wenzelm@46205
   256
          for (Text.Info(range, _) <- _highlight_range) invalidate_range(range)
wenzelm@39132
   257
        }
wenzelm@39131
   258
    }
wenzelm@39131
   259
  }
wenzelm@39131
   260
wenzelm@39131
   261
wenzelm@43381
   262
  /* text area painting */
wenzelm@39044
   263
wenzelm@43381
   264
  private val text_area_painter = new Text_Area_Painter(this)
wenzelm@39700
   265
wenzelm@43381
   266
  private val tooltip_painter = new TextAreaExtension
wenzelm@43381
   267
  {
wenzelm@34784
   268
    override def getToolTipText(x: Int, y: Int): String =
wenzelm@34784
   269
    {
wenzelm@43404
   270
      robust_body(null: String) {
wenzelm@43419
   271
        val snapshot = update_snapshot()
wenzelm@38845
   272
        val offset = text_area.xyToOffset(x, y)
wenzelm@45460
   273
        val range = Text.Range(offset, offset + 1)
wenzelm@46178
   274
        val tip =
wenzelm@46178
   275
          if (control) Isabelle_Rendering.tooltip(snapshot, range)
wenzelm@46178
   276
          else Isabelle_Rendering.tooltip_message(snapshot, range)
wenzelm@46178
   277
        tip.map(Isabelle.tooltip(_)) getOrElse null
wenzelm@34784
   278
      }
wenzelm@34734
   279
    }
immler@34678
   280
  }
immler@34513
   281
wenzelm@42825
   282
  private val gutter_painter = new TextAreaExtension
wenzelm@39175
   283
  {
wenzelm@39175
   284
    override def paintScreenLineRange(gfx: Graphics2D,
wenzelm@39175
   285
      first_line: Int, last_line: Int, physical_lines: Array[Int],
wenzelm@39175
   286
      start: Array[Int], end: Array[Int], y: Int, line_height: Int)
wenzelm@39175
   287
    {
wenzelm@43404
   288
      robust_body(()) {
wenzelm@46920
   289
        Swing_Thread.assert()
wenzelm@46920
   290
wenzelm@43404
   291
        val gutter = text_area.getGutter
wenzelm@43404
   292
        val width = GutterOptionPane.getSelectionAreaWidth
wenzelm@43404
   293
        val border_width = jEdit.getIntegerProperty("view.gutter.borderWidth", 3)
wenzelm@43404
   294
        val FOLD_MARKER_SIZE = 12
wenzelm@43419
   295
wenzelm@43404
   296
        if (gutter.isSelectionAreaEnabled && !gutter.isExpanded && width >= 12 && line_height >= 12) {
wenzelm@46920
   297
          Isabelle.buffer_lock(model.buffer) {
wenzelm@43419
   298
            val snapshot = update_snapshot()
wenzelm@43404
   299
            for (i <- 0 until physical_lines.length) {
wenzelm@43404
   300
              if (physical_lines(i) != -1) {
wenzelm@43404
   301
                val line_range = proper_line_range(start(i), end(i))
wenzelm@43419
   302
wenzelm@43404
   303
                // gutter icons
wenzelm@46178
   304
                Isabelle_Rendering.gutter_message(snapshot, line_range) match {
wenzelm@46178
   305
                  case Some(icon) =>
wenzelm@46227
   306
                    val x0 = (FOLD_MARKER_SIZE + width - border_width - icon.getIconWidth) max 10
wenzelm@46227
   307
                    val y0 = y + i * line_height + (((line_height - icon.getIconHeight) / 2) max 0)
wenzelm@46227
   308
                    icon.paintIcon(gutter, gfx, x0, y0)
wenzelm@46178
   309
                  case None =>
wenzelm@43404
   310
                }
wenzelm@39175
   311
              }
wenzelm@39175
   312
            }
wenzelm@39175
   313
          }
wenzelm@39175
   314
        }
wenzelm@39175
   315
      }
wenzelm@39175
   316
    }
wenzelm@39175
   317
  }
wenzelm@39175
   318
wenzelm@39175
   319
wenzelm@43448
   320
  /* caret range */
wenzelm@43448
   321
wenzelm@43448
   322
  def caret_range(): Text.Range =
wenzelm@46229
   323
    Isabelle.buffer_lock(model.buffer) {
wenzelm@46229
   324
      def text(i: Text.Offset): Char = model.buffer.getText(i, 1).charAt(0)
wenzelm@46229
   325
      val caret = text_area.getCaretPosition
wenzelm@46229
   326
      try {
wenzelm@46229
   327
        val c = text(caret)
wenzelm@46229
   328
        if (Character.isHighSurrogate(c) && Character.isLowSurrogate(text(caret + 1)))
wenzelm@46229
   329
          Text.Range(caret, caret + 2)
wenzelm@46229
   330
        else if (Character.isLowSurrogate(c) && Character.isHighSurrogate(text(caret - 1)))
wenzelm@46229
   331
          Text.Range(caret - 1, caret + 1)
wenzelm@46229
   332
        else Text.Range(caret, caret + 1)
wenzelm@46229
   333
      }
wenzelm@46229
   334
      catch { case _: ArrayIndexOutOfBoundsException => Text.Range(caret, caret + 1) }
wenzelm@43448
   335
    }
wenzelm@43448
   336
wenzelm@43448
   337
wenzelm@37129
   338
  /* caret handling */
wenzelm@34810
   339
wenzelm@37849
   340
  def selected_command(): Option[Command] =
wenzelm@38223
   341
  {
wenzelm@38223
   342
    Swing_Thread.require()
wenzelm@46814
   343
    update_snapshot().node.command_at(text_area.getCaretPosition).map(_._1)
wenzelm@38223
   344
  }
wenzelm@34810
   345
wenzelm@46740
   346
  private val delay_caret_update =
wenzelm@46740
   347
    Swing_Thread.delay_last(session.input_delay) {
wenzelm@44805
   348
      session.caret_focus.event(Session.Caret_Focus)
wenzelm@34810
   349
    }
wenzelm@46740
   350
wenzelm@46740
   351
  private val caret_listener = new CaretListener {
wenzelm@46740
   352
    override def caretUpdate(e: CaretEvent) { delay_caret_update(true) }
wenzelm@34810
   353
  }
wenzelm@34810
   354
wenzelm@34810
   355
wenzelm@46572
   356
  /* text status overview left of scrollbar */
wenzelm@34784
   357
wenzelm@46572
   358
  private val overview = new Text_Overview(this)
wenzelm@46572
   359
  {
wenzelm@46571
   360
    val delay_repaint =
wenzelm@46571
   361
      Swing_Thread.delay_first(Isabelle.session.update_delay) { repaint() }
wenzelm@34784
   362
  }
immler@34403
   363
wenzelm@34784
   364
wenzelm@39740
   365
  /* main actor */
wenzelm@39740
   366
wenzelm@39740
   367
  private val main_actor = actor {
wenzelm@39740
   368
    loop {
wenzelm@39740
   369
      react {
wenzelm@44608
   370
        case changed: Session.Commands_Changed =>
wenzelm@39740
   371
          val buffer = model.buffer
wenzelm@46918
   372
          Swing_Thread.later {
wenzelm@46918
   373
            Isabelle.buffer_lock(buffer) {
wenzelm@46918
   374
              if (model.buffer == text_area.getBuffer) {
wenzelm@46918
   375
                val (updated, snapshot) = flush_snapshot()
wenzelm@39740
   376
wenzelm@46918
   377
                if (updated ||
wenzelm@46918
   378
                    (changed.nodes.contains(model.name) &&
wenzelm@46918
   379
                     changed.commands.exists(snapshot.node.commands.contains)))
wenzelm@46918
   380
                  overview.delay_repaint(true)
wenzelm@39740
   381
wenzelm@46918
   382
                visible_range() match {
wenzelm@46918
   383
                  case Some(visible) =>
wenzelm@46918
   384
                    if (updated) invalidate_range(visible)
wenzelm@46918
   385
                    else {
wenzelm@46918
   386
                      val visible_cmds =
wenzelm@46918
   387
                        snapshot.node.command_range(snapshot.revert(visible)).map(_._1)
wenzelm@46918
   388
                      if (visible_cmds.exists(changed.commands)) {
wenzelm@46918
   389
                        for {
wenzelm@46918
   390
                          line <- 0 until text_area.getVisibleLines
wenzelm@46918
   391
                          val start = text_area.getScreenLineStartOffset(line) if start >= 0
wenzelm@46918
   392
                          val end = text_area.getScreenLineEndOffset(line) if end >= 0
wenzelm@46918
   393
                          val range = proper_line_range(start, end)
wenzelm@46918
   394
                          val line_cmds = snapshot.node.command_range(snapshot.revert(range)).map(_._1)
wenzelm@46918
   395
                          if line_cmds.exists(changed.commands)
wenzelm@46918
   396
                        } text_area.invalidateScreenLineRange(line, line)
wenzelm@46918
   397
                      }
wenzelm@46918
   398
                    }
wenzelm@46918
   399
                  case None =>
wenzelm@46583
   400
                }
wenzelm@46918
   401
              }
wenzelm@39740
   402
            }
wenzelm@39740
   403
          }
wenzelm@39740
   404
wenzelm@39740
   405
        case Session.Global_Settings => html_panel_resize()
wenzelm@39740
   406
wenzelm@39740
   407
        case bad => System.err.println("command_change_actor: ignoring bad message " + bad)
wenzelm@39740
   408
      }
wenzelm@39740
   409
    }
wenzelm@39740
   410
  }
wenzelm@39740
   411
wenzelm@39740
   412
wenzelm@34784
   413
  /* activation */
wenzelm@34784
   414
wenzelm@34808
   415
  private def activate()
wenzelm@34784
   416
  {
wenzelm@42825
   417
    val painter = text_area.getPainter
wenzelm@44437
   418
    painter.addExtension(TextAreaPainter.LOWEST_LAYER, update_perspective)
wenzelm@43387
   419
    painter.addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, tooltip_painter)
wenzelm@43381
   420
    text_area_painter.activate()
wenzelm@42825
   421
    text_area.getGutter.addExtension(gutter_painter)
wenzelm@39131
   422
    text_area.addFocusListener(focus_listener)
wenzelm@39741
   423
    text_area.getView.addWindowListener(window_listener)
wenzelm@42825
   424
    painter.addMouseMotionListener(mouse_motion_listener)
wenzelm@34810
   425
    text_area.addCaretListener(caret_listener)
wenzelm@34810
   426
    text_area.addLeftOfScrollBar(overview)
wenzelm@39740
   427
    session.commands_changed += main_actor
wenzelm@39740
   428
    session.global_settings += main_actor
wenzelm@34784
   429
  }
wenzelm@34784
   430
wenzelm@34808
   431
  private def deactivate()
wenzelm@34784
   432
  {
wenzelm@42825
   433
    val painter = text_area.getPainter
wenzelm@39740
   434
    session.commands_changed -= main_actor
wenzelm@39740
   435
    session.global_settings -= main_actor
wenzelm@39131
   436
    text_area.removeFocusListener(focus_listener)
wenzelm@39741
   437
    text_area.getView.removeWindowListener(window_listener)
wenzelm@42825
   438
    painter.removeMouseMotionListener(mouse_motion_listener)
wenzelm@46740
   439
    text_area.removeCaretListener(caret_listener); delay_caret_update(false)
wenzelm@46740
   440
    text_area.removeLeftOfScrollBar(overview); overview.delay_repaint(false)
wenzelm@42825
   441
    text_area.getGutter.removeExtension(gutter_painter)
wenzelm@43381
   442
    text_area_painter.deactivate()
wenzelm@43381
   443
    painter.removeExtension(tooltip_painter)
wenzelm@44437
   444
    painter.removeExtension(update_perspective)
wenzelm@39740
   445
    exit_popup()
wenzelm@34784
   446
  }
wenzelm@42825
   447
}