author | wenzelm |
Wed, 02 Apr 2025 23:18:12 +0200 | |
changeset 82418 | 6898054035d6 |
parent 82416 | 7b98d2a8ee6e |
child 82419 | 955c5d6c1acf |
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 |
|
58545
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
13 |
import org.gjt.sp.jedit.{jEdit, View, Buffer} |
54706 | 14 |
import org.gjt.sp.jedit.browser.VFSBrowser |
82418 | 15 |
import org.gjt.sp.jedit.textarea.TextArea |
70016 | 16 |
import org.gjt.sp.jedit.io.{VFSManager, VFSFile} |
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 |
|
75393 | 19 |
class JEdit_Editor extends Editor[View] { |
76794 | 20 |
/* PIDE session and document model */ |
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
21 |
|
52980 | 22 |
override def session: Session = PIDE.session |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
23 |
|
66084 | 24 |
def flush_edits(hidden: Boolean = false, purge: Boolean = false): Unit = |
64817 | 25 |
GUI_Thread.require { |
64867 | 26 |
val (doc_blobs, edits) = Document_Model.flush_edits(hidden, purge) |
64817 | 27 |
session.update(doc_blobs, edits) |
28 |
} |
|
66084 | 29 |
override def flush(): Unit = flush_edits() |
73340 | 30 |
def purge(): Unit = flush_edits(purge = true) |
64867 | 31 |
|
76044 | 32 |
private val delay_input: Delay = |
76610 | 33 |
Delay.last(PIDE.session.input_delay, gui = true) { flush() } |
54461 | 34 |
|
76044 | 35 |
private val delay_generated_input: Delay = |
76610 | 36 |
Delay.first(PIDE.session.generated_input_delay, gui = true) { flush() } |
64521
1aef5a0e18d7
delay_first for machine generated editor events: avoid starvation, e.g. when operating on big sessions;
wenzelm
parents:
62248
diff
changeset
|
37 |
|
76044 | 38 |
def invoke(): Unit = delay_input.invoke() |
39 |
def invoke_generated(): Unit = { delay_input.invoke(); delay_generated_input.invoke() } |
|
54461 | 40 |
|
66458
42d0d5c77c78
more robust shutdown, e.g. when plugin is stopped;
wenzelm
parents:
66101
diff
changeset
|
41 |
def shutdown(): Unit = |
42d0d5c77c78
more robust shutdown, e.g. when plugin is stopped;
wenzelm
parents:
66101
diff
changeset
|
42 |
GUI_Thread.require { |
76044 | 43 |
delay_input.revoke() |
44 |
delay_generated_input.revoke() |
|
66458
42d0d5c77c78
more robust shutdown, e.g. when plugin is stopped;
wenzelm
parents:
66101
diff
changeset
|
45 |
Document_Model.flush_edits(hidden = false, purge = false) |
42d0d5c77c78
more robust shutdown, e.g. when plugin is stopped;
wenzelm
parents:
66101
diff
changeset
|
46 |
} |
42d0d5c77c78
more robust shutdown, e.g. when plugin is stopped;
wenzelm
parents:
66101
diff
changeset
|
47 |
|
64799 | 48 |
def visible_node(name: Document.Node.Name): Boolean = |
64840 | 49 |
(for { |
50 |
text_area <- JEdit_Lib.jedit_text_areas() |
|
64882 | 51 |
doc_view <- Document_View.get(text_area) |
64840 | 52 |
} yield doc_view.model.node_name).contains(name) |
64799 | 53 |
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
54 |
|
76794 | 55 |
override def get_models(): Iterable[Document.Model] = Document_Model.get_models() |
56 |
||
57 |
||
76706 | 58 |
/* global changes */ |
76705
ddf5764684dd
proper state change, e.g. on open/close of "Document" panel;
wenzelm
parents:
76610
diff
changeset
|
59 |
|
76706 | 60 |
def state_changed(): Unit = { |
76708 | 61 |
GUI_Thread.later { flush() } |
76706 | 62 |
PIDE.plugin.deps_changed() |
63 |
session.global_options.post(Session.Global_Options(PIDE.options.value)) |
|
76705
ddf5764684dd
proper state change, e.g. on open/close of "Document" panel;
wenzelm
parents:
76610
diff
changeset
|
64 |
} |
ddf5764684dd
proper state change, e.g. on open/close of "Document" panel;
wenzelm
parents:
76610
diff
changeset
|
65 |
|
76715
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76708
diff
changeset
|
66 |
override def document_state_changed(): Unit = state_changed() |
76706 | 67 |
|
76705
ddf5764684dd
proper state change, e.g. on open/close of "Document" panel;
wenzelm
parents:
76610
diff
changeset
|
68 |
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
69 |
/* current situation */ |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
70 |
|
52980 | 71 |
override def current_node(view: View): Option[Document.Node.Name] = |
76768
40c8275f0131
tuned signature: follow terminology of VSCode_Resources;
wenzelm
parents:
76765
diff
changeset
|
72 |
GUI_Thread.require { Document_Model.get_model(view.getBuffer).map(_.node_name) } |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
73 |
|
52980 | 74 |
override def current_node_snapshot(view: View): Option[Document.Snapshot] = |
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76715
diff
changeset
|
75 |
GUI_Thread.require { Document_Model.get_snapshot(view.getBuffer) } |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
76 |
|
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76715
diff
changeset
|
77 |
override def node_snapshot(name: Document.Node.Name): Document.Snapshot = |
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76715
diff
changeset
|
78 |
GUI_Thread.require { Document_Model.get_snapshot(name) getOrElse session.snapshot(name) } |
52974 | 79 |
|
75393 | 80 |
override def current_command(view: View, snapshot: Document.Snapshot): Option[Command] = { |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57611
diff
changeset
|
81 |
GUI_Thread.require {} |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
82 |
|
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53845
diff
changeset
|
83 |
val text_area = view.getTextArea |
54528 | 84 |
val buffer = view.getBuffer |
85 |
||
64882 | 86 |
Document_View.get(text_area) match { |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
54706
diff
changeset
|
87 |
case Some(doc_view) if doc_view.model.is_theory => |
65199
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
wenzelm
parents:
65196
diff
changeset
|
88 |
snapshot.current_command(doc_view.model.node_name, text_area.getCaretPosition) |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
54706
diff
changeset
|
89 |
case _ => |
76768
40c8275f0131
tuned signature: follow terminology of VSCode_Resources;
wenzelm
parents:
76765
diff
changeset
|
90 |
Document_Model.get_model(buffer) match { |
54531
8330faaeebd5
restrict node_required status and Theories panel to actual theories;
wenzelm
parents:
54528
diff
changeset
|
91 |
case Some(model) if !model.is_theory => |
65187 | 92 |
snapshot.version.nodes.commands_loading(model.node_name).headOption |
54528 | 93 |
case _ => None |
94 |
} |
|
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
95 |
} |
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
96 |
} |
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
97 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
98 |
|
66101
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
99 |
/* overlays */ |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
100 |
|
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
101 |
override def node_overlays(name: Document.Node.Name): Document.Node.Overlays = |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
102 |
Document_Model.node_overlays(name) |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
103 |
|
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
104 |
override def insert_overlay(command: Command, fn: String, args: List[String]): Unit = |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
105 |
Document_Model.insert_overlay(command, fn, args) |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
106 |
|
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
107 |
override def remove_overlay(command: Command, fn: String, args: List[String]): Unit = |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
108 |
Document_Model.remove_overlay(command, fn, args) |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
109 |
|
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
110 |
|
55877 | 111 |
/* navigation */ |
52980 | 112 |
|
82413 | 113 |
def record_position(view: View): Unit = { |
114 |
PIDE.plugin.navigator.record(view) |
|
56413 | 115 |
val navigator = jEdit.getPlugin("ise.plugin.nav.NavigatorPlugin") |
116 |
if (navigator != null) { |
|
59080
611914621edb
added Untyped.method convenience (for *this* class only);
wenzelm
parents:
58545
diff
changeset
|
117 |
try { Untyped.method(navigator.getClass, "pushPosition", view.getClass).invoke(null, view) } |
56413 | 118 |
catch { case _: NoSuchMethodException => } |
119 |
} |
|
120 |
} |
|
121 |
||
75393 | 122 |
def goto_buffer(focus: Boolean, view: View, buffer: Buffer, offset: Text.Offset): Unit = { |
58545
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
123 |
GUI_Thread.require {} |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
124 |
|
82413 | 125 |
record_position(view) |
58545
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
126 |
|
60893 | 127 |
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
|
128 |
try { view.getTextArea.moveCaretPosition(offset) } |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
129 |
catch { |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
130 |
case _: ArrayIndexOutOfBoundsException => |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
131 |
case _: IllegalArgumentException => |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
132 |
} |
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 |
|
82418 | 135 |
def goto_file( |
136 |
focus: Boolean, |
|
137 |
view: View, |
|
138 |
name: String, |
|
139 |
offset: Text.Offset = -1, |
|
140 |
line: Int = -1, |
|
141 |
column: Int = -1 |
|
142 |
): Unit = { |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57611
diff
changeset
|
143 |
GUI_Thread.require {} |
52980 | 144 |
|
82413 | 145 |
record_position(view) |
56413 | 146 |
|
54706 | 147 |
JEdit_Lib.jedit_buffer(name) match { |
52980 | 148 |
case Some(buffer) => |
60893 | 149 |
if (focus) view.goToBuffer(buffer) else view.showBuffer(buffer) |
52980 | 150 |
val text_area = view.getTextArea |
151 |
||
152 |
try { |
|
82418 | 153 |
if (offset >= 0) text_area.moveCaretPosition(offset) |
154 |
else if (line >= 0) { |
|
155 |
val line_start = text_area.getBuffer.getLineStartOffset(line) |
|
156 |
text_area.moveCaretPosition(line_start) |
|
157 |
if (column > 0) text_area.moveCaretPosition(line_start + column) |
|
158 |
} |
|
52980 | 159 |
} |
160 |
catch { |
|
161 |
case _: ArrayIndexOutOfBoundsException => |
|
162 |
case _: IllegalArgumentException => |
|
163 |
} |
|
164 |
||
70016 | 165 |
case None => |
70167
b33f28c81ba9
clarified goto_file (again): treat bad entry as plain file to open empty buffer instead of error (amending a8142ac5e4b6);
wenzelm
parents:
70016
diff
changeset
|
166 |
val is_dir = |
70016 | 167 |
try { |
168 |
val vfs = VFSManager.getVFSForPath(name) |
|
169 |
val vfs_file = vfs._getFile((), name, view) |
|
70167
b33f28c81ba9
clarified goto_file (again): treat bad entry as plain file to open empty buffer instead of error (amending a8142ac5e4b6);
wenzelm
parents:
70016
diff
changeset
|
170 |
vfs_file != null && vfs_file.getType == VFSFile.DIRECTORY |
70016 | 171 |
} |
172 |
catch { case ERROR(_) => false } |
|
54706 | 173 |
|
70167
b33f28c81ba9
clarified goto_file (again): treat bad entry as plain file to open empty buffer instead of error (amending a8142ac5e4b6);
wenzelm
parents:
70016
diff
changeset
|
174 |
if (is_dir) VFSBrowser.browseDirectory(view, name) |
73224
49686e3b1909
clarified links to external files, e.g. .pdf within .thy source document;
wenzelm
parents:
72823
diff
changeset
|
175 |
else if (!Isabelle_System.open_external_file(name)) { |
70016 | 176 |
val args = |
82418 | 177 |
if (offset >= 0) Array(name, "+offset:" + offset) |
178 |
else if (line <= 0) Array(name) |
|
70016 | 179 |
else if (column <= 0) Array(name, "+line:" + (line + 1)) |
180 |
else Array(name, "+line:" + (line + 1) + "," + (column + 1)) |
|
181 |
jEdit.openFiles(view, null, args) |
|
182 |
} |
|
52980 | 183 |
} |
184 |
} |
|
185 |
||
75393 | 186 |
def goto_doc(view: View, path: Path): Unit = { |
75120 | 187 |
if (path.is_pdf) Doc.view(path) |
188 |
else goto_file(true, view, File.platform_path(path)) |
|
61660
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
189 |
} |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
190 |
|
55877 | 191 |
|
192 |
/* hyperlinks */ |
|
193 |
||
61660
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
194 |
def hyperlink_doc(name: String): Option[Hyperlink] = |
81350
1818358373e2
misc tuning and clarification: Doc.Entry supports both plain files and pdf documents;
wenzelm
parents:
80225
diff
changeset
|
195 |
Doc.contents().entries(name = _ == name).headOption.map(entry => |
1818358373e2
misc tuning and clarification: Doc.Entry supports both plain files and pdf documents;
wenzelm
parents:
80225
diff
changeset
|
196 |
new Hyperlink { |
1818358373e2
misc tuning and clarification: Doc.Entry supports both plain files and pdf documents;
wenzelm
parents:
80225
diff
changeset
|
197 |
override val external: Boolean = !entry.path.is_file |
1818358373e2
misc tuning and clarification: Doc.Entry supports both plain files and pdf documents;
wenzelm
parents:
80225
diff
changeset
|
198 |
def follow(view: View): Unit = goto_doc(view, entry.path) |
1818358373e2
misc tuning and clarification: Doc.Entry supports both plain files and pdf documents;
wenzelm
parents:
80225
diff
changeset
|
199 |
override def toString: String = "doc " + quote(name) |
75118 | 200 |
}) |
61660
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
201 |
|
56461 | 202 |
def hyperlink_url(name: String): Hyperlink = |
203 |
new Hyperlink { |
|
64663 | 204 |
override val external = true |
56729 | 205 |
def follow(view: View): Unit = |
71692 | 206 |
Isabelle_Thread.fork(name = "hyperlink_url") { |
69901 | 207 |
try { Isabelle_System.open(Url.escape_name(name)) } |
56461 | 208 |
catch { |
209 |
case exn: Throwable => |
|
62062
ee610059b0e9
fewer use of GUI_Thread.now to reduce danger of deadlock on shutdown;
wenzelm
parents:
61728
diff
changeset
|
210 |
GUI_Thread.later { |
ee610059b0e9
fewer use of GUI_Thread.now to reduce danger of deadlock on shutdown;
wenzelm
parents:
61728
diff
changeset
|
211 |
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
|
212 |
} |
56729 | 213 |
} |
214 |
} |
|
56461 | 215 |
override def toString: String = "URL " + quote(name) |
52980 | 216 |
} |
55876 | 217 |
|
82418 | 218 |
def hyperlink_file( |
219 |
focus: Boolean, |
|
220 |
name: String, |
|
221 |
offset: Text.Offset = -1, |
|
222 |
line: Int = -1, |
|
223 |
column: Int = -1 |
|
224 |
): Hyperlink = |
|
56461 | 225 |
new Hyperlink { |
82418 | 226 |
def follow(view: View): Unit = |
227 |
goto_file(focus, view, name, offset = offset, line = line, column = column) |
|
228 |
override def toString: String = "file " + quote(name) |
|
56461 | 229 |
} |
55876 | 230 |
|
75393 | 231 |
def hyperlink_source_file( |
232 |
focus: Boolean, |
|
233 |
source_name: String, |
|
234 |
line1: Int, |
|
235 |
offset: Symbol.Offset |
|
236 |
) : Option[Hyperlink] = { |
|
82193 | 237 |
for (platform_path <- PIDE.resources.source_file(source_name)) yield { |
64841
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
238 |
def hyperlink(pos: Line.Position) = |
82418 | 239 |
hyperlink_file(focus, platform_path, line = pos.line, column = pos.column) |
64841
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
240 |
|
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
241 |
if (offset > 0) { |
82193 | 242 |
PIDE.resources.get_file_content(PIDE.resources.node_name(platform_path)) match { |
64841
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
243 |
case Some(text) => |
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
244 |
hyperlink( |
73358 | 245 |
Symbol.iterator(text).zipWithIndex.takeWhile(p => p._2 < offset - 1).map(_._1). |
246 |
foldLeft(Line.Position.zero)(_.advance(_))) |
|
64841
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
247 |
case None => |
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
248 |
hyperlink(Line.Position((line1 - 1) max 0)) |
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
249 |
} |
55878 | 250 |
} |
64841
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
251 |
else hyperlink(Line.Position((line1 - 1) max 0)) |
55878 | 252 |
} |
253 |
} |
|
55876 | 254 |
|
56461 | 255 |
override def hyperlink_command( |
75393 | 256 |
focus: Boolean, |
257 |
snapshot: Document.Snapshot, |
|
258 |
id: Document_ID.Generic, |
|
259 |
offset: Symbol.Offset = 0 |
|
260 |
) : Option[Hyperlink] = { |
|
56461 | 261 |
if (snapshot.is_outdated) None |
82418 | 262 |
else { |
263 |
snapshot.find_command_position(id, offset) |
|
264 |
.map(pos => hyperlink_file(focus, pos.name, line = pos.line)) |
|
265 |
} |
|
56461 | 266 |
} |
267 |
||
75393 | 268 |
def is_hyperlink_position( |
269 |
snapshot: Document.Snapshot, |
|
270 |
text_offset: Text.Offset, |
|
271 |
pos: Position.T |
|
272 |
): Boolean = { |
|
61011 | 273 |
pos match { |
64667 | 274 |
case Position.Item_Id(id, range) if range.start > 0 => |
64665 | 275 |
snapshot.find_command(id) match { |
72823 | 276 |
case Some((node, command)) if snapshot.get_node(command.node_name) eq node => |
61011 | 277 |
node.command_start(command) match { |
64667 | 278 |
case Some(start) => text_offset == start + command.chunk.decode(range.start) |
61011 | 279 |
case None => false |
280 |
} |
|
281 |
case _ => false |
|
282 |
} |
|
283 |
case _ => false |
|
284 |
} |
|
285 |
} |
|
286 |
||
60893 | 287 |
def hyperlink_position(focus: Boolean, snapshot: Document.Snapshot, pos: Position.T) |
288 |
: Option[Hyperlink] = |
|
60874 | 289 |
pos match { |
64667 | 290 |
case Position.Item_File(name, line, range) => |
291 |
hyperlink_source_file(focus, name, line, range.start) |
|
292 |
case Position.Item_Id(id, range) => |
|
293 |
hyperlink_command(focus, snapshot, id, range.start) |
|
60874 | 294 |
case _ => None |
295 |
} |
|
296 |
||
60893 | 297 |
def hyperlink_def_position(focus: Boolean, snapshot: Document.Snapshot, pos: Position.T) |
298 |
: Option[Hyperlink] = |
|
60874 | 299 |
pos match { |
64667 | 300 |
case Position.Item_Def_File(name, line, range) => |
301 |
hyperlink_source_file(focus, name, line, range.start) |
|
302 |
case Position.Item_Def_Id(id, range) => |
|
303 |
hyperlink_command(focus, snapshot, id, range.start) |
|
60874 | 304 |
case _ => None |
305 |
} |
|
66094 | 306 |
|
307 |
||
308 |
/* dispatcher thread */ |
|
309 |
||
310 |
override def assert_dispatcher[A](body: => A): A = GUI_Thread.assert(body) |
|
311 |
override def require_dispatcher[A](body: => A): A = GUI_Thread.require(body) |
|
312 |
override def send_dispatcher(body: => Unit): Unit = GUI_Thread.later(body) |
|
313 |
override def send_wait_dispatcher(body: => Unit): Unit = GUI_Thread.now(body) |
|
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
314 |
} |