src/Tools/jEdit/src/jedit_editor.scala
changeset 75393 87ebf5a50283
parent 75120 488c7e8923b2
child 76044 c90799513ed0
equal deleted inserted replaced
75388:b3ca4a6ed74b 75393:87ebf5a50283
    15 import org.gjt.sp.jedit.{jEdit, View, Buffer}
    15 import org.gjt.sp.jedit.{jEdit, View, Buffer}
    16 import org.gjt.sp.jedit.browser.VFSBrowser
    16 import org.gjt.sp.jedit.browser.VFSBrowser
    17 import org.gjt.sp.jedit.io.{VFSManager, VFSFile}
    17 import org.gjt.sp.jedit.io.{VFSManager, VFSFile}
    18 
    18 
    19 
    19 
    20 class JEdit_Editor extends Editor[View]
    20 class JEdit_Editor extends Editor[View] {
    21 {
       
    22   /* session */
    21   /* session */
    23 
    22 
    24   override def session: Session = PIDE.session
    23   override def session: Session = PIDE.session
    25 
    24 
    26   def flush_edits(hidden: Boolean = false, purge: Boolean = false): Unit =
    25   def flush_edits(hidden: Boolean = false, purge: Boolean = false): Unit =
    60     GUI_Thread.require { Document_Model.get(view.getBuffer).map(_.node_name) }
    59     GUI_Thread.require { Document_Model.get(view.getBuffer).map(_.node_name) }
    61 
    60 
    62   override def current_node_snapshot(view: View): Option[Document.Snapshot] =
    61   override def current_node_snapshot(view: View): Option[Document.Snapshot] =
    63     GUI_Thread.require { Document_Model.get(view.getBuffer).map(_.snapshot()) }
    62     GUI_Thread.require { Document_Model.get(view.getBuffer).map(_.snapshot()) }
    64 
    63 
    65   override def node_snapshot(name: Document.Node.Name): Document.Snapshot =
    64   override def node_snapshot(name: Document.Node.Name): Document.Snapshot = {
    66   {
       
    67     GUI_Thread.require {}
    65     GUI_Thread.require {}
    68     Document_Model.get(name) match {
    66     Document_Model.get(name) match {
    69       case Some(model) => model.snapshot()
    67       case Some(model) => model.snapshot()
    70       case None => session.snapshot(name)
    68       case None => session.snapshot(name)
    71     }
    69     }
    72   }
    70   }
    73 
    71 
    74   override def current_command(view: View, snapshot: Document.Snapshot): Option[Command] =
    72   override def current_command(view: View, snapshot: Document.Snapshot): Option[Command] = {
    75   {
       
    76     GUI_Thread.require {}
    73     GUI_Thread.require {}
    77 
    74 
    78     val text_area = view.getTextArea
    75     val text_area = view.getTextArea
    79     val buffer = view.getBuffer
    76     val buffer = view.getBuffer
    80 
    77 
   103     Document_Model.remove_overlay(command, fn, args)
   100     Document_Model.remove_overlay(command, fn, args)
   104 
   101 
   105 
   102 
   106   /* navigation */
   103   /* navigation */
   107 
   104 
   108   def push_position(view: View): Unit =
   105   def push_position(view: View): Unit = {
   109   {
       
   110     val navigator = jEdit.getPlugin("ise.plugin.nav.NavigatorPlugin")
   106     val navigator = jEdit.getPlugin("ise.plugin.nav.NavigatorPlugin")
   111     if (navigator != null) {
   107     if (navigator != null) {
   112       try { Untyped.method(navigator.getClass, "pushPosition", view.getClass).invoke(null, view) }
   108       try { Untyped.method(navigator.getClass, "pushPosition", view.getClass).invoke(null, view) }
   113       catch { case _: NoSuchMethodException => }
   109       catch { case _: NoSuchMethodException => }
   114     }
   110     }
   115   }
   111   }
   116 
   112 
   117   def goto_buffer(focus: Boolean, view: View, buffer: Buffer, offset: Text.Offset): Unit =
   113   def goto_buffer(focus: Boolean, view: View, buffer: Buffer, offset: Text.Offset): Unit = {
   118   {
       
   119     GUI_Thread.require {}
   114     GUI_Thread.require {}
   120 
   115 
   121     push_position(view)
   116     push_position(view)
   122 
   117 
   123     if (focus) view.goToBuffer(buffer) else view.showBuffer(buffer)
   118     if (focus) view.goToBuffer(buffer) else view.showBuffer(buffer)
   129   }
   124   }
   130 
   125 
   131   def goto_file(focus: Boolean, view: View, name: String): Unit =
   126   def goto_file(focus: Boolean, view: View, name: String): Unit =
   132     goto_file(focus, view, Line.Node_Position.offside(name))
   127     goto_file(focus, view, Line.Node_Position.offside(name))
   133 
   128 
   134   def goto_file(focus: Boolean, view: View, pos: Line.Node_Position): Unit =
   129   def goto_file(focus: Boolean, view: View, pos: Line.Node_Position): Unit = {
   135   {
       
   136     GUI_Thread.require {}
   130     GUI_Thread.require {}
   137 
   131 
   138     push_position(view)
   132     push_position(view)
   139 
   133 
   140     val name = pos.name
   134     val name = pos.name
   174           jEdit.openFiles(view, null, args)
   168           jEdit.openFiles(view, null, args)
   175         }
   169         }
   176     }
   170     }
   177   }
   171   }
   178 
   172 
   179   def goto_doc(view: View, path: Path): Unit =
   173   def goto_doc(view: View, path: Path): Unit = {
   180   {
       
   181     if (path.is_pdf) Doc.view(path)
   174     if (path.is_pdf) Doc.view(path)
   182     else goto_file(true, view, File.platform_path(path))
   175     else goto_file(true, view, File.platform_path(path))
   183   }
   176   }
   184 
   177 
   185 
   178 
   232           def follow(view: View): Unit = goto_buffer(focus, view, buffer_model.buffer, offset)
   225           def follow(view: View): Unit = goto_buffer(focus, view, buffer_model.buffer, offset)
   233           override def toString: String = "buffer " + quote(model.node_name.node)
   226           override def toString: String = "buffer " + quote(model.node_name.node)
   234         }
   227         }
   235     }
   228     }
   236 
   229 
   237   def hyperlink_source_file(focus: Boolean, source_name: String, line1: Int, offset: Symbol.Offset)
   230   def hyperlink_source_file(
   238     : Option[Hyperlink] =
   231     focus: Boolean,
   239   {
   232     source_name: String,
       
   233     line1: Int,
       
   234     offset: Symbol.Offset
       
   235   ) : Option[Hyperlink] = {
   240     for (name <- PIDE.resources.source_file(source_name)) yield {
   236     for (name <- PIDE.resources.source_file(source_name)) yield {
   241       def hyperlink(pos: Line.Position) =
   237       def hyperlink(pos: Line.Position) =
   242         hyperlink_file(focus, Line.Node_Position(name, pos))
   238         hyperlink_file(focus, Line.Node_Position(name, pos))
   243 
   239 
   244       if (offset > 0) {
   240       if (offset > 0) {
   254       else hyperlink(Line.Position((line1 - 1) max 0))
   250       else hyperlink(Line.Position((line1 - 1) max 0))
   255     }
   251     }
   256   }
   252   }
   257 
   253 
   258   override def hyperlink_command(
   254   override def hyperlink_command(
   259     focus: Boolean, snapshot: Document.Snapshot, id: Document_ID.Generic, offset: Symbol.Offset = 0)
   255     focus: Boolean,
   260       : Option[Hyperlink] =
   256     snapshot: Document.Snapshot,
   261   {
   257     id: Document_ID.Generic,
       
   258     offset: Symbol.Offset = 0
       
   259   ) : Option[Hyperlink] = {
   262     if (snapshot.is_outdated) None
   260     if (snapshot.is_outdated) None
   263     else snapshot.find_command_position(id, offset).map(hyperlink_file(focus, _))
   261     else snapshot.find_command_position(id, offset).map(hyperlink_file(focus, _))
   264   }
   262   }
   265 
   263 
   266   def is_hyperlink_position(snapshot: Document.Snapshot,
   264   def is_hyperlink_position(
   267     text_offset: Text.Offset, pos: Position.T): Boolean =
   265     snapshot: Document.Snapshot,
   268   {
   266     text_offset: Text.Offset,
       
   267     pos: Position.T
       
   268   ): Boolean = {
   269     pos match {
   269     pos match {
   270       case Position.Item_Id(id, range) if range.start > 0 =>
   270       case Position.Item_Id(id, range) if range.start > 0 =>
   271         snapshot.find_command(id) match {
   271         snapshot.find_command(id) match {
   272           case Some((node, command)) if snapshot.get_node(command.node_name) eq node =>
   272           case Some((node, command)) if snapshot.get_node(command.node_name) eq node =>
   273             node.command_start(command) match {
   273             node.command_start(command) match {