author | wenzelm |
Sat, 30 Jul 2022 13:44:26 +0200 | |
changeset 75728 | 3f64fdf75082 |
parent 75394 | 42267c650205 |
child 75847 | 93436389db1c |
permissions | -rw-r--r-- |
43282
5d294220ca43
moved sources -- eliminated Netbeans artifact of jedit package directory;
wenzelm
parents:
40851
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/document_model.scala |
36760 | 2 |
Author: Fabian Immler, TU Munich |
3 |
Author: Makarius |
|
4 |
||
64817 | 5 |
Document model connected to jEdit buffer or external file: content of theory |
6 |
node or auxiliary file (blob). |
|
36760 | 7 |
*/ |
34407 | 8 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
9 |
package isabelle.jedit |
34760 | 10 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
11 |
|
36015 | 12 |
import isabelle._ |
13 |
||
64858 | 14 |
import java.io.{File => JFile} |
15 |
||
34693 | 16 |
import scala.collection.mutable |
66019 | 17 |
import scala.annotation.tailrec |
34446 | 18 |
|
72960 | 19 |
import org.gjt.sp.jedit.View |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
20 |
import org.gjt.sp.jedit.Buffer |
61192 | 21 |
import org.gjt.sp.jedit.buffer.{BufferAdapter, BufferListener, JEditBuffer} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
22 |
|
34760 | 23 |
|
75393 | 24 |
object Document_Model { |
64817 | 25 |
/* document models */ |
26 |
||
27 |
sealed case class State( |
|
28 |
models: Map[Document.Node.Name, Document_Model] = Map.empty, |
|
66101
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66082
diff
changeset
|
29 |
buffer_models: Map[JEditBuffer, Buffer_Model] = Map.empty, |
75393 | 30 |
overlays: Document.Overlays = Document.Overlays.empty |
31 |
) { |
|
64868 | 32 |
def file_models_iterator: Iterator[(Document.Node.Name, File_Model)] = |
64817 | 33 |
for { |
64868 | 34 |
(node_name, model) <- models.iterator |
64817 | 35 |
if model.isInstanceOf[File_Model] |
64868 | 36 |
} yield (node_name, model.asInstanceOf[File_Model]) |
64813 | 37 |
|
68476 | 38 |
def document_blobs: Document.Blobs = |
39 |
Document.Blobs( |
|
40 |
(for { |
|
41 |
(node_name, model) <- models.iterator |
|
42 |
blob <- model.get_blob |
|
43 |
} yield (node_name -> blob)).toMap) |
|
44 |
||
75393 | 45 |
def open_buffer( |
46 |
session: Session, |
|
47 |
node_name: Document.Node.Name, |
|
48 |
buffer: Buffer |
|
49 |
) : (Buffer_Model, State) = { |
|
64817 | 50 |
val old_model = |
51 |
models.get(node_name) match { |
|
52 |
case Some(file_model: File_Model) => Some(file_model) |
|
53 |
case Some(buffer_model: Buffer_Model) => Some(buffer_model.exit()) |
|
54 |
case _ => None |
|
55 |
} |
|
56 |
val buffer_model = Buffer_Model(session, node_name, buffer).init(old_model) |
|
57 |
(buffer_model, |
|
58 |
copy(models = models + (node_name -> buffer_model), |
|
59 |
buffer_models = buffer_models + (buffer -> buffer_model))) |
|
60 |
} |
|
61 |
||
75393 | 62 |
def close_buffer(buffer: JEditBuffer): State = { |
64817 | 63 |
buffer_models.get(buffer) match { |
64 |
case None => this |
|
65 |
case Some(buffer_model) => |
|
66 |
val file_model = buffer_model.exit() |
|
67 |
copy(models = models + (file_model.node_name -> file_model), |
|
68 |
buffer_models = buffer_models - buffer) |
|
69 |
} |
|
70 |
} |
|
64835
fd1efd6dd385
resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents:
64832
diff
changeset
|
71 |
|
fd1efd6dd385
resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents:
64832
diff
changeset
|
72 |
def provide_file(session: Session, node_name: Document.Node.Name, text: String): State = |
fd1efd6dd385
resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents:
64832
diff
changeset
|
73 |
if (models.isDefinedAt(node_name)) this |
fd1efd6dd385
resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents:
64832
diff
changeset
|
74 |
else { |
fd1efd6dd385
resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents:
64832
diff
changeset
|
75 |
val edit = Text.Edit.insert(0, text) |
64863 | 76 |
val model = File_Model.init(session, node_name, text, pending_edits = List(edit)) |
64835
fd1efd6dd385
resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents:
64832
diff
changeset
|
77 |
copy(models = models + (node_name -> model)) |
fd1efd6dd385
resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents:
64832
diff
changeset
|
78 |
} |
64817 | 79 |
} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
80 |
|
64817 | 81 |
private val state = Synchronized(State()) // owned by GUI thread |
82 |
||
73999
6b213c0115f5
clarified global state: allow to deactivate main plugin;
wenzelm
parents:
73702
diff
changeset
|
83 |
def reset(): Unit = state.change(_ => State()) |
6b213c0115f5
clarified global state: allow to deactivate main plugin;
wenzelm
parents:
73702
diff
changeset
|
84 |
|
64835
fd1efd6dd385
resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents:
64832
diff
changeset
|
85 |
def get_models(): Map[Document.Node.Name, Document_Model] = state.value.models |
71601 | 86 |
def get(name: Document.Node.Name): Option[Document_Model] = get_models().get(name) |
64835
fd1efd6dd385
resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents:
64832
diff
changeset
|
87 |
def get(buffer: JEditBuffer): Option[Buffer_Model] = state.value.buffer_models.get(buffer) |
64817 | 88 |
|
68476 | 89 |
def document_blobs(): Document.Blobs = state.value.document_blobs |
90 |
||
66152 | 91 |
|
92 |
/* bibtex */ |
|
93 |
||
64831 | 94 |
def bibtex_entries_iterator(): Iterator[Text.Info[(String, Document_Model)]] = |
66150 | 95 |
Bibtex.entries_iterator(state.value.models) |
64829
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64828
diff
changeset
|
96 |
|
66152 | 97 |
def bibtex_completion(history: Completion.History, rendering: Rendering, caret: Text.Offset) |
98 |
: Option[Completion.Result] = |
|
99 |
Bibtex.completion(history, rendering, caret, state.value.models) |
|
100 |
||
64817 | 101 |
|
66101
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66082
diff
changeset
|
102 |
/* overlays */ |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66082
diff
changeset
|
103 |
|
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66082
diff
changeset
|
104 |
def node_overlays(name: Document.Node.Name): Document.Node.Overlays = |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66082
diff
changeset
|
105 |
state.value.overlays(name) |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66082
diff
changeset
|
106 |
|
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66082
diff
changeset
|
107 |
def insert_overlay(command: Command, fn: String, args: List[String]): Unit = |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66082
diff
changeset
|
108 |
state.change(st => st.copy(overlays = st.overlays.insert(command, fn, args))) |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66082
diff
changeset
|
109 |
|
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66082
diff
changeset
|
110 |
def remove_overlay(command: Command, fn: String, args: List[String]): Unit = |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66082
diff
changeset
|
111 |
state.change(st => st.copy(overlays = st.overlays.remove(command, fn, args))) |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66082
diff
changeset
|
112 |
|
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66082
diff
changeset
|
113 |
|
64858 | 114 |
/* sync external files */ |
115 |
||
75393 | 116 |
def sync_files(changed_files: Set[JFile]): Boolean = { |
75394 | 117 |
state.change_result { st => |
75393 | 118 |
val changed_models = |
119 |
(for { |
|
120 |
(node_name, model) <- st.file_models_iterator |
|
121 |
file <- model.file if changed_files(file) |
|
122 |
text <- PIDE.resources.read_file_content(node_name) |
|
123 |
if model.content.text != text |
|
124 |
} yield { |
|
125 |
val content = Document_Model.File_Content(text) |
|
126 |
val edits = Text.Edit.replace(0, model.content.text, text) |
|
127 |
(node_name, model.copy(content = content, pending_edits = model.pending_edits ::: edits)) |
|
128 |
}).toList |
|
129 |
if (changed_models.isEmpty) (false, st) |
|
130 |
else (true, st.copy(models = changed_models.foldLeft(st.models)(_ + _))) |
|
75394 | 131 |
} |
64858 | 132 |
} |
133 |
||
134 |
||
64836 | 135 |
/* syntax */ |
136 |
||
75393 | 137 |
def syntax_changed(names: List[Document.Node.Name]): Unit = { |
64836 | 138 |
GUI_Thread.require {} |
139 |
||
140 |
val models = state.value.models |
|
141 |
for (name <- names.iterator; model <- models.get(name)) { |
|
142 |
model match { case buffer_model: Buffer_Model => buffer_model.syntax_changed() case _ => } |
|
143 |
} |
|
144 |
} |
|
145 |
||
146 |
||
64817 | 147 |
/* init and exit */ |
148 |
||
75393 | 149 |
def init(session: Session, node_name: Document.Node.Name, buffer: Buffer): Buffer_Model = { |
64817 | 150 |
GUI_Thread.require {} |
151 |
state.change_result(st => |
|
152 |
st.buffer_models.get(buffer) match { |
|
153 |
case Some(buffer_model) if buffer_model.node_name == node_name => |
|
72960 | 154 |
buffer_model.init_token_marker() |
64817 | 155 |
(buffer_model, st) |
156 |
case _ => |
|
157 |
val res = st.close_buffer(buffer).open_buffer(session, node_name, buffer) |
|
72960 | 158 |
buffer.propertiesChanged() |
64817 | 159 |
res |
160 |
}) |
|
161 |
} |
|
162 |
||
75393 | 163 |
def exit(buffer: Buffer): Unit = { |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
164 |
GUI_Thread.require {} |
64813 | 165 |
state.change(st => |
64817 | 166 |
if (st.buffer_models.isDefinedAt(buffer)) { |
167 |
val res = st.close_buffer(buffer) |
|
72960 | 168 |
buffer.propertiesChanged() |
64817 | 169 |
res |
170 |
} |
|
171 |
else st) |
|
172 |
} |
|
173 |
||
75393 | 174 |
def provide_files(session: Session, files: List[(Document.Node.Name, String)]): Unit = { |
64835
fd1efd6dd385
resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents:
64832
diff
changeset
|
175 |
GUI_Thread.require {} |
fd1efd6dd385
resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents:
64832
diff
changeset
|
176 |
state.change(st => |
73358 | 177 |
files.foldLeft(st) { |
178 |
case (st1, (node_name, text)) => st1.provide_file(session, node_name, text) |
|
179 |
}) |
|
64835
fd1efd6dd385
resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents:
64832
diff
changeset
|
180 |
} |
fd1efd6dd385
resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents:
64832
diff
changeset
|
181 |
|
64817 | 182 |
|
183 |
/* required nodes */ |
|
184 |
||
185 |
def required_nodes(): Set[Document.Node.Name] = |
|
186 |
(for { |
|
64868 | 187 |
(node_name, model) <- state.value.models.iterator |
64817 | 188 |
if model.node_required |
64868 | 189 |
} yield node_name).toSet |
64817 | 190 |
|
73340 | 191 |
def node_required( |
75393 | 192 |
name: Document.Node.Name, |
193 |
toggle: Boolean = false, |
|
194 |
set: Boolean = false |
|
195 |
) : Unit = { |
|
64817 | 196 |
GUI_Thread.require {} |
197 |
||
198 |
val changed = |
|
199 |
state.change_result(st => |
|
200 |
st.models.get(name) match { |
|
201 |
case None => (false, st) |
|
202 |
case Some(model) => |
|
203 |
val required = if (toggle) !model.node_required else set |
|
204 |
model match { |
|
205 |
case model1: File_Model if required != model1.node_required => |
|
206 |
(true, st.copy(models = st.models + (name -> model1.copy(node_required = required)))) |
|
207 |
case model1: Buffer_Model if required != model1.node_required => |
|
208 |
model1.set_node_required(required); (true, st) |
|
209 |
case _ => (false, st) |
|
210 |
} |
|
211 |
}) |
|
212 |
if (changed) { |
|
65243 | 213 |
PIDE.plugin.options_changed() |
66082 | 214 |
PIDE.editor.flush() |
64817 | 215 |
} |
216 |
} |
|
217 |
||
218 |
def view_node_required(view: View, toggle: Boolean = false, set: Boolean = false): Unit = |
|
219 |
Document_Model.get(view.getBuffer).foreach(model => |
|
220 |
node_required(model.node_name, toggle = toggle, set = set)) |
|
221 |
||
222 |
||
223 |
/* flushed edits */ |
|
224 |
||
75393 | 225 |
def flush_edits(hidden: Boolean, purge: Boolean): (Document.Blobs, List[Document.Edit_Text]) = { |
64817 | 226 |
GUI_Thread.require {} |
227 |
||
75394 | 228 |
state.change_result { st => |
75393 | 229 |
val doc_blobs = st.document_blobs |
64817 | 230 |
|
75393 | 231 |
val buffer_edits = |
232 |
(for { |
|
233 |
(_, model) <- st.buffer_models.iterator |
|
234 |
edit <- model.flush_edits(doc_blobs, hidden).iterator |
|
235 |
} yield edit).toList |
|
64817 | 236 |
|
75393 | 237 |
val file_edits = |
238 |
(for { |
|
239 |
(node_name, model) <- st.file_models_iterator |
|
240 |
(edits, model1) <- model.flush_edits(doc_blobs, hidden) |
|
241 |
} yield (edits, node_name -> model1)).toList |
|
64867 | 242 |
|
75393 | 243 |
val model_edits = buffer_edits ::: file_edits.flatMap(_._1) |
64867 | 244 |
|
75393 | 245 |
val purge_edits = |
246 |
if (purge) { |
|
247 |
val purged = |
|
248 |
(for ((node_name, model) <- st.file_models_iterator) |
|
249 |
yield (node_name -> model.purge_edits(doc_blobs))).toList |
|
64817 | 250 |
|
75393 | 251 |
val imports = { |
252 |
val open_nodes = |
|
253 |
(for ((_, model) <- st.buffer_models.iterator) yield model.node_name).toList |
|
254 |
val touched_nodes = model_edits.map(_._1) |
|
255 |
val pending_nodes = for ((node_name, None) <- purged) yield node_name |
|
256 |
(open_nodes ::: touched_nodes ::: pending_nodes).map((_, Position.none)) |
|
257 |
} |
|
258 |
val retain = PIDE.resources.dependencies(imports).theories.toSet |
|
64817 | 259 |
|
75393 | 260 |
for ((node_name, Some(edits)) <- purged if !retain(node_name); edit <- edits) |
261 |
yield edit |
|
262 |
} |
|
263 |
else Nil |
|
64867 | 264 |
|
75393 | 265 |
val st1 = st.copy(models = st.models ++ file_edits.map(_._2) -- purge_edits.map(_._1)) |
266 |
PIDE.plugin.file_watcher.purge( |
|
267 |
(for { |
|
268 |
(_, model) <- st1.file_models_iterator |
|
269 |
file <- model.file |
|
270 |
} yield file.getParentFile).toSet) |
|
64867 | 271 |
|
75393 | 272 |
((doc_blobs, model_edits ::: purge_edits), st1) |
75394 | 273 |
} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
274 |
} |
43397 | 275 |
|
64817 | 276 |
|
277 |
/* file content */ |
|
278 |
||
75393 | 279 |
sealed case class File_Content(text: String) { |
64835
fd1efd6dd385
resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents:
64832
diff
changeset
|
280 |
lazy val bytes: Bytes = Bytes(Symbol.encode(text)) |
64817 | 281 |
lazy val chunk: Symbol.Text_Chunk = Symbol.Text_Chunk(text) |
64831 | 282 |
lazy val bibtex_entries: List[Text.Info[String]] = |
66150 | 283 |
try { Bibtex.entries(text) } |
67288
aa9d28034945
avoid spurious noise: Prover IDE is meant to check for errors;
wenzelm
parents:
67265
diff
changeset
|
284 |
catch { case ERROR(_) => Nil } |
64817 | 285 |
} |
66019 | 286 |
|
287 |
||
288 |
/* HTTP preview */ |
|
289 |
||
75393 | 290 |
def open_preview(view: View, plain_text: Boolean): Unit = { |
66019 | 291 |
Document_Model.get(view.getBuffer) match { |
67246
4cedf44f2af1
isabelle.preview presents auxiliary text files as well;
wenzelm
parents:
67244
diff
changeset
|
292 |
case Some(model) => |
75148 | 293 |
val url = Preview_Service.server_url(plain_text, model.node_name) |
67246
4cedf44f2af1
isabelle.preview presents auxiliary text files as well;
wenzelm
parents:
67244
diff
changeset
|
294 |
PIDE.editor.hyperlink_url(url).follow(view) |
66036 | 295 |
case _ => |
66019 | 296 |
} |
297 |
} |
|
298 |
||
75393 | 299 |
object Preview_Service extends HTTP.Service("preview") { |
75148 | 300 |
service => |
301 |
||
302 |
private val plain_text_prefix = "plain_text=" |
|
303 |
||
304 |
def server_url(plain_text: Boolean, node_name: Document.Node.Name): String = |
|
305 |
PIDE.plugin.http_server.url + "/" + service.name + "?" + |
|
306 |
(if (plain_text) plain_text_prefix else "") + Url.encode(node_name.node) |
|
307 |
||
75113 | 308 |
def apply(request: HTTP.Request): Option[HTTP.Response] = |
75107 | 309 |
for { |
75112 | 310 |
query <- request.decode_query |
75107 | 311 |
name = Library.perhaps_unprefix(plain_text_prefix, query) |
312 |
model <- get(PIDE.resources.node_name(name)) |
|
313 |
} |
|
314 |
yield { |
|
315 |
val snapshot = model.await_stable_snapshot() |
|
316 |
val html_context = |
|
317 |
new Presentation.HTML_Context { |
|
75728 | 318 |
override def nodes: Presentation.Nodes = Presentation.Nodes.empty |
75107 | 319 |
override def root_dir: Path = Path.current |
320 |
override def theory_session(name: Document.Node.Name): Sessions.Info = |
|
321 |
PIDE.resources.sessions_structure( |
|
322 |
PIDE.resources.session_base.theory_qualifier(name)) |
|
323 |
} |
|
324 |
val document = |
|
325 |
Presentation.html_document( |
|
326 |
snapshot, html_context, Presentation.elements2, |
|
327 |
plain_text = query.startsWith(plain_text_prefix), |
|
75146 | 328 |
fonts_css = HTML.fonts_css_dir(HTTP.url_path(request.server_name))) |
75107 | 329 |
HTTP.Response.html(document.content) |
75113 | 330 |
} |
331 |
} |
|
64817 | 332 |
} |
333 |
||
75393 | 334 |
sealed abstract class Document_Model extends Document.Model { |
64817 | 335 |
/* perspective */ |
336 |
||
337 |
def document_view_ranges(snapshot: Document.Snapshot): List[Text.Range] = Nil |
|
338 |
||
339 |
def node_perspective( |
|
75393 | 340 |
doc_blobs: Document.Blobs, |
341 |
hidden: Boolean |
|
342 |
): (Boolean, Document.Node.Perspective_Text) = { |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
343 |
GUI_Thread.require {} |
64817 | 344 |
|
345 |
if (Isabelle.continuous_checking && is_theory) { |
|
346 |
val snapshot = this.snapshot() |
|
347 |
||
348 |
val reparse = snapshot.node.load_commands_changed(doc_blobs) |
|
349 |
val perspective = |
|
350 |
if (hidden) Text.Perspective.empty |
|
351 |
else { |
|
352 |
val view_ranges = document_view_ranges(snapshot) |
|
71601 | 353 |
val load_ranges = snapshot.commands_loading_ranges(PIDE.editor.visible_node) |
64817 | 354 |
Text.Perspective(view_ranges ::: load_ranges) |
355 |
} |
|
66082 | 356 |
val overlays = PIDE.editor.node_overlays(node_name) |
64817 | 357 |
|
358 |
(reparse, Document.Node.Perspective(node_required, perspective, overlays)) |
|
359 |
} |
|
360 |
else (false, Document.Node.no_perspective_text) |
|
43397 | 361 |
} |
66019 | 362 |
|
363 |
||
364 |
/* snapshot */ |
|
365 |
||
75393 | 366 |
@tailrec final def await_stable_snapshot(): Document.Snapshot = { |
66019 | 367 |
val snapshot = this.snapshot() |
368 |
if (snapshot.is_outdated) { |
|
73702
7202e12cb324
tuned signature --- following hints by IntelliJ IDEA;
wenzelm
parents:
73518
diff
changeset
|
369 |
PIDE.options.seconds("editor_output_delay").sleep() |
66019 | 370 |
await_stable_snapshot() |
371 |
} |
|
372 |
else snapshot |
|
373 |
} |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
374 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
375 |
|
75393 | 376 |
object File_Model { |
66114 | 377 |
def empty(session: Session): File_Model = |
378 |
File_Model(session, Document.Node.Name.empty, None, Document_Model.File_Content(""), |
|
379 |
false, Document.Node.no_perspective_text, Nil) |
|
380 |
||
64863 | 381 |
def init(session: Session, |
382 |
node_name: Document.Node.Name, |
|
383 |
text: String, |
|
384 |
node_required: Boolean = false, |
|
385 |
last_perspective: Document.Node.Perspective_Text = Document.Node.no_perspective_text, |
|
75393 | 386 |
pending_edits: List[Text.Edit] = Nil |
387 |
): File_Model = { |
|
65469 | 388 |
val file = JEdit_Lib.check_file(node_name.node) |
65245 | 389 |
file.foreach(PIDE.plugin.file_watcher.register_parent(_)) |
64863 | 390 |
|
64864
eec7ffef0be6
accomodate very big file_models and changed_files;
wenzelm
parents:
64863
diff
changeset
|
391 |
val content = Document_Model.File_Content(text) |
71733 | 392 |
val node_required1 = node_required || File_Format.registry.is_theory(node_name) |
67291
1bd9a0142d7a
bibtex theory is always required and thus eventually consolidated;
wenzelm
parents:
67288
diff
changeset
|
393 |
File_Model(session, node_name, file, content, node_required1, last_perspective, pending_edits) |
64863 | 394 |
} |
395 |
} |
|
396 |
||
64817 | 397 |
case class File_Model( |
398 |
session: Session, |
|
399 |
node_name: Document.Node.Name, |
|
64864
eec7ffef0be6
accomodate very big file_models and changed_files;
wenzelm
parents:
64863
diff
changeset
|
400 |
file: Option[JFile], |
64817 | 401 |
content: Document_Model.File_Content, |
64863 | 402 |
node_required: Boolean, |
403 |
last_perspective: Document.Node.Perspective_Text, |
|
75393 | 404 |
pending_edits: List[Text.Edit] |
405 |
) extends Document_Model { |
|
66114 | 406 |
/* text */ |
407 |
||
67014 | 408 |
def get_text(range: Text.Range): Option[String] = |
66114 | 409 |
range.try_substring(content.text) |
410 |
||
411 |
||
64817 | 412 |
/* header */ |
413 |
||
414 |
def node_header: Document.Node.Header = |
|
415 |
PIDE.resources.special_header(node_name) getOrElse |
|
72772 | 416 |
PIDE.resources.check_thy(node_name, Scan.char_reader(content.text), strict = false) |
64817 | 417 |
|
418 |
||
419 |
/* content */ |
|
420 |
||
64829
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64828
diff
changeset
|
421 |
def node_position(offset: Text.Offset): Line.Node_Position = |
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64828
diff
changeset
|
422 |
Line.Node_Position(node_name.node, |
65196
e8760a98db78
discontinued pointless Text.Length: Javascript and Java agree in old-fashioned UTF-16;
wenzelm
parents:
65132
diff
changeset
|
423 |
Line.Position.zero.advance(content.text.substring(0, offset))) |
64829
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64828
diff
changeset
|
424 |
|
64817 | 425 |
def get_blob: Option[Document.Blob] = |
426 |
if (is_theory) None |
|
67265
f32287c95432
store full blob source for the sake of markup_to_XML;
wenzelm
parents:
67262
diff
changeset
|
427 |
else Some(Document.Blob(content.bytes, content.text, content.chunk, pending_edits.nonEmpty)) |
64817 | 428 |
|
64831 | 429 |
def bibtex_entries: List[Text.Info[String]] = |
69255
800b1ce96fce
more general support for Isabelle/PIDE file formats -- less hardwired Bibtex operations;
wenzelm
parents:
68476
diff
changeset
|
430 |
if (Bibtex.is_bibtex(node_name.node)) content.bibtex_entries else Nil |
64680 | 431 |
|
432 |
||
64817 | 433 |
/* edits */ |
434 |
||
435 |
def update_text(text: String): Option[File_Model] = |
|
436 |
Text.Edit.replace(0, content.text, text) match { |
|
437 |
case Nil => None |
|
438 |
case edits => |
|
439 |
val content1 = Document_Model.File_Content(text) |
|
440 |
val pending_edits1 = pending_edits ::: edits |
|
441 |
Some(copy(content = content1, pending_edits = pending_edits1)) |
|
442 |
} |
|
38222
dac5fa0ac971
replaced individual Document_Model history by all-inclusive one in Session;
wenzelm
parents:
38158
diff
changeset
|
443 |
|
75393 | 444 |
def flush_edits( |
445 |
doc_blobs: Document.Blobs, |
|
446 |
hidden: Boolean |
|
447 |
) : Option[(List[Document.Edit_Text], File_Model)] = { |
|
64817 | 448 |
val (reparse, perspective) = node_perspective(doc_blobs, hidden) |
449 |
if (reparse || pending_edits.nonEmpty || last_perspective != perspective) { |
|
64867 | 450 |
val edits = node_edits(node_header, pending_edits, perspective) |
64817 | 451 |
Some((edits, copy(last_perspective = perspective, pending_edits = Nil))) |
452 |
} |
|
453 |
else None |
|
454 |
} |
|
455 |
||
64867 | 456 |
def purge_edits(doc_blobs: Document.Blobs): Option[List[Document.Edit_Text]] = |
67310 | 457 |
if (pending_edits.nonEmpty || |
71733 | 458 |
!File_Format.registry.is_theory(node_name) && |
67310 | 459 |
(node_required || !Document.Node.is_no_perspective_text(last_perspective))) None |
64867 | 460 |
else { |
461 |
val text_edits = List(Text.Edit.remove(0, content.text)) |
|
462 |
Some(node_edits(Document.Node.no_header, text_edits, Document.Node.no_perspective_text)) |
|
463 |
} |
|
464 |
||
64817 | 465 |
|
466 |
/* snapshot */ |
|
467 |
||
468 |
def is_stable: Boolean = pending_edits.isEmpty |
|
64818
67a0a563d2b3
clarified buffer events: exit model while loading;
wenzelm
parents:
64817
diff
changeset
|
469 |
def snapshot(): Document.Snapshot = session.snapshot(node_name, pending_edits) |
64817 | 470 |
} |
471 |
||
472 |
case class Buffer_Model(session: Session, node_name: Document.Node.Name, buffer: Buffer) |
|
75393 | 473 |
extends Document_Model { |
66114 | 474 |
/* text */ |
475 |
||
67014 | 476 |
def get_text(range: Text.Range): Option[String] = |
477 |
JEdit_Lib.get_text(buffer, range) |
|
66114 | 478 |
|
479 |
||
64817 | 480 |
/* header */ |
54509
1f77110c94ef
maintain document model for all files, with document view for theory only, and special blob for non-theory files;
wenzelm
parents:
54464
diff
changeset
|
481 |
|
75393 | 482 |
def node_header(): Document.Node.Header = { |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
483 |
GUI_Thread.require {} |
54509
1f77110c94ef
maintain document model for all files, with document view for theory only, and special blob for non-theory files;
wenzelm
parents:
54464
diff
changeset
|
484 |
|
64673
b5965890e54d
more uniform treatment of file name vs. theory name and special header;
wenzelm
parents:
63446
diff
changeset
|
485 |
PIDE.resources.special_header(node_name) getOrElse |
64826
c97296294f6d
clarified check_thy_reader: check node_name here;
wenzelm
parents:
64825
diff
changeset
|
486 |
JEdit_Lib.buffer_lock(buffer) { |
72772 | 487 |
PIDE.resources.check_thy(node_name, JEdit_Lib.buffer_reader(buffer), strict = false) |
46748
8f3ae4d04a2d
refined node_header -- more direct buffer access (again);
wenzelm
parents:
46740
diff
changeset
|
488 |
} |
46920
5f44c8bea84e
more explicit indication of swing thread context;
wenzelm
parents:
46750
diff
changeset
|
489 |
} |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
490 |
|
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
491 |
|
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
492 |
/* perspective */ |
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
493 |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
494 |
// owned by GUI thread |
52816
c608e0ade554
home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents:
52815
diff
changeset
|
495 |
private var _node_required = false |
c608e0ade554
home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents:
52815
diff
changeset
|
496 |
def node_required: Boolean = _node_required |
73340 | 497 |
def set_node_required(b: Boolean): Unit = GUI_Thread.require { _node_required = b } |
52808
143f225e50f5
allow explicit indication of required node: full eval, no prints;
wenzelm
parents:
52807
diff
changeset
|
498 |
|
64883 | 499 |
def document_view_iterator: Iterator[Document_View] = |
500 |
for { |
|
501 |
text_area <- JEdit_Lib.jedit_text_areas(buffer) |
|
502 |
doc_view <- Document_View.get(text_area) |
|
503 |
} yield doc_view |
|
504 |
||
75393 | 505 |
override def document_view_ranges(snapshot: Document.Snapshot): List[Text.Range] = { |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
506 |
GUI_Thread.require {} |
52759
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
50565
diff
changeset
|
507 |
|
64817 | 508 |
(for { |
64883 | 509 |
doc_view <- document_view_iterator |
64817 | 510 |
range <- doc_view.perspective(snapshot).ranges.iterator |
511 |
} yield range).toList |
|
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
512 |
} |
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
513 |
|
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
514 |
|
54509
1f77110c94ef
maintain document model for all files, with document view for theory only, and special blob for non-theory files;
wenzelm
parents:
54464
diff
changeset
|
515 |
/* blob */ |
1f77110c94ef
maintain document model for all files, with document view for theory only, and special blob for non-theory files;
wenzelm
parents:
54464
diff
changeset
|
516 |
|
64885 | 517 |
// owned by GUI thread |
67265
f32287c95432
store full blob source for the sake of markup_to_XML;
wenzelm
parents:
67262
diff
changeset
|
518 |
private var _blob: Option[(Bytes, String, Symbol.Text_Chunk)] = None |
54511 | 519 |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
520 |
private def reset_blob(): Unit = GUI_Thread.require { _blob = None } |
54511 | 521 |
|
64817 | 522 |
def get_blob: Option[Document.Blob] = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
523 |
GUI_Thread.require { |
55783 | 524 |
if (is_theory) None |
525 |
else { |
|
67265
f32287c95432
store full blob source for the sake of markup_to_XML;
wenzelm
parents:
67262
diff
changeset
|
526 |
val (bytes, text, chunk) = |
55783 | 527 |
_blob match { |
528 |
case Some(x) => x |
|
529 |
case None => |
|
64835
fd1efd6dd385
resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents:
64832
diff
changeset
|
530 |
val bytes = PIDE.resources.make_file_content(buffer) |
67265
f32287c95432
store full blob source for the sake of markup_to_XML;
wenzelm
parents:
67262
diff
changeset
|
531 |
val text = buffer.getText(0, buffer.getLength) |
f32287c95432
store full blob source for the sake of markup_to_XML;
wenzelm
parents:
67262
diff
changeset
|
532 |
val chunk = Symbol.Text_Chunk(text) |
f32287c95432
store full blob source for the sake of markup_to_XML;
wenzelm
parents:
67262
diff
changeset
|
533 |
val x = (bytes, text, chunk) |
f32287c95432
store full blob source for the sake of markup_to_XML;
wenzelm
parents:
67262
diff
changeset
|
534 |
_blob = Some(x) |
f32287c95432
store full blob source for the sake of markup_to_XML;
wenzelm
parents:
67262
diff
changeset
|
535 |
x |
55783 | 536 |
} |
64818
67a0a563d2b3
clarified buffer events: exit model while loading;
wenzelm
parents:
64817
diff
changeset
|
537 |
val changed = pending_edits.nonEmpty |
67265
f32287c95432
store full blob source for the sake of markup_to_XML;
wenzelm
parents:
67262
diff
changeset
|
538 |
Some(Document.Blob(bytes, text, chunk, changed)) |
54511 | 539 |
} |
540 |
} |
|
54509
1f77110c94ef
maintain document model for all files, with document view for theory only, and special blob for non-theory files;
wenzelm
parents:
54464
diff
changeset
|
541 |
|
1f77110c94ef
maintain document model for all files, with document view for theory only, and special blob for non-theory files;
wenzelm
parents:
54464
diff
changeset
|
542 |
|
58543 | 543 |
/* bibtex entries */ |
544 |
||
64885 | 545 |
// owned by GUI thread |
546 |
private var _bibtex_entries: Option[List[Text.Info[String]]] = None |
|
58543 | 547 |
|
64817 | 548 |
private def reset_bibtex_entries(): Unit = GUI_Thread.require { _bibtex_entries = None } |
58543 | 549 |
|
64831 | 550 |
def bibtex_entries: List[Text.Info[String]] = |
58543 | 551 |
GUI_Thread.require { |
69255
800b1ce96fce
more general support for Isabelle/PIDE file formats -- less hardwired Bibtex operations;
wenzelm
parents:
68476
diff
changeset
|
552 |
if (Bibtex.is_bibtex(node_name.node)) { |
64817 | 553 |
_bibtex_entries match { |
58543 | 554 |
case Some(entries) => entries |
555 |
case None => |
|
64817 | 556 |
val text = JEdit_Lib.buffer_text(buffer) |
64828 | 557 |
val entries = |
66150 | 558 |
try { Bibtex.entries(text) } |
64828 | 559 |
catch { case ERROR(msg) => Output.warning(msg); Nil } |
64817 | 560 |
_bibtex_entries = Some(entries) |
58543 | 561 |
entries |
562 |
} |
|
563 |
} |
|
564 |
else Nil |
|
565 |
} |
|
566 |
||
567 |
||
50344
608265769ce0
emit bulk edits on initialization of multiple buffers, which greatly improves performance when starting big sessions (e.g. JinjaThreads);
wenzelm
parents:
50207
diff
changeset
|
568 |
/* pending edits */ |
43648 | 569 |
|
75393 | 570 |
private object pending_edits { |
38425 | 571 |
private val pending = new mutable.ListBuffer[Text.Edit] |
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57612
diff
changeset
|
572 |
private var last_perspective = Document.Node.no_perspective_text |
44438 | 573 |
|
64818
67a0a563d2b3
clarified buffer events: exit model while loading;
wenzelm
parents:
64817
diff
changeset
|
574 |
def nonEmpty: Boolean = synchronized { pending.nonEmpty } |
67a0a563d2b3
clarified buffer events: exit model while loading;
wenzelm
parents:
64817
diff
changeset
|
575 |
def get_edits: List[Text.Edit] = synchronized { pending.toList } |
64817 | 576 |
def get_last_perspective: Document.Node.Perspective_Text = synchronized { last_perspective } |
577 |
def set_last_perspective(perspective: Document.Node.Perspective_Text): Unit = |
|
578 |
synchronized { last_perspective = perspective } |
|
38224 | 579 |
|
64817 | 580 |
def flush_edits(doc_blobs: Document.Blobs, hidden: Boolean): List[Document.Edit_Text] = |
61728
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
581 |
synchronized { |
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
582 |
GUI_Thread.require {} |
60272
4f72b00d9952
no GUI_Thread for SideKick parsers (in contrast to 4c8205fe3644), to avoid danger of deadlock due to nested context switch;
wenzelm
parents:
59737
diff
changeset
|
583 |
|
64818
67a0a563d2b3
clarified buffer events: exit model while loading;
wenzelm
parents:
64817
diff
changeset
|
584 |
val edits = get_edits |
64817 | 585 |
val (reparse, perspective) = node_perspective(doc_blobs, hidden) |
64818
67a0a563d2b3
clarified buffer events: exit model while loading;
wenzelm
parents:
64817
diff
changeset
|
586 |
if (reparse || edits.nonEmpty || last_perspective != perspective) { |
73367 | 587 |
pending.clear() |
61728
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
588 |
last_perspective = perspective |
71601 | 589 |
node_edits(node_header(), edits, perspective) |
61728
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
590 |
} |
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
591 |
else Nil |
43648 | 592 |
} |
38224 | 593 |
|
75380 | 594 |
def edit(edits: List[Text.Edit]): Unit = synchronized { |
60272
4f72b00d9952
no GUI_Thread for SideKick parsers (in contrast to 4c8205fe3644), to avoid danger of deadlock due to nested context switch;
wenzelm
parents:
59737
diff
changeset
|
595 |
GUI_Thread.require {} |
4f72b00d9952
no GUI_Thread for SideKick parsers (in contrast to 4c8205fe3644), to avoid danger of deadlock due to nested context switch;
wenzelm
parents:
59737
diff
changeset
|
596 |
|
54511 | 597 |
reset_blob() |
64817 | 598 |
reset_bibtex_entries() |
54511 | 599 |
|
64883 | 600 |
for (doc_view <- document_view_iterator) |
61538
bf4969660913
avoid highlighted area getting "stuck" after edit;
wenzelm
parents:
61192
diff
changeset
|
601 |
doc_view.rich_text_area.active_reset() |
bf4969660913
avoid highlighted area getting "stuck" after edit;
wenzelm
parents:
61192
diff
changeset
|
602 |
|
64818
67a0a563d2b3
clarified buffer events: exit model while loading;
wenzelm
parents:
64817
diff
changeset
|
603 |
pending ++= edits |
66082 | 604 |
PIDE.editor.invoke() |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
605 |
} |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
606 |
} |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
607 |
|
64835
fd1efd6dd385
resolve dependencies implicitly via File_Model, without jEdit Buffer_Model;
wenzelm
parents:
64832
diff
changeset
|
608 |
def is_stable: Boolean = !pending_edits.nonEmpty |
64818
67a0a563d2b3
clarified buffer events: exit model while loading;
wenzelm
parents:
64817
diff
changeset
|
609 |
def snapshot(): Document.Snapshot = session.snapshot(node_name, pending_edits.get_edits) |
60933
6d03e05ef041
more robust access to stable tip version: take all pending edits into account, don't assume model for current buffer;
wenzelm
parents:
60274
diff
changeset
|
610 |
|
64817 | 611 |
def flush_edits(doc_blobs: Document.Blobs, hidden: Boolean): List[Document.Edit_Text] = |
612 |
pending_edits.flush_edits(doc_blobs, hidden) |
|
34828 | 613 |
|
614 |
||
615 |
/* buffer listener */ |
|
616 |
||
75393 | 617 |
private val buffer_listener: BufferListener = new BufferAdapter { |
618 |
override def contentInserted( |
|
619 |
buffer: JEditBuffer, |
|
620 |
start_line: Int, |
|
621 |
offset: Int, |
|
622 |
num_lines: Int, |
|
623 |
length: Int |
|
624 |
): Unit = { |
|
64818
67a0a563d2b3
clarified buffer events: exit model while loading;
wenzelm
parents:
64817
diff
changeset
|
625 |
pending_edits.edit(List(Text.Edit.insert(offset, buffer.getText(offset, length)))) |
34828 | 626 |
} |
627 |
||
75393 | 628 |
override def preContentRemoved( |
629 |
buffer: JEditBuffer, |
|
630 |
start_line: Int, |
|
631 |
offset: Int, |
|
632 |
num_lines: Int, |
|
633 |
removed_length: Int |
|
634 |
): Unit = { |
|
64818
67a0a563d2b3
clarified buffer events: exit model while loading;
wenzelm
parents:
64817
diff
changeset
|
635 |
pending_edits.edit(List(Text.Edit.remove(offset, buffer.getText(offset, removed_length)))) |
34828 | 636 |
} |
637 |
} |
|
638 |
||
639 |
||
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
640 |
/* syntax */ |
37557
1ae272fd4082
refresh Isabelle token marker after buffer properties changed, e.g. when fold mode is switched;
wenzelm
parents:
37555
diff
changeset
|
641 |
|
75393 | 642 |
def syntax_changed(): Unit = { |
61192 | 643 |
JEdit_Lib.buffer_line_manager(buffer).setFirstInvalidLineContext(0) |
59080
611914621edb
added Untyped.method convenience (for *this* class only);
wenzelm
parents:
59079
diff
changeset
|
644 |
for (text_area <- JEdit_Lib.jedit_text_areas(buffer)) |
611914621edb
added Untyped.method convenience (for *this* class only);
wenzelm
parents:
59079
diff
changeset
|
645 |
Untyped.method(Class.forName("org.gjt.sp.jedit.textarea.TextArea"), "foldStructureChanged"). |
611914621edb
added Untyped.method convenience (for *this* class only);
wenzelm
parents:
59079
diff
changeset
|
646 |
invoke(text_area) |
72960 | 647 |
buffer.invalidateCachedFoldLevels() |
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
648 |
} |
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
649 |
|
75393 | 650 |
def init_token_marker(): Unit = { |
59077
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
651 |
Isabelle.buffer_token_marker(buffer) match { |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
652 |
case Some(marker) if marker != buffer.getTokenMarker => |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
653 |
buffer.setTokenMarker(marker) |
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
654 |
syntax_changed() |
59077
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
655 |
case _ => |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
656 |
} |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
657 |
} |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
658 |
|
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
659 |
|
64817 | 660 |
/* init */ |
661 |
||
75393 | 662 |
def init(old_model: Option[File_Model]): Buffer_Model = { |
64817 | 663 |
GUI_Thread.require {} |
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
664 |
|
64817 | 665 |
old_model match { |
666 |
case None => |
|
64818
67a0a563d2b3
clarified buffer events: exit model while loading;
wenzelm
parents:
64817
diff
changeset
|
667 |
pending_edits.edit(List(Text.Edit.insert(0, JEdit_Lib.buffer_text(buffer)))) |
64817 | 668 |
case Some(file_model) => |
669 |
set_node_required(file_model.node_required) |
|
670 |
pending_edits.set_last_perspective(file_model.last_perspective) |
|
64818
67a0a563d2b3
clarified buffer events: exit model while loading;
wenzelm
parents:
64817
diff
changeset
|
671 |
pending_edits.edit( |
67a0a563d2b3
clarified buffer events: exit model while loading;
wenzelm
parents:
64817
diff
changeset
|
672 |
file_model.pending_edits ::: |
67a0a563d2b3
clarified buffer events: exit model while loading;
wenzelm
parents:
64817
diff
changeset
|
673 |
Text.Edit.replace(0, file_model.content.text, JEdit_Lib.buffer_text(buffer))) |
64817 | 674 |
} |
675 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
676 |
buffer.addBufferListener(buffer_listener) |
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
677 |
init_token_marker() |
64817 | 678 |
|
679 |
this |
|
34680 | 680 |
} |
681 |
||
64817 | 682 |
|
683 |
/* exit */ |
|
684 |
||
75393 | 685 |
def exit(): File_Model = { |
64817 | 686 |
GUI_Thread.require {} |
687 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
688 |
buffer.removeBufferListener(buffer_listener) |
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
689 |
init_token_marker() |
64817 | 690 |
|
64863 | 691 |
File_Model.init(session, node_name, JEdit_Lib.buffer_text(buffer), node_required, |
692 |
pending_edits.get_last_perspective, pending_edits.get_edits) |
|
34680 | 693 |
} |
34447 | 694 |
} |