author | wenzelm |
Sun, 15 Aug 2010 22:48:56 +0200 | |
changeset 38426 | 2858ec7b6dd8 |
parent 38370 | 8b15d0f98962 |
child 38427 | 7066fbd315ae |
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 |
{ |
|
38223 | 43 |
Swing_Thread.assert() |
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34784
diff
changeset
|
44 |
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
|
45 |
case Some(model) => |
38151 | 46 |
val snapshot = model.snapshot() |
38153
469555615ec7
renamed to_current to convert, and from_current to revert;
wenzelm
parents:
38152
diff
changeset
|
47 |
val offset = snapshot.revert(original_offset) |
38152
eab0d1c2e46e
Change.Snapshot: include from_current/to_current here, with precomputed changes;
wenzelm
parents:
38151
diff
changeset
|
48 |
snapshot.node.command_at(offset) match { |
34855
81d0410dc3ac
iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents:
34832
diff
changeset
|
49 |
case Some((command, command_start)) => |
38356
443fb83a21e8
consider command state as part of Snapshot, not Document;
wenzelm
parents:
38223
diff
changeset
|
50 |
snapshot.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
|
51 |
case Some(ref) => |
38426 | 52 |
val begin = snapshot.convert(command_start + ref.range.start) |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
53 |
val line = buffer.getLineOfOffset(begin) |
38426 | 54 |
val end = snapshot.convert(command_start + ref.range.stop) |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
55 |
ref.info match { |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
56 |
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
|
57 |
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
|
58 |
case Command.RefInfo(_, _, Some(id), Some(offset)) => |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38356
diff
changeset
|
59 |
snapshot.lookup_command(id) match { // FIXME Command_ID vs. Exec_ID (!??) |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38356
diff
changeset
|
60 |
case Some(ref_cmd) => |
38152
eab0d1c2e46e
Change.Snapshot: include from_current/to_current here, with precomputed changes;
wenzelm
parents:
38151
diff
changeset
|
61 |
snapshot.node.command_start(ref_cmd) match { |
34858 | 62 |
case Some(ref_cmd_start) => |
63 |
new Internal_Hyperlink(begin, end, line, |
|
38153
469555615ec7
renamed to_current to convert, and from_current to revert;
wenzelm
parents:
38152
diff
changeset
|
64 |
snapshot.convert(ref_cmd_start + offset - 1)) |
34858 | 65 |
case None => null // FIXME external ref |
66 |
} |
|
34816
d33312514220
maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents:
34791
diff
changeset
|
67 |
case _ => null |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
68 |
} |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
69 |
case _ => null |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
70 |
} |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
71 |
case None => null |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
72 |
} |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
73 |
case None => null |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
74 |
} |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34760
diff
changeset
|
75 |
case None => null |
34568
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 |
} |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
78 |
} |