author | blanchet |
Thu, 20 Nov 2014 17:29:18 +0100 | |
changeset 59018 | ec8ea2465d2a |
parent 58545 | 30b75b7958d6 |
child 59080 | 611914621edb |
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 |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57611
diff
changeset
|
25 |
// owned by GUI thread |
57611
b6256ea3b7c5
proper change of perspective for removed nodes (stemming from closed buffers);
wenzelm
parents:
56770
diff
changeset
|
26 |
private var removed_nodes = Set.empty[Document.Node.Name] |
b6256ea3b7c5
proper change of perspective for removed nodes (stemming from closed buffers);
wenzelm
parents:
56770
diff
changeset
|
27 |
|
b6256ea3b7c5
proper change of perspective for removed nodes (stemming from closed buffers);
wenzelm
parents:
56770
diff
changeset
|
28 |
def remove_node(name: Document.Node.Name): Unit = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57611
diff
changeset
|
29 |
GUI_Thread.require { removed_nodes += name } |
57611
b6256ea3b7c5
proper change of perspective for removed nodes (stemming from closed buffers);
wenzelm
parents:
56770
diff
changeset
|
30 |
|
52980 | 31 |
override def flush() |
52974 | 32 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57611
diff
changeset
|
33 |
GUI_Thread.require {} |
52974 | 34 |
|
55783 | 35 |
val doc_blobs = PIDE.document_blobs() |
57611
b6256ea3b7c5
proper change of perspective for removed nodes (stemming from closed buffers);
wenzelm
parents:
56770
diff
changeset
|
36 |
val models = PIDE.document_models() |
b6256ea3b7c5
proper change of perspective for removed nodes (stemming from closed buffers);
wenzelm
parents:
56770
diff
changeset
|
37 |
|
b6256ea3b7c5
proper change of perspective for removed nodes (stemming from closed buffers);
wenzelm
parents:
56770
diff
changeset
|
38 |
val removed = removed_nodes; removed_nodes = Set.empty |
b6256ea3b7c5
proper change of perspective for removed nodes (stemming from closed buffers);
wenzelm
parents:
56770
diff
changeset
|
39 |
val removed_perspective = |
b6256ea3b7c5
proper change of perspective for removed nodes (stemming from closed buffers);
wenzelm
parents:
56770
diff
changeset
|
40 |
(removed -- models.iterator.map(_.node_name)).toList.map( |
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57612
diff
changeset
|
41 |
name => (name, Document.Node.no_perspective_text)) |
57611
b6256ea3b7c5
proper change of perspective for removed nodes (stemming from closed buffers);
wenzelm
parents:
56770
diff
changeset
|
42 |
|
b6256ea3b7c5
proper change of perspective for removed nodes (stemming from closed buffers);
wenzelm
parents:
56770
diff
changeset
|
43 |
val edits = models.flatMap(_.flushed_edits(doc_blobs)) ::: removed_perspective |
55783 | 44 |
if (!edits.isEmpty) session.update(doc_blobs, edits) |
52974 | 45 |
} |
46 |
||
54461 | 47 |
private val delay_flush = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57611
diff
changeset
|
48 |
GUI_Thread.delay_last(PIDE.options.seconds("editor_input_delay")) { flush() } |
54461 | 49 |
|
56770
e160ae47db94
mane delayed events outside of Swing thread -- triggers no longer require Swing_Thread.later;
wenzelm
parents:
56729
diff
changeset
|
50 |
def invoke(): Unit = delay_flush.invoke() |
54461 | 51 |
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
52 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
53 |
/* current situation */ |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
54 |
|
52980 | 55 |
override def current_context: View = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57611
diff
changeset
|
56 |
GUI_Thread.require { jEdit.getActiveView() } |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
57 |
|
52980 | 58 |
override def current_node(view: View): Option[Document.Node.Name] = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57611
diff
changeset
|
59 |
GUI_Thread.require { PIDE.document_model(view.getBuffer).map(_.node_name) } |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
60 |
|
52980 | 61 |
override def current_node_snapshot(view: View): Option[Document.Snapshot] = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57611
diff
changeset
|
62 |
GUI_Thread.require { PIDE.document_model(view.getBuffer).map(_.snapshot()) } |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
63 |
|
52980 | 64 |
override def node_snapshot(name: Document.Node.Name): Document.Snapshot = |
52974 | 65 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57611
diff
changeset
|
66 |
GUI_Thread.require {} |
52974 | 67 |
|
56457
eea4bbe15745
tuned signature -- prefer static type Document.Node.Name;
wenzelm
parents:
56413
diff
changeset
|
68 |
JEdit_Lib.jedit_buffer(name) match { |
52974 | 69 |
case Some(buffer) => |
70 |
PIDE.document_model(buffer) match { |
|
71 |
case Some(model) => model.snapshot |
|
72 |
case None => session.snapshot(name) |
|
73 |
} |
|
74 |
case None => session.snapshot(name) |
|
75 |
} |
|
76 |
} |
|
77 |
||
53844
71f103629327
skip ignored commands, similar to former proper_command_at (see d68ea01d5084) -- relevant to Output, Query_Operation etc.;
wenzelm
parents:
52980
diff
changeset
|
78 |
override def current_command(view: View, snapshot: Document.Snapshot): Option[Command] = |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
79 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57611
diff
changeset
|
80 |
GUI_Thread.require {} |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
81 |
|
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53845
diff
changeset
|
82 |
val text_area = view.getTextArea |
54528 | 83 |
val buffer = view.getBuffer |
84 |
||
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53845
diff
changeset
|
85 |
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
|
86 |
case Some(doc_view) if doc_view.model.is_theory => |
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53845
diff
changeset
|
87 |
val node = snapshot.version.nodes(doc_view.model.node_name) |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53845
diff
changeset
|
88 |
val caret = snapshot.revert(text_area.getCaretPosition) |
54528 | 89 |
if (caret < buffer.getLength) { |
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56314
diff
changeset
|
90 |
val caret_command_iterator = node.command_iterator(caret) |
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56314
diff
changeset
|
91 |
if (caret_command_iterator.hasNext) { |
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56314
diff
changeset
|
92 |
val (cmd0, _) = caret_command_iterator.next |
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53845
diff
changeset
|
93 |
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
|
94 |
} |
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53845
diff
changeset
|
95 |
else None |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53845
diff
changeset
|
96 |
} |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53845
diff
changeset
|
97 |
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
|
98 |
case _ => |
54528 | 99 |
PIDE.document_model(buffer) match { |
54531
8330faaeebd5
restrict node_required status and Theories panel to actual theories;
wenzelm
parents:
54528
diff
changeset
|
100 |
case Some(model) if !model.is_theory => |
56314 | 101 |
snapshot.version.nodes.load_commands(model.node_name) match { |
54528 | 102 |
case cmd :: _ => Some(cmd) |
103 |
case Nil => None |
|
104 |
} |
|
105 |
case _ => None |
|
106 |
} |
|
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
107 |
} |
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
108 |
} |
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
109 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
110 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
111 |
/* overlays */ |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
112 |
|
57873 | 113 |
private val overlays = Synchronized(Document.Overlays.empty) |
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
114 |
|
52980 | 115 |
override def node_overlays(name: Document.Node.Name): Document.Node.Overlays = |
57873 | 116 |
overlays.value(name) |
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
117 |
|
52980 | 118 |
override def insert_overlay(command: Command, fn: String, args: List[String]): Unit = |
57873 | 119 |
overlays.change(_.insert(command, fn, args)) |
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
120 |
|
52980 | 121 |
override def remove_overlay(command: Command, fn: String, args: List[String]): Unit = |
57873 | 122 |
overlays.change(_.remove(command, fn, args)) |
52980 | 123 |
|
124 |
||
55877 | 125 |
/* navigation */ |
52980 | 126 |
|
56413 | 127 |
def push_position(view: View) |
128 |
{ |
|
129 |
val navigator = jEdit.getPlugin("ise.plugin.nav.NavigatorPlugin") |
|
130 |
if (navigator != null) { |
|
131 |
try { |
|
132 |
val m = navigator.getClass.getDeclaredMethod("pushPosition", view.getClass) |
|
133 |
m.invoke(null, view) |
|
134 |
} |
|
135 |
catch { case _: NoSuchMethodException => } |
|
136 |
} |
|
137 |
} |
|
138 |
||
58545
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
139 |
def goto_buffer(view: View, buffer: Buffer, offset: Text.Offset) |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
140 |
{ |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
141 |
GUI_Thread.require {} |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
142 |
|
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
143 |
push_position(view) |
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 |
view.goToBuffer(buffer) |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
146 |
try { view.getTextArea.moveCaretPosition(offset) } |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
147 |
catch { |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
148 |
case _: ArrayIndexOutOfBoundsException => |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
149 |
case _: IllegalArgumentException => |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
150 |
} |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
151 |
} |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
152 |
|
55877 | 153 |
def goto_file(view: View, name: String, line: Int = 0, column: Int = 0) |
52980 | 154 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57611
diff
changeset
|
155 |
GUI_Thread.require {} |
52980 | 156 |
|
56413 | 157 |
push_position(view) |
158 |
||
54706 | 159 |
JEdit_Lib.jedit_buffer(name) match { |
52980 | 160 |
case Some(buffer) => |
161 |
view.goToBuffer(buffer) |
|
162 |
val text_area = view.getTextArea |
|
163 |
||
164 |
try { |
|
165 |
val line_start = text_area.getBuffer.getLineStartOffset(line - 1) |
|
166 |
text_area.moveCaretPosition(line_start) |
|
167 |
if (column > 0) text_area.moveCaretPosition(line_start + column - 1) |
|
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) |
180 |
else if (column <= 0) Array(name, "+line:" + line.toInt) |
|
181 |
else Array(name, "+line:" + line.toInt + "," + column.toInt) |
|
52980 | 182 |
jEdit.openFiles(view, null, args) |
183 |
} |
|
184 |
} |
|
185 |
||
55877 | 186 |
|
187 |
/* hyperlinks */ |
|
188 |
||
56461 | 189 |
def hyperlink_url(name: String): Hyperlink = |
190 |
new Hyperlink { |
|
56494
1b74abf064e1
avoid confusion about pointless cursor movement with external links;
wenzelm
parents:
56462
diff
changeset
|
191 |
val external = true |
56729 | 192 |
def follow(view: View): Unit = |
193 |
Future.fork { |
|
56461 | 194 |
try { Isabelle_System.open(name) } |
195 |
catch { |
|
196 |
case exn: Throwable => |
|
197 |
GUI.error_dialog(view, "System error", GUI.scrollable_text(Exn.message(exn))) |
|
56729 | 198 |
} |
199 |
} |
|
56461 | 200 |
override def toString: String = "URL " + quote(name) |
52980 | 201 |
} |
55876 | 202 |
|
58545
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
203 |
def hyperlink_buffer(buffer: Buffer, offset: Text.Offset): Hyperlink = |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
204 |
new Hyperlink { |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
205 |
val external = false |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
206 |
def follow(view: View): Unit = goto_buffer(view, buffer, offset) |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
207 |
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
|
208 |
} |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
209 |
|
55876 | 210 |
def hyperlink_file(name: String, line: Int = 0, column: Int = 0): Hyperlink = |
56461 | 211 |
new Hyperlink { |
56494
1b74abf064e1
avoid confusion about pointless cursor movement with external links;
wenzelm
parents:
56462
diff
changeset
|
212 |
val external = false |
56729 | 213 |
def follow(view: View): Unit = goto_file(view, name, line, column) |
56461 | 214 |
override def toString: String = "file " + quote(name) |
215 |
} |
|
55876 | 216 |
|
55884
f2c0eaedd579
tuned signature -- emphasize symbol positions (prover) vs. decoded text offsets (editor);
wenzelm
parents:
55879
diff
changeset
|
217 |
def hyperlink_source_file(source_name: String, line: Int, offset: Symbol.Offset) |
55878 | 218 |
: Option[Hyperlink] = |
219 |
{ |
|
56458
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
220 |
val opt_name = |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
221 |
if (Path.is_wellformed(source_name)) { |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
222 |
if (Path.is_valid(source_name)) { |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
223 |
val path = Path.explode(source_name) |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
224 |
Some(Isabelle_System.platform_path(Isabelle_System.source_file(path) getOrElse path)) |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
225 |
} |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
226 |
else None |
55878 | 227 |
} |
56458
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
228 |
else Some(source_name) |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
229 |
|
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
230 |
opt_name match { |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
231 |
case Some(name) => |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
232 |
JEdit_Lib.jedit_buffer(name) match { |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
233 |
case Some(buffer) if offset > 0 => |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
234 |
val (line, column) = |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
235 |
JEdit_Lib.buffer_lock(buffer) { |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
236 |
((1, 1) /: |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
237 |
(Symbol.iterator(JEdit_Lib.buffer_text(buffer)). |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
238 |
zipWithIndex.takeWhile(p => p._2 < offset - 1).map(_._1)))( |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
239 |
Symbol.advance_line_column) |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
240 |
} |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
241 |
Some(hyperlink_file(name, line, column)) |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
242 |
case _ => Some(hyperlink_file(name, line)) |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
243 |
} |
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56457
diff
changeset
|
244 |
case None => None |
55878 | 245 |
} |
246 |
} |
|
55876 | 247 |
|
56461 | 248 |
override def hyperlink_command( |
249 |
snapshot: Document.Snapshot, command: Command, offset: Symbol.Offset = 0): Option[Hyperlink] = |
|
250 |
{ |
|
251 |
if (snapshot.is_outdated) None |
|
252 |
else { |
|
253 |
snapshot.state.find_command(snapshot.version, command.id) match { |
|
254 |
case None => None |
|
255 |
case Some((node, _)) => |
|
256 |
val file_name = command.node_name.node |
|
257 |
val sources_iterator = |
|
258 |
node.commands.iterator.takeWhile(_ != command).map(_.source) ++ |
|
259 |
(if (offset == 0) Iterator.empty |
|
56462
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
wenzelm
parents:
56461
diff
changeset
|
260 |
else Iterator.single(command.source(Text.Range(0, command.chunk.decode(offset))))) |
56461 | 261 |
val (line, column) = ((1, 1) /: sources_iterator)(Symbol.advance_line_column) |
262 |
Some(hyperlink_file(file_name, line, column)) |
|
263 |
} |
|
55876 | 264 |
} |
56461 | 265 |
} |
266 |
||
267 |
def hyperlink_command_id( |
|
268 |
snapshot: Document.Snapshot, |
|
269 |
id: Document_ID.Generic, |
|
57878
51a2f9140175
follow link to originating command, to ensure that Simplifier_Trace_Dockable displays its results (via current_command);
wenzelm
parents:
57873
diff
changeset
|
270 |
offset: Symbol.Offset = 0): Option[Hyperlink] = |
56461 | 271 |
{ |
272 |
snapshot.state.find_command(snapshot.version, id) match { |
|
273 |
case Some((node, command)) => hyperlink_command(snapshot, command, offset) |
|
274 |
case None => None |
|
275 |
} |
|
276 |
} |
|
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
277 |
} |