src/Tools/jEdit/src/jedit_editor.scala
changeset 52971 31926d2c04ee
child 52973 d5f7fa1498b7
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Tools/jEdit/src/jedit_editor.scala	Mon Aug 12 11:39:29 2013 +0200
     1.3 @@ -0,0 +1,44 @@
     1.4 +/*  Title:      Tools/jEdit/src/jedit_editor.scala
     1.5 +    Author:     Makarius
     1.6 +
     1.7 +PIDE editor operations for jEdit.
     1.8 +*/
     1.9 +
    1.10 +package isabelle.jedit
    1.11 +
    1.12 +
    1.13 +import isabelle._
    1.14 +
    1.15 +
    1.16 +import org.gjt.sp.jedit.{jEdit, View}
    1.17 +
    1.18 +
    1.19 +class JEdit_Editor extends Editor[View]
    1.20 +{
    1.21 +  def session: Session = PIDE.session
    1.22 +
    1.23 +  def current_context: View =
    1.24 +    Swing_Thread.require { jEdit.getActiveView() }
    1.25 +
    1.26 +  def current_node(view: View): Option[Document.Node.Name] =
    1.27 +    Swing_Thread.require { PIDE.document_model(view.getBuffer).map(_.name) }
    1.28 +
    1.29 +  def current_snapshot(view: View): Option[Document.Snapshot] =
    1.30 +    Swing_Thread.require { PIDE.document_model(view.getBuffer).map(_.snapshot()) }
    1.31 +
    1.32 +  def current_command(view: View, snapshot: Document.Snapshot): Option[(Command, Text.Offset)] =
    1.33 +  {
    1.34 +    Swing_Thread.require()
    1.35 +
    1.36 +    if (snapshot.is_outdated) None
    1.37 +    else {
    1.38 +      val text_area = view.getTextArea
    1.39 +      PIDE.document_view(text_area) match {
    1.40 +        case Some(doc_view) =>
    1.41 +          val node = snapshot.version.nodes(doc_view.model.name)
    1.42 +          node.command_at(text_area.getCaretPosition)
    1.43 +        case None => None
    1.44 +      }
    1.45 +    }
    1.46 +  }
    1.47 +}