author | wenzelm |
Mon, 17 Sep 2012 17:49:11 +0200 | |
changeset 49406 | 38db4832b210 |
parent 49360 | 37c1297aa562 |
child 49407 | 215ba6884bdf |
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} |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47993
diff
changeset
|
20 |
import java.awt.event.{MouseMotionAdapter, MouseAdapter, MouseEvent, |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
21 |
FocusAdapter, FocusEvent, WindowEvent, WindowAdapter} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
22 |
import javax.swing.event.{CaretListener, CaretEvent} |
34734 | 23 |
|
43404 | 24 |
import org.gjt.sp.util.Log |
25 |
||
42839
19df8385f38d
basic support for overpainting of text, imitating jEdit internals;
wenzelm
parents:
42838
diff
changeset
|
26 |
import org.gjt.sp.jedit.{jEdit, OperatingSystem, Debug} |
34709 | 27 |
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
|
28 |
import org.gjt.sp.jedit.options.GutterOptionPane |
47392 | 29 |
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea, TextAreaExtension, TextAreaPainter} |
43369
4c86b3405010
separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents:
43282
diff
changeset
|
30 |
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
|
31 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
32 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
33 |
object Document_View |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
34 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
35 |
/* 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
|
36 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
37 |
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
|
38 |
|
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
39 |
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
|
40 |
{ |
38223 | 41 |
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
|
42 |
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
|
43 |
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
|
44 |
case _ => None |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
45 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
46 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
47 |
|
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
48 |
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
|
49 |
{ |
38223 | 50 |
Swing_Thread.require() |
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34784
diff
changeset
|
51 |
apply(text_area) match { |
39636 | 52 |
case None => |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
53 |
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
|
54 |
doc_view.deactivate() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
55 |
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
|
56 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
57 |
} |
43397 | 58 |
|
59 |
def init(model: Document_Model, text_area: JEditTextArea): Document_View = |
|
60 |
{ |
|
61 |
exit(text_area) |
|
62 |
val doc_view = new Document_View(model, text_area) |
|
63 |
text_area.putClientProperty(key, doc_view) |
|
64 |
doc_view.activate() |
|
65 |
doc_view |
|
66 |
} |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
67 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
68 |
|
34733 | 69 |
|
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43369
diff
changeset
|
70 |
class Document_View(val model: Document_Model, val text_area: JEditTextArea) |
34654 | 71 |
{ |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
72 |
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
|
73 |
|
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
74 |
|
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
|
75 |
/* robust extension body */ |
43404 | 76 |
|
77 |
def robust_body[A](default: A)(body: => A): A = |
|
43417
83be997a11d6
more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents:
43414
diff
changeset
|
78 |
{ |
83be997a11d6
more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents:
43414
diff
changeset
|
79 |
try { |
83be997a11d6
more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents:
43414
diff
changeset
|
80 |
Swing_Thread.require() |
83be997a11d6
more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents:
43414
diff
changeset
|
81 |
if (model.buffer == text_area.getBuffer) body |
83be997a11d6
more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents:
43414
diff
changeset
|
82 |
else { |
43650 | 83 |
Log.log(Log.ERROR, this, ERROR("Inconsistent document model")) |
43417
83be997a11d6
more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents:
43414
diff
changeset
|
84 |
default |
43404 | 85 |
} |
86 |
} |
|
43417
83be997a11d6
more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents:
43414
diff
changeset
|
87 |
catch { case t: Throwable => Log.log(Log.ERROR, this, t); default } |
83be997a11d6
more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents:
43414
diff
changeset
|
88 |
} |
43404 | 89 |
|
90 |
||
44378 | 91 |
/* visible text range */ |
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
92 |
|
46815 | 93 |
// NB: TextArea.getScreenLineEndOffset of last line is beyond Buffer.getLength |
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
94 |
def proper_line_range(start: Text.Offset, end: Text.Offset): Text.Range = |
46812
3d55ef732cd7
clarified special eol treatment and moved to gfx_range -- enables error messages at end of input, e.g. "prop PROP";
wenzelm
parents:
46740
diff
changeset
|
95 |
Text.Range(start, end min model.buffer.getLength) |
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
96 |
|
46583 | 97 |
def visible_range(): Option[Text.Range] = |
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
98 |
{ |
46583 | 99 |
val n = text_area.getVisibleLines |
100 |
if (n > 0) { |
|
101 |
val start = text_area.getScreenLineStartOffset(0) |
|
102 |
val raw_end = text_area.getScreenLineEndOffset(n - 1) |
|
103 |
Some(proper_line_range(start, if (raw_end >= 0) raw_end else model.buffer.getLength)) |
|
104 |
} |
|
105 |
else None |
|
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
106 |
} |
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
107 |
|
44378 | 108 |
def invalidate_range(range: Text.Range) |
39132 | 109 |
{ |
110 |
text_area.invalidateLineRange( |
|
111 |
model.buffer.getLineOfOffset(range.start), |
|
112 |
model.buffer.getLineOfOffset(range.stop)) |
|
113 |
} |
|
114 |
||
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
115 |
|
44379 | 116 |
/* perspective */ |
117 |
||
118 |
def perspective(): Text.Perspective = |
|
119 |
{ |
|
120 |
Swing_Thread.require() |
|
44776
47e8c8daccae
added "check" button: adhoc change to full buffer perspective;
wenzelm
parents:
44615
diff
changeset
|
121 |
val buffer_range = model.buffer_range() |
44473 | 122 |
Text.Perspective( |
44379 | 123 |
for { |
124 |
i <- 0 until text_area.getVisibleLines |
|
46997 | 125 |
start = text_area.getScreenLineStartOffset(i) |
126 |
stop = text_area.getScreenLineEndOffset(i) |
|
44379 | 127 |
if start >= 0 && stop >= 0 |
46997 | 128 |
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
|
129 |
if !range.is_singularity |
44379 | 130 |
} |
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
|
131 |
yield range) |
44379 | 132 |
} |
133 |
||
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
|
134 |
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
|
135 |
{ |
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
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
{ |
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
|
140 |
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
|
141 |
} |
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
|
142 |
} |
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
|
143 |
|
44379 | 144 |
|
49357 | 145 |
/* active areas within the text */ |
39740 | 146 |
|
49357 | 147 |
private class Active_Area[A]( |
148 |
rendering: Isabelle_Rendering => Text.Range => Option[Text.Info[A]]) |
|
149 |
{ |
|
150 |
private var the_info: Option[Text.Info[A]] = None |
|
34834
df9af932e418
slightly more uniform/robust handling of visible document;
wenzelm
parents:
34832
diff
changeset
|
151 |
|
49357 | 152 |
def info: Option[Text.Info[A]] = the_info |
38881
c8123e77acc5
tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents:
38880
diff
changeset
|
153 |
|
49357 | 154 |
def update(new_info: Option[Text.Info[A]]) |
155 |
{ |
|
156 |
val old_info = the_info |
|
157 |
if (new_info != old_info) { |
|
158 |
for { opt <- List(old_info, new_info); Text.Info(range, _) <- opt } |
|
159 |
invalidate_range(range) |
|
160 |
the_info = new_info |
|
161 |
} |
|
162 |
} |
|
38884
9ec5f6010d6e
Document_View: repaint overview for any command change of this node (again);
wenzelm
parents:
38883
diff
changeset
|
163 |
|
49357 | 164 |
def update_rendering(r: Isabelle_Rendering, range: Text.Range) |
165 |
{ update(rendering(r)(range)) } |
|
166 |
||
167 |
def reset { update(None) } |
|
39740 | 168 |
} |
38884
9ec5f6010d6e
Document_View: repaint overview for any command change of this node (again);
wenzelm
parents:
38883
diff
changeset
|
169 |
|
49357 | 170 |
// owned by Swing thread |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47993
diff
changeset
|
171 |
|
40338
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
172 |
private var control: Boolean = false |
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
173 |
|
49358 | 174 |
private val highlight_area = new Active_Area[Color]((r: Isabelle_Rendering) => r.highlight _) |
49357 | 175 |
def highlight_info(): Option[Text.Info[Color]] = highlight_area.info |
176 |
||
177 |
private val hyperlink_area = new Active_Area[Hyperlink]((r: Isabelle_Rendering) => r.hyperlink _) |
|
178 |
def hyperlink_info(): Option[Text.Info[Hyperlink]] = hyperlink_area.info |
|
179 |
||
180 |
private val active_areas = List(highlight_area, hyperlink_area) |
|
181 |
private def active_reset(): Unit = active_areas.foreach(_.reset) |
|
39740 | 182 |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
183 |
private val focus_listener = new FocusAdapter { |
49357 | 184 |
override def focusLost(e: FocusEvent) { active_reset() } |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
185 |
} |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
186 |
|
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
187 |
private val window_listener = new WindowAdapter { |
49357 | 188 |
override def windowIconified(e: WindowEvent) { active_reset() } |
189 |
override def windowDeactivated(e: WindowEvent) { active_reset() } |
|
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
190 |
} |
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
191 |
|
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47993
diff
changeset
|
192 |
private val mouse_listener = new MouseAdapter { |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47993
diff
changeset
|
193 |
override def mouseClicked(e: MouseEvent) { |
49357 | 194 |
hyperlink_area.info match { |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47993
diff
changeset
|
195 |
case Some(Text.Info(range, link)) => link.follow(text_area.getView) |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47993
diff
changeset
|
196 |
case None => |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47993
diff
changeset
|
197 |
} |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47993
diff
changeset
|
198 |
} |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47993
diff
changeset
|
199 |
} |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47993
diff
changeset
|
200 |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
201 |
private val mouse_motion_listener = new MouseMotionAdapter { |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
202 |
override def mouseMoved(e: MouseEvent) { |
40338
e2f03de2b3c7
clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents:
40154
diff
changeset
|
203 |
control = if (OperatingSystem.isMacOS()) e.isMetaDown else e.isControlDown |
49357 | 204 |
if (control && model.buffer.isLoaded) { |
49406 | 205 |
JEdit_Lib.buffer_lock(model.buffer) { |
49357 | 206 |
val rendering = Isabelle_Rendering(model.snapshot(), Isabelle.options.value) |
207 |
val mouse_range = model.point_range(text_area.xyToOffset(e.getX(), e.getY())) |
|
208 |
active_areas.foreach(_.update_rendering(rendering, mouse_range)) |
|
39132 | 209 |
} |
49357 | 210 |
} |
211 |
else active_reset() |
|
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
212 |
} |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
213 |
} |
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
214 |
|
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
215 |
|
43381 | 216 |
/* text area painting */ |
39044 | 217 |
|
43381 | 218 |
private val text_area_painter = new Text_Area_Painter(this) |
39700
fa55cf2c1ae4
more precise treatment of backgrounds vs. rectangles;
wenzelm
parents:
39690
diff
changeset
|
219 |
|
43381 | 220 |
private val tooltip_painter = new TextAreaExtension |
221 |
{ |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
222 |
override def getToolTipText(x: Int, y: Int): String = |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
223 |
{ |
43404 | 224 |
robust_body(null: String) { |
49356 | 225 |
val rendering = Isabelle_Rendering(model.snapshot(), Isabelle.options.value) |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38843
diff
changeset
|
226 |
val offset = text_area.xyToOffset(x, y) |
45460 | 227 |
val range = Text.Range(offset, offset + 1) |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
45744
diff
changeset
|
228 |
val tip = |
49356 | 229 |
if (control) rendering.tooltip(range) |
230 |
else rendering.tooltip_message(range) |
|
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
45744
diff
changeset
|
231 |
tip.map(Isabelle.tooltip(_)) getOrElse null |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
232 |
} |
34734 | 233 |
} |
34678 | 234 |
} |
34513 | 235 |
|
42825 | 236 |
private val gutter_painter = new TextAreaExtension |
39175 | 237 |
{ |
238 |
override def paintScreenLineRange(gfx: Graphics2D, |
|
239 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
|
240 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
|
241 |
{ |
|
43404 | 242 |
robust_body(()) { |
46920
5f44c8bea84e
more explicit indication of swing thread context;
wenzelm
parents:
46918
diff
changeset
|
243 |
Swing_Thread.assert() |
5f44c8bea84e
more explicit indication of swing thread context;
wenzelm
parents:
46918
diff
changeset
|
244 |
|
43404 | 245 |
val gutter = text_area.getGutter |
246 |
val width = GutterOptionPane.getSelectionAreaWidth |
|
247 |
val border_width = jEdit.getIntegerProperty("view.gutter.borderWidth", 3) |
|
248 |
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
|
249 |
|
43404 | 250 |
if (gutter.isSelectionAreaEnabled && !gutter.isExpanded && width >= 12 && line_height >= 12) { |
49406 | 251 |
JEdit_Lib.buffer_lock(model.buffer) { |
49356 | 252 |
val rendering = Isabelle_Rendering(model.snapshot(), Isabelle.options.value) |
253 |
||
43404 | 254 |
for (i <- 0 until physical_lines.length) { |
255 |
if (physical_lines(i) != -1) { |
|
256 |
val line_range = proper_line_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
|
257 |
|
43404 | 258 |
// gutter icons |
49356 | 259 |
rendering.gutter_message(line_range) match { |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
45744
diff
changeset
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
icon.paintIcon(gutter, gfx, x0, y0) |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
45744
diff
changeset
|
264 |
case None => |
43404 | 265 |
} |
39175 | 266 |
} |
267 |
} |
|
268 |
} |
|
269 |
} |
|
270 |
} |
|
271 |
} |
|
272 |
} |
|
273 |
||
274 |
||
37129 | 275 |
/* caret handling */ |
34810 | 276 |
|
46740
852baa599351
explicitly revoke delay, to avoid spurious timer events after deactivation of related components;
wenzelm
parents:
46583
diff
changeset
|
277 |
private val delay_caret_update = |
49288 | 278 |
Swing_Thread.delay_last(Time.seconds(Isabelle.options.real("editor_input_delay"))) { |
44805 | 279 |
session.caret_focus.event(Session.Caret_Focus) |
34810 | 280 |
} |
46740
852baa599351
explicitly revoke delay, to avoid spurious timer events after deactivation of related components;
wenzelm
parents:
46583
diff
changeset
|
281 |
|
852baa599351
explicitly revoke delay, to avoid spurious timer events after deactivation of related components;
wenzelm
parents:
46583
diff
changeset
|
282 |
private val caret_listener = new CaretListener { |
49195 | 283 |
override def caretUpdate(e: CaretEvent) { delay_caret_update.invoke() } |
34810 | 284 |
} |
285 |
||
286 |
||
46572 | 287 |
/* 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
|
288 |
|
47993 | 289 |
private object overview extends Text_Overview(this) |
46572 | 290 |
{ |
46571
edcccd7a9eee
overview.delay_repaint: avoid wasting GUI cycles via update_delay;
wenzelm
parents:
46550
diff
changeset
|
291 |
val delay_repaint = |
49288 | 292 |
Swing_Thread.delay_first( |
293 |
Time.seconds(Isabelle.options.real("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
|
294 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
295 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
296 |
|
39740 | 297 |
/* main actor */ |
298 |
||
299 |
private val main_actor = actor { |
|
300 |
loop { |
|
301 |
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
|
302 |
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
|
303 |
Swing_Thread.later { |
49288 | 304 |
overview.delay_repaint.postpone( |
305 |
Time.seconds(Isabelle.options.real("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
|
306 |
} |
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
|
307 |
|
44608 | 308 |
case changed: Session.Commands_Changed => |
39740 | 309 |
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
|
310 |
Swing_Thread.later { |
49406 | 311 |
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
|
312 |
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
|
313 |
val snapshot = model.snapshot() |
39740 | 314 |
|
47027
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents:
47013
diff
changeset
|
315 |
if (changed.assignment || |
46918
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
316 |
(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
|
317 |
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
|
318 |
Swing_Thread.later { overview.delay_repaint.invoke() } |
39740 | 319 |
|
46918
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
320 |
visible_range() match { |
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
321 |
case Some(visible) => |
47027
fc3bb6c02a3c
explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents:
47013
diff
changeset
|
322 |
if (changed.assignment) invalidate_range(visible) |
46918
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
323 |
else { |
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
324 |
val visible_cmds = |
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
325 |
snapshot.node.command_range(snapshot.revert(visible)).map(_._1) |
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
326 |
if (visible_cmds.exists(changed.commands)) { |
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
327 |
for { |
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
328 |
line <- 0 until text_area.getVisibleLines |
46997 | 329 |
start = text_area.getScreenLineStartOffset(line) if start >= 0 |
330 |
end = text_area.getScreenLineEndOffset(line) if end >= 0 |
|
331 |
range = proper_line_range(start, end) |
|
332 |
line_cmds = snapshot.node.command_range(snapshot.revert(range)).map(_._1) |
|
46918
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
333 |
if line_cmds.exists(changed.commands) |
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
334 |
} text_area.invalidateScreenLineRange(line, line) |
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
335 |
} |
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
336 |
} |
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
337 |
case None => |
46583 | 338 |
} |
46918
1752164d916b
prefer asynchronous context switch from actor to swing thread, to reduce danger of deadlocks;
wenzelm
parents:
46815
diff
changeset
|
339 |
} |
39740 | 340 |
} |
341 |
} |
|
342 |
||
343 |
case bad => System.err.println("command_change_actor: ignoring bad message " + bad) |
|
344 |
} |
|
345 |
} |
|
346 |
} |
|
347 |
||
348 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
349 |
/* activation */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
350 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
351 |
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
|
352 |
{ |
42825 | 353 |
val painter = text_area.getPainter |
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
|
354 |
painter.addExtension(TextAreaPainter.LOWEST_LAYER, update_perspective) |
43387
a59ae768249e
recovered tooltip Entity content (odd effect of layer change!? cf. 806878ae2219);
wenzelm
parents:
43381
diff
changeset
|
355 |
painter.addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, tooltip_painter) |
43381 | 356 |
text_area_painter.activate() |
42825 | 357 |
text_area.getGutter.addExtension(gutter_painter) |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
358 |
text_area.addFocusListener(focus_listener) |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
359 |
text_area.getView.addWindowListener(window_listener) |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47993
diff
changeset
|
360 |
painter.addMouseListener(mouse_listener) |
42825 | 361 |
painter.addMouseMotionListener(mouse_motion_listener) |
34810 | 362 |
text_area.addCaretListener(caret_listener) |
363 |
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
|
364 |
session.raw_edits += main_actor |
39740 | 365 |
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
|
366 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
367 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
368 |
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
|
369 |
{ |
42825 | 370 |
val painter = text_area.getPainter |
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
|
371 |
session.raw_edits -= main_actor |
39740 | 372 |
session.commands_changed -= main_actor |
39131
947c62440026
basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents:
39044
diff
changeset
|
373 |
text_area.removeFocusListener(focus_listener) |
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
374 |
text_area.getView.removeWindowListener(window_listener) |
42825 | 375 |
painter.removeMouseMotionListener(mouse_motion_listener) |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
47993
diff
changeset
|
376 |
painter.removeMouseListener(mouse_listener) |
49195 | 377 |
text_area.removeCaretListener(caret_listener); delay_caret_update.revoke() |
378 |
text_area.removeLeftOfScrollBar(overview); overview.delay_repaint.revoke() |
|
42825 | 379 |
text_area.getGutter.removeExtension(gutter_painter) |
43381 | 380 |
text_area_painter.deactivate() |
381 |
painter.removeExtension(tooltip_painter) |
|
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
|
382 |
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
|
383 |
} |
42825 | 384 |
} |