author | wenzelm |
Tue, 23 Aug 2011 12:20:12 +0200 | |
changeset 44385 | e7fdb008aa7d |
parent 43661 | 39fdbd814c7f |
child 44580 | 3bc9a215a56d |
permissions | -rw-r--r-- |
43282
5d294220ca43
moved sources -- eliminated Netbeans artifact of jedit package directory;
wenzelm
parents:
42327
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/isabelle_hyperlinks.scala |
36760 | 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 |
|
42327
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
19 |
private class Internal_Hyperlink(start: Int, end: Int, line: Int, def_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) { |
42327
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
23 |
view.getTextArea.moveCaretPosition(def_offset) |
34568
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 |
|
42327
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
27 |
class External_Hyperlink(start: Int, end: Int, line: Int, def_file: String, def_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) = { |
43661
39fdbd814c7f
quasi-static Isabelle_System -- reduced tendency towards "functorial style";
wenzelm
parents:
43606
diff
changeset
|
31 |
Isabelle_System.source_file(Path.explode(def_file)) match { |
38853 | 32 |
case None => |
42327
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
33 |
Library.error_dialog(view, "File not found", "Could not find source file " + def_file) |
34602
782b1948aca9
ExternalHyperlink.click: use IsabelleSystem.source_file provided in http://isabelle.in.tum.de/repos/isabelle/rev/dde1b4d1c95b
wenzelm
parents:
34588
diff
changeset
|
34 |
case Some(file) => |
42327
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
35 |
jEdit.openFiles(view, file.getParent, Array(file.getName, "+line:" + def_line)) |
34573 | 36 |
} |
34602
782b1948aca9
ExternalHyperlink.click: use IsabelleSystem.source_file provided in http://isabelle.in.tum.de/repos/isabelle/rev/dde1b4d1c95b
wenzelm
parents:
34588
diff
changeset
|
37 |
} |
34569 | 38 |
} |
39 |
||
34760 | 40 |
class Isabelle_Hyperlinks extends HyperlinkSource |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
41 |
{ |
38575
80d962964216
Isabelle_Hyperlinks: select relevant information directly from Markup_Tree, without intermediate RefInfo;
wenzelm
parents:
38427
diff
changeset
|
42 |
def getHyperlink(buffer: Buffer, buffer_offset: Int): Hyperlink = |
37175 | 43 |
{ |
38223 | 44 |
Swing_Thread.assert() |
38843 | 45 |
Isabelle.buffer_lock(buffer) { |
46 |
Document_Model(buffer) match { |
|
47 |
case Some(model) => |
|
48 |
val snapshot = model.snapshot() |
|
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
49 |
val markup = |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
50 |
snapshot.select_markup(Text.Range(buffer_offset, buffer_offset + 1)) { |
38843 | 51 |
// FIXME Isar_Document.Hyperlink extractor |
42327
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
52 |
case Text.Info(info_range, |
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
53 |
XML.Elem(Markup(Markup.ENTITY, props), _)) |
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
54 |
if (props.find( |
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
55 |
{ case (Markup.KIND, Markup.ML_OPEN) => true |
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
56 |
case (Markup.KIND, Markup.ML_STRUCT) => true |
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
57 |
case _ => false }).isEmpty) => |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
58 |
val Text.Range(begin, end) = info_range |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
59 |
val line = buffer.getLineOfOffset(begin) |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
60 |
(Position.File.unapply(props), Position.Line.unapply(props)) match { |
42327
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
61 |
case (Some(def_file), Some(def_line)) => |
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
62 |
new External_Hyperlink(begin, end, line, def_file, def_line) |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
63 |
case _ => |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
64 |
(props, props) match { |
42327
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
65 |
case (Position.Id(def_id), Position.Offset(def_offset)) => |
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
66 |
snapshot.lookup_command(def_id) match { |
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
67 |
case Some(def_cmd) => |
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
68 |
snapshot.node.command_start(def_cmd) match { |
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
69 |
case Some(def_cmd_start) => |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
70 |
new Internal_Hyperlink(begin, end, line, |
42327
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
39177
diff
changeset
|
71 |
snapshot.convert(def_cmd_start + def_cmd.decode(def_offset))) |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
72 |
case None => null |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
73 |
} |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
74 |
case None => null |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
75 |
} |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
76 |
case _ => null |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
77 |
} |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
78 |
} |
39177
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38853
diff
changeset
|
79 |
} |
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38853
diff
changeset
|
80 |
markup match { |
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38853
diff
changeset
|
81 |
case Text.Info(_, Some(link)) #:: _ => link |
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38853
diff
changeset
|
82 |
case _ => null |
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38853
diff
changeset
|
83 |
} |
38843 | 84 |
case None => null |
85 |
} |
|
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
86 |
} |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
87 |
} |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
diff
changeset
|
88 |
} |