author | wenzelm |
Sat, 07 Jan 2017 14:34:53 +0100 | |
changeset 64817 | 0bb6b582bb4f |
parent 64813 | 7283f41d05ab |
child 64829 | 07f209e957bc |
permissions | -rw-r--r-- |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/jedit_editor.scala |
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
3 |
|
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
4 |
PIDE editor operations for jEdit. |
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
6 |
|
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle.jedit |
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
8 |
|
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
9 |
|
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
10 |
import isabelle._ |
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
11 |
|
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
12 |
|
54706 | 13 |
import java.io.{File => JFile} |
14 |
||
58545
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
15 |
import org.gjt.sp.jedit.{jEdit, View, Buffer} |
54706 | 16 |
import org.gjt.sp.jedit.browser.VFSBrowser |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
17 |
|
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
18 |
|
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
19 |
class JEdit_Editor extends Editor[View] |
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
20 |
{ |
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
21 |
/* session */ |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
22 |
|
52980 | 23 |
override def session: Session = PIDE.session |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
24 |
|
64817 | 25 |
override def flush(hidden: Boolean = false): Unit = |
26 |
GUI_Thread.require { |
|
27 |
val (doc_blobs, edits) = Document_Model.flush_edits(hidden) |
|
28 |
session.update(doc_blobs, edits) |
|
29 |
} |
|
52974 | 30 |
|
64524
e6a3c55b929b
explicit option editor_generated_input_delay, which is more aggressive by default;
wenzelm
parents:
64521
diff
changeset
|
31 |
private val delay1_flush = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57611
diff
changeset
|
32 |
GUI_Thread.delay_last(PIDE.options.seconds("editor_input_delay")) { flush() } |
54461 | 33 |
|
64524
e6a3c55b929b
explicit option editor_generated_input_delay, which is more aggressive by default;
wenzelm
parents:
64521
diff
changeset
|
34 |
private val delay2_flush = |
e6a3c55b929b
explicit option editor_generated_input_delay, which is more aggressive by default;
wenzelm
parents:
64521
diff
changeset
|
35 |
GUI_Thread.delay_first(PIDE.options.seconds("editor_generated_input_delay")) { flush() } |
64521
1aef5a0e18d7
delay_first for machine generated editor events: avoid starvation, e.g. when operating on big sessions;
wenzelm
parents:
62248
diff
changeset
|
36 |
|
64524
e6a3c55b929b
explicit option editor_generated_input_delay, which is more aggressive by default;
wenzelm
parents:
64521
diff
changeset
|
37 |
def invoke(): Unit = delay1_flush.invoke() |
e6a3c55b929b
explicit option editor_generated_input_delay, which is more aggressive by default;
wenzelm
parents:
64521
diff
changeset
|
38 |
def invoke_generated(): Unit = { delay1_flush.invoke(); delay2_flush.invoke() } |
54461 | 39 |
|
60933
6d03e05ef041
more robust access to stable tip version: take all pending edits into account, don't assume model for current buffer;
wenzelm
parents:
60893
diff
changeset
|
40 |
def stable_tip_version(): Option[Document.Version] = |
6d03e05ef041
more robust access to stable tip version: take all pending edits into account, don't assume model for current buffer;
wenzelm
parents:
60893
diff
changeset
|
41 |
GUI_Thread.require { |
64817 | 42 |
if (Document_Model.is_stable()) |
60933
6d03e05ef041
more robust access to stable tip version: take all pending edits into account, don't assume model for current buffer;
wenzelm
parents:
60893
diff
changeset
|
43 |
session.current_state().stable_tip_version |
6d03e05ef041
more robust access to stable tip version: take all pending edits into account, don't assume model for current buffer;
wenzelm
parents:
60893
diff
changeset
|
44 |
else None |
6d03e05ef041
more robust access to stable tip version: take all pending edits into account, don't assume model for current buffer;
wenzelm
parents:
60893
diff
changeset
|
45 |
} |
6d03e05ef041
more robust access to stable tip version: take all pending edits into account, don't assume model for current buffer;
wenzelm
parents:
60893
diff
changeset
|
46 |
|
64799 | 47 |
def visible_node(name: Document.Node.Name): Boolean = |
48 |
JEdit_Lib.jedit_buffer(name) match { |
|
49 |
case Some(buffer) => JEdit_Lib.jedit_text_areas(buffer).nonEmpty |
|
50 |
case None => false |
|
51 |
} |
|
52 |
||
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
53 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
54 |
/* current situation */ |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
55 |
|
52980 | 56 |
override def current_context: View = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57611
diff
changeset
|
57 |
GUI_Thread.require { jEdit.getActiveView() } |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
58 |
|
52980 | 59 |
override def current_node(view: View): Option[Document.Node.Name] = |
64813 | 60 |
GUI_Thread.require { Document_Model.get(view.getBuffer).map(_.node_name) } |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
61 |
|
52980 | 62 |
override def current_node_snapshot(view: View): Option[Document.Snapshot] = |
64813 | 63 |
GUI_Thread.require { Document_Model.get(view.getBuffer).map(_.snapshot()) } |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
64 |
|
52980 | 65 |
override def node_snapshot(name: Document.Node.Name): Document.Snapshot = |
52974 | 66 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57611
diff
changeset
|
67 |
GUI_Thread.require {} |
64817 | 68 |
Document_Model.get(name) match { |
69 |
case Some(model) => model.snapshot |
|
52974 | 70 |
case None => session.snapshot(name) |
71 |
} |
|
72 |
} |
|
73 |
||
53844
71f103629327
skip ignored commands, similar to former proper_command_at (see d68ea01d5084) -- relevant to Output, Query_Operation etc.;
wenzelm
parents:
52980
diff
changeset
|
74 |
override def current_command(view: View, snapshot: Document.Snapshot): Option[Command] = |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
75 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57611
diff
changeset
|
76 |
GUI_Thread.require {} |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
77 |
|
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53845
diff
changeset
|
78 |
val text_area = view.getTextArea |
54528 | 79 |
val buffer = view.getBuffer |
80 |
||
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53845
diff
changeset
|
81 |
PIDE.document_view(text_area) match { |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
54706
diff
changeset
|
82 |
case Some(doc_view) if doc_view.model.is_theory => |
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53845
diff
changeset
|
83 |
val node = snapshot.version.nodes(doc_view.model.node_name) |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53845
diff
changeset
|
84 |
val caret = snapshot.revert(text_area.getCaretPosition) |
54528 | 85 |
if (caret < buffer.getLength) { |
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56314
diff
changeset
|
86 |
val caret_command_iterator = node.command_iterator(caret) |
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56314
diff
changeset
|
87 |
if (caret_command_iterator.hasNext) { |
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56314
diff
changeset
|
88 |
val (cmd0, _) = caret_command_iterator.next |
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53845
diff
changeset
|
89 |
node.commands.reverse.iterator(cmd0).find(cmd => !cmd.is_ignored) |
53844
71f103629327
skip ignored commands, similar to former proper_command_at (see d68ea01d5084) -- relevant to Output, Query_Operation etc.;
wenzelm
parents:
52980
diff
changeset
|
90 |
} |
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53845
diff
changeset
|
91 |
else None |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53845
diff
changeset
|
92 |
} |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53845
diff
changeset
|
93 |
else node.commands.reverse.iterator.find(cmd => !cmd.is_ignored) |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
54706
diff
changeset
|
94 |
case _ => |
64813 | 95 |
Document_Model.get(buffer) match { |
54531
8330faaeebd5
restrict node_required status and Theories panel to actual theories;
wenzelm
parents:
54528
diff
changeset
|
96 |
case Some(model) if !model.is_theory => |
64799 | 97 |
snapshot.version.nodes.commands_loading(model.node_name) match { |
54528 | 98 |
case cmd :: _ => Some(cmd) |
99 |
case Nil => None |
|
100 |
} |
|
101 |
case _ => None |
|
102 |
} |
|
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
103 |
} |
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
104 |
} |
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
105 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
106 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
107 |
/* overlays */ |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
108 |
|
57873 | 109 |
private val overlays = Synchronized(Document.Overlays.empty) |
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
110 |
|
52980 | 111 |
override def node_overlays(name: Document.Node.Name): Document.Node.Overlays = |
57873 | 112 |
overlays.value(name) |
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
113 |
|
52980 | 114 |
override def insert_overlay(command: Command, fn: String, args: List[String]): Unit = |
57873 | 115 |
overlays.change(_.insert(command, fn, args)) |
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
116 |
|
52980 | 117 |
override def remove_overlay(command: Command, fn: String, args: List[String]): Unit = |
57873 | 118 |
overlays.change(_.remove(command, fn, args)) |
52980 | 119 |
|
120 |
||
55877 | 121 |
/* navigation */ |
52980 | 122 |
|
56413 | 123 |
def push_position(view: View) |
124 |
{ |
|
125 |
val navigator = jEdit.getPlugin("ise.plugin.nav.NavigatorPlugin") |
|
126 |
if (navigator != null) { |
|
59080
611914621edb
added Untyped.method convenience (for *this* class only);
wenzelm
parents:
58545
diff
changeset
|
127 |
try { Untyped.method(navigator.getClass, "pushPosition", view.getClass).invoke(null, view) } |
56413 | 128 |
catch { case _: NoSuchMethodException => } |
129 |
} |
|
130 |
} |
|
131 |
||
60893 | 132 |
def goto_buffer(focus: Boolean, view: View, buffer: Buffer, offset: Text.Offset) |
58545
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
133 |
{ |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
134 |
GUI_Thread.require {} |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
135 |
|
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
136 |
push_position(view) |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
137 |
|
60893 | 138 |
if (focus) view.goToBuffer(buffer) else view.showBuffer(buffer) |
58545
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
139 |
try { view.getTextArea.moveCaretPosition(offset) } |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
140 |
catch { |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
141 |
case _: ArrayIndexOutOfBoundsException => |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
142 |
case _: IllegalArgumentException => |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
143 |
} |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
144 |
} |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
145 |
|
64653 | 146 |
def goto_file(focus: Boolean, view: View, name: String): Unit = |
147 |
goto_file(focus, view, Line.Node_Position(name)) |
|
148 |
||
149 |
def goto_file(focus: Boolean, view: View, pos: Line.Node_Position) |
|
52980 | 150 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57611
diff
changeset
|
151 |
GUI_Thread.require {} |
52980 | 152 |
|
56413 | 153 |
push_position(view) |
154 |
||
64653 | 155 |
val name = pos.name |
156 |
val line = pos.line |
|
157 |
val column = pos.column |
|
158 |
||
54706 | 159 |
JEdit_Lib.jedit_buffer(name) match { |
52980 | 160 |
case Some(buffer) => |
60893 | 161 |
if (focus) view.goToBuffer(buffer) else view.showBuffer(buffer) |
52980 | 162 |
val text_area = view.getTextArea |
163 |
||
164 |
try { |
|
64653 | 165 |
val line_start = text_area.getBuffer.getLineStartOffset(line) |
52980 | 166 |
text_area.moveCaretPosition(line_start) |
64653 | 167 |
if (column > 0) text_area.moveCaretPosition(line_start + column) |
52980 | 168 |
} |
169 |
catch { |
|
170 |
case _: ArrayIndexOutOfBoundsException => |
|
171 |
case _: IllegalArgumentException => |
|
172 |
} |
|
173 |
||
54706 | 174 |
case None if (new JFile(name)).isDirectory => |
175 |
VFSBrowser.browseDirectory(view, name) |
|
176 |
||
52980 | 177 |
case None => |
178 |
val args = |
|
54706 | 179 |
if (line <= 0) Array(name) |
64653 | 180 |
else if (column <= 0) Array(name, "+line:" + (line + 1)) |
181 |
else Array(name, "+line:" + (line + 1) + "," + (column + 1)) |
|
52980 | 182 |
jEdit.openFiles(view, null, args) |
183 |
} |
|
184 |
} |
|
185 |
||
61660
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
186 |
def goto_doc(view: View, path: Path) |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
187 |
{ |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
188 |
if (path.is_file) |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
189 |
goto_file(true, view, File.platform_path(path)) |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
190 |
else { |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
191 |
Standard_Thread.fork("documentation") { |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
192 |
try { Doc.view(path) } |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
193 |
catch { |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
194 |
case exn: Throwable => |
62062
ee610059b0e9
fewer use of GUI_Thread.now to reduce danger of deadlock on shutdown;
wenzelm
parents:
61728
diff
changeset
|
195 |
GUI_Thread.later { |
ee610059b0e9
fewer use of GUI_Thread.now to reduce danger of deadlock on shutdown;
wenzelm
parents:
61728
diff
changeset
|
196 |
GUI.error_dialog(view, |
ee610059b0e9
fewer use of GUI_Thread.now to reduce danger of deadlock on shutdown;
wenzelm
parents:
61728
diff
changeset
|
197 |
"Documentation error", GUI.scrollable_text(Exn.message(exn))) |
ee610059b0e9
fewer use of GUI_Thread.now to reduce danger of deadlock on shutdown;
wenzelm
parents:
61728
diff
changeset
|
198 |
} |
61660
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
199 |
} |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
200 |
} |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
201 |
} |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
202 |
} |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
203 |
|
55877 | 204 |
|
205 |
/* hyperlinks */ |
|
206 |
||
61660
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
207 |
def hyperlink_doc(name: String): Option[Hyperlink] = |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
208 |
Doc.contents().collectFirst({ |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
209 |
case doc: Doc.Text_File if doc.name == name => doc.path |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
210 |
case doc: Doc.Doc if doc.name == name => doc.path}).map(path => |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
211 |
new Hyperlink { |
64663 | 212 |
override val external = !path.is_file |
61660
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
213 |
def follow(view: View): Unit = goto_doc(view, path) |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
214 |
override def toString: String = "doc " + quote(name) |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
215 |
}) |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
216 |
|
56461 | 217 |
def hyperlink_url(name: String): Hyperlink = |
218 |
new Hyperlink { |
|
64663 | 219 |
override val external = true |
56729 | 220 |
def follow(view: View): Unit = |
61557 | 221 |
Standard_Thread.fork("hyperlink_url") { |
62248 | 222 |
try { Isabelle_System.open(Url.escape(name)) } |
56461 | 223 |
catch { |
224 |
case exn: Throwable => |
|
62062
ee610059b0e9
fewer use of GUI_Thread.now to reduce danger of deadlock on shutdown;
wenzelm
parents:
61728
diff
changeset
|
225 |
GUI_Thread.later { |
ee610059b0e9
fewer use of GUI_Thread.now to reduce danger of deadlock on shutdown;
wenzelm
parents:
61728
diff
changeset
|
226 |
GUI.error_dialog(view, "System error", GUI.scrollable_text(Exn.message(exn))) |
ee610059b0e9
fewer use of GUI_Thread.now to reduce danger of deadlock on shutdown;
wenzelm
parents:
61728
diff
changeset
|
227 |
} |
56729 | 228 |
} |
229 |
} |
|
56461 | 230 |
override def toString: String = "URL " + quote(name) |
52980 | 231 |
} |
55876 | 232 |
|
60893 | 233 |
def hyperlink_buffer(focus: Boolean, buffer: Buffer, offset: Text.Offset): Hyperlink = |
58545
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
234 |
new Hyperlink { |
60893 | 235 |
def follow(view: View): Unit = goto_buffer(focus, view, buffer, offset) |
58545
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
236 |
override def toString: String = "buffer " + quote(JEdit_Lib.buffer_name(buffer)) |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
237 |
} |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
238 |
|
64653 | 239 |
def hyperlink_file(focus: Boolean, name: String): Hyperlink = |
240 |
hyperlink_file(focus, Line.Node_Position(name)) |
|
241 |
||
242 |
def hyperlink_file(focus: Boolean, pos: Line.Node_Position): Hyperlink = |
|
56461 | 243 |
new Hyperlink { |
64653 | 244 |
def follow(view: View): Unit = goto_file(focus, view, pos) |
245 |
override def toString: String = "file " + quote(pos.name) |
|
56461 | 246 |
} |
55876 | 247 |
|
64653 | 248 |
def hyperlink_source_file(focus: Boolean, source_name: String, line1: Int, offset: Symbol.Offset) |
55878 | 249 |
: Option[Hyperlink] = |
250 |
{ |
|
64657 | 251 |
for (name <- PIDE.resources.source_file(source_name)) yield { |
252 |
JEdit_Lib.jedit_buffer(name) match { |
|
253 |
case Some(buffer) if offset > 0 => |
|
254 |
val pos = |
|
255 |
JEdit_Lib.buffer_lock(buffer) { |
|
256 |
(Line.Position.zero /: |
|
257 |
(Symbol.iterator(JEdit_Lib.buffer_text(buffer)). |
|
64682 | 258 |
zipWithIndex.takeWhile(p => p._2 < offset - 1). |
259 |
map(_._1)))(_.advance(_, Text.Length)) |
|
64657 | 260 |
} |
261 |
hyperlink_file(focus, Line.Node_Position(name, pos)) |
|
262 |
case _ => |
|
263 |
hyperlink_file(focus, Line.Node_Position(name, Line.Position((line1 - 1) max 0))) |
|
55878 | 264 |
} |
265 |
} |
|
266 |
} |
|
55876 | 267 |
|
56461 | 268 |
override def hyperlink_command( |
64664 | 269 |
focus: Boolean, snapshot: Document.Snapshot, id: Document_ID.Generic, offset: Symbol.Offset = 0) |
60893 | 270 |
: Option[Hyperlink] = |
56461 | 271 |
{ |
272 |
if (snapshot.is_outdated) None |
|
64665 | 273 |
else snapshot.find_command_position(id, offset).map(hyperlink_file(focus, _)) |
56461 | 274 |
} |
275 |
||
61011 | 276 |
def is_hyperlink_position(snapshot: Document.Snapshot, |
277 |
text_offset: Text.Offset, pos: Position.T): Boolean = |
|
278 |
{ |
|
279 |
pos match { |
|
64667 | 280 |
case Position.Item_Id(id, range) if range.start > 0 => |
64665 | 281 |
snapshot.find_command(id) match { |
61011 | 282 |
case Some((node, command)) if snapshot.version.nodes(command.node_name) eq node => |
283 |
node.command_start(command) match { |
|
64667 | 284 |
case Some(start) => text_offset == start + command.chunk.decode(range.start) |
61011 | 285 |
case None => false |
286 |
} |
|
287 |
case _ => false |
|
288 |
} |
|
289 |
case _ => false |
|
290 |
} |
|
291 |
} |
|
292 |
||
60893 | 293 |
def hyperlink_position(focus: Boolean, snapshot: Document.Snapshot, pos: Position.T) |
294 |
: Option[Hyperlink] = |
|
60874 | 295 |
pos match { |
64667 | 296 |
case Position.Item_File(name, line, range) => |
297 |
hyperlink_source_file(focus, name, line, range.start) |
|
298 |
case Position.Item_Id(id, range) => |
|
299 |
hyperlink_command(focus, snapshot, id, range.start) |
|
60874 | 300 |
case _ => None |
301 |
} |
|
302 |
||
60893 | 303 |
def hyperlink_def_position(focus: Boolean, snapshot: Document.Snapshot, pos: Position.T) |
304 |
: Option[Hyperlink] = |
|
60874 | 305 |
pos match { |
64667 | 306 |
case Position.Item_Def_File(name, line, range) => |
307 |
hyperlink_source_file(focus, name, line, range.start) |
|
308 |
case Position.Item_Def_Id(id, range) => |
|
309 |
hyperlink_command(focus, snapshot, id, range.start) |
|
60874 | 310 |
case _ => None |
311 |
} |
|
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
312 |
} |