author | wenzelm |
Tue, 02 Dec 2014 17:30:53 +0100 | |
changeset 59080 | 611914621edb |
parent 59079 | 12a689755c3d |
child 59319 | 677615cba30d |
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 |
34446 | 15 |
|
59077
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
16 |
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
|
17 |
import org.gjt.sp.jedit.Buffer |
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
18 |
import org.gjt.sp.jedit.buffer.{BufferAdapter, BufferListener, JEditBuffer, LineManager} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
19 |
|
34760 | 20 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
21 |
object Document_Model |
34588 | 22 |
{ |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
23 |
/* 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
|
24 |
|
50565 | 25 |
private val key = "PIDE.document_model" |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
26 |
|
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34784
diff
changeset
|
27 |
def apply(buffer: Buffer): Option[Document_Model] = |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
28 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
29 |
GUI_Thread.require {} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
30 |
buffer.getProperty(key) match { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
31 |
case model: Document_Model => Some(model) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
32 |
case _ => None |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
33 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
34 |
} |
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 {} |
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34784
diff
changeset
|
39 |
apply(buffer) match { |
39636 | 40 |
case None => |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
41 |
case Some(model) => |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
42 |
model.deactivate() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
43 |
buffer.unsetProperty(key) |
47058
34761733526c
refined init_model: allow change of buffer name as caused by "Save as", for example;
wenzelm
parents:
46920
diff
changeset
|
44 |
buffer.propertiesChanged |
34653 | 45 |
} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
46 |
} |
43397 | 47 |
|
59077
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
48 |
def init(session: Session, buffer: Buffer, node_name: Document.Node.Name, |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
49 |
old_model: Option[Document_Model]): Document_Model = |
43397 | 50 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
51 |
GUI_Thread.require {} |
59077
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
52 |
|
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
53 |
old_model match { |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
54 |
case Some(old) |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
55 |
if old.node_name == node_name && Isabelle.buffer_token_marker(buffer).isEmpty => old |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
56 |
|
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
57 |
case _ => |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
58 |
apply(buffer).map(_.deactivate) |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
59 |
val model = new Document_Model(session, buffer, node_name) |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
60 |
buffer.setProperty(key, model) |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
61 |
model.activate() |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
62 |
buffer.propertiesChanged |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
63 |
model |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
64 |
} |
43397 | 65 |
} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
66 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
67 |
|
38151 | 68 |
|
52973 | 69 |
class Document_Model(val session: Session, val buffer: Buffer, val node_name: Document.Node.Name) |
34588 | 70 |
{ |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
71 |
/* header */ |
38222
dac5fa0ac971
replaced individual Document_Model history by all-inclusive one in Session;
wenzelm
parents:
38158
diff
changeset
|
72 |
|
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
|
73 |
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
|
74 |
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
47393
diff
changeset
|
75 |
def node_header(): Document.Node.Header = |
46920
5f44c8bea84e
more explicit indication of swing thread context;
wenzelm
parents:
46750
diff
changeset
|
76 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
77 |
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
|
78 |
|
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 |
if (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 |
JEdit_Lib.buffer_lock(buffer) { |
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
|
81 |
Exn.capture { |
56823
37be55461dbe
more frugal access to theory text via Reader, reduced costs for I/O text decoding;
wenzelm
parents:
56801
diff
changeset
|
82 |
PIDE.resources.check_thy_reader("", node_name, JEdit_Lib.buffer_reader(buffer)) |
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
|
83 |
} match { |
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 |
case Exn.Res(header) => header |
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
|
85 |
case Exn.Exn(exn) => Document.Node.bad_header(Exn.message(exn)) |
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
|
86 |
} |
46748
8f3ae4d04a2d
refined node_header -- more direct buffer access (again);
wenzelm
parents:
46740
diff
changeset
|
87 |
} |
8f3ae4d04a2d
refined node_header -- more direct buffer access (again);
wenzelm
parents:
46740
diff
changeset
|
88 |
} |
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
|
89 |
else Document.Node.no_header |
46920
5f44c8bea84e
more explicit indication of swing thread context;
wenzelm
parents:
46750
diff
changeset
|
90 |
} |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
91 |
|
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
92 |
|
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
93 |
/* perspective */ |
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
94 |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
95 |
// 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
|
96 |
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
|
97 |
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
|
98 |
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
|
99 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
100 |
GUI_Thread.require {} |
54531
8330faaeebd5
restrict node_required status and Theories panel to actual theories;
wenzelm
parents:
54530
diff
changeset
|
101 |
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
|
102 |
_node_required = b |
c608e0ade554
home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents:
52815
diff
changeset
|
103 |
PIDE.options_changed() |
52974 | 104 |
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
|
105 |
} |
c608e0ade554
home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents:
52815
diff
changeset
|
106 |
} |
52808
143f225e50f5
allow explicit indication of required node: full eval, no prints;
wenzelm
parents:
52807
diff
changeset
|
107 |
|
55783 | 108 |
def node_perspective(doc_blobs: Document.Blobs): (Boolean, Document.Node.Perspective_Text) = |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
109 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
110 |
GUI_Thread.require {} |
52759
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
50565
diff
changeset
|
111 |
|
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
|
112 |
if (Isabelle.continuous_checking && is_theory) { |
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
52977
diff
changeset
|
113 |
val snapshot = this.snapshot() |
54530
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
114 |
|
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
115 |
val document_view_ranges = |
57883
d50aeb916a4b
tuned -- eliminated redundant check (see 1f77110c94ef);
wenzelm
parents:
57621
diff
changeset
|
116 |
for { |
d50aeb916a4b
tuned -- eliminated redundant check (see 1f77110c94ef);
wenzelm
parents:
57621
diff
changeset
|
117 |
doc_view <- PIDE.document_views(buffer) |
d50aeb916a4b
tuned -- eliminated redundant check (see 1f77110c94ef);
wenzelm
parents:
57621
diff
changeset
|
118 |
range <- doc_view.perspective(snapshot).ranges |
d50aeb916a4b
tuned -- eliminated redundant check (see 1f77110c94ef);
wenzelm
parents:
57621
diff
changeset
|
119 |
} yield range |
54530
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
120 |
|
56314 | 121 |
val load_ranges = |
54530
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
122 |
for { |
56314 | 123 |
cmd <- snapshot.node.load_commands |
54530
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
124 |
blob_name <- cmd.blobs_names |
56457
eea4bbe15745
tuned signature -- prefer static type Document.Node.Name;
wenzelm
parents:
56335
diff
changeset
|
125 |
blob_buffer <- JEdit_Lib.jedit_buffer(blob_name) |
54530
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
126 |
if !JEdit_Lib.jedit_text_areas(blob_buffer).isEmpty |
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
127 |
start <- snapshot.node.command_start(cmd) |
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
128 |
range = snapshot.convert(cmd.proper_range + start) |
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
129 |
} yield range |
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
130 |
|
56314 | 131 |
val reparse = snapshot.node.load_commands.exists(_.blobs_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
|
132 |
|
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
|
133 |
(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
|
134 |
Document.Node.Perspective(node_required, |
56314 | 135 |
Text.Perspective(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
|
136 |
PIDE.editor.node_overlays(node_name))) |
52849 | 137 |
} |
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57612
diff
changeset
|
138 |
else (false, Document.Node.no_perspective_text) |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
139 |
} |
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
140 |
|
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
141 |
|
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
|
142 |
/* 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
|
143 |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
144 |
private var _blob: Option[(Bytes, Symbol.Text_Chunk)] = None // owned by GUI thread |
54511 | 145 |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
146 |
private def reset_blob(): Unit = GUI_Thread.require { _blob = None } |
54511 | 147 |
|
55783 | 148 |
def get_blob(): Option[Document.Blob] = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
149 |
GUI_Thread.require { |
55783 | 150 |
if (is_theory) None |
151 |
else { |
|
56473 | 152 |
val (bytes, chunk) = |
55783 | 153 |
_blob match { |
154 |
case Some(x) => x |
|
155 |
case None => |
|
56208 | 156 |
val bytes = PIDE.resources.file_content(buffer) |
56746 | 157 |
val chunk = Symbol.Text_Chunk(buffer.getSegment(0, buffer.getLength)) |
56473 | 158 |
_blob = Some((bytes, chunk)) |
159 |
(bytes, chunk) |
|
55783 | 160 |
} |
161 |
val changed = pending_edits.is_pending() |
|
56473 | 162 |
Some(Document.Blob(bytes, chunk, changed)) |
54511 | 163 |
} |
164 |
} |
|
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
|
165 |
|
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
|
166 |
|
58543 | 167 |
/* bibtex entries */ |
168 |
||
169 |
private var _bibtex: Option[List[(String, Text.Offset)]] = None // owned by GUI thread |
|
170 |
||
171 |
private def reset_bibtex(): Unit = GUI_Thread.require { _bibtex = None } |
|
172 |
||
173 |
def bibtex_entries(): List[(String, Text.Offset)] = |
|
174 |
GUI_Thread.require { |
|
58546 | 175 |
if (Bibtex_JEdit.check(buffer)) { |
58543 | 176 |
_bibtex match { |
177 |
case Some(entries) => entries |
|
178 |
case None => |
|
58547 | 179 |
val entries = Bibtex_JEdit.parse_buffer_entries(buffer) |
58543 | 180 |
_bibtex = Some(entries) |
181 |
entries |
|
182 |
} |
|
183 |
} |
|
184 |
else Nil |
|
185 |
} |
|
186 |
||
187 |
||
50363
2f8dc9e65401
tuned signature in accordance to document operations;
wenzelm
parents:
50344
diff
changeset
|
188 |
/* 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
|
189 |
|
54461 | 190 |
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
|
191 |
clear: Boolean, |
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents:
56314
diff
changeset
|
192 |
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
|
193 |
perspective: Document.Node.Perspective_Text): List[Document.Edit_Text] = |
57621 | 194 |
{ |
195 |
val edits: List[Document.Edit_Text] = |
|
196 |
get_blob() match { |
|
197 |
case None => |
|
198 |
val header_edit = session.header_edit(node_name, node_header()) |
|
199 |
if (clear) |
|
200 |
List(header_edit, |
|
201 |
node_name -> Document.Node.Clear(), |
|
202 |
node_name -> Document.Node.Edits(text_edits), |
|
203 |
node_name -> perspective) |
|
204 |
else |
|
205 |
List(header_edit, |
|
206 |
node_name -> Document.Node.Edits(text_edits), |
|
207 |
node_name -> perspective) |
|
208 |
case Some(blob) => |
|
209 |
List(node_name -> Document.Node.Blob(blob), |
|
210 |
node_name -> Document.Node.Edits(text_edits)) |
|
211 |
} |
|
212 |
edits.filterNot(_._2.is_void) |
|
213 |
} |
|
50363
2f8dc9e65401
tuned signature in accordance to document operations;
wenzelm
parents:
50344
diff
changeset
|
214 |
|
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
|
215 |
|
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
|
216 |
/* pending edits */ |
43648 | 217 |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
218 |
private object pending_edits // owned by GUI thread |
38224 | 219 |
{ |
54461 | 220 |
private var pending_clear = false |
38425 | 221 |
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
|
222 |
private var last_perspective = Document.Node.no_perspective_text |
44438 | 223 |
|
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
|
224 |
def is_pending(): Boolean = pending_clear || !pending.isEmpty |
38425 | 225 |
def snapshot(): List[Text.Edit] = pending.toList |
38224 | 226 |
|
55783 | 227 |
def flushed_edits(doc_blobs: Document.Blobs): List[Document.Edit_Text] = |
38224 | 228 |
{ |
54461 | 229 |
val clear = pending_clear |
47393
d760049b2d18
more robust update_perspective, e.g. required after reload of buffer that is not at start position;
wenzelm
parents:
47058
diff
changeset
|
230 |
val edits = snapshot() |
55783 | 231 |
val (reparse, perspective) = node_perspective(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
|
232 |
if (clear || reparse || !edits.isEmpty || last_perspective != perspective) { |
54461 | 233 |
pending_clear = false |
47393
d760049b2d18
more robust update_perspective, e.g. required after reload of buffer that is not at start position;
wenzelm
parents:
47058
diff
changeset
|
234 |
pending.clear |
54461 | 235 |
last_perspective = perspective |
236 |
node_edits(clear, edits, perspective) |
|
43648 | 237 |
} |
52759
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
50565
diff
changeset
|
238 |
else Nil |
38224 | 239 |
} |
240 |
||
54461 | 241 |
def edit(clear: Boolean, e: Text.Edit) |
38224 | 242 |
{ |
54511 | 243 |
reset_blob() |
58543 | 244 |
reset_bibtex() |
54511 | 245 |
|
54461 | 246 |
if (clear) { |
247 |
pending_clear = true |
|
248 |
pending.clear |
|
249 |
} |
|
250 |
pending += e |
|
251 |
PIDE.editor.invoke() |
|
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
252 |
} |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
253 |
} |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
254 |
|
54464 | 255 |
def snapshot(): Document.Snapshot = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
256 |
GUI_Thread.require { session.snapshot(node_name, pending_edits.snapshot()) } |
34731
c0cb6bd10eec
keep BufferListener and TextAreaExtension private;
wenzelm
parents:
34724
diff
changeset
|
257 |
|
55783 | 258 |
def flushed_edits(doc_blobs: Document.Blobs): List[Document.Edit_Text] = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57610
diff
changeset
|
259 |
GUI_Thread.require { pending_edits.flushed_edits(doc_blobs) } |
34828 | 260 |
|
261 |
||
262 |
/* buffer listener */ |
|
263 |
||
264 |
private val buffer_listener: BufferListener = new BufferAdapter |
|
265 |
{ |
|
40478
4bae781b8f7c
replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents:
40474
diff
changeset
|
266 |
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
|
267 |
{ |
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
|
268 |
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
|
269 |
} |
4bae781b8f7c
replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents:
40474
diff
changeset
|
270 |
|
34828 | 271 |
override def contentInserted(buffer: JEditBuffer, |
272 |
start_line: Int, offset: Int, num_lines: Int, length: Int) |
|
273 |
{ |
|
40478
4bae781b8f7c
replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents:
40474
diff
changeset
|
274 |
if (!buffer.isLoading) |
54461 | 275 |
pending_edits.edit(false, Text.Edit.insert(offset, buffer.getText(offset, length))) |
34828 | 276 |
} |
277 |
||
278 |
override def preContentRemoved(buffer: JEditBuffer, |
|
38426 | 279 |
start_line: Int, offset: Int, num_lines: Int, removed_length: Int) |
34828 | 280 |
{ |
40478
4bae781b8f7c
replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents:
40474
diff
changeset
|
281 |
if (!buffer.isLoading) |
54461 | 282 |
pending_edits.edit(false, Text.Edit.remove(offset, buffer.getText(offset, removed_length))) |
34828 | 283 |
} |
284 |
} |
|
285 |
||
286 |
||
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
287 |
/* syntax */ |
37557
1ae272fd4082
refresh Isabelle token marker after buffer properties changed, e.g. when fold mode is switched;
wenzelm
parents:
37555
diff
changeset
|
288 |
|
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
289 |
def syntax_changed() |
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
290 |
{ |
59079 | 291 |
Untyped.get[LineManager](buffer, "lineMgr").setFirstInvalidLineContext(0) |
59080
611914621edb
added Untyped.method convenience (for *this* class only);
wenzelm
parents:
59079
diff
changeset
|
292 |
for (text_area <- JEdit_Lib.jedit_text_areas(buffer)) |
611914621edb
added Untyped.method convenience (for *this* class only);
wenzelm
parents:
59079
diff
changeset
|
293 |
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
|
294 |
invoke(text_area) |
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
295 |
} |
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
296 |
|
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
297 |
private def init_token_marker() |
59077
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
298 |
{ |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
299 |
Isabelle.buffer_token_marker(buffer) match { |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
300 |
case Some(marker) if marker != buffer.getTokenMarker => |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
301 |
buffer.setTokenMarker(marker) |
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
302 |
syntax_changed() |
59077
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
303 |
case _ => |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
304 |
} |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
305 |
} |
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
306 |
|
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
307 |
|
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
308 |
/* activation */ |
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
309 |
|
43512 | 310 |
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
|
311 |
{ |
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
|
312 |
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
|
313 |
buffer.addBufferListener(buffer_listener) |
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
314 |
init_token_marker() |
34680 | 315 |
} |
316 |
||
43512 | 317 |
private def deactivate() |
34680 | 318 |
{ |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
319 |
buffer.removeBufferListener(buffer_listener) |
59078
cf255dc2b48f
more careful syntax_changed propagation -- avoid global jEdit.propertiesChanged;
wenzelm
parents:
59077
diff
changeset
|
320 |
init_token_marker() |
34680 | 321 |
} |
34447 | 322 |
} |