src/Tools/jEdit/src/document_view.scala
changeset 43282 5d294220ca43
parent 42839 19df8385f38d
child 43369 4c86b3405010
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Tools/jEdit/src/document_view.scala	Wed Jun 08 17:42:07 2011 +0200
     1.3 @@ -0,0 +1,587 @@
     1.4 +/*  Title:      Tools/jEdit/src/document_view.scala
     1.5 +    Author:     Fabian Immler, TU Munich
     1.6 +    Author:     Makarius
     1.7 +
     1.8 +Document view connected to jEdit text area.
     1.9 +*/
    1.10 +
    1.11 +package isabelle.jedit
    1.12 +
    1.13 +
    1.14 +import isabelle._
    1.15 +
    1.16 +import scala.actors.Actor._
    1.17 +
    1.18 +import java.awt.{BorderLayout, Graphics, Color, Dimension, Graphics2D, Point}
    1.19 +import java.awt.event.{MouseAdapter, MouseMotionAdapter, MouseEvent,
    1.20 +  FocusAdapter, FocusEvent, WindowEvent, WindowAdapter}
    1.21 +import javax.swing.{JPanel, ToolTipManager, Popup, PopupFactory, SwingUtilities, BorderFactory}
    1.22 +import javax.swing.event.{CaretListener, CaretEvent}
    1.23 +import java.util.ArrayList
    1.24 +
    1.25 +import org.gjt.sp.jedit.{jEdit, OperatingSystem, Debug}
    1.26 +import org.gjt.sp.jedit.gui.RolloverButton
    1.27 +import org.gjt.sp.jedit.options.GutterOptionPane
    1.28 +import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea, TextAreaExtension, TextAreaPainter}
    1.29 +import org.gjt.sp.jedit.syntax.{SyntaxStyle, DisplayTokenHandler, Chunk, Token}
    1.30 +
    1.31 +
    1.32 +object Document_View
    1.33 +{
    1.34 +  /* document view of text area */
    1.35 +
    1.36 +  private val key = new Object
    1.37 +
    1.38 +  def init(model: Document_Model, text_area: JEditTextArea): Document_View =
    1.39 +  {
    1.40 +    Swing_Thread.require()
    1.41 +    val doc_view = new Document_View(model, text_area)
    1.42 +    text_area.putClientProperty(key, doc_view)
    1.43 +    doc_view.activate()
    1.44 +    doc_view
    1.45 +  }
    1.46 +
    1.47 +  def apply(text_area: JEditTextArea): Option[Document_View] =
    1.48 +  {
    1.49 +    Swing_Thread.require()
    1.50 +    text_area.getClientProperty(key) match {
    1.51 +      case doc_view: Document_View => Some(doc_view)
    1.52 +      case _ => None
    1.53 +    }
    1.54 +  }
    1.55 +
    1.56 +  def exit(text_area: JEditTextArea)
    1.57 +  {
    1.58 +    Swing_Thread.require()
    1.59 +    apply(text_area) match {
    1.60 +      case None =>
    1.61 +      case Some(doc_view) =>
    1.62 +        doc_view.deactivate()
    1.63 +        text_area.putClientProperty(key, null)
    1.64 +    }
    1.65 +  }
    1.66 +}
    1.67 +
    1.68 +
    1.69 +class Document_View(val model: Document_Model, text_area: JEditTextArea)
    1.70 +{
    1.71 +  private val session = model.session
    1.72 +
    1.73 +
    1.74 +  /** token handling **/
    1.75 +
    1.76 +  /* extended token styles */
    1.77 +
    1.78 +  private var styles: Array[SyntaxStyle] = null  // owned by Swing thread
    1.79 +
    1.80 +  def extend_styles()
    1.81 +  {
    1.82 +    Swing_Thread.require()
    1.83 +    styles = Document_Model.Token_Markup.extend_styles(text_area.getPainter.getStyles)
    1.84 +  }
    1.85 +  extend_styles()
    1.86 +
    1.87 +  def set_styles()
    1.88 +  {
    1.89 +    Swing_Thread.require()
    1.90 +    text_area.getPainter.setStyles(styles)
    1.91 +  }
    1.92 +
    1.93 +
    1.94 +  /* wrap_margin -- cf. org.gjt.sp.jedit.textarea.TextArea.propertiesChanged */
    1.95 +
    1.96 +  def wrap_margin(): Int =
    1.97 +  {
    1.98 +    val buffer = text_area.getBuffer
    1.99 +    val painter = text_area.getPainter
   1.100 +    val font = painter.getFont
   1.101 +    val font_context = painter.getFontRenderContext
   1.102 +
   1.103 +    val soft_wrap = buffer.getStringProperty("wrap") == "soft"
   1.104 +    val max = buffer.getIntegerProperty("maxLineLen", 0)
   1.105 +
   1.106 +    if (max > 0) font.getStringBounds(" " * max, font_context).getWidth.toInt
   1.107 +    else if (soft_wrap)
   1.108 +      painter.getWidth - (font.getStringBounds(" ", font_context).getWidth.round.toInt) * 3
   1.109 +    else 0
   1.110 +  }
   1.111 +
   1.112 +
   1.113 +  /* chunks */
   1.114 +
   1.115 +  def line_chunks(physical_lines: Set[Int]): Map[Text.Offset, Chunk] =
   1.116 +  {
   1.117 +    import scala.collection.JavaConversions._
   1.118 +
   1.119 +    val buffer = text_area.getBuffer
   1.120 +    val painter = text_area.getPainter
   1.121 +    val margin = wrap_margin().toFloat
   1.122 +
   1.123 +    val out = new ArrayList[Chunk]
   1.124 +    val handler = new DisplayTokenHandler
   1.125 +
   1.126 +    var result = Map[Text.Offset, Chunk]()
   1.127 +    for (line <- physical_lines) {
   1.128 +      out.clear
   1.129 +      handler.init(painter.getStyles, painter.getFontRenderContext, painter, out, margin)
   1.130 +      buffer.markTokens(line, handler)
   1.131 +
   1.132 +      val line_start = buffer.getLineStartOffset(line)
   1.133 +      for (chunk <- handler.getChunkList.iterator)
   1.134 +        result += (line_start + chunk.offset -> chunk)
   1.135 +    }
   1.136 +    result
   1.137 +  }
   1.138 +
   1.139 +
   1.140 +  /* visible line ranges */
   1.141 +
   1.142 +  // simplify slightly odd result of TextArea.getScreenLineEndOffset etc.
   1.143 +  // NB: jEdit already normalizes \r\n and \r to \n
   1.144 +  def proper_line_range(start: Text.Offset, end: Text.Offset): Text.Range =
   1.145 +  {
   1.146 +    val stop = if (start < end) end - 1 else end min model.buffer.getLength
   1.147 +    Text.Range(start, stop)
   1.148 +  }
   1.149 +
   1.150 +  def screen_lines_range(): Text.Range =
   1.151 +  {
   1.152 +    val start = text_area.getScreenLineStartOffset(0)
   1.153 +    val raw_end = text_area.getScreenLineEndOffset(text_area.getVisibleLines - 1 max 0)
   1.154 +    proper_line_range(start, if (raw_end >= 0) raw_end else model.buffer.getLength)
   1.155 +  }
   1.156 +
   1.157 +  def invalidate_line_range(range: Text.Range)
   1.158 +  {
   1.159 +    text_area.invalidateLineRange(
   1.160 +      model.buffer.getLineOfOffset(range.start),
   1.161 +      model.buffer.getLineOfOffset(range.stop))
   1.162 +  }
   1.163 +
   1.164 +
   1.165 +  /* HTML popups */
   1.166 +
   1.167 +  private var html_popup: Option[Popup] = None
   1.168 +
   1.169 +  private def exit_popup() { html_popup.map(_.hide) }
   1.170 +
   1.171 +  private val html_panel =
   1.172 +    new HTML_Panel(Isabelle.system, Isabelle.font_family(), scala.math.round(Isabelle.font_size()))
   1.173 +  html_panel.setBorder(BorderFactory.createLineBorder(Color.black))
   1.174 +
   1.175 +  private def html_panel_resize()
   1.176 +  {
   1.177 +    Swing_Thread.now {
   1.178 +      html_panel.resize(Isabelle.font_family(), scala.math.round(Isabelle.font_size()))
   1.179 +    }
   1.180 +  }
   1.181 +
   1.182 +  private def init_popup(snapshot: Document.Snapshot, x: Int, y: Int)
   1.183 +  {
   1.184 +    exit_popup()
   1.185 +/* FIXME broken
   1.186 +    val offset = text_area.xyToOffset(x, y)
   1.187 +    val p = new Point(x, y); SwingUtilities.convertPointToScreen(p, text_area.getPainter)
   1.188 +
   1.189 +    // FIXME snapshot.cumulate
   1.190 +    snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Markup.popup) match {
   1.191 +      case Text.Info(_, Some(msg)) #:: _ =>
   1.192 +        val popup = PopupFactory.getSharedInstance().getPopup(text_area, html_panel, p.x, p.y + 60)
   1.193 +        html_panel.render_sync(List(msg))
   1.194 +        Thread.sleep(10)  // FIXME !?
   1.195 +        popup.show
   1.196 +        html_popup = Some(popup)
   1.197 +      case _ =>
   1.198 +    }
   1.199 +*/
   1.200 +  }
   1.201 +
   1.202 +
   1.203 +  /* subexpression highlighting */
   1.204 +
   1.205 +  private def subexp_range(snapshot: Document.Snapshot, x: Int, y: Int)
   1.206 +    : Option[(Text.Range, Color)] =
   1.207 +  {
   1.208 +    val offset = text_area.xyToOffset(x, y)
   1.209 +    snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Markup.subexp) match {
   1.210 +      case Text.Info(_, Some((range, color))) #:: _ => Some((snapshot.convert(range), color))
   1.211 +      case _ => None
   1.212 +    }
   1.213 +  }
   1.214 +
   1.215 +  private var highlight_range: Option[(Text.Range, Color)] = None
   1.216 +
   1.217 +
   1.218 +  /* CONTROL-mouse management */
   1.219 +
   1.220 +  private var control: Boolean = false
   1.221 +
   1.222 +  private def exit_control()
   1.223 +  {
   1.224 +    exit_popup()
   1.225 +    highlight_range = None
   1.226 +  }
   1.227 +
   1.228 +  private val focus_listener = new FocusAdapter {
   1.229 +    override def focusLost(e: FocusEvent) {
   1.230 +      highlight_range = None // FIXME exit_control !?
   1.231 +    }
   1.232 +  }
   1.233 +
   1.234 +  private val window_listener = new WindowAdapter {
   1.235 +    override def windowIconified(e: WindowEvent) { exit_control() }
   1.236 +    override def windowDeactivated(e: WindowEvent) { exit_control() }
   1.237 +  }
   1.238 +
   1.239 +  private val mouse_motion_listener = new MouseMotionAdapter {
   1.240 +    override def mouseMoved(e: MouseEvent) {
   1.241 +      control = if (OperatingSystem.isMacOS()) e.isMetaDown else e.isControlDown
   1.242 +      val x = e.getX()
   1.243 +      val y = e.getY()
   1.244 +
   1.245 +      if (!model.buffer.isLoaded) exit_control()
   1.246 +      else
   1.247 +        Isabelle.swing_buffer_lock(model.buffer) {
   1.248 +          val snapshot = model.snapshot
   1.249 +
   1.250 +          if (control) init_popup(snapshot, x, y)
   1.251 +
   1.252 +          highlight_range map { case (range, _) => invalidate_line_range(range) }
   1.253 +          highlight_range = if (control) subexp_range(snapshot, x, y) else None
   1.254 +          highlight_range map { case (range, _) => invalidate_line_range(range) }
   1.255 +        }
   1.256 +    }
   1.257 +  }
   1.258 +
   1.259 +
   1.260 +  /* TextArea painters */
   1.261 +
   1.262 +  private val background_painter = new TextAreaExtension
   1.263 +  {
   1.264 +    override def paintScreenLineRange(gfx: Graphics2D,
   1.265 +      first_line: Int, last_line: Int, physical_lines: Array[Int],
   1.266 +      start: Array[Int], end: Array[Int], y: Int, line_height: Int)
   1.267 +    {
   1.268 +      Isabelle.swing_buffer_lock(model.buffer) {
   1.269 +        val snapshot = model.snapshot()
   1.270 +        val ascent = text_area.getPainter.getFontMetrics.getAscent
   1.271 +
   1.272 +        for (i <- 0 until physical_lines.length) {
   1.273 +          if (physical_lines(i) != -1) {
   1.274 +            val line_range = proper_line_range(start(i), end(i))
   1.275 +
   1.276 +            // background color: status
   1.277 +            val cmds = snapshot.node.command_range(snapshot.revert(line_range))
   1.278 +            for {
   1.279 +              (command, command_start) <- cmds if !command.is_ignored
   1.280 +              val range = line_range.restrict(snapshot.convert(command.range + command_start))
   1.281 +              r <- Isabelle.gfx_range(text_area, range)
   1.282 +              color <- Isabelle_Markup.status_color(snapshot, command)
   1.283 +            } {
   1.284 +              gfx.setColor(color)
   1.285 +              gfx.fillRect(r.x, y + i * line_height, r.length, line_height)
   1.286 +            }
   1.287 +
   1.288 +            // background color (1): markup
   1.289 +            for {
   1.290 +              Text.Info(range, Some(color)) <-
   1.291 +                snapshot.select_markup(line_range)(Isabelle_Markup.background1).iterator
   1.292 +              r <- Isabelle.gfx_range(text_area, range)
   1.293 +            } {
   1.294 +              gfx.setColor(color)
   1.295 +              gfx.fillRect(r.x, y + i * line_height, r.length, line_height)
   1.296 +            }
   1.297 +
   1.298 +            // background color (2): markup
   1.299 +            for {
   1.300 +              Text.Info(range, Some(color)) <-
   1.301 +                snapshot.select_markup(line_range)(Isabelle_Markup.background2).iterator
   1.302 +              r <- Isabelle.gfx_range(text_area, range)
   1.303 +            } {
   1.304 +              gfx.setColor(color)
   1.305 +              gfx.fillRect(r.x + 2, y + i * line_height + 2, r.length - 4, line_height - 4)
   1.306 +            }
   1.307 +
   1.308 +            // sub-expression highlighting -- potentially from other snapshot
   1.309 +            highlight_range match {
   1.310 +              case Some((range, color)) if line_range.overlaps(range) =>
   1.311 +                Isabelle.gfx_range(text_area, line_range.restrict(range)) match {
   1.312 +                  case None =>
   1.313 +                  case Some(r) =>
   1.314 +                    gfx.setColor(color)
   1.315 +                    gfx.drawRect(r.x, y + i * line_height, r.length - 1, line_height - 1)
   1.316 +                }
   1.317 +              case _ =>
   1.318 +            }
   1.319 +
   1.320 +            // squiggly underline
   1.321 +            for {
   1.322 +              Text.Info(range, Some(color)) <-
   1.323 +                snapshot.select_markup(line_range)(Isabelle_Markup.message).iterator
   1.324 +              r <- Isabelle.gfx_range(text_area, range)
   1.325 +            } {
   1.326 +              gfx.setColor(color)
   1.327 +              val x0 = (r.x / 2) * 2
   1.328 +              val y0 = r.y + ascent + 1
   1.329 +              for (x1 <- Range(x0, x0 + r.length, 2)) {
   1.330 +                val y1 = if (x1 % 4 < 2) y0 else y0 + 1
   1.331 +                gfx.drawLine(x1, y1, x1 + 1, y1)
   1.332 +              }
   1.333 +            }
   1.334 +          }
   1.335 +        }
   1.336 +      }
   1.337 +    }
   1.338 +
   1.339 +    override def getToolTipText(x: Int, y: Int): String =
   1.340 +    {
   1.341 +      Isabelle.swing_buffer_lock(model.buffer) {
   1.342 +        val snapshot = model.snapshot()
   1.343 +        val offset = text_area.xyToOffset(x, y)
   1.344 +        if (control) {
   1.345 +          snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Markup.tooltip) match
   1.346 +          {
   1.347 +            case Text.Info(_, Some(text)) #:: _ => Isabelle.tooltip(text)
   1.348 +            case _ => null
   1.349 +          }
   1.350 +        }
   1.351 +        else {
   1.352 +          // FIXME snapshot.cumulate
   1.353 +          snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Markup.popup) match
   1.354 +          {
   1.355 +            case Text.Info(_, Some(text)) #:: _ => Isabelle.tooltip(text)
   1.356 +            case _ => null
   1.357 +          }
   1.358 +        }
   1.359 +      }
   1.360 +    }
   1.361 +  }
   1.362 +
   1.363 +  var use_text_painter = false
   1.364 +
   1.365 +  private val text_painter = new TextAreaExtension
   1.366 +  {
   1.367 +    override def paintScreenLineRange(gfx: Graphics2D,
   1.368 +      first_line: Int, last_line: Int, physical_lines: Array[Int],
   1.369 +      start: Array[Int], end: Array[Int], y: Int, line_height: Int)
   1.370 +    {
   1.371 +      if (use_text_painter) {
   1.372 +        Isabelle.swing_buffer_lock(model.buffer) {
   1.373 +          val painter = text_area.getPainter
   1.374 +          val fm = painter.getFontMetrics
   1.375 +
   1.376 +          val all_chunks = line_chunks(Set[Int]() ++ physical_lines.iterator.filter(i => i != -1))
   1.377 +
   1.378 +          val x0 = text_area.getHorizontalOffset
   1.379 +          var y0 = y + fm.getHeight - (fm.getLeading + 1) - fm.getDescent
   1.380 +          for (i <- 0 until physical_lines.length) {
   1.381 +            if (physical_lines(i) != -1) {
   1.382 +              all_chunks.get(start(i)) match {
   1.383 +                case Some(chunk) =>
   1.384 +                  Chunk.paintChunkList(chunk, gfx, x0, y0, !Debug.DISABLE_GLYPH_VECTOR)
   1.385 +                case None =>
   1.386 +              }
   1.387 +            }
   1.388 +            y0 += line_height
   1.389 +          }
   1.390 +        }
   1.391 +      }
   1.392 +    }
   1.393 +  }
   1.394 +
   1.395 +  private val gutter_painter = new TextAreaExtension
   1.396 +  {
   1.397 +    override def paintScreenLineRange(gfx: Graphics2D,
   1.398 +      first_line: Int, last_line: Int, physical_lines: Array[Int],
   1.399 +      start: Array[Int], end: Array[Int], y: Int, line_height: Int)
   1.400 +    {
   1.401 +      val gutter = text_area.getGutter
   1.402 +      val width = GutterOptionPane.getSelectionAreaWidth
   1.403 +      val border_width = jEdit.getIntegerProperty("view.gutter.borderWidth", 3)
   1.404 +      val FOLD_MARKER_SIZE = 12
   1.405 +
   1.406 +      if (gutter.isSelectionAreaEnabled && !gutter.isExpanded && width >= 12 && line_height >= 12) {
   1.407 +        Isabelle.swing_buffer_lock(model.buffer) {
   1.408 +          val snapshot = model.snapshot()
   1.409 +          for (i <- 0 until physical_lines.length) {
   1.410 +            if (physical_lines(i) != -1) {
   1.411 +              val line_range = proper_line_range(start(i), end(i))
   1.412 +
   1.413 +              // gutter icons
   1.414 +              val icons =
   1.415 +                (for (Text.Info(_, Some(icon)) <- // FIXME snapshot.cumulate
   1.416 +                  snapshot.select_markup(line_range)(Isabelle_Markup.gutter_message).iterator)
   1.417 +                yield icon).toList.sortWith(_ >= _)
   1.418 +              icons match {
   1.419 +                case icon :: _ =>
   1.420 +                  val icn = icon.icon
   1.421 +                  val x0 = (FOLD_MARKER_SIZE + width - border_width - icn.getIconWidth) max 10
   1.422 +                  val y0 = y + i * line_height + (((line_height - icn.getIconHeight) / 2) max 0)
   1.423 +                  icn.paintIcon(gutter, gfx, x0, y0)
   1.424 +                case Nil =>
   1.425 +              }
   1.426 +            }
   1.427 +          }
   1.428 +        }
   1.429 +      }
   1.430 +    }
   1.431 +  }
   1.432 +
   1.433 +
   1.434 +  /* caret handling */
   1.435 +
   1.436 +  def selected_command(): Option[Command] =
   1.437 +  {
   1.438 +    Swing_Thread.require()
   1.439 +    model.snapshot().node.proper_command_at(text_area.getCaretPosition)
   1.440 +  }
   1.441 +
   1.442 +  private val caret_listener = new CaretListener {
   1.443 +    private val delay = Swing_Thread.delay_last(session.input_delay) {
   1.444 +      session.perspective.event(Session.Perspective)
   1.445 +    }
   1.446 +    override def caretUpdate(e: CaretEvent) { delay() }
   1.447 +  }
   1.448 +
   1.449 +
   1.450 +  /* overview of command status left of scrollbar */
   1.451 +
   1.452 +  private val overview = new JPanel(new BorderLayout)
   1.453 +  {
   1.454 +    private val WIDTH = 10
   1.455 +    private val HEIGHT = 2
   1.456 +
   1.457 +    setPreferredSize(new Dimension(WIDTH, 0))
   1.458 +
   1.459 +    setRequestFocusEnabled(false)
   1.460 +
   1.461 +    addMouseListener(new MouseAdapter {
   1.462 +      override def mousePressed(event: MouseEvent) {
   1.463 +        val line = y_to_line(event.getY)
   1.464 +        if (line >= 0 && line < text_area.getLineCount)
   1.465 +          text_area.setCaretPosition(text_area.getLineStartOffset(line))
   1.466 +      }
   1.467 +    })
   1.468 +
   1.469 +    override def addNotify() {
   1.470 +      super.addNotify()
   1.471 +      ToolTipManager.sharedInstance.registerComponent(this)
   1.472 +    }
   1.473 +
   1.474 +    override def removeNotify() {
   1.475 +      ToolTipManager.sharedInstance.unregisterComponent(this)
   1.476 +      super.removeNotify
   1.477 +    }
   1.478 +
   1.479 +    override def paintComponent(gfx: Graphics)
   1.480 +    {
   1.481 +      super.paintComponent(gfx)
   1.482 +      Swing_Thread.assert()
   1.483 +
   1.484 +      val buffer = model.buffer
   1.485 +      Isabelle.buffer_lock(buffer) {
   1.486 +        val snapshot = model.snapshot()
   1.487 +
   1.488 +        def line_range(command: Command, start: Text.Offset): Option[(Int, Int)] =
   1.489 +        {
   1.490 +          try {
   1.491 +            val line1 = buffer.getLineOfOffset(snapshot.convert(start))
   1.492 +            val line2 = buffer.getLineOfOffset(snapshot.convert(start + command.length)) + 1
   1.493 +            Some((line1, line2))
   1.494 +          }
   1.495 +          catch { case e: ArrayIndexOutOfBoundsException => None }
   1.496 +        }
   1.497 +        for {
   1.498 +          (command, start) <- snapshot.node.command_starts
   1.499 +          if !command.is_ignored
   1.500 +          (line1, line2) <- line_range(command, start)
   1.501 +          val y = line_to_y(line1)
   1.502 +          val height = HEIGHT * (line2 - line1)
   1.503 +          color <- Isabelle_Markup.overview_color(snapshot, command)
   1.504 +        } {
   1.505 +          gfx.setColor(color)
   1.506 +          gfx.fillRect(0, y, getWidth - 1, height)
   1.507 +        }
   1.508 +      }
   1.509 +    }
   1.510 +
   1.511 +    private def line_to_y(line: Int): Int =
   1.512 +      (line * getHeight) / (text_area.getBuffer.getLineCount max text_area.getVisibleLines)
   1.513 +
   1.514 +    private def y_to_line(y: Int): Int =
   1.515 +      (y * (text_area.getBuffer.getLineCount max text_area.getVisibleLines)) / getHeight
   1.516 +  }
   1.517 +
   1.518 +
   1.519 +  /* main actor */
   1.520 +
   1.521 +  private val main_actor = actor {
   1.522 +    loop {
   1.523 +      react {
   1.524 +        case Session.Commands_Changed(changed) =>
   1.525 +          val buffer = model.buffer
   1.526 +          Isabelle.swing_buffer_lock(buffer) {
   1.527 +            val snapshot = model.snapshot()
   1.528 +
   1.529 +            if (changed.exists(snapshot.node.commands.contains))
   1.530 +              overview.repaint()
   1.531 +
   1.532 +            val visible_range = screen_lines_range()
   1.533 +            val visible_cmds = snapshot.node.command_range(snapshot.revert(visible_range)).map(_._1)
   1.534 +            if (visible_cmds.exists(changed)) {
   1.535 +              for {
   1.536 +                line <- 0 until text_area.getVisibleLines
   1.537 +                val start = text_area.getScreenLineStartOffset(line) if start >= 0
   1.538 +                val end = text_area.getScreenLineEndOffset(line) if end >= 0
   1.539 +                val range = proper_line_range(start, end)
   1.540 +                val line_cmds = snapshot.node.command_range(snapshot.revert(range)).map(_._1)
   1.541 +                if line_cmds.exists(changed)
   1.542 +              } text_area.invalidateScreenLineRange(line, line)
   1.543 +
   1.544 +              // FIXME danger of deadlock!?
   1.545 +              // FIXME potentially slow!?
   1.546 +              model.buffer.propertiesChanged()
   1.547 +            }
   1.548 +          }
   1.549 +
   1.550 +        case Session.Global_Settings => html_panel_resize()
   1.551 +
   1.552 +        case bad => System.err.println("command_change_actor: ignoring bad message " + bad)
   1.553 +      }
   1.554 +    }
   1.555 +  }
   1.556 +
   1.557 +
   1.558 +  /* activation */
   1.559 +
   1.560 +  private def activate()
   1.561 +  {
   1.562 +    val painter = text_area.getPainter
   1.563 +    painter.addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, background_painter)
   1.564 +    painter.addExtension(TextAreaPainter.TEXT_LAYER + 1, text_painter)
   1.565 +    text_area.getGutter.addExtension(gutter_painter)
   1.566 +    text_area.addFocusListener(focus_listener)
   1.567 +    text_area.getView.addWindowListener(window_listener)
   1.568 +    painter.addMouseMotionListener(mouse_motion_listener)
   1.569 +    text_area.addCaretListener(caret_listener)
   1.570 +    text_area.addLeftOfScrollBar(overview)
   1.571 +    session.commands_changed += main_actor
   1.572 +    session.global_settings += main_actor
   1.573 +  }
   1.574 +
   1.575 +  private def deactivate()
   1.576 +  {
   1.577 +    val painter = text_area.getPainter
   1.578 +    session.commands_changed -= main_actor
   1.579 +    session.global_settings -= main_actor
   1.580 +    text_area.removeFocusListener(focus_listener)
   1.581 +    text_area.getView.removeWindowListener(window_listener)
   1.582 +    painter.removeMouseMotionListener(mouse_motion_listener)
   1.583 +    text_area.removeCaretListener(caret_listener)
   1.584 +    text_area.removeLeftOfScrollBar(overview)
   1.585 +    text_area.getGutter.removeExtension(gutter_painter)
   1.586 +    painter.removeExtension(text_painter)
   1.587 +    painter.removeExtension(background_painter)
   1.588 +    exit_popup()
   1.589 +  }
   1.590 +}