author | wenzelm |
Tue, 08 Dec 2009 16:30:20 +0100 | |
changeset 34760 | dc7f5e0d9d27 |
parent 34759 | bfea7839d9e1 |
child 34777 | 91d6089cef88 |
permissions | -rw-r--r-- |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
1 |
/* |
34588 | 2 |
* Hyperlink setup for Isabelle proof documents |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
3 |
* |
34588 | 4 |
* @author Fabian Immler, TU Munich |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
5 |
*/ |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
6 |
|
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
7 |
package isabelle.jedit |
34569 | 8 |
|
34760 | 9 |
|
34569 | 10 |
import java.io.File |
11 |
||
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
12 |
import gatchan.jedit.hyperlinks.Hyperlink |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
13 |
import gatchan.jedit.hyperlinks.HyperlinkSource |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
14 |
import gatchan.jedit.hyperlinks.AbstractHyperlink |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
15 |
|
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
16 |
import org.gjt.sp.jedit.View |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
17 |
import org.gjt.sp.jedit.jEdit |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
18 |
import org.gjt.sp.jedit.Buffer |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
19 |
import org.gjt.sp.jedit.TextUtilities |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
20 |
|
34760 | 21 |
import isabelle.proofdocument.Command |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
22 |
|
34588 | 23 |
|
34760 | 24 |
private class Internal_Hyperlink(start: Int, end: Int, line: Int, ref_offset: Int) |
34569 | 25 |
extends AbstractHyperlink(start, end, line, "") |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
26 |
{ |
34582 | 27 |
override def click(view: View) { |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
28 |
view.getTextArea.moveCaretPosition(ref_offset) |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
29 |
} |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
30 |
} |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
31 |
|
34760 | 32 |
class External_Hyperlink(start: Int, end: Int, line: Int, ref_file: String, ref_line: Int) |
34569 | 33 |
extends AbstractHyperlink(start, end, line, "") |
34 |
{ |
|
34602
782b1948aca9
ExternalHyperlink.click: use IsabelleSystem.source_file provided in http://isabelle.in.tum.de/repos/isabelle/rev/dde1b4d1c95b
wenzelm
parents:
34588
diff
changeset
|
35 |
override def click(view: View) = { |
782b1948aca9
ExternalHyperlink.click: use IsabelleSystem.source_file provided in http://isabelle.in.tum.de/repos/isabelle/rev/dde1b4d1c95b
wenzelm
parents:
34588
diff
changeset
|
36 |
Isabelle.system.source_file(ref_file) match { |
34760 | 37 |
case None => System.err.println("Could not find source file " + ref_file) // FIXME ?? |
34602
782b1948aca9
ExternalHyperlink.click: use IsabelleSystem.source_file provided in http://isabelle.in.tum.de/repos/isabelle/rev/dde1b4d1c95b
wenzelm
parents:
34588
diff
changeset
|
38 |
case Some(file) => |
34573 | 39 |
jEdit.openFiles(view, file.getParent, Array(file.getName, "+line:" + ref_line)) |
40 |
} |
|
34602
782b1948aca9
ExternalHyperlink.click: use IsabelleSystem.source_file provided in http://isabelle.in.tum.de/repos/isabelle/rev/dde1b4d1c95b
wenzelm
parents:
34588
diff
changeset
|
41 |
} |
34569 | 42 |
} |
43 |
||
34760 | 44 |
class Isabelle_Hyperlinks extends HyperlinkSource |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
45 |
{ |
34760 | 46 |
def getHyperlink(buffer: Buffer, original_offset: Int): Hyperlink = |
47 |
{ |
|
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
48 |
val prover = Isabelle.prover_setup(buffer).map(_.prover) |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
49 |
val theory_view_opt = Isabelle.prover_setup(buffer).map(_.theory_view) |
34714 | 50 |
if (prover.isEmpty || theory_view_opt.isEmpty) null |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
51 |
else if (prover.get == null || theory_view_opt.get == null) null |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
52 |
else { |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
53 |
val theory_view = theory_view_opt.get |
34650 | 54 |
val document = theory_view.current_document() |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
55 |
val offset = theory_view.from_current(document, original_offset) |
34712
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
56 |
document.command_at(offset) match { |
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
57 |
case Some(command) => |
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
58 |
command.ref_at(document, offset - command.start(document)) match { |
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
59 |
case Some(ref) => |
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
60 |
val command_start = command.start(document) |
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
61 |
val begin = theory_view.to_current(document, command_start + ref.start) |
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
62 |
val line = buffer.getLineOfOffset(begin) |
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
63 |
val end = theory_view.to_current(document, command_start + ref.stop) |
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
64 |
ref.info match { |
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
65 |
case Command.RefInfo(Some(ref_file), Some(ref_line), _, _) => |
34760 | 66 |
new External_Hyperlink(begin, end, line, ref_file, ref_line) |
34712
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
67 |
case Command.RefInfo(_, _, Some(id), Some(offset)) => |
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
68 |
prover.get.command(id) match { |
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
69 |
case Some(ref_cmd) => |
34760 | 70 |
new Internal_Hyperlink(begin, end, line, |
34712
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
71 |
theory_view.to_current(document, ref_cmd.start(document) + offset - 1)) |
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
72 |
case None => null |
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
73 |
} |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
74 |
case _ => null |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
75 |
} |
34712
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
76 |
case None => null |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
77 |
} |
34712
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
78 |
case None => null |
4f0ee5ab0380
replaced find_command_at by command_at -- null-free, proper Option;
wenzelm
parents:
34707
diff
changeset
|
79 |
} |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
80 |
} |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
81 |
} |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
82 |
} |