author | wenzelm |
Sun, 01 Mar 2020 22:05:47 +0100 | |
changeset 71500 | a3ed1b0a132f |
parent 70284 | 3e17c3a5fd39 |
child 71501 | 248402f42cac |
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 |
|
58766 | 13 |
import java.awt.{Color, Font, Toolkit, Window} |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
14 |
import java.awt.event.KeyEvent |
62214
451bd09b8277
bypass input method for better imitation of read-only mode (cf. f26a4d5e82b5): e.g. relevant for composition of ALT-u u on Mac OS X;
wenzelm
parents:
61570
diff
changeset
|
15 |
import java.awt.im.InputMethodRequests |
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
16 |
import javax.swing.JTextField |
56885
3020f6bbd119
clarified GUI events, e.g. relevant for insert via completion;
wenzelm
parents:
56883
diff
changeset
|
17 |
import javax.swing.event.{DocumentListener, DocumentEvent} |
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
18 |
|
56907
0f3c375fd27c
enable "PIDE" docking framework by default, and rely on its "Detach" menu item;
wenzelm
parents:
56885
diff
changeset
|
19 |
import scala.swing.{Label, Component} |
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
20 |
import scala.util.matching.Regex |
56881 | 21 |
|
61570
f26a4d5e82b5
dummy input handler to imitate former read-only mode, which has changed its meaning in jedit-5.3.0 as mere hint for saving;
wenzelm
parents:
61561
diff
changeset
|
22 |
import org.gjt.sp.jedit.{jEdit, View, Registers, JEditBeanShellAction} |
f26a4d5e82b5
dummy input handler to imitate former read-only mode, which has changed its meaning in jedit-5.3.0 as mere hint for saving;
wenzelm
parents:
61561
diff
changeset
|
23 |
import org.gjt.sp.jedit.input.{DefaultInputHandlerProvider, TextAreaInputHandler} |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
24 |
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
|
25 |
import org.gjt.sp.jedit.syntax.SyntaxStyle |
61570
f26a4d5e82b5
dummy input handler to imitate former read-only mode, which has changed its meaning in jedit-5.3.0 as mere hint for saving;
wenzelm
parents:
61561
diff
changeset
|
26 |
import org.gjt.sp.jedit.gui.KeyEventTranslator |
50640 | 27 |
import org.gjt.sp.util.{SyntaxUtilities, Log} |
49412 | 28 |
|
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
29 |
|
49412 | 30 |
object Pretty_Text_Area |
31 |
{ |
|
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
32 |
/* auxiliary */ |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
33 |
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50306
diff
changeset
|
34 |
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
|
35 |
formatted_body: XML.Body): (String, Document.State) = |
49412 | 36 |
{ |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
37 |
val command = Command.rich_text(Document_ID.make(), base_results, formatted_body) |
49412 | 38 |
val node_name = command.node_name |
39 |
val edits: List[Document.Edit_Text] = |
|
49414 | 40 |
List(node_name -> Document.Node.Edits(List(Text.Edit.insert(0, command.source)))) |
49412 | 41 |
|
49419
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
49416
diff
changeset
|
42 |
val state0 = base_snapshot.state.define_command(command) |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
49416
diff
changeset
|
43 |
val version0 = base_snapshot.version |
49412 | 44 |
val nodes0 = version0.nodes |
45 |
||
46 |
val nodes1 = nodes0 + (node_name -> nodes0(node_name).update_commands(Linear_Set(command))) |
|
59077
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
47 |
val version1 = Document.Version.make(nodes1) |
49412 | 48 |
val state1 = |
56711 | 49 |
state0.continue_history(Future.value(version0), edits, Future.value(version1)) |
49412 | 50 |
.define_version(version1, state0.the_assignment(version0)) |
70284
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
wenzelm
parents:
69358
diff
changeset
|
51 |
.assign(version1.id, Nil, List(command.id -> List(Document_ID.make())))._2 |
49412 | 52 |
|
49416
1053a564dd25
some actual rich text markup via XML.content_markup;
wenzelm
parents:
49414
diff
changeset
|
53 |
(command.source, state1) |
49412 | 54 |
} |
51495
5944b20c41bf
apply small result immediately, to avoid visible delay of text update after window move;
wenzelm
parents:
51493
diff
changeset
|
55 |
|
5944b20c41bf
apply small result immediately, to avoid visible delay of text update after window move;
wenzelm
parents:
51493
diff
changeset
|
56 |
private def text_rendering(base_snapshot: Document.Snapshot, base_results: Command.Results, |
64621 | 57 |
formatted_body: XML.Body): (String, JEdit_Rendering) = |
51495
5944b20c41bf
apply small result immediately, to avoid visible delay of text update after window move;
wenzelm
parents:
51493
diff
changeset
|
58 |
{ |
5944b20c41bf
apply small result immediately, to avoid visible delay of text update after window move;
wenzelm
parents:
51493
diff
changeset
|
59 |
val (text, state) = document_state(base_snapshot, base_results, formatted_body) |
66114 | 60 |
val model = File_Model.empty(PIDE.session) |
61 |
val rendering = JEdit_Rendering(state.snapshot(), model, PIDE.options.value) |
|
51495
5944b20c41bf
apply small result immediately, to avoid visible delay of text update after window move;
wenzelm
parents:
51493
diff
changeset
|
62 |
(text, rendering) |
5944b20c41bf
apply small result immediately, to avoid visible delay of text update after window move;
wenzelm
parents:
51493
diff
changeset
|
63 |
} |
49412 | 64 |
} |
65 |
||
50538
48cb76b785da
init gutter according to view properties, which improves symmetry of windows and allows use of folds etc;
wenzelm
parents:
50507
diff
changeset
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
propagate_keys: Boolean = false) extends JEditEmbeddedTextArea |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
70 |
{ |
49446 | 71 |
text_area => |
72 |
||
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57042
diff
changeset
|
73 |
GUI_Thread.require {} |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
74 |
|
55826 | 75 |
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
|
76 |
private var current_body: XML.Body = Nil |
52972 | 77 |
private var current_base_snapshot = Document.Snapshot.init |
50507 | 78 |
private var current_base_results = Command.Results.empty |
64621 | 79 |
private var current_rendering: JEdit_Rendering = |
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50306
diff
changeset
|
80 |
Pretty_Text_Area.text_rendering(current_base_snapshot, current_base_results, Nil)._2 |
61561 | 81 |
private var future_refresh: Option[Future[Unit]] = None |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
82 |
|
50306 | 83 |
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
|
84 |
new Rich_Text_Area(view, text_area, () => current_rendering, close_action, |
63028 | 85 |
get_search_pattern _, () => (), caret_visible = false, enable_hovering = true) |
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
86 |
|
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
87 |
private var current_search_pattern: Option[Regex] = None |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57042
diff
changeset
|
88 |
def get_search_pattern(): Option[Regex] = GUI_Thread.require { current_search_pattern } |
49416
1053a564dd25
some actual rich text markup via XML.content_markup;
wenzelm
parents:
49414
diff
changeset
|
89 |
|
51451
e4203ebfe750
recovered special background handling from 8d6e478934dc, particularly relevant for gutter border;
wenzelm
parents:
51449
diff
changeset
|
90 |
def get_background(): Option[Color] = None |
e4203ebfe750
recovered special background handling from 8d6e478934dc, particularly relevant for gutter border;
wenzelm
parents:
51449
diff
changeset
|
91 |
|
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
92 |
def refresh() |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
93 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57042
diff
changeset
|
94 |
GUI_Thread.require {} |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
95 |
|
55825 | 96 |
val font = current_font_info.font |
50168
4a575ef46466
always refresh font metrics, to help window size calculation (amending 2585c81d840a);
wenzelm
parents:
50166
diff
changeset
|
97 |
getPainter.setFont(font) |
4a575ef46466
always refresh font metrics, to help window size calculation (amending 2585c81d840a);
wenzelm
parents:
50166
diff
changeset
|
98 |
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
|
99 |
getPainter.setFractionalFontMetricsEnabled(jEdit.getBooleanProperty("view.fracFontMetrics")) |
55825 | 100 |
getPainter.setStyles( |
101 |
SyntaxUtilities.loadStyles(current_font_info.family, current_font_info.size.round)) |
|
56789 | 102 |
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
|
103 |
|
50542
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50538
diff
changeset
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
SyntaxUtilities.parseStyle( |
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50538
diff
changeset
|
108 |
jEdit.getProperty("view.style.foldLine." + i), |
55825 | 109 |
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
|
110 |
} |
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50538
diff
changeset
|
111 |
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
|
112 |
|
51439
b10b64679c5b
more precise tooltip window size (NB: dimensions are known after layout pack, before making content visible);
wenzelm
parents:
50915
diff
changeset
|
113 |
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
|
114 |
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
|
115 |
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
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
getPainter.getBackground) |
60250
baf2c8fddaa4
proper fold painter according to jEdit options, not the hardwired default of JEditEmbeddedTextArea;
wenzelm
parents:
59286
diff
changeset
|
123 |
getGutter.setFoldPainter(view.getTextArea.getFoldPainter) |
51439
b10b64679c5b
more precise tooltip window size (NB: dimensions are known after layout pack, before making content visible);
wenzelm
parents:
50915
diff
changeset
|
124 |
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
|
125 |
|
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
|
126 |
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
|
127 |
val metric = JEdit_Lib.pretty_metric(getPainter) |
51493
59d8a1031c00
allow fractional pretty margin -- avoid premature rounding;
wenzelm
parents:
51492
diff
changeset
|
128 |
val margin = (getPainter.getWidth.toDouble / metric.unit) max 20.0 |
49471
97964515a676
text_rendering as managed task, with cancellation;
wenzelm
parents:
49446
diff
changeset
|
129 |
|
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
|
130 |
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
|
131 |
val base_results = current_base_results |
67547
aefe7a7b330a
clarified breakgain: keeping it constant avoids margin fluctuation in Pretty_Tooltip vs. Pretty_Text_Area;
wenzelm
parents:
66114
diff
changeset
|
132 |
val formatted_body = Pretty.formatted(current_body, margin = margin, metric = metric) |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
133 |
|
61561 | 134 |
future_refresh.map(_.cancel) |
61193 | 135 |
future_refresh = |
61561 | 136 |
Some(Future.fork { |
51498
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
137 |
val (text, rendering) = |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
138 |
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
|
139 |
catch { case exn: Throwable => Log.log(Log.ERROR, this, exn); throw exn } |
56860 | 140 |
Exn.Interrupt.expose() |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
141 |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57042
diff
changeset
|
142 |
GUI_Thread.later { |
51498
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
143 |
current_rendering = rendering |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
144 |
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
|
145 |
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
|
146 |
getBuffer.setFoldHandler(new Fold_Handling.Document_Fold_Handler(rendering)) |
68060
3931ed905e93
avoid output showing up in kill ring (via TextArea.setText, JEditBuffer.remove, UndoManager.contentRemoved), e.g. relevant for action "paste-deleted";
wenzelm
parents:
67547
diff
changeset
|
147 |
JEdit_Lib.buffer_undo_in_progress(getBuffer, setText(text)) |
51498
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
148 |
setCaretPosition(0) |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
149 |
} |
979592b765f8
reverted most of 5944b20c41bf -- tends to cause race condition of synchronous vs. asynchronous version;
wenzelm
parents:
51497
diff
changeset
|
150 |
} |
56730
e723f041b6d0
tuned signature -- separate pool for JFuture tasks, which can be canceled;
wenzelm
parents:
56711
diff
changeset
|
151 |
}) |
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
|
152 |
} |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
153 |
} |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
154 |
|
55825 | 155 |
def resize(font_info: Font_Info) |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
156 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57042
diff
changeset
|
157 |
GUI_Thread.require {} |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
158 |
|
55825 | 159 |
current_font_info = font_info |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
160 |
refresh() |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
161 |
} |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
162 |
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50306
diff
changeset
|
163 |
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
|
164 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57042
diff
changeset
|
165 |
GUI_Thread.require {} |
49419
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
49416
diff
changeset
|
166 |
require(!base_snapshot.is_outdated) |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
167 |
|
49419
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
49416
diff
changeset
|
168 |
current_base_snapshot = base_snapshot |
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50306
diff
changeset
|
169 |
current_base_results = base_results |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
170 |
current_body = body |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
171 |
refresh() |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
172 |
} |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
173 |
|
56880 | 174 |
def detach |
175 |
{ |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57042
diff
changeset
|
176 |
GUI_Thread.require {} |
56880 | 177 |
Info_Dockable(view, current_base_snapshot, current_base_results, current_body) |
178 |
} |
|
179 |
||
56918 | 180 |
def detach_operation: Option[() => Unit] = |
181 |
if (current_body.isEmpty) None else Some(() => detach) |
|
182 |
||
49422
21f77309d93a
minimal clipboard support (similar to org.lobobrowser.html.gui.HtmlBlockPanel);
wenzelm
parents:
49421
diff
changeset
|
183 |
|
56881 | 184 |
/* common GUI components */ |
185 |
||
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
186 |
val search_label: Component = new Label("Search:") { |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
187 |
tooltip = "Search and highlight output via regular expression" |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
188 |
} |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
189 |
|
57042 | 190 |
val search_field: Component = |
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
191 |
Component.wrap(new Completion_Popup.History_Text_Field("isabelle-search") |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
192 |
{ |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
193 |
private val input_delay = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57042
diff
changeset
|
194 |
GUI_Thread.delay_last(PIDE.options.seconds("editor_input_delay")) { |
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
195 |
search_action(this) |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
196 |
} |
56885
3020f6bbd119
clarified GUI events, e.g. relevant for insert via completion;
wenzelm
parents:
56883
diff
changeset
|
197 |
getDocument.addDocumentListener(new DocumentListener { |
3020f6bbd119
clarified GUI events, e.g. relevant for insert via completion;
wenzelm
parents:
56883
diff
changeset
|
198 |
def changedUpdate(e: DocumentEvent) { input_delay.invoke() } |
3020f6bbd119
clarified GUI events, e.g. relevant for insert via completion;
wenzelm
parents:
56883
diff
changeset
|
199 |
def insertUpdate(e: DocumentEvent) { input_delay.invoke() } |
3020f6bbd119
clarified GUI events, e.g. relevant for insert via completion;
wenzelm
parents:
56883
diff
changeset
|
200 |
def removeUpdate(e: DocumentEvent) { input_delay.invoke() } |
3020f6bbd119
clarified GUI events, e.g. relevant for insert via completion;
wenzelm
parents:
56883
diff
changeset
|
201 |
}) |
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
202 |
setColumns(20) |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
203 |
setToolTipText(search_label.tooltip) |
69358
71ef6e6da3dc
prefer Isabelle_Fonts.sans (not mono) as derived GUI font;
wenzelm
parents:
68060
diff
changeset
|
204 |
setFont(GUI.imitate_font(getFont, scale = 1.2)) |
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
205 |
}) |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
206 |
|
57042 | 207 |
private val search_field_foreground = search_field.foreground |
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
208 |
|
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
209 |
private def search_action(text_field: JTextField) |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
210 |
{ |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
211 |
val (pattern, ok) = |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
212 |
text_field.getText match { |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
213 |
case null | "" => (None, true) |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
214 |
case s => |
59224 | 215 |
val re = Library.make_regex(s) |
216 |
(re, re.isDefined) |
|
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
217 |
} |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
218 |
if (current_search_pattern != pattern) { |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
219 |
current_search_pattern = pattern |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
220 |
text_area.getPainter.repaint() |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
221 |
} |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
222 |
text_field.setForeground( |
65911 | 223 |
if (ok) search_field_foreground |
224 |
else current_rendering.color(Rendering.Color.error)) |
|
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
225 |
} |
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56881
diff
changeset
|
226 |
|
56881 | 227 |
|
50726
27478c11f63c
more elementary key handling: listen to low-level KEY_PRESSED events (without consuming);
wenzelm
parents:
50640
diff
changeset
|
228 |
/* key handling */ |
49422
21f77309d93a
minimal clipboard support (similar to org.lobobrowser.html.gui.HtmlBlockPanel);
wenzelm
parents:
49421
diff
changeset
|
229 |
|
62214
451bd09b8277
bypass input method for better imitation of read-only mode (cf. f26a4d5e82b5): e.g. relevant for composition of ALT-u u on Mac OS X;
wenzelm
parents:
61570
diff
changeset
|
230 |
override def getInputMethodRequests: InputMethodRequests = null |
451bd09b8277
bypass input method for better imitation of read-only mode (cf. f26a4d5e82b5): e.g. relevant for composition of ALT-u u on Mac OS X;
wenzelm
parents:
61570
diff
changeset
|
231 |
|
61570
f26a4d5e82b5
dummy input handler to imitate former read-only mode, which has changed its meaning in jedit-5.3.0 as mere hint for saving;
wenzelm
parents:
61561
diff
changeset
|
232 |
inputHandlerProvider = |
f26a4d5e82b5
dummy input handler to imitate former read-only mode, which has changed its meaning in jedit-5.3.0 as mere hint for saving;
wenzelm
parents:
61561
diff
changeset
|
233 |
new DefaultInputHandlerProvider(new TextAreaInputHandler(text_area) { |
f26a4d5e82b5
dummy input handler to imitate former read-only mode, which has changed its meaning in jedit-5.3.0 as mere hint for saving;
wenzelm
parents:
61561
diff
changeset
|
234 |
override def getAction(action: String): JEditBeanShellAction = |
f26a4d5e82b5
dummy input handler to imitate former read-only mode, which has changed its meaning in jedit-5.3.0 as mere hint for saving;
wenzelm
parents:
61561
diff
changeset
|
235 |
text_area.getActionContext.getAction(action) |
f26a4d5e82b5
dummy input handler to imitate former read-only mode, which has changed its meaning in jedit-5.3.0 as mere hint for saving;
wenzelm
parents:
61561
diff
changeset
|
236 |
override def processKeyEvent(evt: KeyEvent, from: Int, global: Boolean) {} |
f26a4d5e82b5
dummy input handler to imitate former read-only mode, which has changed its meaning in jedit-5.3.0 as mere hint for saving;
wenzelm
parents:
61561
diff
changeset
|
237 |
override def handleKey(key: KeyEventTranslator.Key, dry_run: Boolean): Boolean = false |
f26a4d5e82b5
dummy input handler to imitate former read-only mode, which has changed its meaning in jedit-5.3.0 as mere hint for saving;
wenzelm
parents:
61561
diff
changeset
|
238 |
}) |
f26a4d5e82b5
dummy input handler to imitate former read-only mode, which has changed its meaning in jedit-5.3.0 as mere hint for saving;
wenzelm
parents:
61561
diff
changeset
|
239 |
|
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
240 |
addKeyListener(JEdit_Lib.key_listener( |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
241 |
key_pressed = (evt: KeyEvent) => |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
242 |
{ |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
243 |
evt.getKeyCode match { |
58835 | 244 |
case KeyEvent.VK_C | KeyEvent.VK_INSERT |
71500 | 245 |
if (evt.getModifiersEx & Toolkit.getDefaultToolkit.getMenuShortcutKeyMaskEx) != 0 && |
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
|
246 |
text_area.getSelectionCount != 0 => |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
247 |
Registers.copy(text_area, '$') |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
248 |
evt.consume |
53227
68cc55ceb7f6
more standard key handling according to jEdit (with workaround);
wenzelm
parents:
53226
diff
changeset
|
249 |
|
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
250 |
case KeyEvent.VK_A |
71500 | 251 |
if (evt.getModifiersEx & Toolkit.getDefaultToolkit.getMenuShortcutKeyMaskEx) != 0 => |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
252 |
text_area.selectAll |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
253 |
evt.consume |
53227
68cc55ceb7f6
more standard key handling according to jEdit (with workaround);
wenzelm
parents:
53226
diff
changeset
|
254 |
|
68cc55ceb7f6
more standard key handling according to jEdit (with workaround);
wenzelm
parents:
53226
diff
changeset
|
255 |
case KeyEvent.VK_ESCAPE => |
65240 | 256 |
if (Isabelle.dismissed_popups(view)) evt.consume |
53227
68cc55ceb7f6
more standard key handling according to jEdit (with workaround);
wenzelm
parents:
53226
diff
changeset
|
257 |
|
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
258 |
case _ => |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
259 |
} |
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
|
260 |
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
|
261 |
}, |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
262 |
key_typed = (evt: KeyEvent) => |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
263 |
{ |
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
|
264 |
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
|
265 |
} |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
266 |
) |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53179
diff
changeset
|
267 |
) |
49422
21f77309d93a
minimal clipboard support (similar to org.lobobrowser.html.gui.HtmlBlockPanel);
wenzelm
parents:
49421
diff
changeset
|
268 |
|
21f77309d93a
minimal clipboard support (similar to org.lobobrowser.html.gui.HtmlBlockPanel);
wenzelm
parents:
49421
diff
changeset
|
269 |
|
21f77309d93a
minimal clipboard support (similar to org.lobobrowser.html.gui.HtmlBlockPanel);
wenzelm
parents:
49421
diff
changeset
|
270 |
/* init */ |
21f77309d93a
minimal clipboard support (similar to org.lobobrowser.html.gui.HtmlBlockPanel);
wenzelm
parents:
49421
diff
changeset
|
271 |
|
49472 | 272 |
getPainter.setStructureHighlightEnabled(false) |
49475 | 273 |
getPainter.setLineHighlightEnabled(false) |
274 |
||
59076
65babcd8b0e6
clarified token marker / syntax for mode vs. buffer;
wenzelm
parents:
58835
diff
changeset
|
275 |
getBuffer.setTokenMarker(Isabelle.mode_token_marker("isabelle-output").get) |
63261
90a44d271683
proper noWordSep as in "isabelle" mode (cf. 5024d0c48e02);
wenzelm
parents:
63028
diff
changeset
|
276 |
getBuffer.setStringProperty("noWordSep", "_'?⇩") |
49475 | 277 |
|
49412 | 278 |
rich_text_area.activate() |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
279 |
} |