author | wenzelm |
Sun, 24 Dec 2023 13:20:40 +0100 | |
changeset 79353 | af7881b2299d |
parent 76794 | 941d4f527091 |
child 80225 | d9ff4296e3b7 |
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 |
70016 | 17 |
import org.gjt.sp.jedit.io.{VFSManager, VFSFile} |
52971
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 |
|
75393 | 20 |
class JEdit_Editor extends Editor[View] { |
76794 | 21 |
/* PIDE session and document model */ |
52977
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 |
|
66084 | 25 |
def flush_edits(hidden: Boolean = false, purge: Boolean = false): Unit = |
64817 | 26 |
GUI_Thread.require { |
64867 | 27 |
val (doc_blobs, edits) = Document_Model.flush_edits(hidden, purge) |
64817 | 28 |
session.update(doc_blobs, edits) |
29 |
} |
|
66084 | 30 |
override def flush(): Unit = flush_edits() |
73340 | 31 |
def purge(): Unit = flush_edits(purge = true) |
64867 | 32 |
|
76044 | 33 |
private val delay_input: Delay = |
76610 | 34 |
Delay.last(PIDE.session.input_delay, gui = true) { flush() } |
54461 | 35 |
|
76044 | 36 |
private val delay_generated_input: Delay = |
76610 | 37 |
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
|
38 |
|
76044 | 39 |
def invoke(): Unit = delay_input.invoke() |
40 |
def invoke_generated(): Unit = { delay_input.invoke(); delay_generated_input.invoke() } |
|
54461 | 41 |
|
66458
42d0d5c77c78
more robust shutdown, e.g. when plugin is stopped;
wenzelm
parents:
66101
diff
changeset
|
42 |
def shutdown(): Unit = |
42d0d5c77c78
more robust shutdown, e.g. when plugin is stopped;
wenzelm
parents:
66101
diff
changeset
|
43 |
GUI_Thread.require { |
76044 | 44 |
delay_input.revoke() |
45 |
delay_generated_input.revoke() |
|
66458
42d0d5c77c78
more robust shutdown, e.g. when plugin is stopped;
wenzelm
parents:
66101
diff
changeset
|
46 |
Document_Model.flush_edits(hidden = false, purge = false) |
42d0d5c77c78
more robust shutdown, e.g. when plugin is stopped;
wenzelm
parents:
66101
diff
changeset
|
47 |
} |
42d0d5c77c78
more robust shutdown, e.g. when plugin is stopped;
wenzelm
parents:
66101
diff
changeset
|
48 |
|
64799 | 49 |
def visible_node(name: Document.Node.Name): Boolean = |
64840 | 50 |
(for { |
51 |
text_area <- JEdit_Lib.jedit_text_areas() |
|
64882 | 52 |
doc_view <- Document_View.get(text_area) |
64840 | 53 |
} yield doc_view.model.node_name).contains(name) |
64799 | 54 |
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
55 |
|
76794 | 56 |
override def get_models(): Iterable[Document.Model] = Document_Model.get_models() |
57 |
||
58 |
||
76706 | 59 |
/* global changes */ |
76705
ddf5764684dd
proper state change, e.g. on open/close of "Document" panel;
wenzelm
parents:
76610
diff
changeset
|
60 |
|
76706 | 61 |
def state_changed(): Unit = { |
76708 | 62 |
GUI_Thread.later { flush() } |
76706 | 63 |
PIDE.plugin.deps_changed() |
64 |
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
|
65 |
} |
ddf5764684dd
proper state change, e.g. on open/close of "Document" panel;
wenzelm
parents:
76610
diff
changeset
|
66 |
|
76715
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76708
diff
changeset
|
67 |
override def document_state_changed(): Unit = state_changed() |
76706 | 68 |
|
76705
ddf5764684dd
proper state change, e.g. on open/close of "Document" panel;
wenzelm
parents:
76610
diff
changeset
|
69 |
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
70 |
/* current situation */ |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
71 |
|
52980 | 72 |
override def current_node(view: View): Option[Document.Node.Name] = |
76768
40c8275f0131
tuned signature: follow terminology of VSCode_Resources;
wenzelm
parents:
76765
diff
changeset
|
73 |
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
|
74 |
|
52980 | 75 |
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
|
76 |
GUI_Thread.require { Document_Model.get_snapshot(view.getBuffer) } |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
77 |
|
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76715
diff
changeset
|
78 |
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
|
79 |
GUI_Thread.require { Document_Model.get_snapshot(name) getOrElse session.snapshot(name) } |
52974 | 80 |
|
75393 | 81 |
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
|
82 |
GUI_Thread.require {} |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
83 |
|
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53845
diff
changeset
|
84 |
val text_area = view.getTextArea |
54528 | 85 |
val buffer = view.getBuffer |
86 |
||
64882 | 87 |
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
|
88 |
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
|
89 |
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
|
90 |
case _ => |
76768
40c8275f0131
tuned signature: follow terminology of VSCode_Resources;
wenzelm
parents:
76765
diff
changeset
|
91 |
Document_Model.get_model(buffer) match { |
54531
8330faaeebd5
restrict node_required status and Theories panel to actual theories;
wenzelm
parents:
54528
diff
changeset
|
92 |
case Some(model) if !model.is_theory => |
65187 | 93 |
snapshot.version.nodes.commands_loading(model.node_name).headOption |
54528 | 94 |
case _ => None |
95 |
} |
|
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
96 |
} |
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
97 |
} |
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
98 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
99 |
|
66101
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
100 |
/* overlays */ |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
101 |
|
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
102 |
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
|
103 |
Document_Model.node_overlays(name) |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
104 |
|
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
105 |
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
|
106 |
Document_Model.insert_overlay(command, fn, args) |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
107 |
|
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
108 |
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
|
109 |
Document_Model.remove_overlay(command, fn, args) |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
110 |
|
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
111 |
|
55877 | 112 |
/* navigation */ |
52980 | 113 |
|
75393 | 114 |
def push_position(view: View): Unit = { |
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 |
|
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
57878
diff
changeset
|
125 |
push_position(view) |
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 |
|
64653 | 135 |
def goto_file(focus: Boolean, view: View, name: String): Unit = |
66605
261dcd52c5a0
less aggressive default position: prefer persistent defaults maintained by jEdit (amending 89c5bb2a2128);
wenzelm
parents:
66458
diff
changeset
|
136 |
goto_file(focus, view, Line.Node_Position.offside(name)) |
64653 | 137 |
|
75393 | 138 |
def goto_file(focus: Boolean, view: View, pos: Line.Node_Position): Unit = { |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57611
diff
changeset
|
139 |
GUI_Thread.require {} |
52980 | 140 |
|
56413 | 141 |
push_position(view) |
142 |
||
64653 | 143 |
val name = pos.name |
144 |
val line = pos.line |
|
145 |
val column = pos.column |
|
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 { |
|
64653 | 153 |
val line_start = text_area.getBuffer.getLineStartOffset(line) |
52980 | 154 |
text_area.moveCaretPosition(line_start) |
64653 | 155 |
if (column > 0) text_area.moveCaretPosition(line_start + column) |
52980 | 156 |
} |
157 |
catch { |
|
158 |
case _: ArrayIndexOutOfBoundsException => |
|
159 |
case _: IllegalArgumentException => |
|
160 |
} |
|
161 |
||
70016 | 162 |
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
|
163 |
val is_dir = |
70016 | 164 |
try { |
165 |
val vfs = VFSManager.getVFSForPath(name) |
|
166 |
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
|
167 |
vfs_file != null && vfs_file.getType == VFSFile.DIRECTORY |
70016 | 168 |
} |
169 |
catch { case ERROR(_) => false } |
|
54706 | 170 |
|
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
|
171 |
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
|
172 |
else if (!Isabelle_System.open_external_file(name)) { |
70016 | 173 |
val args = |
174 |
if (line <= 0) Array(name) |
|
175 |
else if (column <= 0) Array(name, "+line:" + (line + 1)) |
|
176 |
else Array(name, "+line:" + (line + 1) + "," + (column + 1)) |
|
177 |
jEdit.openFiles(view, null, args) |
|
178 |
} |
|
52980 | 179 |
} |
180 |
} |
|
181 |
||
75393 | 182 |
def goto_doc(view: View, path: Path): Unit = { |
75120 | 183 |
if (path.is_pdf) Doc.view(path) |
184 |
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
|
185 |
} |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
186 |
|
55877 | 187 |
|
188 |
/* hyperlinks */ |
|
189 |
||
61660
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
190 |
def hyperlink_doc(name: String): Option[Hyperlink] = |
75118 | 191 |
Doc.contents().entries.collectFirst( |
192 |
{ case entry if entry.name == name => |
|
193 |
new Hyperlink { |
|
194 |
override val external: Boolean = !entry.path.is_file |
|
195 |
def follow(view: View): Unit = goto_doc(view, entry.path) |
|
196 |
override def toString: String = "doc " + quote(name) |
|
197 |
} |
|
198 |
}) |
|
61660
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61557
diff
changeset
|
199 |
|
56461 | 200 |
def hyperlink_url(name: String): Hyperlink = |
201 |
new Hyperlink { |
|
64663 | 202 |
override val external = true |
56729 | 203 |
def follow(view: View): Unit = |
71692 | 204 |
Isabelle_Thread.fork(name = "hyperlink_url") { |
69901 | 205 |
try { Isabelle_System.open(Url.escape_name(name)) } |
56461 | 206 |
catch { |
207 |
case exn: Throwable => |
|
62062
ee610059b0e9
fewer use of GUI_Thread.now to reduce danger of deadlock on shutdown;
wenzelm
parents:
61728
diff
changeset
|
208 |
GUI_Thread.later { |
ee610059b0e9
fewer use of GUI_Thread.now to reduce danger of deadlock on shutdown;
wenzelm
parents:
61728
diff
changeset
|
209 |
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
|
210 |
} |
56729 | 211 |
} |
212 |
} |
|
56461 | 213 |
override def toString: String = "URL " + quote(name) |
52980 | 214 |
} |
55876 | 215 |
|
64653 | 216 |
def hyperlink_file(focus: Boolean, name: String): Hyperlink = |
66605
261dcd52c5a0
less aggressive default position: prefer persistent defaults maintained by jEdit (amending 89c5bb2a2128);
wenzelm
parents:
66458
diff
changeset
|
217 |
hyperlink_file(focus, Line.Node_Position.offside(name)) |
64653 | 218 |
|
219 |
def hyperlink_file(focus: Boolean, pos: Line.Node_Position): Hyperlink = |
|
56461 | 220 |
new Hyperlink { |
64653 | 221 |
def follow(view: View): Unit = goto_file(focus, view, pos) |
222 |
override def toString: String = "file " + quote(pos.name) |
|
56461 | 223 |
} |
55876 | 224 |
|
64829
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64817
diff
changeset
|
225 |
def hyperlink_model(focus: Boolean, model: Document_Model, offset: Text.Offset): Hyperlink = |
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64817
diff
changeset
|
226 |
model match { |
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64817
diff
changeset
|
227 |
case file_model: File_Model => |
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64817
diff
changeset
|
228 |
val pos = |
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64817
diff
changeset
|
229 |
try { file_model.node_position(offset) } |
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64817
diff
changeset
|
230 |
catch { case ERROR(_) => Line.Node_Position(file_model.node_name.node) } |
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64817
diff
changeset
|
231 |
hyperlink_file(focus, pos) |
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64817
diff
changeset
|
232 |
case buffer_model: Buffer_Model => |
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64817
diff
changeset
|
233 |
new Hyperlink { |
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64817
diff
changeset
|
234 |
def follow(view: View): Unit = goto_buffer(focus, view, buffer_model.buffer, offset) |
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64817
diff
changeset
|
235 |
override def toString: String = "buffer " + quote(model.node_name.node) |
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64817
diff
changeset
|
236 |
} |
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64817
diff
changeset
|
237 |
} |
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64817
diff
changeset
|
238 |
|
75393 | 239 |
def hyperlink_source_file( |
240 |
focus: Boolean, |
|
241 |
source_name: String, |
|
242 |
line1: Int, |
|
243 |
offset: Symbol.Offset |
|
244 |
) : Option[Hyperlink] = { |
|
64657 | 245 |
for (name <- PIDE.resources.source_file(source_name)) yield { |
64841
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
246 |
def hyperlink(pos: Line.Position) = |
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
247 |
hyperlink_file(focus, Line.Node_Position(name, pos)) |
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
248 |
|
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
249 |
if (offset > 0) { |
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
250 |
PIDE.resources.get_file_content(PIDE.resources.node_name(name)) match { |
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
251 |
case Some(text) => |
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
252 |
hyperlink( |
73358 | 253 |
Symbol.iterator(text).zipWithIndex.takeWhile(p => p._2 < offset - 1).map(_._1). |
254 |
foldLeft(Line.Position.zero)(_.advance(_))) |
|
64841
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
255 |
case None => |
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
256 |
hyperlink(Line.Position((line1 - 1) max 0)) |
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
257 |
} |
55878 | 258 |
} |
64841
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64840
diff
changeset
|
259 |
else hyperlink(Line.Position((line1 - 1) max 0)) |
55878 | 260 |
} |
261 |
} |
|
55876 | 262 |
|
56461 | 263 |
override def hyperlink_command( |
75393 | 264 |
focus: Boolean, |
265 |
snapshot: Document.Snapshot, |
|
266 |
id: Document_ID.Generic, |
|
267 |
offset: Symbol.Offset = 0 |
|
268 |
) : Option[Hyperlink] = { |
|
56461 | 269 |
if (snapshot.is_outdated) None |
64665 | 270 |
else snapshot.find_command_position(id, offset).map(hyperlink_file(focus, _)) |
56461 | 271 |
} |
272 |
||
75393 | 273 |
def is_hyperlink_position( |
274 |
snapshot: Document.Snapshot, |
|
275 |
text_offset: Text.Offset, |
|
276 |
pos: Position.T |
|
277 |
): Boolean = { |
|
61011 | 278 |
pos match { |
64667 | 279 |
case Position.Item_Id(id, range) if range.start > 0 => |
64665 | 280 |
snapshot.find_command(id) match { |
72823 | 281 |
case Some((node, command)) if snapshot.get_node(command.node_name) eq node => |
61011 | 282 |
node.command_start(command) match { |
64667 | 283 |
case Some(start) => text_offset == start + command.chunk.decode(range.start) |
61011 | 284 |
case None => false |
285 |
} |
|
286 |
case _ => false |
|
287 |
} |
|
288 |
case _ => false |
|
289 |
} |
|
290 |
} |
|
291 |
||
60893 | 292 |
def hyperlink_position(focus: Boolean, snapshot: Document.Snapshot, pos: Position.T) |
293 |
: Option[Hyperlink] = |
|
60874 | 294 |
pos match { |
64667 | 295 |
case Position.Item_File(name, line, range) => |
296 |
hyperlink_source_file(focus, name, line, range.start) |
|
297 |
case Position.Item_Id(id, range) => |
|
298 |
hyperlink_command(focus, snapshot, id, range.start) |
|
60874 | 299 |
case _ => None |
300 |
} |
|
301 |
||
60893 | 302 |
def hyperlink_def_position(focus: Boolean, snapshot: Document.Snapshot, pos: Position.T) |
303 |
: Option[Hyperlink] = |
|
60874 | 304 |
pos match { |
64667 | 305 |
case Position.Item_Def_File(name, line, range) => |
306 |
hyperlink_source_file(focus, name, line, range.start) |
|
307 |
case Position.Item_Def_Id(id, range) => |
|
308 |
hyperlink_command(focus, snapshot, id, range.start) |
|
60874 | 309 |
case _ => None |
310 |
} |
|
66094 | 311 |
|
312 |
||
313 |
/* dispatcher thread */ |
|
314 |
||
315 |
override def assert_dispatcher[A](body: => A): A = GUI_Thread.assert(body) |
|
316 |
override def require_dispatcher[A](body: => A): A = GUI_Thread.require(body) |
|
317 |
override def send_dispatcher(body: => Unit): Unit = GUI_Thread.later(body) |
|
318 |
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
|
319 |
} |