author | wenzelm |
Fri, 06 Jan 2017 13:27:18 +0100 | |
changeset 64813 | 7283f41d05ab |
parent 64799 | c0c648911f1a |
child 64817 | 0bb6b582bb4f |
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 |
||
55778 | 5 |
Document model connected to jEdit buffer (node in theory graph or |
6 |
auxiliary file). |
|
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 |
||
34693 | 14 |
import scala.collection.mutable |
59736
5c1a0069b9d3
tight span for theory header, which is relevant for error positions (including semantic completion);
wenzelm
parents:
59715
diff
changeset
|
15 |
import scala.util.parsing.input.CharSequenceReader |
34446 | 16 |
|
59077
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
17 |
import org.gjt.sp.jedit.jEdit |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
18 |
import org.gjt.sp.jedit.Buffer |
61192 | 19 |
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
|
20 |
|
34760 | 21 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
22 |
object Document_Model |
34588 | 23 |
{ |
64813 | 24 |
/* global state */ |
25 |
||
26 |
sealed case class State(buffer_models: Map[JEditBuffer, Document_Model] = Map.empty) |
|
27 |
||
28 |
private val state = Synchronized(State()) |
|
29 |
||
30 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
31 |
/* document model of buffer */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
32 |
|
64813 | 33 |
def get(buffer: JEditBuffer): Option[Document_Model] = |
34 |
state.value.buffer_models.get(buffer) |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
35 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
36 |
def exit(buffer: Buffer) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
37 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
38 |
GUI_Thread.require {} |
64813 | 39 |
state.change(st => |
40 |
st.buffer_models.get(buffer) match { |
|
41 |
case None => st |
|
42 |
case Some(model) => |
|
43 |
model.deactivate() |
|
44 |
buffer.propertiesChanged |
|
45 |
st.copy(buffer_models = st.buffer_models - buffer) |
|
46 |
}) |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
47 |
} |
43397 | 48 |
|
64813 | 49 |
def init(session: Session, buffer: Buffer, node_name: Document.Node.Name): Document_Model = |
43397 | 50 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
51 |
GUI_Thread.require {} |
60274
c2837a39da01
more conservative Document_Model.init: avoid Document.Node.Clear due to change of token marker (e.g. due to change of jEdit mode properties);
wenzelm
parents:
60272
diff
changeset
|
52 |
val model = |
64813 | 53 |
state.change_result(st => |
54 |
{ |
|
55 |
val old_model = st.buffer_models.get(buffer) |
|
56 |
old_model match { |
|
57 |
case Some(model) if model.node_name == node_name => (model, st) |
|
58 |
case _ => |
|
59 |
old_model.foreach(_.deactivate) |
|
60 |
val model = new Document_Model(session, buffer, node_name) |
|
61 |
model.activate() |
|
62 |
buffer.propertiesChanged |
|
63 |
(model, st.copy(st.buffer_models + (buffer -> model))) |
|
64 |
} |
|
65 |
}) |
|
60274
c2837a39da01
more conservative Document_Model.init: avoid Document.Node.Clear due to change of token marker (e.g. due to change of jEdit mode properties);
wenzelm
parents:
60272
diff
changeset
|
66 |
model.init_token_marker |
c2837a39da01
more conservative Document_Model.init: avoid Document.Node.Clear due to change of token marker (e.g. due to change of jEdit mode properties);
wenzelm
parents:
60272
diff
changeset
|
67 |
model |
43397 | 68 |
} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
69 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
70 |
|
64813 | 71 |
class Document_Model private( |
72 |
val session: Session, val buffer: Buffer, val node_name: Document.Node.Name) |
|
34588 | 73 |
{ |
64680 | 74 |
override def toString: String = node_name.toString |
75 |
||
76 |
||
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
77 |
/* header */ |
38222
dac5fa0ac971
replaced individual Document_Model history by all-inclusive one in Session;
wenzelm
parents:
38158
diff
changeset
|
78 |
|
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
|
79 |
def is_theory: Boolean = node_name.is_theory |
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
|
80 |
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
47393
diff
changeset
|
81 |
def node_header(): Document.Node.Header = |
46920
5f44c8bea84e
more explicit indication of swing thread context;
wenzelm
parents:
46750
diff
changeset
|
82 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
83 |
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
|
84 |
|
64673
b5965890e54d
more uniform treatment of file name vs. theory name and special header;
wenzelm
parents:
63446
diff
changeset
|
85 |
PIDE.resources.special_header(node_name) getOrElse |
b5965890e54d
more uniform treatment of file name vs. theory name and special header;
wenzelm
parents:
63446
diff
changeset
|
86 |
{ |
b5965890e54d
more uniform treatment of file name vs. theory name and special header;
wenzelm
parents:
63446
diff
changeset
|
87 |
if (is_theory) { |
63022 | 88 |
JEdit_Lib.buffer_lock(buffer) { |
89 |
Token_Markup.line_token_iterator( |
|
90 |
Thy_Header.bootstrap_syntax, buffer, 0, buffer.getLineCount).collectFirst( |
|
91 |
{ |
|
63446 | 92 |
case Text.Info(range, tok) if tok.is_command(Thy_Header.THEORY) => range.start |
63022 | 93 |
}) |
94 |
match { |
|
95 |
case Some(offset) => |
|
96 |
val length = buffer.getLength - offset |
|
97 |
PIDE.resources.check_thy_reader("", node_name, |
|
98 |
new CharSequenceReader(buffer.getSegment(offset, length)), Token.Pos.command) |
|
64673
b5965890e54d
more uniform treatment of file name vs. theory name and special header;
wenzelm
parents:
63446
diff
changeset
|
99 |
case None => |
b5965890e54d
more uniform treatment of file name vs. theory name and special header;
wenzelm
parents:
63446
diff
changeset
|
100 |
Document.Node.no_header |
63022 | 101 |
} |
102 |
} |
|
46748
8f3ae4d04a2d
refined node_header -- more direct buffer access (again);
wenzelm
parents:
46740
diff
changeset
|
103 |
} |
64673
b5965890e54d
more uniform treatment of file name vs. theory name and special header;
wenzelm
parents:
63446
diff
changeset
|
104 |
else Document.Node.no_header |
46748
8f3ae4d04a2d
refined node_header -- more direct buffer access (again);
wenzelm
parents:
46740
diff
changeset
|
105 |
} |
46920
5f44c8bea84e
more explicit indication of swing thread context;
wenzelm
parents:
46750
diff
changeset
|
106 |
} |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
107 |
|
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
108 |
|
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
109 |
/* perspective */ |
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
110 |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
111 |
// 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
|
112 |
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
|
113 |
def node_required: Boolean = _node_required |
c608e0ade554
home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents:
52815
diff
changeset
|
114 |
def node_required_=(b: Boolean) |
c608e0ade554
home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents:
52815
diff
changeset
|
115 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
116 |
GUI_Thread.require {} |
54531
8330faaeebd5
restrict node_required status and Theories panel to actual theories;
wenzelm
parents:
54530
diff
changeset
|
117 |
if (_node_required != b && is_theory) { |
52816
c608e0ade554
home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents:
52815
diff
changeset
|
118 |
_node_required = b |
c608e0ade554
home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents:
52815
diff
changeset
|
119 |
PIDE.options_changed() |
52974 | 120 |
PIDE.editor.flush() |
52816
c608e0ade554
home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents:
52815
diff
changeset
|
121 |
} |
c608e0ade554
home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents:
52815
diff
changeset
|
122 |
} |
52808
143f225e50f5
allow explicit indication of required node: full eval, no prints;
wenzelm
parents:
52807
diff
changeset
|
123 |
|
64799 | 124 |
def node_perspective(hidden: Boolean, doc_blobs: Document.Blobs) |
125 |
: (Boolean, Document.Node.Perspective_Text) = |
|
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
126 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
127 |
GUI_Thread.require {} |
52759
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
50565
diff
changeset
|
128 |
|
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
|
129 |
if (Isabelle.continuous_checking && is_theory) { |
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
52977
diff
changeset
|
130 |
val snapshot = this.snapshot() |
54530
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
131 |
|
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
132 |
val document_view_ranges = |
57883
d50aeb916a4b
tuned -- eliminated redundant check (see 1f77110c94ef);
wenzelm
parents:
57621
diff
changeset
|
133 |
for { |
d50aeb916a4b
tuned -- eliminated redundant check (see 1f77110c94ef);
wenzelm
parents:
57621
diff
changeset
|
134 |
doc_view <- PIDE.document_views(buffer) |
d50aeb916a4b
tuned -- eliminated redundant check (see 1f77110c94ef);
wenzelm
parents:
57621
diff
changeset
|
135 |
range <- doc_view.perspective(snapshot).ranges |
d50aeb916a4b
tuned -- eliminated redundant check (see 1f77110c94ef);
wenzelm
parents:
57621
diff
changeset
|
136 |
} yield range |
54530
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
137 |
|
64799 | 138 |
val load_ranges = snapshot.commands_loading_ranges(PIDE.editor.visible_node(_)) |
139 |
val reparse = snapshot.node.load_commands_changed(doc_blobs) |
|
55781
b3a4207fb9a6
proper update of text perspective for nodes with changed blobs, which is important to refresh the corresponding command perspective (otherwise it might refer to invalid thy_load commands and cause full execution of the node by the prover);
wenzelm
parents:
55778
diff
changeset
|
140 |
|
b3a4207fb9a6
proper update of text perspective for nodes with changed blobs, which is important to refresh the corresponding command perspective (otherwise it might refer to invalid thy_load commands and cause full execution of the node by the prover);
wenzelm
parents:
55778
diff
changeset
|
141 |
(reparse, |
b3a4207fb9a6
proper update of text perspective for nodes with changed blobs, which is important to refresh the corresponding command perspective (otherwise it might refer to invalid thy_load commands and cause full execution of the node by the prover);
wenzelm
parents:
55778
diff
changeset
|
142 |
Document.Node.Perspective(node_required, |
61728
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
143 |
Text.Perspective(if (hidden) Nil else document_view_ranges ::: load_ranges), |
55781
b3a4207fb9a6
proper update of text perspective for nodes with changed blobs, which is important to refresh the corresponding command perspective (otherwise it might refer to invalid thy_load commands and cause full execution of the node by the prover);
wenzelm
parents:
55778
diff
changeset
|
144 |
PIDE.editor.node_overlays(node_name))) |
52849 | 145 |
} |
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57612
diff
changeset
|
146 |
else (false, Document.Node.no_perspective_text) |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
147 |
} |
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
148 |
|
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
149 |
|
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
|
150 |
/* 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
|
151 |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
152 |
private var _blob: Option[(Bytes, Symbol.Text_Chunk)] = None // owned by GUI thread |
54511 | 153 |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
154 |
private def reset_blob(): Unit = GUI_Thread.require { _blob = None } |
54511 | 155 |
|
55783 | 156 |
def get_blob(): Option[Document.Blob] = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
157 |
GUI_Thread.require { |
55783 | 158 |
if (is_theory) None |
159 |
else { |
|
56473 | 160 |
val (bytes, chunk) = |
55783 | 161 |
_blob match { |
162 |
case Some(x) => x |
|
163 |
case None => |
|
56208 | 164 |
val bytes = PIDE.resources.file_content(buffer) |
56746 | 165 |
val chunk = Symbol.Text_Chunk(buffer.getSegment(0, buffer.getLength)) |
56473 | 166 |
_blob = Some((bytes, chunk)) |
167 |
(bytes, chunk) |
|
55783 | 168 |
} |
169 |
val changed = pending_edits.is_pending() |
|
56473 | 170 |
Some(Document.Blob(bytes, chunk, changed)) |
54511 | 171 |
} |
172 |
} |
|
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
|
173 |
|
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
|
174 |
|
58543 | 175 |
/* bibtex entries */ |
176 |
||
177 |
private var _bibtex: Option[List[(String, Text.Offset)]] = None // owned by GUI thread |
|
178 |
||
179 |
private def reset_bibtex(): Unit = GUI_Thread.require { _bibtex = None } |
|
180 |
||
181 |
def bibtex_entries(): List[(String, Text.Offset)] = |
|
182 |
GUI_Thread.require { |
|
58546 | 183 |
if (Bibtex_JEdit.check(buffer)) { |
58543 | 184 |
_bibtex match { |
185 |
case Some(entries) => entries |
|
186 |
case None => |
|
58547 | 187 |
val entries = Bibtex_JEdit.parse_buffer_entries(buffer) |
58543 | 188 |
_bibtex = Some(entries) |
189 |
entries |
|
190 |
} |
|
191 |
} |
|
192 |
else Nil |
|
193 |
} |
|
194 |
||
195 |
||
50363
2f8dc9e65401
tuned signature in accordance to document operations;
wenzelm
parents:
50344
diff
changeset
|
196 |
/* edits */ |
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
|
197 |
|
54461 | 198 |
def node_edits( |
56335
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents:
56314
diff
changeset
|
199 |
clear: Boolean, |
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents:
56314
diff
changeset
|
200 |
text_edits: List[Text.Edit], |
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents:
56314
diff
changeset
|
201 |
perspective: Document.Node.Perspective_Text): List[Document.Edit_Text] = |
57621 | 202 |
{ |
203 |
val edits: List[Document.Edit_Text] = |
|
204 |
get_blob() match { |
|
205 |
case None => |
|
206 |
val header_edit = session.header_edit(node_name, node_header()) |
|
207 |
if (clear) |
|
208 |
List(header_edit, |
|
209 |
node_name -> Document.Node.Clear(), |
|
210 |
node_name -> Document.Node.Edits(text_edits), |
|
211 |
node_name -> perspective) |
|
212 |
else |
|
213 |
List(header_edit, |
|
214 |
node_name -> Document.Node.Edits(text_edits), |
|
215 |
node_name -> perspective) |
|
216 |
case Some(blob) => |
|
217 |
List(node_name -> Document.Node.Blob(blob), |
|
218 |
node_name -> Document.Node.Edits(text_edits)) |
|
219 |
} |
|
220 |
edits.filterNot(_._2.is_void) |
|
221 |
} |
|
50363
2f8dc9e65401
tuned signature in accordance to document operations;
wenzelm
parents:
50344
diff
changeset
|
222 |
|
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
|
223 |
|
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
|
224 |
/* pending edits */ |
43648 | 225 |
|
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
|
226 |
private object pending_edits |
38224 | 227 |
{ |
54461 | 228 |
private var pending_clear = false |
38425 | 229 |
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
|
230 |
private var last_perspective = Document.Node.no_perspective_text |
44438 | 231 |
|
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
|
232 |
def is_pending(): Boolean = synchronized { pending_clear || pending.nonEmpty } |
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
|
233 |
def snapshot(): List[Text.Edit] = synchronized { pending.toList } |
38224 | 234 |
|
61728
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
235 |
def flushed_edits(hidden: Boolean, doc_blobs: Document.Blobs): List[Document.Edit_Text] = |
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
236 |
synchronized { |
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
237 |
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
|
238 |
|
61728
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
239 |
val clear = pending_clear |
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
240 |
val edits = snapshot() |
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
241 |
val (reparse, perspective) = node_perspective(hidden, doc_blobs) |
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
242 |
if (clear || reparse || edits.nonEmpty || last_perspective != perspective) { |
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
243 |
pending_clear = false |
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
244 |
pending.clear |
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
245 |
last_perspective = perspective |
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
246 |
node_edits(clear, edits, perspective) |
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
247 |
} |
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
248 |
else Nil |
43648 | 249 |
} |
38224 | 250 |
|
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
|
251 |
def edit(clear: Boolean, e: Text.Edit): Unit = synchronized |
38224 | 252 |
{ |
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
|
253 |
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
|
254 |
|
54511 | 255 |
reset_blob() |
58543 | 256 |
reset_bibtex() |
54511 | 257 |
|
61538
bf4969660913
avoid highlighted area getting "stuck" after edit;
wenzelm
parents:
61192
diff
changeset
|
258 |
for (doc_view <- PIDE.document_views(buffer)) |
bf4969660913
avoid highlighted area getting "stuck" after edit;
wenzelm
parents:
61192
diff
changeset
|
259 |
doc_view.rich_text_area.active_reset() |
bf4969660913
avoid highlighted area getting "stuck" after edit;
wenzelm
parents:
61192
diff
changeset
|
260 |
|
54461 | 261 |
if (clear) { |
262 |
pending_clear = true |
|
263 |
pending.clear |
|
264 |
} |
|
265 |
pending += e |
|
266 |
PIDE.editor.invoke() |
|
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
267 |
} |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
268 |
} |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
269 |
|
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
|
270 |
def is_stable(): Boolean = !pending_edits.is_pending(); |
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
|
271 |
|
54464 | 272 |
def snapshot(): Document.Snapshot = |
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
|
273 |
session.snapshot(node_name, pending_edits.snapshot()) |
34731
c0cb6bd10eec
keep BufferListener and TextAreaExtension private;
wenzelm
parents:
34724
diff
changeset
|
274 |
|
61728
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
275 |
def flushed_edits(hidden: Boolean, doc_blobs: Document.Blobs): List[Document.Edit_Text] = |
5f5ff1eab407
double flush to ensure persistent "state" output is reset;
wenzelm
parents:
61538
diff
changeset
|
276 |
pending_edits.flushed_edits(hidden, doc_blobs) |
34828 | 277 |
|
278 |
||
279 |
/* buffer listener */ |
|
280 |
||
281 |
private val buffer_listener: BufferListener = new BufferAdapter |
|
282 |
{ |
|
40478
4bae781b8f7c
replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents:
40474
diff
changeset
|
283 |
override def bufferLoaded(buffer: JEditBuffer) |
4bae781b8f7c
replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents:
40474
diff
changeset
|
284 |
{ |
55791
5821b1937fa5
clarified init_models: simultaneous initialization of all document models, before flushing edits by regular means (via PIDE.editor.invoke) -- important for consolidated doc_blobs when determining initial edits;
wenzelm
parents:
55785
diff
changeset
|
285 |
pending_edits.edit(true, Text.Edit.insert(0, JEdit_Lib.buffer_text(buffer))) |
40478
4bae781b8f7c
replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents:
40474
diff
changeset
|
286 |
} |
4bae781b8f7c
replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents:
40474
diff
changeset
|
287 |
|
34828 | 288 |
override def contentInserted(buffer: JEditBuffer, |
289 |
start_line: Int, offset: Int, num_lines: Int, length: Int) |
|
290 |
{ |
|
40478
4bae781b8f7c
replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents:
40474
diff
changeset
|
291 |
if (!buffer.isLoading) |
54461 | 292 |
pending_edits.edit(false, Text.Edit.insert(offset, buffer.getText(offset, length))) |
34828 | 293 |
} |
294 |
||
295 |
override def preContentRemoved(buffer: JEditBuffer, |
|
38426 | 296 |
start_line: Int, offset: Int, num_lines: Int, removed_length: Int) |
34828 | 297 |
{ |
40478
4bae781b8f7c
replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents:
40474
diff
changeset
|
298 |
if (!buffer.isLoading) |
54461 | 299 |
pending_edits.edit(false, Text.Edit.remove(offset, buffer.getText(offset, removed_length))) |
34828 | 300 |
} |
301 |
} |
|
302 |
||
303 |
||
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
304 |
/* syntax */ |
37557
1ae272fd4082
refresh Isabelle token marker after buffer properties changed, e.g. when fold mode is switched;
wenzelm
parents:
37555
diff
changeset
|
305 |
|
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
306 |
def syntax_changed() |
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
307 |
{ |
61192 | 308 |
JEdit_Lib.buffer_line_manager(buffer).setFirstInvalidLineContext(0) |
59080
611914621edb
added Untyped.method convenience (for *this* class only);
wenzelm
parents:
59079
diff
changeset
|
309 |
for (text_area <- JEdit_Lib.jedit_text_areas(buffer)) |
611914621edb
added Untyped.method convenience (for *this* class only);
wenzelm
parents:
59079
diff
changeset
|
310 |
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
|
311 |
invoke(text_area) |
62246
d9410066dbd5
more thorough syntax_changed: new commands need require new folds;
wenzelm
parents:
61728
diff
changeset
|
312 |
buffer.invalidateCachedFoldLevels |
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
313 |
} |
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
314 |
|
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
315 |
private def init_token_marker() |
59077
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
316 |
{ |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
317 |
Isabelle.buffer_token_marker(buffer) match { |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
318 |
case Some(marker) if marker != buffer.getTokenMarker => |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
319 |
buffer.setTokenMarker(marker) |
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
320 |
syntax_changed() |
59077
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
321 |
case _ => |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
322 |
} |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
323 |
} |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
324 |
|
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
325 |
|
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
326 |
/* activation */ |
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
327 |
|
43512 | 328 |
private def activate() |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
329 |
{ |
55791
5821b1937fa5
clarified init_models: simultaneous initialization of all document models, before flushing edits by regular means (via PIDE.editor.invoke) -- important for consolidated doc_blobs when determining initial edits;
wenzelm
parents:
55785
diff
changeset
|
330 |
pending_edits.edit(true, Text.Edit.insert(0, JEdit_Lib.buffer_text(buffer))) |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
331 |
buffer.addBufferListener(buffer_listener) |
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
332 |
init_token_marker() |
34680 | 333 |
} |
334 |
||
43512 | 335 |
private def deactivate() |
34680 | 336 |
{ |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
337 |
buffer.removeBufferListener(buffer_listener) |
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
338 |
init_token_marker() |
34680 | 339 |
} |
34447 | 340 |
} |