author | wenzelm |
Thu, 05 Aug 2010 14:35:35 +0200 | |
changeset 38150 | 67fc24df3721 |
parent 37175 | be764a7adb10 |
child 38151 | 2837c952ca31 |
permissions | -rw-r--r-- |
36760 | 1 |
/* Title: Tools/jEdit/src/jedit/isabelle_hyperlinks.scala |
2 |
Author: Fabian Immler, TU Munich |
|
3 |
||
4 |
Hyperlink setup for Isabelle proof documents. |
|
5 |
*/ |
|
34568
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 |
|
36015 | 10 |
import isabelle._ |
11 |
||
34569 | 12 |
import java.io.File |
13 |
||
34791 | 14 |
import gatchan.jedit.hyperlinks.{Hyperlink, HyperlinkSource, AbstractHyperlink} |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
15 |
|
34791 | 16 |
import org.gjt.sp.jedit.{View, jEdit, Buffer, TextUtilities} |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
17 |
|
34588 | 18 |
|
34760 | 19 |
private class Internal_Hyperlink(start: Int, end: Int, line: Int, ref_offset: Int) |
34569 | 20 |
extends AbstractHyperlink(start, end, line, "") |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
21 |
{ |
34582 | 22 |
override def click(view: View) { |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
23 |
view.getTextArea.moveCaretPosition(ref_offset) |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
24 |
} |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
25 |
} |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
26 |
|
34760 | 27 |
class External_Hyperlink(start: Int, end: Int, line: Int, ref_file: String, ref_line: Int) |
34569 | 28 |
extends AbstractHyperlink(start, end, line, "") |
29 |
{ |
|
34602
782b1948aca9
ExternalHyperlink.click: use IsabelleSystem.source_file provided in http://isabelle.in.tum.de/repos/isabelle/rev/dde1b4d1c95b
wenzelm
parents:
34588
diff
changeset
|
30 |
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
|
31 |
Isabelle.system.source_file(ref_file) match { |
34760 | 32 |
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
|
33 |
case Some(file) => |
34573 | 34 |
jEdit.openFiles(view, file.getParent, Array(file.getName, "+line:" + ref_line)) |
35 |
} |
|
34602
782b1948aca9
ExternalHyperlink.click: use IsabelleSystem.source_file provided in http://isabelle.in.tum.de/repos/isabelle/rev/dde1b4d1c95b
wenzelm
parents:
34588
diff
changeset
|
36 |
} |
34569 | 37 |
} |
38 |
||
34760 | 39 |
class Isabelle_Hyperlinks extends HyperlinkSource |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
40 |
{ |
37175 | 41 |
def getHyperlink(buffer: Buffer, original_offset: Int): Hyperlink = |
42 |
{ |
|
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34784
diff
changeset
|
43 |
Document_Model(buffer) match { |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
44 |
case Some(model) => |
34824
ac35eee85f5c
renamed current_document to recent_document (might be a bit older than current_change);
wenzelm
parents:
34816
diff
changeset
|
45 |
val document = model.recent_document() |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
46 |
val offset = model.from_current(document, original_offset) |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37175
diff
changeset
|
47 |
document.command_at(model.thy_name, offset) match { |
34855
81d0410dc3ac
iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents:
34832
diff
changeset
|
48 |
case Some((command, command_start)) => |
36990
449628c148cf
explicit Command.Status.UNDEFINED -- avoid fragile/cumbersome treatment of Option[State];
wenzelm
parents:
36760
diff
changeset
|
49 |
document.current_state(command).ref_at(offset - command_start) match { |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
50 |
case Some(ref) => |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
ref.info match { |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
55 |
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
|
56 |
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
|
57 |
case Command.RefInfo(_, _, Some(id), Some(offset)) => |
34816
d33312514220
maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents:
34791
diff
changeset
|
58 |
Isabelle.session.lookup_entity(id) match { |
d33312514220
maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents:
34791
diff
changeset
|
59 |
case Some(ref_cmd: Command) => |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37175
diff
changeset
|
60 |
document.command_start(model.thy_name, ref_cmd) match { |
34858 | 61 |
case Some(ref_cmd_start) => |
62 |
new Internal_Hyperlink(begin, end, line, |
|
63 |
model.to_current(document, ref_cmd_start + offset - 1)) |
|
64 |
case None => null // FIXME external ref |
|
65 |
} |
|
34816
d33312514220
maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents:
34791
diff
changeset
|
66 |
case _ => null |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
67 |
} |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
68 |
case _ => 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 None => 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 |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
75 |
} |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
76 |
} |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
77 |
} |