src/Tools/jEdit/src/jedit_editor.scala
author wenzelm
Tue, 11 Feb 2014 21:58:31 +0100
changeset 55432 9c53198dbb1c
parent 54706 d3c656f0b7ab
child 55781 b3a4207fb9a6
permissions -rw-r--r--
maintain multiple command chunks and markup trees: for main chunk and loaded files; document view for all text areas, including auxiliary files;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52971
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
     1
/*  Title:      Tools/jEdit/src/jedit_editor.scala
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
     3
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
     4
PIDE editor operations for jEdit.
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
     5
*/
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
     6
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
     7
package isabelle.jedit
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
     8
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
     9
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    10
import isabelle._
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    11
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    12
54706
d3c656f0b7ab browse directory hyperlink as well;
wenzelm
parents: 54702
diff changeset
    13
import java.io.{File => JFile}
d3c656f0b7ab browse directory hyperlink as well;
wenzelm
parents: 54702
diff changeset
    14
52971
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    15
import org.gjt.sp.jedit.{jEdit, View}
54706
d3c656f0b7ab browse directory hyperlink as well;
wenzelm
parents: 54702
diff changeset
    16
import org.gjt.sp.jedit.browser.VFSBrowser
52971
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    17
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    18
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    19
class JEdit_Editor extends Editor[View]
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    20
{
52977
15254e32d299 central management of Document.Overlays, independent of Document_Model;
wenzelm
parents: 52974
diff changeset
    21
  /* session */
15254e32d299 central management of Document.Overlays, independent of Document_Model;
wenzelm
parents: 52974
diff changeset
    22
52980
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
    23
  override def session: Session = PIDE.session
52971
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    24
52980
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
    25
  override def flush()
52974
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
    26
  {
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
    27
    Swing_Thread.require()
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
    28
54522
761be40990f1 tuned signature;
wenzelm
parents: 54521
diff changeset
    29
    val edits = PIDE.document_models().flatMap(_.flushed_edits())
761be40990f1 tuned signature;
wenzelm
parents: 54521
diff changeset
    30
    if (!edits.isEmpty) session.update(PIDE.document_blobs(), edits)
52974
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
    31
  }
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
    32
54461
6c360a6ade0e centralized management of pending buffer edits;
wenzelm
parents: 54325
diff changeset
    33
  private val delay_flush =
6c360a6ade0e centralized management of pending buffer edits;
wenzelm
parents: 54325
diff changeset
    34
    Swing_Thread.delay_last(PIDE.options.seconds("editor_input_delay")) { flush() }
6c360a6ade0e centralized management of pending buffer edits;
wenzelm
parents: 54325
diff changeset
    35
6c360a6ade0e centralized management of pending buffer edits;
wenzelm
parents: 54325
diff changeset
    36
  def invoke(): Unit = Swing_Thread.require { delay_flush.invoke() }
6c360a6ade0e centralized management of pending buffer edits;
wenzelm
parents: 54325
diff changeset
    37
52977
15254e32d299 central management of Document.Overlays, independent of Document_Model;
wenzelm
parents: 52974
diff changeset
    38
15254e32d299 central management of Document.Overlays, independent of Document_Model;
wenzelm
parents: 52974
diff changeset
    39
  /* current situation */
15254e32d299 central management of Document.Overlays, independent of Document_Model;
wenzelm
parents: 52974
diff changeset
    40
52980
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
    41
  override def current_context: View =
52971
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    42
    Swing_Thread.require { jEdit.getActiveView() }
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    43
52980
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
    44
  override def current_node(view: View): Option[Document.Node.Name] =
52973
d5f7fa1498b7 tuned signature;
wenzelm
parents: 52971
diff changeset
    45
    Swing_Thread.require { PIDE.document_model(view.getBuffer).map(_.node_name) }
52971
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    46
52980
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
    47
  override def current_node_snapshot(view: View): Option[Document.Snapshot] =
52971
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    48
    Swing_Thread.require { PIDE.document_model(view.getBuffer).map(_.snapshot()) }
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    49
52980
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
    50
  override def node_snapshot(name: Document.Node.Name): Document.Snapshot =
52974
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
    51
  {
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
    52
    Swing_Thread.require()
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
    53
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
    54
    JEdit_Lib.jedit_buffer(name.node) match {
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
    55
      case Some(buffer) =>
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
    56
        PIDE.document_model(buffer) match {
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
    57
          case Some(model) => model.snapshot
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
    58
          case None => session.snapshot(name)
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
    59
        }
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
    60
      case None => session.snapshot(name)
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
    61
    }
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
    62
  }
908e8a36e975 tuned signature;
wenzelm
parents: 52973
diff changeset
    63
53844
71f103629327 skip ignored commands, similar to former proper_command_at (see d68ea01d5084) -- relevant to Output, Query_Operation etc.;
wenzelm
parents: 52980
diff changeset
    64
  override def current_command(view: View, snapshot: Document.Snapshot): Option[Command] =
52971
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    65
  {
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    66
    Swing_Thread.require()
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    67
54325
2c4155003352 clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents: 53845
diff changeset
    68
    val text_area = view.getTextArea
54528
842adea880a4 refer to thy_load command of auxiliary file;
wenzelm
parents: 54522
diff changeset
    69
    val buffer = view.getBuffer
842adea880a4 refer to thy_load command of auxiliary file;
wenzelm
parents: 54522
diff changeset
    70
54325
2c4155003352 clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents: 53845
diff changeset
    71
    PIDE.document_view(text_area) match {
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 54706
diff changeset
    72
      case Some(doc_view) if doc_view.model.is_theory =>
54325
2c4155003352 clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents: 53845
diff changeset
    73
        val node = snapshot.version.nodes(doc_view.model.node_name)
2c4155003352 clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents: 53845
diff changeset
    74
        val caret = snapshot.revert(text_area.getCaretPosition)
54528
842adea880a4 refer to thy_load command of auxiliary file;
wenzelm
parents: 54522
diff changeset
    75
        if (caret < buffer.getLength) {
54325
2c4155003352 clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents: 53845
diff changeset
    76
          val caret_commands = node.command_range(caret)
2c4155003352 clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents: 53845
diff changeset
    77
          if (caret_commands.hasNext) {
2c4155003352 clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents: 53845
diff changeset
    78
            val (cmd0, _) = caret_commands.next
2c4155003352 clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents: 53845
diff changeset
    79
            node.commands.reverse.iterator(cmd0).find(cmd => !cmd.is_ignored)
53844
71f103629327 skip ignored commands, similar to former proper_command_at (see d68ea01d5084) -- relevant to Output, Query_Operation etc.;
wenzelm
parents: 52980
diff changeset
    80
          }
54325
2c4155003352 clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents: 53845
diff changeset
    81
          else None
2c4155003352 clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents: 53845
diff changeset
    82
        }
2c4155003352 clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents: 53845
diff changeset
    83
        else node.commands.reverse.iterator.find(cmd => !cmd.is_ignored)
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 54706
diff changeset
    84
      case _ =>
54528
842adea880a4 refer to thy_load command of auxiliary file;
wenzelm
parents: 54522
diff changeset
    85
        PIDE.document_model(buffer) match {
54531
8330faaeebd5 restrict node_required status and Theories panel to actual theories;
wenzelm
parents: 54528
diff changeset
    86
          case Some(model) if !model.is_theory =>
54528
842adea880a4 refer to thy_load command of auxiliary file;
wenzelm
parents: 54522
diff changeset
    87
            snapshot.version.nodes.thy_load_commands(model.node_name) match {
842adea880a4 refer to thy_load command of auxiliary file;
wenzelm
parents: 54522
diff changeset
    88
              case cmd :: _ => Some(cmd)
842adea880a4 refer to thy_load command of auxiliary file;
wenzelm
parents: 54522
diff changeset
    89
              case Nil => None
842adea880a4 refer to thy_load command of auxiliary file;
wenzelm
parents: 54522
diff changeset
    90
            }
842adea880a4 refer to thy_load command of auxiliary file;
wenzelm
parents: 54522
diff changeset
    91
          case _ => None
842adea880a4 refer to thy_load command of auxiliary file;
wenzelm
parents: 54522
diff changeset
    92
        }
52971
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    93
    }
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
    94
  }
52977
15254e32d299 central management of Document.Overlays, independent of Document_Model;
wenzelm
parents: 52974
diff changeset
    95
15254e32d299 central management of Document.Overlays, independent of Document_Model;
wenzelm
parents: 52974
diff changeset
    96
15254e32d299 central management of Document.Overlays, independent of Document_Model;
wenzelm
parents: 52974
diff changeset
    97
  /* overlays */
15254e32d299 central management of Document.Overlays, independent of Document_Model;
wenzelm
parents: 52974
diff changeset
    98
15254e32d299 central management of Document.Overlays, independent of Document_Model;
wenzelm
parents: 52974
diff changeset
    99
  private var overlays = Document.Overlays.empty
15254e32d299 central management of Document.Overlays, independent of Document_Model;
wenzelm
parents: 52974
diff changeset
   100
52980
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   101
  override def node_overlays(name: Document.Node.Name): Document.Node.Overlays =
52977
15254e32d299 central management of Document.Overlays, independent of Document_Model;
wenzelm
parents: 52974
diff changeset
   102
    synchronized { overlays(name) }
15254e32d299 central management of Document.Overlays, independent of Document_Model;
wenzelm
parents: 52974
diff changeset
   103
52980
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   104
  override def insert_overlay(command: Command, fn: String, args: List[String]): Unit =
52977
15254e32d299 central management of Document.Overlays, independent of Document_Model;
wenzelm
parents: 52974
diff changeset
   105
    synchronized { overlays = overlays.insert(command, fn, args) }
15254e32d299 central management of Document.Overlays, independent of Document_Model;
wenzelm
parents: 52974
diff changeset
   106
52980
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   107
  override def remove_overlay(command: Command, fn: String, args: List[String]): Unit =
52977
15254e32d299 central management of Document.Overlays, independent of Document_Model;
wenzelm
parents: 52974
diff changeset
   108
    synchronized { overlays = overlays.remove(command, fn, args) }
52980
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   109
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   110
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   111
  /* hyperlinks */
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   112
54706
d3c656f0b7ab browse directory hyperlink as well;
wenzelm
parents: 54702
diff changeset
   113
  def goto(view: View, name: String, line: Int = 0, column: Int = 0)
52980
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   114
  {
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   115
    Swing_Thread.require()
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   116
54706
d3c656f0b7ab browse directory hyperlink as well;
wenzelm
parents: 54702
diff changeset
   117
    JEdit_Lib.jedit_buffer(name) match {
52980
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   118
      case Some(buffer) =>
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   119
        view.goToBuffer(buffer)
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   120
        val text_area = view.getTextArea
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   121
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   122
        try {
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   123
          val line_start = text_area.getBuffer.getLineStartOffset(line - 1)
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   124
          text_area.moveCaretPosition(line_start)
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   125
          if (column > 0) text_area.moveCaretPosition(line_start + column - 1)
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   126
        }
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   127
        catch {
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   128
          case _: ArrayIndexOutOfBoundsException =>
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   129
          case _: IllegalArgumentException =>
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   130
        }
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   131
54706
d3c656f0b7ab browse directory hyperlink as well;
wenzelm
parents: 54702
diff changeset
   132
      case None if (new JFile(name)).isDirectory =>
d3c656f0b7ab browse directory hyperlink as well;
wenzelm
parents: 54702
diff changeset
   133
        VFSBrowser.browseDirectory(view, name)
d3c656f0b7ab browse directory hyperlink as well;
wenzelm
parents: 54702
diff changeset
   134
52980
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   135
      case None =>
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   136
        val args =
54706
d3c656f0b7ab browse directory hyperlink as well;
wenzelm
parents: 54702
diff changeset
   137
          if (line <= 0) Array(name)
d3c656f0b7ab browse directory hyperlink as well;
wenzelm
parents: 54702
diff changeset
   138
          else if (column <= 0) Array(name, "+line:" + line.toInt)
d3c656f0b7ab browse directory hyperlink as well;
wenzelm
parents: 54702
diff changeset
   139
          else Array(name, "+line:" + line.toInt + "," + column.toInt)
52980
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   140
        jEdit.openFiles(view, null, args)
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   141
    }
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   142
  }
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   143
54702
3daeba5130f0 added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
wenzelm
parents: 54531
diff changeset
   144
  override def hyperlink_url(name: String): Hyperlink =
3daeba5130f0 added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
wenzelm
parents: 54531
diff changeset
   145
    new Hyperlink {
3daeba5130f0 added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
wenzelm
parents: 54531
diff changeset
   146
      def follow(view: View) =
3daeba5130f0 added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
wenzelm
parents: 54531
diff changeset
   147
        default_thread_pool.submit(() =>
3daeba5130f0 added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
wenzelm
parents: 54531
diff changeset
   148
          try { Isabelle_System.open(name) }
3daeba5130f0 added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
wenzelm
parents: 54531
diff changeset
   149
          catch {
3daeba5130f0 added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
wenzelm
parents: 54531
diff changeset
   150
            case exn: Throwable =>
3daeba5130f0 added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
wenzelm
parents: 54531
diff changeset
   151
              GUI.error_dialog(view, "System error", GUI.scrollable_text(Exn.message(exn)))
3daeba5130f0 added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
wenzelm
parents: 54531
diff changeset
   152
          })
3daeba5130f0 added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
wenzelm
parents: 54531
diff changeset
   153
    }
3daeba5130f0 added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
wenzelm
parents: 54531
diff changeset
   154
54706
d3c656f0b7ab browse directory hyperlink as well;
wenzelm
parents: 54702
diff changeset
   155
  override def hyperlink_file(name: String, line: Int = 0, column: Int = 0): Hyperlink =
d3c656f0b7ab browse directory hyperlink as well;
wenzelm
parents: 54702
diff changeset
   156
    new Hyperlink { def follow(view: View) = goto(view, name, line, column) }
52980
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   157
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   158
  override def hyperlink_command(snapshot: Document.Snapshot, command: Command, offset: Int = 0)
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   159
    : Option[Hyperlink] =
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   160
  {
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   161
    if (snapshot.is_outdated) None
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   162
    else {
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   163
      snapshot.state.find_command(snapshot.version, command.id) match {
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   164
        case None => None
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   165
        case Some((node, _)) =>
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   166
          val file_name = command.node_name.node
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   167
          val sources =
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   168
            node.commands.iterator.takeWhile(_ != command).map(_.source) ++
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   169
              (if (offset == 0) Iterator.empty
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   170
               else Iterator.single(command.source(Text.Range(0, command.decode(offset)))))
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   171
          val (line, column) = ((1, 1) /: sources)(Symbol.advance_line_column)
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   172
          Some(new Hyperlink { def follow(view: View) { goto(view, file_name, line, column) } })
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   173
      }
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   174
    }
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52978
diff changeset
   175
  }
52971
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff changeset
   176
}