author | wenzelm |
Wed, 12 Feb 2014 11:28:17 +0100 | |
changeset 55435 | 662e0fd39823 |
parent 55432 | 9c53198dbb1c |
child 55778 | e1fd8780f997 |
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 |
||
38222
dac5fa0ac971
replaced individual Document_Model history by all-inclusive one in Session;
wenzelm
parents:
38158
diff
changeset
|
5 |
Document model connected to jEdit buffer -- single node in theory graph. |
36760 | 6 |
*/ |
34407 | 7 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
8 |
package isabelle.jedit |
34760 | 9 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
10 |
|
36015 | 11 |
import isabelle._ |
12 |
||
34693 | 13 |
import scala.collection.mutable |
34446 | 14 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
15 |
import org.gjt.sp.jedit.Buffer |
34783
cb95d6bbf5f1
clarified BufferListener: use adapter, listen to contentInserted instead of preContentInserted;
wenzelm
parents:
34778
diff
changeset
|
16 |
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
|
17 |
|
34760 | 18 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
19 |
object Document_Model |
34588 | 20 |
{ |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
21 |
/* 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
|
22 |
|
50565 | 23 |
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
|
24 |
|
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34784
diff
changeset
|
25 |
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
|
26 |
{ |
38223 | 27 |
Swing_Thread.require() |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
28 |
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
|
29 |
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
|
30 |
case _ => None |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
31 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
32 |
} |
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 |
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
|
35 |
{ |
38223 | 36 |
Swing_Thread.require() |
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34784
diff
changeset
|
37 |
apply(buffer) match { |
39636 | 38 |
case None => |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
39 |
case Some(model) => |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
40 |
model.deactivate() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
41 |
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
|
42 |
buffer.propertiesChanged |
34653 | 43 |
} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
44 |
} |
43397 | 45 |
|
52973 | 46 |
def init(session: Session, buffer: Buffer, node_name: Document.Node.Name): Document_Model = |
43397 | 47 |
{ |
47058
34761733526c
refined init_model: allow change of buffer name as caused by "Save as", for example;
wenzelm
parents:
46920
diff
changeset
|
48 |
Swing_Thread.require() |
34761733526c
refined init_model: allow change of buffer name as caused by "Save as", for example;
wenzelm
parents:
46920
diff
changeset
|
49 |
apply(buffer).map(_.deactivate) |
52973 | 50 |
val model = new Document_Model(session, buffer, node_name) |
43397 | 51 |
buffer.setProperty(key, model) |
52 |
model.activate() |
|
47058
34761733526c
refined init_model: allow change of buffer name as caused by "Save as", for example;
wenzelm
parents:
46920
diff
changeset
|
53 |
buffer.propertiesChanged |
43397 | 54 |
model |
55 |
} |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
56 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
57 |
|
38151 | 58 |
|
52973 | 59 |
class Document_Model(val session: Session, val buffer: Buffer, val node_name: Document.Node.Name) |
34588 | 60 |
{ |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
61 |
/* header */ |
38222
dac5fa0ac971
replaced individual Document_Model history by all-inclusive one in Session;
wenzelm
parents:
38158
diff
changeset
|
62 |
|
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
|
63 |
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
|
64 |
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
47393
diff
changeset
|
65 |
def node_header(): Document.Node.Header = |
46920
5f44c8bea84e
more explicit indication of swing thread context;
wenzelm
parents:
46750
diff
changeset
|
66 |
{ |
5f44c8bea84e
more explicit indication of swing thread context;
wenzelm
parents:
46750
diff
changeset
|
67 |
Swing_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
|
68 |
|
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
|
69 |
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
|
70 |
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
|
71 |
Exn.capture { |
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
|
72 |
PIDE.thy_load.check_thy_text(node_name, buffer.getSegment(0, buffer.getLength)) |
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 |
} 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
|
74 |
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
|
75 |
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
|
76 |
} |
46748
8f3ae4d04a2d
refined node_header -- more direct buffer access (again);
wenzelm
parents:
46740
diff
changeset
|
77 |
} |
8f3ae4d04a2d
refined node_header -- more direct buffer access (again);
wenzelm
parents:
46740
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 |
else Document.Node.no_header |
46920
5f44c8bea84e
more explicit indication of swing thread context;
wenzelm
parents:
46750
diff
changeset
|
80 |
} |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
81 |
|
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
82 |
|
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
83 |
/* perspective */ |
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
84 |
|
52849 | 85 |
// owned by Swing thread |
52816
c608e0ade554
home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents:
52815
diff
changeset
|
86 |
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
|
87 |
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
|
88 |
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
|
89 |
{ |
c608e0ade554
home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents:
52815
diff
changeset
|
90 |
Swing_Thread.require() |
54531
8330faaeebd5
restrict node_required status and Theories panel to actual theories;
wenzelm
parents:
54530
diff
changeset
|
91 |
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
|
92 |
_node_required = b |
c608e0ade554
home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents:
52815
diff
changeset
|
93 |
PIDE.options_changed() |
52974 | 94 |
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
|
95 |
} |
c608e0ade554
home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents:
52815
diff
changeset
|
96 |
} |
52808
143f225e50f5
allow explicit indication of required node: full eval, no prints;
wenzelm
parents:
52807
diff
changeset
|
97 |
|
52849 | 98 |
val empty_perspective: Document.Node.Perspective_Text = |
52887 | 99 |
Document.Node.Perspective(false, Text.Perspective.empty, Document.Node.Overlays.empty) |
52849 | 100 |
|
52808
143f225e50f5
allow explicit indication of required node: full eval, no prints;
wenzelm
parents:
52807
diff
changeset
|
101 |
def node_perspective(): Document.Node.Perspective_Text = |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
102 |
{ |
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
103 |
Swing_Thread.require() |
52759
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
50565
diff
changeset
|
104 |
|
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
|
105 |
if (Isabelle.continuous_checking && is_theory) { |
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
52977
diff
changeset
|
106 |
val snapshot = this.snapshot() |
54530
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
107 |
|
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
108 |
val document_view_ranges = |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
109 |
if (is_theory) { |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
110 |
for { |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
111 |
doc_view <- PIDE.document_views(buffer) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
112 |
range <- doc_view.perspective(snapshot).ranges |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
113 |
} yield range |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
114 |
} |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
115 |
else Nil |
54530
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
116 |
|
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
117 |
val thy_load_ranges = |
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
118 |
for { |
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
119 |
cmd <- snapshot.node.thy_load_commands |
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
120 |
blob_name <- cmd.blobs_names |
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
121 |
blob_buffer <- JEdit_Lib.jedit_buffer(blob_name.node) |
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
122 |
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
|
123 |
start <- snapshot.node.command_start(cmd) |
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
124 |
range = snapshot.convert(cmd.proper_range + start) |
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
125 |
} yield range |
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
126 |
|
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
127 |
Document.Node.Perspective(node_required, |
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
128 |
Text.Perspective(document_view_ranges ::: thy_load_ranges), |
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54521
diff
changeset
|
129 |
PIDE.editor.node_overlays(node_name)) |
52849 | 130 |
} |
131 |
else empty_perspective |
|
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
132 |
} |
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
133 |
|
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44379
diff
changeset
|
134 |
|
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
|
135 |
/* 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
|
136 |
|
55431
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
54531
diff
changeset
|
137 |
private var _blob: Option[(Bytes, Command.File)] = None // owned by Swing thread |
54511 | 138 |
|
139 |
private def reset_blob(): Unit = Swing_Thread.require { _blob = None } |
|
140 |
||
55431
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
54531
diff
changeset
|
141 |
def blob(): (Bytes, Command.File) = |
54511 | 142 |
Swing_Thread.require { |
143 |
_blob match { |
|
55431
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
54531
diff
changeset
|
144 |
case Some(x) => x |
54511 | 145 |
case None => |
146 |
val b = PIDE.thy_load.file_content(buffer) |
|
55431
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
54531
diff
changeset
|
147 |
val file = new Command.File(node_name.node, buffer.getSegment(0, buffer.getLength)) |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
54531
diff
changeset
|
148 |
_blob = Some((b, file)) |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
54531
diff
changeset
|
149 |
(b, file) |
54511 | 150 |
} |
151 |
} |
|
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
|
152 |
|
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
|
153 |
|
50363
2f8dc9e65401
tuned signature in accordance to document operations;
wenzelm
parents:
50344
diff
changeset
|
154 |
/* 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
|
155 |
|
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
|
156 |
def init_edits(): List[Document.Edit_Text] = |
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
|
157 |
{ |
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
|
158 |
Swing_Thread.require() |
52815
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
52808
diff
changeset
|
159 |
|
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
|
160 |
val header = node_header() |
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
|
161 |
val text = JEdit_Lib.buffer_text(buffer) |
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
|
162 |
val perspective = node_perspective() |
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
|
163 |
|
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
|
164 |
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
|
165 |
List(session.header_edit(node_name, 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
|
166 |
node_name -> Document.Node.Clear(), |
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
|
167 |
node_name -> Document.Node.Edits(List(Text.Edit.insert(0, text))), |
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
|
168 |
node_name -> perspective) |
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
|
169 |
else |
55435
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
wenzelm
parents:
55432
diff
changeset
|
170 |
List(node_name -> Document.Node.Blob(), |
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
wenzelm
parents:
55432
diff
changeset
|
171 |
node_name -> Document.Node.Edits(List(Text.Edit.insert(0, text)))) |
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
|
172 |
} |
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
|
173 |
|
54461 | 174 |
def node_edits( |
175 |
clear: Boolean, |
|
176 |
text_edits: List[Text.Edit], |
|
177 |
perspective: Document.Node.Perspective_Text): List[Document.Edit_Text] = |
|
50363
2f8dc9e65401
tuned signature in accordance to document operations;
wenzelm
parents:
50344
diff
changeset
|
178 |
{ |
2f8dc9e65401
tuned signature in accordance to document operations;
wenzelm
parents:
50344
diff
changeset
|
179 |
Swing_Thread.require() |
52815
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
52808
diff
changeset
|
180 |
|
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
|
181 |
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
|
182 |
val header_edit = session.header_edit(node_name, node_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
|
183 |
if (clear) |
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
|
184 |
List(header_edit, |
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
|
185 |
node_name -> Document.Node.Clear(), |
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
|
186 |
node_name -> Document.Node.Edits(text_edits), |
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
|
187 |
node_name -> perspective) |
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
|
188 |
else |
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
|
189 |
List(header_edit, |
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
|
190 |
node_name -> Document.Node.Edits(text_edits), |
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
|
191 |
node_name -> perspective) |
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
|
192 |
} |
54461 | 193 |
else |
55435
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
wenzelm
parents:
55432
diff
changeset
|
194 |
List(node_name -> Document.Node.Blob(), |
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
wenzelm
parents:
55432
diff
changeset
|
195 |
node_name -> Document.Node.Edits(text_edits)) |
50363
2f8dc9e65401
tuned signature in accordance to document operations;
wenzelm
parents:
50344
diff
changeset
|
196 |
} |
2f8dc9e65401
tuned signature in accordance to document operations;
wenzelm
parents:
50344
diff
changeset
|
197 |
|
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
|
198 |
|
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
|
199 |
/* pending edits */ |
43648 | 200 |
|
43644 | 201 |
private object pending_edits // owned by Swing thread |
38224 | 202 |
{ |
54461 | 203 |
private var pending_clear = false |
38425 | 204 |
private val pending = new mutable.ListBuffer[Text.Edit] |
52849 | 205 |
private var last_perspective = empty_perspective |
44438 | 206 |
|
38425 | 207 |
def snapshot(): List[Text.Edit] = pending.toList |
38224 | 208 |
|
52759
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
50565
diff
changeset
|
209 |
def flushed_edits(): List[Document.Edit_Text] = |
38224 | 210 |
{ |
54461 | 211 |
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
|
212 |
val edits = snapshot() |
54461 | 213 |
val perspective = node_perspective() |
54521
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents:
54513
diff
changeset
|
214 |
if (clear || !edits.isEmpty || last_perspective != perspective) { |
54461 | 215 |
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
|
216 |
pending.clear |
54461 | 217 |
last_perspective = perspective |
218 |
node_edits(clear, edits, perspective) |
|
43648 | 219 |
} |
52759
a20631db9c8a
support declarative editor_execution_range, instead of old-style check/cancel buttons;
wenzelm
parents:
50565
diff
changeset
|
220 |
else Nil |
38224 | 221 |
} |
222 |
||
54461 | 223 |
def edit(clear: Boolean, e: Text.Edit) |
38224 | 224 |
{ |
54511 | 225 |
reset_blob() |
226 |
||
54461 | 227 |
if (clear) { |
228 |
pending_clear = true |
|
229 |
pending.clear |
|
230 |
} |
|
231 |
pending += e |
|
232 |
PIDE.editor.invoke() |
|
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
233 |
} |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
234 |
} |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
235 |
|
54464 | 236 |
def snapshot(): Document.Snapshot = |
237 |
Swing_Thread.require { session.snapshot(node_name, pending_edits.snapshot()) } |
|
34731
c0cb6bd10eec
keep BufferListener and TextAreaExtension private;
wenzelm
parents:
34724
diff
changeset
|
238 |
|
54464 | 239 |
def flushed_edits(): List[Document.Edit_Text] = |
240 |
Swing_Thread.require { pending_edits.flushed_edits() } |
|
34828 | 241 |
|
242 |
||
243 |
/* buffer listener */ |
|
244 |
||
245 |
private val buffer_listener: BufferListener = new BufferAdapter |
|
246 |
{ |
|
40478
4bae781b8f7c
replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents:
40474
diff
changeset
|
247 |
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
|
248 |
{ |
54461 | 249 |
pending_edits.edit(true, Text.Edit.insert(0, buffer.getText(0, buffer.getLength))) |
40478
4bae781b8f7c
replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents:
40474
diff
changeset
|
250 |
} |
4bae781b8f7c
replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents:
40474
diff
changeset
|
251 |
|
34828 | 252 |
override def contentInserted(buffer: JEditBuffer, |
253 |
start_line: Int, offset: Int, num_lines: Int, length: Int) |
|
254 |
{ |
|
40478
4bae781b8f7c
replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents:
40474
diff
changeset
|
255 |
if (!buffer.isLoading) |
54461 | 256 |
pending_edits.edit(false, Text.Edit.insert(offset, buffer.getText(offset, length))) |
34828 | 257 |
} |
258 |
||
259 |
override def preContentRemoved(buffer: JEditBuffer, |
|
38426 | 260 |
start_line: Int, offset: Int, num_lines: Int, removed_length: Int) |
34828 | 261 |
{ |
40478
4bae781b8f7c
replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents:
40474
diff
changeset
|
262 |
if (!buffer.isLoading) |
54461 | 263 |
pending_edits.edit(false, Text.Edit.remove(offset, buffer.getText(offset, removed_length))) |
34828 | 264 |
} |
265 |
} |
|
266 |
||
267 |
||
38158 | 268 |
/* activation */ |
37557
1ae272fd4082
refresh Isabelle token marker after buffer properties changed, e.g. when fold mode is switched;
wenzelm
parents:
37555
diff
changeset
|
269 |
|
43512 | 270 |
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
|
271 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
272 |
buffer.addBufferListener(buffer_listener) |
44358
2a2df4de1bbe
more robust initialization of token marker and line context wrt. session startup;
wenzelm
parents:
44182
diff
changeset
|
273 |
Token_Markup.refresh_buffer(buffer) |
34680 | 274 |
} |
275 |
||
43512 | 276 |
private def deactivate() |
34680 | 277 |
{ |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34783
diff
changeset
|
278 |
buffer.removeBufferListener(buffer_listener) |
44358
2a2df4de1bbe
more robust initialization of token marker and line context wrt. session startup;
wenzelm
parents:
44182
diff
changeset
|
279 |
Token_Markup.refresh_buffer(buffer) |
34680 | 280 |
} |
34447 | 281 |
} |