49492
|
1 |
/* Title: Tools/jEdit/src/sendback.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Clickable "sendback" areas within the source text.
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle.jedit
|
|
8 |
|
|
9 |
|
|
10 |
import isabelle._
|
|
11 |
|
|
12 |
import org.gjt.sp.jedit.{View, jEdit}
|
|
13 |
import org.gjt.sp.jedit.textarea.JEditTextArea
|
|
14 |
|
|
15 |
|
|
16 |
object Sendback
|
|
17 |
{
|
|
18 |
def apply(command: Command, body: XML.Body): Sendback = new Sendback(command, body)
|
|
19 |
}
|
|
20 |
|
|
21 |
class Sendback private(command: Command, body: XML.Body)
|
|
22 |
{
|
|
23 |
def activate(view: View)
|
|
24 |
{
|
|
25 |
Swing_Thread.require()
|
|
26 |
|
|
27 |
Document_View(view.getTextArea) match {
|
|
28 |
case Some(doc_view) =>
|
|
29 |
doc_view.rich_text_area.robust_body() {
|
|
30 |
val model = doc_view.model
|
|
31 |
val buffer = model.buffer
|
|
32 |
val snapshot = model.snapshot()
|
|
33 |
snapshot.node.command_start(command) match {
|
|
34 |
case Some(start) if !snapshot.is_outdated =>
|
|
35 |
val text = Pretty.string_of(body)
|
|
36 |
try {
|
|
37 |
buffer.beginCompoundEdit()
|
|
38 |
buffer.remove(start, command.proper_range.length)
|
|
39 |
buffer.insert(start, text)
|
|
40 |
}
|
|
41 |
finally { buffer.endCompoundEdit() }
|
|
42 |
case _ =>
|
|
43 |
}
|
|
44 |
}
|
|
45 |
case None =>
|
|
46 |
}
|
|
47 |
}
|
|
48 |
}
|
|
49 |
|