author | wenzelm |
Wed, 02 Apr 2014 13:03:01 +0200 | |
changeset 56360 | 1d122af2b11a |
parent 56323 | e925118b1875 |
child 56662 | f373fb77e0a4 |
permissions | -rw-r--r-- |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/pretty_text_area.scala |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
3 |
|
50160 | 4 |
GUI component for pretty-printed text with markup, rendered like jEdit |
5 |
text area. |
|
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
6 |
*/ |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
7 |
|
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
8 |
package isabelle.jedit |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
9 |
|
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
10 |
|
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
11 |
import isabelle._ |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
12 |
|
50726
27478c11f63c
more elementary key handling: listen to low-level KEY_PRESSED events (without consuming);
wenzelm
parents:
50640
diff
changeset
|
13 |
import java.awt.{Color, Font, FontMetrics, Toolkit, Window} |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
14 |
import java.awt.event.KeyEvent |
49412 | 15 |
|
49422
21f77309d93a
minimal clipboard support (similar to org.lobobrowser.html.gui.HtmlBlockPanel);
wenzelm
parents:
49421
diff
changeset
|
16 |
import org.gjt.sp.jedit.{jEdit, View, Registers} |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
17 |
import org.gjt.sp.jedit.textarea.{AntiAlias, JEditEmbeddedTextArea} |
50542
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50538
diff
changeset
|
18 |
import org.gjt.sp.jedit.syntax.SyntaxStyle |
50640 | 19 |
import org.gjt.sp.util.{SyntaxUtilities, Log} |
49412 | 20 |
|
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
21 |
|
49412 | 22 |
object Pretty_Text_Area |
23 |
{ |
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50306
diff
changeset
|
24 |
private def document_state(base_snapshot: Document.Snapshot, base_results: Command.Results, |
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50306
diff
changeset
|
25 |
formatted_body: XML.Body): (String, Document.State) = |
49412 | 26 |
{ |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
27 |
val command = Command.rich_text(Document_ID.make(), base_results, formatted_body) |
49412 | 28 |
val node_name = command.node_name |
29 |
val edits: List[Document.Edit_Text] = |
|
49414 | 30 |
List(node_name -> Document.Node.Edits(List(Text.Edit.insert(0, command.source)))) |
49412 | 31 |
|
49419
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
49416
diff
changeset
|
32 |
val state0 = base_snapshot.state.define_command(command) |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
49416
diff
changeset
|
33 |
val version0 = base_snapshot.version |
49412 | 34 |
val nodes0 = version0.nodes |
35 |
||
36 |
val nodes1 = nodes0 + (node_name -> nodes0(node_name).update_commands(Linear_Set(command))) |
|
37 |
val version1 = Document.Version.make(version0.syntax, nodes1) |
|
38 |
val state1 = |
|
39 |
state0.continue_history(Future.value(version0), edits, Future.value(version1))._2 |
|
40 |
.define_version(version1, state0.the_assignment(version0)) |
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
41 |
.assign(version1.id, List(command.id -> List(Document_ID.make())))._2 |
49412 | 42 |
|
49416
1053a564dd25
some actual rich text markup via XML.content_markup;
wenzelm
parents:
49414
diff
changeset
|
43 |
(command.source, state1) |
49412 | 44 |
} |
51495
5944b20c41bf
apply small result immediately, to avoid visible delay of text update after window move;
wenzelm
parents:
51493
diff
changeset
|
45 |
|
5944b20c41bf
apply small result immediately, to avoid visible delay of text update after window move;
wenzelm
parents:
51493
diff
changeset
|
46 |
private def text_rendering(base_snapshot: Document.Snapshot, base_results: Command.Results, |
5944b20c41bf
apply small result immediately, to avoid visible delay of text update after window move;
wenzelm
parents:
51493
diff
changeset
|
47 |
formatted_body: XML.Body): (String, Rendering) = |
5944b20c41bf
apply small result immediately, to avoid visible delay of text update after window move;
wenzelm
parents:
51493
diff
changeset
|
48 |
{ |
5944b20c41bf
apply small result immediately, to avoid visible delay of text update after window move;
wenzelm
parents:
51493
diff
changeset
|
49 |
val (text, state) = document_state(base_snapshot, base_results, formatted_body) |
5944b20c41bf
apply small result immediately, to avoid visible delay of text update after window move;
wenzelm
parents:
51493
diff
changeset
|
50 |
val rendering = Rendering(state.snapshot(), PIDE.options.value) |
5944b20c41bf
apply small result immediately, to avoid visible delay of text update after window move;
wenzelm
parents:
51493
diff
changeset
|
51 |
(text, rendering) |
5944b20c41bf
apply small result immediately, to avoid visible delay of text update after window move;
wenzelm
parents:
51493
diff
changeset
|
52 |
} |
49412 | 53 |
} |
54 |
||
50538
48cb76b785da
init gutter according to view properties, which improves symmetry of windows and allows use of folds etc;
wenzelm
parents:
50507
diff
changeset
|
55 |
class Pretty_Text_Area( |
48cb76b785da
init gutter according to view properties, which improves symmetry of windows and allows use of folds etc;
wenzelm
parents:
50507
diff
changeset
|
56 |
view: View, |
50915
12de8ea66f54
close tooltip after Active.action, to make it look more interactive (notably due to lack of dynamic update);
wenzelm
parents:
50849
diff
changeset
|
57 |
close_action: () => Unit = () => (), |
50743
44571ac53fed
propagate keys to enclosing view like org.gjt.sp.jedit.gui.CompletionPopup, but without its KeyEventInterceptor;
wenzelm
parents:
50726
diff
changeset
|
58 |
propagate_keys: Boolean = false) extends JEditEmbeddedTextArea |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
59 |
{ |
49446 | 60 |
text_area => |
61 |
||
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
62 |
Swing_Thread.require() |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
63 |
|
55826 | 64 |
private var current_font_info: Font_Info = Font_Info.main() |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
65 |
private var current_body: XML.Body = Nil |
52972 | 66 |
private var current_base_snapshot = Document.Snapshot.init |
50507 | 67 |
private var current_base_results = Command.Results.empty |
50199
6d04e2422769
quasi-abstract module Rendering, with Isabelle-specific implementation;
wenzelm
parents:
50195
diff
changeset
|
68 |
private var current_rendering: Rendering = |
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50306
diff
changeset
|
69 |
Pretty_Text_Area.text_rendering(current_base_snapshot, current_base_results, Nil)._2 |
49471
97964515a676
text_rendering as managed task, with cancellation;
wenzelm
parents:
49446
diff
changeset
|
70 |
private var future_rendering: Option[java.util.concurrent.Future[Unit]] = None |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
71 |
|
50306 | 72 |
private 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:
50849
diff
changeset
|
73 |
new Rich_Text_Area(view, text_area, () => current_rendering, close_action, |
53179 | 74 |
caret_visible = false, enable_hovering = true) |
49416
1053a564dd25
some actual rich text markup via XML.content_markup;
wenzelm
parents:
49414
diff
changeset
|
75 |
|
51451
e4203ebfe750
recovered special background handling from 8d6e478934dc, particularly relevant for gutter border;
wenzelm
parents:
51449
diff
changeset
|
76 |
def get_background(): Option[Color] = None |
e4203ebfe750
recovered special background handling from 8d6e478934dc, particularly relevant for gutter border;
wenzelm
parents:
51449
diff
changeset
|
77 |
|
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
78 |
def refresh() |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
79 |
{ |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
80 |
Swing_Thread.require() |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
81 |
|
55825 | 82 |
val font = current_font_info.font |
50168
4a575ef46466
always refresh font metrics, to help window size calculation (amending 2585c81d840a);
wenzelm
parents:
50166
diff
changeset
|
83 |
getPainter.setFont(font) |
4a575ef46466
always refresh font metrics, to help window size calculation (amending 2585c81d840a);
wenzelm
parents:
50166
diff
changeset
|
84 |
getPainter.setAntiAlias(new AntiAlias(jEdit.getProperty("view.antiAlias"))) |
51497
7e8968c9a549
no censorship of "view.fracFontMetrics", although it often degrades rendering quality;
wenzelm
parents:
51495
diff
changeset
|
85 |
getPainter.setFractionalFontMetricsEnabled(jEdit.getBooleanProperty("view.fracFontMetrics")) |
55825 | 86 |
getPainter.setStyles( |
87 |
SyntaxUtilities.loadStyles(current_font_info.family, current_font_info.size.round)) |
|
56360 | 88 |
getPainter.setLineExtraSpacing(jEdit.getIntegerProperty("options.textarea.lineSpacing", 0)) |
50168
4a575ef46466
always refresh font metrics, to help window size calculation (amending 2585c81d840a);
wenzelm
parents:
50166
diff
changeset
|
89 |
|
50542
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50538
diff
changeset
|
90 |
val fold_line_style = new Array[SyntaxStyle](4) |
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50538
diff
changeset
|
91 |
for (i <- 0 to 3) { |
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50538
diff
changeset
|
92 |
fold_line_style(i) = |
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50538
diff
changeset
|
93 |
SyntaxUtilities.parseStyle( |
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50538
diff
changeset
|
94 |
jEdit.getProperty("view.style.foldLine." + i), |
55825 | 95 |
current_font_info.family, current_font_info.size.round, true) |
50542
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50538
diff
changeset
|
96 |
} |
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50538
diff
changeset
|
97 |
getPainter.setFoldLineStyle(fold_line_style) |
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50538
diff
changeset
|
98 |
|
51439
b10b64679c5b
more precise tooltip window size (NB: dimensions are known after layout pack, before making content visible);
wenzelm
parents:
50915
diff
changeset
|
99 |
getGutter.setForeground(jEdit.getColorProperty("view.gutter.fgColor")) |
b10b64679c5b
more precise tooltip window size (NB: dimensions are known after layout pack, before making content visible);
wenzelm
parents:
50915
diff
changeset
|
100 |
getGutter.setBackground(jEdit.getColorProperty("view.gutter.bgColor")) |
51451
e4203ebfe750
recovered special background handling from 8d6e478934dc, particularly relevant for gutter border;
wenzelm
parents:
51449
diff
changeset
|
101 |
get_background().map(bg => { getPainter.setBackground(bg); getGutter.setBackground(bg) }) |
51439
b10b64679c5b
more precise tooltip window size (NB: dimensions are known after layout pack, before making content visible);
wenzelm
parents:
50915
diff
changeset
|
102 |
getGutter.setHighlightedForeground(jEdit.getColorProperty("view.gutter.highlightColor")) |
b10b64679c5b
more precise tooltip window size (NB: dimensions are known after layout pack, before making content visible);
wenzelm
parents:
50915
diff
changeset
|
103 |
getGutter.setFoldColor(jEdit.getColorProperty("view.gutter.foldColor")) |
b10b64679c5b
more precise tooltip window size (NB: dimensions are known after layout pack, before making content visible);
wenzelm
parents:
50915
diff
changeset
|
104 |
getGutter.setFont(jEdit.getFontProperty("view.gutter.font")) |
b10b64679c5b
more precise tooltip window size (NB: dimensions are known after layout pack, before making content visible);
wenzelm
parents:
50915
diff
changeset
|
105 |
getGutter.setBorder(0, |
b10b64679c5b
more precise tooltip window size (NB: dimensions are known after layout pack, before making content visible);
wenzelm
parents:
50915
diff
changeset
|
106 |
jEdit.getColorProperty("view.gutter.focusBorderColor"), |
b10b64679c5b
more precise tooltip window size (NB: dimensions are known after layout pack, before making content visible);
wenzelm
parents:
50915
diff
changeset
|
107 |
jEdit.getColorProperty("view.gutter.noFocusBorderColor"), |
b10b64679c5b
more precise tooltip window size (NB: dimensions are known after layout pack, before making content visible);
wenzelm
parents:
50915
diff
changeset
|
108 |
getPainter.getBackground) |
b10b64679c5b
more precise tooltip window size (NB: dimensions are known after layout pack, before making content visible);
wenzelm
parents:
50915
diff
changeset
|
109 |
getGutter.setFoldPainter(getFoldPainter) |
b10b64679c5b
more precise tooltip window size (NB: dimensions are known after layout pack, before making content visible);
wenzelm
parents:
50915
diff
changeset
|
110 |
getGutter.setGutterEnabled(jEdit.getBooleanProperty("view.gutter.enabled")) |
b10b64679c5b
more precise tooltip window size (NB: dimensions are known after layout pack, before making content visible);
wenzelm
parents:
50915
diff
changeset
|
111 |
|
50166
2585c81d840a
take component width as indication if it is already visible/layed-out, to avoid multiple formatting with minimal margin;
wenzelm
parents:
50160
diff
changeset
|
112 |
if (getWidth > 0) { |
51492
eaa1c4cc1106
more explicit Pretty.Metric, with clear distinction of unit (space width) vs. average char width (for visual adjustments) -- NB: Pretty formatting works via full space characters (despite a981a5c8a505 and 70f7483df9cb);
wenzelm
parents:
51469
diff
changeset
|
113 |
val metric = JEdit_Lib.pretty_metric(getPainter) |
51493
59d8a1031c00
allow fractional pretty margin -- avoid premature rounding;
wenzelm
parents:
51492
diff
changeset
|
114 |
val margin = (getPainter.getWidth.toDouble / metric.unit) max 20.0 |
49471
97964515a676
text_rendering as managed task, with cancellation;
wenzelm
parents:
49446
diff
changeset
|
115 |
|
50166
2585c81d840a
take component width as indication if it is already visible/layed-out, to avoid multiple formatting with minimal margin;
wenzelm
parents:
50160
diff
changeset
|
116 |
val base_snapshot = current_base_snapshot |
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50306
diff
changeset
|
117 |
val base_results = current_base_results |
51492
eaa1c4cc1106
more explicit Pretty.Metric, with clear distinction of unit (space width) vs. average char width (for visual adjustments) -- NB: Pretty formatting works via full space characters (despite a981a5c8a505 and 70f7483df9cb);
wenzelm
parents:
51469
diff
changeset
|
118 |
val formatted_body = Pretty.formatted(current_body, margin, metric) |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
119 |
|
51498
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
120 |
future_rendering.map(_.cancel(true)) |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
121 |
future_rendering = Some(default_thread_pool.submit(() => |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
122 |
{ |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
123 |
val (text, rendering) = |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
124 |
try { Pretty_Text_Area.text_rendering(base_snapshot, base_results, formatted_body) } |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
125 |
catch { case exn: Throwable => Log.log(Log.ERROR, this, exn); throw exn } |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
126 |
Simple_Thread.interrupted_exception() |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
127 |
|
51498
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
128 |
Swing_Thread.later { |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
129 |
current_rendering = rendering |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
130 |
JEdit_Lib.buffer_edit(getBuffer) { |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
131 |
rich_text_area.active_reset() |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
132 |
getBuffer.setReadOnly(false) |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
133 |
getBuffer.setFoldHandler(new Fold_Handling.Document_Fold_Handler(rendering)) |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
134 |
setText(text) |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
135 |
setCaretPosition(0) |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
136 |
getBuffer.setReadOnly(true) |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
137 |
} |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
138 |
} |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
139 |
})) |
50166
2585c81d840a
take component width as indication if it is already visible/layed-out, to avoid multiple formatting with minimal margin;
wenzelm
parents:
50160
diff
changeset
|
140 |
} |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
141 |
} |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
142 |
|
55825 | 143 |
def resize(font_info: Font_Info) |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
144 |
{ |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
145 |
Swing_Thread.require() |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
146 |
|
55825 | 147 |
current_font_info = font_info |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
148 |
refresh() |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
149 |
} |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
150 |
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50306
diff
changeset
|
151 |
def update(base_snapshot: Document.Snapshot, base_results: Command.Results, body: XML.Body) |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
152 |
{ |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
153 |
Swing_Thread.require() |
49419
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
49416
diff
changeset
|
154 |
require(!base_snapshot.is_outdated) |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
155 |
|
49419
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
49416
diff
changeset
|
156 |
current_base_snapshot = base_snapshot |
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50306
diff
changeset
|
157 |
current_base_results = base_results |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
158 |
current_body = body |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
159 |
refresh() |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
160 |
} |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
161 |
|
49422
21f77309d93a
minimal clipboard support (similar to org.lobobrowser.html.gui.HtmlBlockPanel);
wenzelm
parents:
49421
diff
changeset
|
162 |
|
50726
27478c11f63c
more elementary key handling: listen to low-level KEY_PRESSED events (without consuming);
wenzelm
parents:
50640
diff
changeset
|
163 |
/* key handling */ |
49422
21f77309d93a
minimal clipboard support (similar to org.lobobrowser.html.gui.HtmlBlockPanel);
wenzelm
parents:
49421
diff
changeset
|
164 |
|
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
165 |
addKeyListener(JEdit_Lib.key_listener( |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
166 |
key_pressed = (evt: KeyEvent) => |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
167 |
{ |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
168 |
evt.getKeyCode match { |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
169 |
case KeyEvent.VK_C |
56323
e925118b1875
do not absorb vacuous copy operation, e.g. relevant when tooltip has focus but no selection, while the main text area has a selection but no focus;
wenzelm
parents:
55826
diff
changeset
|
170 |
if (evt.getModifiers & Toolkit.getDefaultToolkit.getMenuShortcutKeyMask) != 0 && |
e925118b1875
do not absorb vacuous copy operation, e.g. relevant when tooltip has focus but no selection, while the main text area has a selection but no focus;
wenzelm
parents:
55826
diff
changeset
|
171 |
text_area.getSelectionCount != 0 => |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
172 |
Registers.copy(text_area, '$') |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
173 |
evt.consume |
53227
68cc55ceb7f6
more standard key handling according to jEdit (with workaround);
wenzelm
parents:
53226
diff
changeset
|
174 |
|
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
175 |
case KeyEvent.VK_A |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
176 |
if (evt.getModifiers & Toolkit.getDefaultToolkit.getMenuShortcutKeyMask) != 0 => |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
177 |
text_area.selectAll |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
178 |
evt.consume |
53227
68cc55ceb7f6
more standard key handling according to jEdit (with workaround);
wenzelm
parents:
53226
diff
changeset
|
179 |
|
68cc55ceb7f6
more standard key handling according to jEdit (with workaround);
wenzelm
parents:
53226
diff
changeset
|
180 |
case KeyEvent.VK_ESCAPE => |
53244 | 181 |
if (PIDE.dismissed_popups(view)) evt.consume |
53227
68cc55ceb7f6
more standard key handling according to jEdit (with workaround);
wenzelm
parents:
53226
diff
changeset
|
182 |
|
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
183 |
case _ => |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
184 |
} |
53231
423e29f1f304
avoid complication and event duplication due to KeyEventInterceptor -- NB: popup has focus within root window, it is closed on loss of focus;
wenzelm
parents:
53227
diff
changeset
|
185 |
if (propagate_keys) JEdit_Lib.propagate_key(view, evt) |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
186 |
}, |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
187 |
key_typed = (evt: KeyEvent) => |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
188 |
{ |
53231
423e29f1f304
avoid complication and event duplication due to KeyEventInterceptor -- NB: popup has focus within root window, it is closed on loss of focus;
wenzelm
parents:
53227
diff
changeset
|
189 |
if (propagate_keys) JEdit_Lib.propagate_key(view, evt) |
49422
21f77309d93a
minimal clipboard support (similar to org.lobobrowser.html.gui.HtmlBlockPanel);
wenzelm
parents:
49421
diff
changeset
|
190 |
} |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
191 |
) |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
192 |
) |
49422
21f77309d93a
minimal clipboard support (similar to org.lobobrowser.html.gui.HtmlBlockPanel);
wenzelm
parents:
49421
diff
changeset
|
193 |
|
21f77309d93a
minimal clipboard support (similar to org.lobobrowser.html.gui.HtmlBlockPanel);
wenzelm
parents:
49421
diff
changeset
|
194 |
|
21f77309d93a
minimal clipboard support (similar to org.lobobrowser.html.gui.HtmlBlockPanel);
wenzelm
parents:
49421
diff
changeset
|
195 |
/* init */ |
21f77309d93a
minimal clipboard support (similar to org.lobobrowser.html.gui.HtmlBlockPanel);
wenzelm
parents:
49421
diff
changeset
|
196 |
|
49472 | 197 |
getPainter.setStructureHighlightEnabled(false) |
49475 | 198 |
getPainter.setLineHighlightEnabled(false) |
199 |
||
53277
6aa348237973
more uniform configuration of editor modes and token markers;
wenzelm
parents:
53244
diff
changeset
|
200 |
getBuffer.setTokenMarker(Isabelle.token_marker("isabelle-output").get) |
49446 | 201 |
getBuffer.setReadOnly(true) |
53002
9dd1a6dcebfd
imitate "noWordSep" of isabelle mode, e.g. relevant for word selection via double-click;
wenzelm
parents:
53001
diff
changeset
|
202 |
getBuffer.setStringProperty("noWordSep", "_'.?") |
49475 | 203 |
|
49412 | 204 |
rich_text_area.activate() |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
205 |
} |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
206 |