author | wenzelm |
Mon, 06 Apr 2020 12:53:45 +0200 | |
changeset 71704 | b9a5eb0f3b43 |
parent 71601 | 97ccf48c2f0c |
child 73340 | 0ffcad1f6130 |
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 |
||
54441 | 13 |
import java.awt.Graphics2D |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
14 |
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
|
15 |
import javax.swing.event.{CaretListener, CaretEvent} |
34734 | 16 |
|
54441 | 17 |
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
|
18 |
import org.gjt.sp.jedit.options.GutterOptionPane |
55712 | 19 |
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
|
20 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
21 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
22 |
object Document_View |
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 |
/* 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
|
25 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
26 |
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
|
27 |
|
64882 | 28 |
def get(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
|
29 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56883
diff
changeset
|
30 |
GUI_Thread.require {} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
31 |
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
|
32 |
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
|
33 |
case _ => None |
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 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
36 |
|
39741
62b91eb2d39a
CONTROL-mouse management: handle windowIconified;
wenzelm
parents:
39740
diff
changeset
|
37 |
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
|
38 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56883
diff
changeset
|
39 |
GUI_Thread.require {} |
64882 | 40 |
get(text_area) match { |
39636 | 41 |
case None => |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
42 |
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
|
43 |
doc_view.deactivate() |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
44 |
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
|
45 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
46 |
} |
43397 | 47 |
|
64817 | 48 |
def init(model: Buffer_Model, text_area: JEditTextArea): Document_View = |
43397 | 49 |
{ |
50 |
exit(text_area) |
|
51 |
val doc_view = new Document_View(model, text_area) |
|
52 |
text_area.putClientProperty(key, doc_view) |
|
53 |
doc_view.activate() |
|
54 |
doc_view |
|
55 |
} |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
56 |
} |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
57 |
|
34733 | 58 |
|
64817 | 59 |
class Document_View(val model: Buffer_Model, val text_area: JEditTextArea) |
34654 | 60 |
{ |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
61 |
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
|
62 |
|
66114 | 63 |
def get_rendering(): JEdit_Rendering = |
64 |
JEdit_Rendering(model.snapshot(), model, PIDE.options.value) |
|
49411 | 65 |
|
50306 | 66 |
val rich_text_area = |
63028 | 67 |
new Rich_Text_Area(text_area.getView, text_area, get_rendering _, () => (), () => None, |
68 |
() => delay_caret_update.invoke(), caret_visible = true, enable_hovering = false) |
|
49411 | 69 |
|
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
70 |
|
44379 | 71 |
/* perspective */ |
72 |
||
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
73 |
def perspective(snapshot: Document.Snapshot): Text.Perspective = |
44379 | 74 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56883
diff
changeset
|
75 |
GUI_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
|
76 |
|
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
77 |
val active_command = |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
78 |
{ |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
79 |
val view = text_area.getView |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
80 |
if (view != null && view.getTextArea == text_area) { |
66082 | 81 |
PIDE.editor.current_command(view, snapshot) match { |
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
82 |
case Some(command) => |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
83 |
snapshot.node.command_start(command) match { |
68728 | 84 |
case Some(start) => List(snapshot.convert(command.core_range + start)) |
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
85 |
case None => Nil |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
86 |
} |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
87 |
case None => Nil |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
88 |
} |
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
89 |
} |
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
|
90 |
else Nil |
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
91 |
} |
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
|
92 |
|
50363
2f8dc9e65401
tuned signature in accordance to document operations;
wenzelm
parents:
50306
diff
changeset
|
93 |
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
|
94 |
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
|
95 |
(for { |
56356
c3dbaa155ece
tuned for-comprehensions -- less structure mapping;
wenzelm
parents:
56314
diff
changeset
|
96 |
i <- (0 until text_area.getVisibleLines).iterator |
46997 | 97 |
start = text_area.getScreenLineStartOffset(i) |
98 |
stop = text_area.getScreenLineEndOffset(i) |
|
44379 | 99 |
if start >= 0 && stop >= 0 |
46997 | 100 |
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
|
101 |
if !range.is_singularity |
44379 | 102 |
} |
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
|
103 |
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
|
104 |
|
54325
2c4155003352
clarified Editor.current_command: allow outdated snapshot;
wenzelm
parents:
53780
diff
changeset
|
105 |
Text.Perspective(active_command ::: visible_lines) |
44379 | 106 |
} |
107 |
||
54461 | 108 |
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
|
109 |
{ |
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 |
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
|
111 |
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
|
112 |
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
|
113 |
{ |
49424 | 114 |
// no robust_body |
66082 | 115 |
PIDE.editor.invoke_generated() |
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
|
116 |
} |
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 |
|
44379 | 119 |
|
49411 | 120 |
/* gutter */ |
34513 | 121 |
|
42825 | 122 |
private val gutter_painter = new TextAreaExtension |
39175 | 123 |
{ |
124 |
override def paintScreenLineRange(gfx: Graphics2D, |
|
125 |
first_line: Int, last_line: Int, physical_lines: Array[Int], |
|
126 |
start: Array[Int], end: Array[Int], y: Int, line_height: Int) |
|
127 |
{ |
|
49411 | 128 |
rich_text_area.robust_body(()) { |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56883
diff
changeset
|
129 |
GUI_Thread.assert {} |
46920
5f44c8bea84e
more explicit indication of swing thread context;
wenzelm
parents:
46918
diff
changeset
|
130 |
|
43404 | 131 |
val gutter = text_area.getGutter |
59129
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
132 |
val sel_width = GutterOptionPane.getSelectionAreaWidth |
43404 | 133 |
val border_width = jEdit.getIntegerProperty("view.gutter.borderWidth", 3) |
134 |
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
|
135 |
|
59129
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
136 |
val buffer = model.buffer |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
137 |
JEdit_Lib.buffer_lock(buffer) { |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
138 |
val rendering = get_rendering() |
49356 | 139 |
|
71601 | 140 |
for (i <- physical_lines.indices) { |
59129
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
141 |
if (physical_lines(i) != -1) { |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
142 |
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
|
143 |
|
59129
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
144 |
rendering.gutter_content(line_range) match { |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
145 |
case Some((icon, color)) => |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
146 |
// icons within selection area |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
147 |
if (!gutter.isExpanded && |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
148 |
gutter.isSelectionAreaEnabled && sel_width >= 12 && line_height >= 12) |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
149 |
{ |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
150 |
val x0 = |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
151 |
(FOLD_MARKER_SIZE + sel_width - border_width - icon.getIconWidth) max 10 |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
152 |
val y0 = |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
153 |
y + i * line_height + (((line_height - icon.getIconHeight) / 2) max 0) |
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
|
154 |
icon.paintIcon(gutter, gfx, x0, y0) |
59129
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
155 |
} |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
156 |
// background |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
157 |
else { |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
158 |
val y0 = y + i * line_height |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
159 |
gfx.setColor(color) |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
160 |
gfx.fillRect(0, y0, gutter.getWidth, line_height) |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
161 |
} |
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
58748
diff
changeset
|
162 |
case None => |
39175 | 163 |
} |
164 |
} |
|
165 |
} |
|
166 |
} |
|
167 |
} |
|
168 |
} |
|
169 |
} |
|
170 |
||
171 |
||
52479
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
172 |
/* key listener */ |
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
173 |
|
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
174 |
private val key_listener = |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
175 |
JEdit_Lib.key_listener( |
53227
68cc55ceb7f6
more standard key handling according to jEdit (with workaround);
wenzelm
parents:
53226
diff
changeset
|
176 |
key_pressed = (evt: KeyEvent) => |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
177 |
{ |
65240 | 178 |
if (evt.getKeyCode == KeyEvent.VK_ESCAPE && Isabelle.dismissed_popups(text_area.getView)) |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
179 |
evt.consume |
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53272
diff
changeset
|
180 |
} |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
181 |
) |
52479
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
182 |
|
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
183 |
|
37129 | 184 |
/* caret handling */ |
34810 | 185 |
|
46740
852baa599351
explicitly revoke delay, to avoid spurious timer events after deactivation of related components;
wenzelm
parents:
46583
diff
changeset
|
186 |
private val delay_caret_update = |
71704 | 187 |
Delay.last(PIDE.options.seconds("editor_input_delay"), gui = true) { |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
188 |
session.caret_focus.post(Session.Caret_Focus) |
62986 | 189 |
JEdit_Lib.invalidate(text_area) |
34810 | 190 |
} |
46740
852baa599351
explicitly revoke delay, to avoid spurious timer events after deactivation of related components;
wenzelm
parents:
46583
diff
changeset
|
191 |
|
852baa599351
explicitly revoke delay, to avoid spurious timer events after deactivation of related components;
wenzelm
parents:
46583
diff
changeset
|
192 |
private val caret_listener = new CaretListener { |
49195 | 193 |
override def caretUpdate(e: CaretEvent) { delay_caret_update.invoke() } |
34810 | 194 |
} |
195 |
||
196 |
||
46572 | 197 |
/* 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
|
198 |
|
69775
5a8ae7a4b7d0
added option jedit_text_overview for visual appearance (not performance, see also 72216713733a);
wenzelm
parents:
68728
diff
changeset
|
199 |
private val text_overview: Option[Text_Overview] = |
5a8ae7a4b7d0
added option jedit_text_overview for visual appearance (not performance, see also 72216713733a);
wenzelm
parents:
68728
diff
changeset
|
200 |
if (PIDE.options.bool("jedit_text_overview")) Some(new Text_Overview(this)) else None |
34403
6c812a3cb170
information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff
changeset
|
201 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
202 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
203 |
/* main */ |
39740 | 204 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
205 |
private val main = |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
206 |
Session.Consumer[Any](getClass.getName) { |
61723
7feee72b5897
render snapshot.is_outdated in text overview, where other status information is shown already;
wenzelm
parents:
61195
diff
changeset
|
207 |
case _: Session.Raw_Edits => |
69775
5a8ae7a4b7d0
added option jedit_text_overview for visual appearance (not performance, see also 72216713733a);
wenzelm
parents:
68728
diff
changeset
|
208 |
text_overview.foreach(_.invoke()) |
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
|
209 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
210 |
case changed: Session.Commands_Changed => |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
211 |
val buffer = model.buffer |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56883
diff
changeset
|
212 |
GUI_Thread.later { |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
213 |
JEdit_Lib.buffer_lock(buffer) { |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
214 |
if (model.buffer == text_area.getBuffer) { |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
215 |
val snapshot = model.snapshot() |
39740 | 216 |
|
64799 | 217 |
if (changed.assignment || |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
218 |
(changed.nodes.contains(model.node_name) && |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
219 |
changed.commands.exists(snapshot.node.commands.contains))) |
69775
5a8ae7a4b7d0
added option jedit_text_overview for visual appearance (not performance, see also 72216713733a);
wenzelm
parents:
68728
diff
changeset
|
220 |
text_overview.foreach(_.invoke()) |
39740 | 221 |
|
62986 | 222 |
JEdit_Lib.invalidate(text_area) |
39740 | 223 |
} |
224 |
} |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
225 |
} |
39740 | 226 |
} |
227 |
||
228 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
229 |
/* activation */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34777
diff
changeset
|
230 |
|
34808
e462572536e9
eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents:
34806
diff
changeset
|
231 |
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
|
232 |
{ |
42825 | 233 |
val painter = text_area.getPainter |
49410
34acbcc33adf
tuned signature -- more general Text_Area_Painter operations;
wenzelm
parents:
49408
diff
changeset
|
234 |
|
54461 | 235 |
painter.addExtension(TextAreaPainter.LOWEST_LAYER, update_view) |
49411 | 236 |
rich_text_area.activate() |
42825 | 237 |
text_area.getGutter.addExtension(gutter_painter) |
52479
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
238 |
text_area.addKeyListener(key_listener) |
34810 | 239 |
text_area.addCaretListener(caret_listener) |
69775
5a8ae7a4b7d0
added option jedit_text_overview for visual appearance (not performance, see also 72216713733a);
wenzelm
parents:
68728
diff
changeset
|
240 |
text_overview.foreach(text_area.addLeftOfScrollBar(_)) |
5a8ae7a4b7d0
added option jedit_text_overview for visual appearance (not performance, see also 72216713733a);
wenzelm
parents:
68728
diff
changeset
|
241 |
text_area.revalidate() |
5a8ae7a4b7d0
added option jedit_text_overview for visual appearance (not performance, see also 72216713733a);
wenzelm
parents:
68728
diff
changeset
|
242 |
text_area.repaint() |
58748 | 243 |
Isabelle.structure_matchers(JEdit_Lib.buffer_mode(text_area.getBuffer)). |
71601 | 244 |
foreach(text_area.addStructureMatcher) |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
245 |
session.raw_edits += main |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
246 |
session.commands_changed += main |
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 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
253 |
session.raw_edits -= main |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
254 |
session.commands_changed -= main |
58748 | 255 |
Isabelle.structure_matchers(JEdit_Lib.buffer_mode(text_area.getBuffer)). |
71601 | 256 |
foreach(text_area.removeStructureMatcher) |
69775
5a8ae7a4b7d0
added option jedit_text_overview for visual appearance (not performance, see also 72216713733a);
wenzelm
parents:
68728
diff
changeset
|
257 |
text_overview.foreach(_.revoke()) |
5a8ae7a4b7d0
added option jedit_text_overview for visual appearance (not performance, see also 72216713733a);
wenzelm
parents:
68728
diff
changeset
|
258 |
text_overview.foreach(text_area.removeLeftOfScrollBar(_)) |
5a8ae7a4b7d0
added option jedit_text_overview for visual appearance (not performance, see also 72216713733a);
wenzelm
parents:
68728
diff
changeset
|
259 |
text_area.removeCaretListener(caret_listener) |
5a8ae7a4b7d0
added option jedit_text_overview for visual appearance (not performance, see also 72216713733a);
wenzelm
parents:
68728
diff
changeset
|
260 |
delay_caret_update.revoke() |
52479
bb516d01d259
more aggresive ESCAPE handling, while retaining its regular meaning for jEdit;
wenzelm
parents:
50915
diff
changeset
|
261 |
text_area.removeKeyListener(key_listener) |
42825 | 262 |
text_area.getGutter.removeExtension(gutter_painter) |
49411 | 263 |
rich_text_area.deactivate() |
54461 | 264 |
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
|
265 |
} |
42825 | 266 |
} |