author | wenzelm |
Tue, 15 Dec 2009 19:50:55 +0100 | |
changeset 34784 | 02959dcea756 |
parent 34777 | 91d6089cef88 |
child 34788 | 3779c54a2d21 |
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 |
{ |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
48 |
Document_Model.get(buffer) match { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
49 |
case Some(model) => |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
50 |
val document = model.current_document() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
51 |
val offset = model.from_current(document, original_offset) |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
52 |
document.command_at(offset) match { |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
53 |
case Some(command) => |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
54 |
command.ref_at(document, offset - command.start(document)) match { |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
55 |
case Some(ref) => |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
56 |
val command_start = command.start(document) |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
57 |
val begin = model.to_current(document, command_start + ref.start) |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
58 |
val line = buffer.getLineOfOffset(begin) |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
59 |
val end = model.to_current(document, command_start + ref.stop) |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
60 |
ref.info match { |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
61 |
case Command.RefInfo(Some(ref_file), Some(ref_line), _, _) => |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
62 |
new External_Hyperlink(begin, end, line, ref_file, ref_line) |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
63 |
case Command.RefInfo(_, _, Some(id), Some(offset)) => |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
64 |
Isabelle.session.command(id) match { |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
65 |
case Some(ref_cmd) => |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
66 |
new Internal_Hyperlink(begin, end, line, |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
67 |
model.to_current(document, ref_cmd.start(document) + offset - 1)) |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
68 |
case None => null |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
69 |
} |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
70 |
case _ => null |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
71 |
} |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
72 |
case None => null |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
73 |
} |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
74 |
case None => null |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
75 |
} |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
76 |
case None => null |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
77 |
} |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
78 |
} |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
79 |
} |