adhoc event handler to insert 'sendback' text into the buffer, replacing the original command
authorkrauss
Thu, 26 May 2011 00:20:28 +0200
changeset 42978 6b41a075251f
parent 42977 a59db6677521
child 42979 5b9e16259341
adhoc event handler to insert 'sendback' text into the buffer, replacing the original command
src/Tools/jEdit/src/jedit/output_dockable.scala
--- a/src/Tools/jEdit/src/jedit/output_dockable.scala	Thu May 26 00:12:30 2011 +0200
+++ b/src/Tools/jEdit/src/jedit/output_dockable.scala	Thu May 26 00:20:28 2011 +0200
@@ -26,6 +26,25 @@
 
   private val html_panel =
     new HTML_Panel(Isabelle.system, Isabelle.font_family(), scala.math.round(Isabelle.font_size()))
+  {
+    override val handler: PartialFunction[HTML_Panel.Event, Unit] = {
+      case HTML_Panel.Mouse_Click(elem, event) if elem.getClassName() == "sendback" =>
+        val text = elem.getFirstChild().getNodeValue()
+
+        Document_View(view.getTextArea) match {
+          case Some(doc_view) =>
+            val cmd = current_command.get
+            val start_ofs = doc_view.model.snapshot().node.command_start(cmd).get
+            val buffer = view.getBuffer
+            buffer.beginCompoundEdit()
+            buffer.remove(start_ofs, cmd.length)
+            buffer.insert(start_ofs, text)
+            buffer.endCompoundEdit()
+          case None =>
+        }
+    }       
+  }
+
   set_content(html_panel)