author | wenzelm |
Wed, 09 Apr 2014 15:03:07 +0200 | |
changeset 56495 | 0b9334adcf05 |
parent 56373 | 0605d90be6fc |
child 56662 | f373fb77e0a4 |
permissions | -rw-r--r-- |
43282
5d294220ca43
moved sources -- eliminated Netbeans artifact of jedit package directory;
wenzelm
parents:
42839
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/document_view.scala |
36760 | 2 |
Author: Fabian Immler, TU Munich |
3 |
Author: Makarius |
|
4 |
||
5 |
Document view connected to jEdit text area. |
|
6 |
*/ |
|
34408 | 7 |
|
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
8 |
package isabelle.jedit |
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
9 |
|
34760 | 10 |
|
36015 | 11 |
import isabelle._ |
12 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
13 |
import scala.actors.Actor._ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
14 |
|
54441 | 15 |
import java.awt.Graphics2D |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
16 |
import java.awt.event.KeyEvent |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
17 |
import javax.swing.event.{CaretListener, CaretEvent} |
34734 | 18 |
|
54441 | 19 |
import org.gjt.sp.jedit.jEdit |
39176
b8fdd3ae8815
Document_View: more precise painting of gutter icons, only if line selection area is sufficiently large;
wenzelm
parents:
39175
diff
changeset
|
20 |
import org.gjt.sp.jedit.options.GutterOptionPane |
55712 | 21 |
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea, TextAreaExtension, TextAreaPainter} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
22 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
23 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
24 |
object Document_View |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
25 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
26 |
/* document view of text area */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
27 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
28 |
private val key = new Object |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
29 |
|
55712 | 30 |
def apply(text_area: TextArea): Option[Document_View] = |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
31 |
{ |
38223 | 32 |
Swing_Thread.require() |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
33 |
text_area.getClientProperty(key) match { |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
34 |
case doc_view: Document_View => Some(doc_view) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
35 |
case _ => None |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
36 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
37 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
38 |
|
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
39 |
def exit(text_area: JEditTextArea) |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
40 |
{ |
38223 | 41 |
Swing_Thread.require() |
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34784
diff
changeset
|
42 |
apply(text_area) match { |
39636 | 43 |
case None => |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
44 |
case Some(doc_view) => |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
45 |
doc_view.deactivate() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
46 |
text_area.putClientProperty(key, null) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
47 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
48 |
} |
43397 | 49 |
|
50 |
def init(model: Document_Model, text_area: JEditTextArea): Document_View = |
|
51 |
{ |
|
52 |
exit(text_area) |
|
53 |
val doc_view = new Document_View(model, text_area) |
|
54 |
text_area.putClientProperty(key, doc_view) |
|
55 |
doc_view.activate() |
|
56 |
doc_view |
|
57 |
} |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
58 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
59 |
|
34733 | 60 |
|
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43369
diff
changeset
|
61 |
class Document_View(val model: Document_Model, val text_area: JEditTextArea) |
34654 | 62 |
{ |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
63 |
private val session = model.session |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
64 |
|
50205 | 65 |
def get_rendering(): Rendering = Rendering(model.snapshot(), PIDE.options.value) |
49411 | 66 |
|
50306 | 67 |
val rich_text_area = |
50915
12de8ea66f54
close tooltip after Active.action, to make it look more interactive (notably due to lack of dynamic update);
wenzelm
parents:
50770
diff
changeset
|
68 |
new Rich_Text_Area(text_area.getView, text_area, get_rendering _, () => (), |
53179 | 69 |
caret_visible = true, enable_hovering = false) |
49411 | 70 |
|
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
71 |
|
44379 | 72 |
/* perspective */ |
73 |
||
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
74 |
def perspective(snapshot: Document.Snapshot): Text.Perspective = |
44379 | 75 |
{ |
76 |
Swing_Thread.require() |
|
53780
ef62204a126b
caret range of active text area counts as visible (e.g. relevant for Output after scrolling outside of text view);
wenzelm
parents:
53274
diff
changeset
|
77 |
|
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
78 |
val active_command = |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
79 |
{ |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
80 |
val view = text_area.getView |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
81 |
if (view != null && view.getTextArea == text_area) { |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
82 |
PIDE.editor.current_command(view, snapshot) match { |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
83 |
case Some(command) => |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
84 |
snapshot.node.command_start(command) match { |
54530
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54461
diff
changeset
|
85 |
case Some(start) => List(snapshot.convert(command.proper_range + start)) |
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
86 |
case None => Nil |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
87 |
} |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
88 |
case None => Nil |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
89 |
} |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
90 |
} |
53780
ef62204a126b
caret range of active text area counts as visible (e.g. relevant for Output after scrolling outside of text view);
wenzelm
parents:
53274
diff
changeset
|
91 |
else Nil |
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
92 |
} |
53780
ef62204a126b
caret range of active text area counts as visible (e.g. relevant for Output after scrolling outside of text view);
wenzelm
parents:
53274
diff
changeset
|
93 |
|
50363
2f8dc9e65401
tuned signature in accordance to document operations;
wenzelm
parents:
50306
diff
changeset
|
94 |
val buffer_range = JEdit_Lib.buffer_range(model.buffer) |
53780
ef62204a126b
caret range of active text area counts as visible (e.g. relevant for Output after scrolling outside of text view);
wenzelm
parents:
53274
diff
changeset
|
95 |
val visible_lines = |
ef62204a126b
caret range of active text area counts as visible (e.g. relevant for Output after scrolling outside of text view);
wenzelm
parents:
53274
diff
changeset
|
96 |
(for { |
56356
c3dbaa155ece
tuned for-comprehensions -- less structure mapping;
wenzelm
parents:
56314
diff
changeset
|
97 |
i <- (0 until text_area.getVisibleLines).iterator |
46997 | 98 |
start = text_area.getScreenLineStartOffset(i) |
99 |
stop = text_area.getScreenLineEndOffset(i) |
|
44379 | 100 |
if start >= 0 && stop >= 0 |
46997 | 101 |
range <- buffer_range.try_restrict(Text.Range(start, stop)) |
44583
022509c908fb
restrict perspective to actual buffer_range, to avoid spurious edits due to faulty last_exec_offset (NB: jEdit screenlines may be silently extended by trailing newline);
wenzelm
parents:
44473
diff
changeset
|
102 |
if !range.is_singularity |
44379 | 103 |
} |
53780
ef62204a126b
caret range of active text area counts as visible (e.g. relevant for Output after scrolling outside of text view);
wenzelm
parents:
53274
diff
changeset
|
104 |
yield range).toList |
ef62204a126b
caret range of active text area counts as visible (e.g. relevant for Output after scrolling outside of text view);
wenzelm
parents:
53274
diff
changeset
|
105 |
|
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
106 |
Text.Perspective(active_command ::: visible_lines) |
44379 | 107 |
} |
108 |
||
54461 | 109 |
private def update_view = new TextAreaExtension |
44437
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
110 |
{ |
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
111 |
override def paintScreenLineRange(gfx: Graphics2D, |
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
112 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
113 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
114 |
{ |
49424 | 115 |
// no robust_body |
54461 | 116 |
PIDE.editor.invoke() |
44437
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
117 |
} |
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
118 |
} |
bebe15799192
more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents:
44436
diff
changeset
|
119 |
|
44379 | 120 |
|
49411 | 121 |
/* gutter */ |
34513 | 122 |
|
42825 | 123 |
private val gutter_painter = new TextAreaExtension |
39175 | 124 |
{ |
125 |
override def paintScreenLineRange(gfx: Graphics2D, |
|
126 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
|
127 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
|
128 |
{ |
|
49411 | 129 |
rich_text_area.robust_body(()) { |
46920
5f44c8bea84e
more explicit indication of swing thread context;
wenzelm
parents:
46918
diff
changeset
|
130 |
Swing_Thread.assert() |
5f44c8bea84e
more explicit indication of swing thread context;
wenzelm
parents:
46918
diff
changeset
|
131 |
|
43404 | 132 |
val gutter = text_area.getGutter |
133 |
val width = GutterOptionPane.getSelectionAreaWidth |
|
134 |
val border_width = jEdit.getIntegerProperty("view.gutter.borderWidth", 3) |
|
135 |
val FOLD_MARKER_SIZE = 12 |
|
43419
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
136 |
|
43404 | 137 |
if (gutter.isSelectionAreaEnabled && !gutter.isExpanded && width >= 12 && line_height >= 12) { |
49408 | 138 |
val buffer = model.buffer |
139 |
JEdit_Lib.buffer_lock(buffer) { |
|
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49408
diff
changeset
|
140 |
val rendering = get_rendering() |
49356 | 141 |
|
43404 | 142 |
for (i <- 0 until physical_lines.length) { |
143 |
if (physical_lines(i) != -1) { |
|
49843
afddf4e26fac
further refinement of jEdit line range, avoiding lack of final \n;
wenzelm
parents:
49492
diff
changeset
|
144 |
val line_range = Text.Range(start(i), end(i)) |
43419
6ed49c52d463
flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents:
43417
diff
changeset
|
145 |
|
43404 | 146 |
// gutter icons |
56495 | 147 |
rendering.gutter_icon(line_range) match { |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
45744
diff
changeset
|
148 |
case Some(icon) => |
46227
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46205
diff
changeset
|
149 |
val x0 = (FOLD_MARKER_SIZE + width - border_width - icon.getIconWidth) max 10 |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46205
diff
changeset
|
150 |
val y0 = y + i * line_height + (((line_height - icon.getIconHeight) / 2) max 0) |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46205
diff
changeset
|
151 |
icon.paintIcon(gutter, gfx, x0, y0) |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
45744
diff
changeset
|
152 |
case None => |
43404 | 153 |
} |
39175 | 154 |
} |
155 |
} |
|
156 |
} |
|
157 |
} |
|
158 |
} |
|
159 |
} |
|
160 |
} |
|
161 |
||
162 |
||
52479
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
163 |
/* key listener */ |
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
164 |
|
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
165 |
private val key_listener = |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
166 |
JEdit_Lib.key_listener( |
53227
68cc55ceb7f6
more standard key handling according to jEdit (with workaround);
wenzelm
parents:
53226
diff
changeset
|
167 |
key_pressed = (evt: KeyEvent) => |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
168 |
{ |
53244 | 169 |
if (evt.getKeyCode == KeyEvent.VK_ESCAPE && PIDE.dismissed_popups(text_area.getView)) |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
170 |
evt.consume |
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53272
diff
changeset
|
171 |
} |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
172 |
) |
52479
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
173 |
|
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
174 |
|
37129 | 175 |
/* caret handling */ |
34810 | 176 |
|
46740
852baa599351
explicitly revoke delay, to avoid spurious timer events after deactivation of related components;
wenzelm
parents:
46583
diff
changeset
|
177 |
private val delay_caret_update = |
50207 | 178 |
Swing_Thread.delay_last(PIDE.options.seconds("editor_input_delay")) { |
44805 | 179 |
session.caret_focus.event(Session.Caret_Focus) |
34810 | 180 |
} |
46740
852baa599351
explicitly revoke delay, to avoid spurious timer events after deactivation of related components;
wenzelm
parents:
46583
diff
changeset
|
181 |
|
852baa599351
explicitly revoke delay, to avoid spurious timer events after deactivation of related components;
wenzelm
parents:
46583
diff
changeset
|
182 |
private val caret_listener = new CaretListener { |
49195 | 183 |
override def caretUpdate(e: CaretEvent) { delay_caret_update.invoke() } |
34810 | 184 |
} |
185 |
||
186 |
||
46572 | 187 |
/* text status overview left of scrollbar */ |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
188 |
|
47993 | 189 |
private object overview extends Text_Overview(this) |
46572 | 190 |
{ |
46571
edcccd7a9eee
overview.delay_repaint: avoid wasting GUI cycles via update_delay;
wenzelm
parents:
46550
diff
changeset
|
191 |
val delay_repaint = |
50207 | 192 |
Swing_Thread.delay_first(PIDE.options.seconds("editor_update_delay")) { repaint() } |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
193 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
194 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
195 |
|
39740 | 196 |
/* main actor */ |
197 |
||
198 |
private val main_actor = actor { |
|
199 |
loop { |
|
200 |
react { |
|
49196
1d63ceb0d177
postpone update of text overview panel after incoming session edits, to improve reactivity of editing massive theories like src/HOL/Multivariate_Analysis;
wenzelm
parents:
49195
diff
changeset
|
201 |
case _: Session.Raw_Edits => |
1d63ceb0d177
postpone update of text overview panel after incoming session edits, to improve reactivity of editing massive theories like src/HOL/Multivariate_Analysis;
wenzelm
parents:
49195
diff
changeset
|
202 |
Swing_Thread.later { |
50207 | 203 |
overview.delay_repaint.postpone(PIDE.options.seconds("editor_input_delay")) |
49196
1d63ceb0d177
postpone update of text overview panel after incoming session edits, to improve reactivity of editing massive theories like src/HOL/Multivariate_Analysis;
wenzelm
parents:
49195
diff
changeset
|
204 |
} |
1d63ceb0d177
postpone update of text overview panel after incoming session edits, to improve reactivity of editing massive theories like src/HOL/Multivariate_Analysis;
wenzelm
parents:
49195
diff
changeset
|
205 |
|
44608 | 206 |
case changed: Session.Commands_Changed => |
39740 | 207 |
val buffer = model.buffer |
46918
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
208 |
Swing_Thread.later { |
49406 | 209 |
JEdit_Lib.buffer_lock(buffer) { |
46918
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
210 |
if (model.buffer == text_area.getBuffer) { |
47027
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents:
47013
diff
changeset
|
211 |
val snapshot = model.snapshot() |
39740 | 212 |
|
56314 | 213 |
val load_changed = |
214 |
snapshot.load_commands.exists(changed.commands.contains) |
|
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
54530
diff
changeset
|
215 |
|
56314 | 216 |
if (changed.assignment || load_changed || |
52973 | 217 |
(changed.nodes.contains(model.node_name) && |
46918
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
218 |
changed.commands.exists(snapshot.node.commands.contains))) |
49196
1d63ceb0d177
postpone update of text overview panel after incoming session edits, to improve reactivity of editing massive theories like src/HOL/Multivariate_Analysis;
wenzelm
parents:
49195
diff
changeset
|
219 |
Swing_Thread.later { overview.delay_repaint.invoke() } |
39740 | 220 |
|
50770
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
221 |
val visible_lines = text_area.getVisibleLines |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
222 |
if (visible_lines > 0) { |
56314 | 223 |
if (changed.assignment || load_changed) |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
54530
diff
changeset
|
224 |
text_area.invalidateScreenLineRange(0, visible_lines) |
50770
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
225 |
else { |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
226 |
val visible_range = JEdit_Lib.visible_range(text_area).get |
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56356
diff
changeset
|
227 |
val visible_iterator = |
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56356
diff
changeset
|
228 |
snapshot.node.command_iterator(snapshot.revert(visible_range)).map(_._1) |
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56356
diff
changeset
|
229 |
if (visible_iterator.exists(changed.commands)) { |
50770
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
230 |
for { |
56356
c3dbaa155ece
tuned for-comprehensions -- less structure mapping;
wenzelm
parents:
56314
diff
changeset
|
231 |
line <- (0 until visible_lines).iterator |
50770
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
232 |
start = text_area.getScreenLineStartOffset(line) if start >= 0 |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
233 |
end = text_area.getScreenLineEndOffset(line) if end >= 0 |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
234 |
range = Text.Range(start, end) |
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56356
diff
changeset
|
235 |
line_cmds = snapshot.node.command_iterator(snapshot.revert(range)).map(_._1) |
50770
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
236 |
if line_cmds.exists(changed.commands) |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
237 |
} text_area.invalidateScreenLineRange(line, line) |
46918
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
238 |
} |
50770
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
239 |
} |
46583 | 240 |
} |
46918
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
241 |
} |
39740 | 242 |
} |
243 |
} |
|
244 |
||
54441 | 245 |
case bad => |
55618 | 246 |
System.err.println("command_change_actor: ignoring bad message " + bad) |
39740 | 247 |
} |
248 |
} |
|
249 |
} |
|
250 |
||
251 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
252 |
/* activation */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
253 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
254 |
private def activate() |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
255 |
{ |
42825 | 256 |
val painter = text_area.getPainter |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49408
diff
changeset
|
257 |
|
54461 | 258 |
painter.addExtension(TextAreaPainter.LOWEST_LAYER, update_view) |
49411 | 259 |
rich_text_area.activate() |
42825 | 260 |
text_area.getGutter.addExtension(gutter_painter) |
52479
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
261 |
text_area.addKeyListener(key_listener) |
34810 | 262 |
text_area.addCaretListener(caret_listener) |
263 |
text_area.addLeftOfScrollBar(overview) |
|
49196
1d63ceb0d177
postpone update of text overview panel after incoming session edits, to improve reactivity of editing massive theories like src/HOL/Multivariate_Analysis;
wenzelm
parents:
49195
diff
changeset
|
264 |
session.raw_edits += main_actor |
39740 | 265 |
session.commands_changed += main_actor |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
266 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
267 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
268 |
private def deactivate() |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
269 |
{ |
42825 | 270 |
val painter = text_area.getPainter |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49408
diff
changeset
|
271 |
|
49196
1d63ceb0d177
postpone update of text overview panel after incoming session edits, to improve reactivity of editing massive theories like src/HOL/Multivariate_Analysis;
wenzelm
parents:
49195
diff
changeset
|
272 |
session.raw_edits -= main_actor |
39740 | 273 |
session.commands_changed -= main_actor |
52479
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
274 |
text_area.removeLeftOfScrollBar(overview); overview.delay_repaint.revoke() |
49195 | 275 |
text_area.removeCaretListener(caret_listener); delay_caret_update.revoke() |
52479
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
276 |
text_area.removeKeyListener(key_listener) |
42825 | 277 |
text_area.getGutter.removeExtension(gutter_painter) |
49411 | 278 |
rich_text_area.deactivate() |
54461 | 279 |
painter.removeExtension(update_view) |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
280 |
} |
42825 | 281 |
} |