author | wenzelm |
Sat, 13 Jul 2013 13:25:42 +0200 | |
changeset 52643 | 34c29356930e |
parent 52548 | a1a8248a4677 |
child 52759 | a20631db9c8a |
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 |
||
44379 | 13 |
import scala.collection.mutable |
45460 | 14 |
import scala.collection.immutable.SortedMap |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
15 |
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
|
16 |
|
43520
cec9b95fa35d
explicit import java.lang.System to prevent odd scope problems;
wenzelm
parents:
43510
diff
changeset
|
17 |
import java.lang.System |
45744
0ad063afa3d6
caret_range based on BreakIterator, which handles combined unicode characters as well;
wenzelm
parents:
45665
diff
changeset
|
18 |
import java.text.BreakIterator |
46572 | 19 |
import java.awt.{Color, Graphics2D, Point} |
52479
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
20 |
import java.awt.event.{KeyEvent, KeyAdapter} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
21 |
import javax.swing.event.{CaretListener, CaretEvent} |
34734 | 22 |
|
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49408
diff
changeset
|
23 |
import org.gjt.sp.jedit.{jEdit, Debug} |
34709 | 24 |
import org.gjt.sp.jedit.gui.RolloverButton |
39176
b8fdd3ae8815
Document_View: more precise painting of gutter icons, only if line selection area is sufficiently large;
wenzelm
parents:
39175
diff
changeset
|
25 |
import org.gjt.sp.jedit.options.GutterOptionPane |
47392 | 26 |
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea, TextAreaExtension, TextAreaPainter} |
52479
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
27 |
import org.gjt.sp.jedit.syntax.SyntaxStyle |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
28 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
29 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
30 |
object Document_View |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
31 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
32 |
/* 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
|
33 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
34 |
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
|
35 |
|
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
36 |
def apply(text_area: JEditTextArea): 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
|
37 |
{ |
38223 | 38 |
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
|
39 |
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
|
40 |
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
|
41 |
case _ => None |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
42 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
43 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
44 |
|
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
45 |
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
|
46 |
{ |
38223 | 47 |
Swing_Thread.require() |
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34784
diff
changeset
|
48 |
apply(text_area) match { |
39636 | 49 |
case None => |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
50 |
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
|
51 |
doc_view.deactivate() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
52 |
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
|
53 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
54 |
} |
43397 | 55 |
|
56 |
def init(model: Document_Model, text_area: JEditTextArea): Document_View = |
|
57 |
{ |
|
58 |
exit(text_area) |
|
59 |
val doc_view = new Document_View(model, text_area) |
|
60 |
text_area.putClientProperty(key, doc_view) |
|
61 |
doc_view.activate() |
|
62 |
doc_view |
|
63 |
} |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
64 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
65 |
|
34733 | 66 |
|
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43369
diff
changeset
|
67 |
class Document_View(val model: Document_Model, val text_area: JEditTextArea) |
34654 | 68 |
{ |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
69 |
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
|
70 |
|
50205 | 71 |
def get_rendering(): Rendering = Rendering(model.snapshot(), PIDE.options.value) |
49411 | 72 |
|
50306 | 73 |
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
|
74 |
new Rich_Text_Area(text_area.getView, text_area, get_rendering _, () => (), |
50306 | 75 |
caret_visible = true, hovering = false) |
49411 | 76 |
|
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
77 |
|
44379 | 78 |
/* perspective */ |
79 |
||
80 |
def perspective(): Text.Perspective = |
|
81 |
{ |
|
82 |
Swing_Thread.require() |
|
50363
2f8dc9e65401
tuned signature in accordance to document operations;
wenzelm
parents:
50306
diff
changeset
|
83 |
val buffer_range = JEdit_Lib.buffer_range(model.buffer) |
44473 | 84 |
Text.Perspective( |
44379 | 85 |
for { |
86 |
i <- 0 until text_area.getVisibleLines |
|
46997 | 87 |
start = text_area.getScreenLineStartOffset(i) |
88 |
stop = text_area.getScreenLineEndOffset(i) |
|
44379 | 89 |
if start >= 0 && stop >= 0 |
46997 | 90 |
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
|
91 |
if !range.is_singularity |
44379 | 92 |
} |
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
|
93 |
yield range) |
44379 | 94 |
} |
95 |
||
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
|
96 |
private def update_perspective = new TextAreaExtension |
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
|
97 |
{ |
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
|
98 |
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
|
99 |
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
|
100 |
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
|
101 |
{ |
49424 | 102 |
// no robust_body |
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
|
103 |
model.update_perspective() |
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
|
104 |
} |
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
|
105 |
} |
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
|
106 |
|
44379 | 107 |
|
49411 | 108 |
/* gutter */ |
34513 | 109 |
|
42825 | 110 |
private val gutter_painter = new TextAreaExtension |
39175 | 111 |
{ |
112 |
override def paintScreenLineRange(gfx: Graphics2D, |
|
113 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
|
114 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
|
115 |
{ |
|
49411 | 116 |
rich_text_area.robust_body(()) { |
46920
5f44c8bea84e
more explicit indication of swing thread context;
wenzelm
parents:
46918
diff
changeset
|
117 |
Swing_Thread.assert() |
5f44c8bea84e
more explicit indication of swing thread context;
wenzelm
parents:
46918
diff
changeset
|
118 |
|
43404 | 119 |
val gutter = text_area.getGutter |
120 |
val width = GutterOptionPane.getSelectionAreaWidth |
|
121 |
val border_width = jEdit.getIntegerProperty("view.gutter.borderWidth", 3) |
|
122 |
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
|
123 |
|
43404 | 124 |
if (gutter.isSelectionAreaEnabled && !gutter.isExpanded && width >= 12 && line_height >= 12) { |
49408 | 125 |
val buffer = model.buffer |
126 |
JEdit_Lib.buffer_lock(buffer) { |
|
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49408
diff
changeset
|
127 |
val rendering = get_rendering() |
49356 | 128 |
|
43404 | 129 |
for (i <- 0 until physical_lines.length) { |
130 |
if (physical_lines(i) != -1) { |
|
49843
afddf4e26fac
further refinement of jEdit line range, avoiding lack of final \n;
wenzelm
parents:
49492
diff
changeset
|
131 |
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
|
132 |
|
43404 | 133 |
// gutter icons |
49356 | 134 |
rendering.gutter_message(line_range) match { |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
45744
diff
changeset
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
icon.paintIcon(gutter, gfx, x0, y0) |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
45744
diff
changeset
|
139 |
case None => |
43404 | 140 |
} |
39175 | 141 |
} |
142 |
} |
|
143 |
} |
|
144 |
} |
|
145 |
} |
|
146 |
} |
|
147 |
} |
|
148 |
||
149 |
||
52479
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
150 |
/* key listener */ |
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
151 |
|
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
152 |
private val key_listener = new KeyAdapter { |
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
153 |
override def keyTyped(evt: KeyEvent) |
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
154 |
{ |
52548
a1a8248a4677
some attempts to avoid sandwiching of actions stemming from single ESCAPE key event, to avoid potential conflict with ongoing text selection;
wenzelm
parents:
52479
diff
changeset
|
155 |
if (evt.getKeyChar == 27 && Pretty_Tooltip.dismissed_all()) |
a1a8248a4677
some attempts to avoid sandwiching of actions stemming from single ESCAPE key event, to avoid potential conflict with ongoing text selection;
wenzelm
parents:
52479
diff
changeset
|
156 |
evt.consume |
52479
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
157 |
} |
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
158 |
} |
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
159 |
|
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
160 |
|
37129 | 161 |
/* caret handling */ |
34810 | 162 |
|
46740
852baa599351
explicitly revoke delay, to avoid spurious timer events after deactivation of related components;
wenzelm
parents:
46583
diff
changeset
|
163 |
private val delay_caret_update = |
50207 | 164 |
Swing_Thread.delay_last(PIDE.options.seconds("editor_input_delay")) { |
44805 | 165 |
session.caret_focus.event(Session.Caret_Focus) |
34810 | 166 |
} |
46740
852baa599351
explicitly revoke delay, to avoid spurious timer events after deactivation of related components;
wenzelm
parents:
46583
diff
changeset
|
167 |
|
852baa599351
explicitly revoke delay, to avoid spurious timer events after deactivation of related components;
wenzelm
parents:
46583
diff
changeset
|
168 |
private val caret_listener = new CaretListener { |
49195 | 169 |
override def caretUpdate(e: CaretEvent) { delay_caret_update.invoke() } |
34810 | 170 |
} |
171 |
||
172 |
||
46572 | 173 |
/* 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
|
174 |
|
47993 | 175 |
private object overview extends Text_Overview(this) |
46572 | 176 |
{ |
46571
edcccd7a9eee
overview.delay_repaint: avoid wasting GUI cycles via update_delay;
wenzelm
parents:
46550
diff
changeset
|
177 |
val delay_repaint = |
50207 | 178 |
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
|
179 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
180 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
181 |
|
39740 | 182 |
/* main actor */ |
183 |
||
184 |
private val main_actor = actor { |
|
185 |
loop { |
|
186 |
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
|
187 |
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
|
188 |
Swing_Thread.later { |
50207 | 189 |
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
|
190 |
} |
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
|
191 |
|
44608 | 192 |
case changed: Session.Commands_Changed => |
39740 | 193 |
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
|
194 |
Swing_Thread.later { |
49406 | 195 |
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
|
196 |
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
|
197 |
val snapshot = model.snapshot() |
39740 | 198 |
|
47027
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents:
47013
diff
changeset
|
199 |
if (changed.assignment || |
46918
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
200 |
(changed.nodes.contains(model.name) && |
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
201 |
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
|
202 |
Swing_Thread.later { overview.delay_repaint.invoke() } |
39740 | 203 |
|
50770
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
204 |
val visible_lines = text_area.getVisibleLines |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
205 |
if (visible_lines > 0) { |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
206 |
if (changed.assignment) text_area.invalidateScreenLineRange(0, visible_lines) |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
207 |
else { |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
208 |
val visible_range = JEdit_Lib.visible_range(text_area).get |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
209 |
val visible_cmds = |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
210 |
snapshot.node.command_range(snapshot.revert(visible_range)).map(_._1) |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
211 |
if (visible_cmds.exists(changed.commands)) { |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
212 |
for { |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
213 |
line <- 0 until visible_lines |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
214 |
start = text_area.getScreenLineStartOffset(line) if start >= 0 |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
215 |
end = text_area.getScreenLineEndOffset(line) if end >= 0 |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
216 |
range = Text.Range(start, end) |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
217 |
line_cmds = snapshot.node.command_range(snapshot.revert(range)).map(_._1) |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
218 |
if line_cmds.exists(changed.commands) |
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
219 |
} 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
|
220 |
} |
50770
82d48783fd7a
more direct invalidateScreenLineRange after changed assignment;
wenzelm
parents:
50363
diff
changeset
|
221 |
} |
46583 | 222 |
} |
46918
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
223 |
} |
39740 | 224 |
} |
225 |
} |
|
226 |
||
227 |
case bad => System.err.println("command_change_actor: ignoring bad message " + bad) |
|
228 |
} |
|
229 |
} |
|
230 |
} |
|
231 |
||
232 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
233 |
/* activation */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
234 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
235 |
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
|
236 |
{ |
42825 | 237 |
val painter = text_area.getPainter |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49408
diff
changeset
|
238 |
|
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
|
239 |
painter.addExtension(TextAreaPainter.LOWEST_LAYER, update_perspective) |
49411 | 240 |
rich_text_area.activate() |
42825 | 241 |
text_area.getGutter.addExtension(gutter_painter) |
52479
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
242 |
text_area.addKeyListener(key_listener) |
34810 | 243 |
text_area.addCaretListener(caret_listener) |
244 |
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
|
245 |
session.raw_edits += main_actor |
39740 | 246 |
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
|
247 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
248 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
249 |
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
|
250 |
{ |
42825 | 251 |
val painter = text_area.getPainter |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49408
diff
changeset
|
252 |
|
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
|
253 |
session.raw_edits -= main_actor |
39740 | 254 |
session.commands_changed -= main_actor |
52479
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
255 |
text_area.removeLeftOfScrollBar(overview); overview.delay_repaint.revoke() |
49195 | 256 |
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
|
257 |
text_area.removeKeyListener(key_listener) |
42825 | 258 |
text_area.getGutter.removeExtension(gutter_painter) |
49411 | 259 |
rich_text_area.deactivate() |
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
|
260 |
painter.removeExtension(update_perspective) |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
261 |
} |
42825 | 262 |
} |