author | wenzelm |
Wed, 12 Feb 2025 00:40:57 +0100 | |
changeset 82142 | 508a673c87ac |
parent 81558 | b57996a0688c |
permissions | -rw-r--r-- |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
64621
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/jedit_rendering.scala |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
3 |
|
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
64621
diff
changeset
|
4 |
Isabelle/jEdit-specific implementation of quasi-abstract rendering and |
50199
6d04e2422769
quasi-abstract module Rendering, with Isabelle-specific implementation;
wenzelm
parents:
50196
diff
changeset
|
5 |
markup interpretation. |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
6 |
*/ |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
7 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
8 |
package isabelle.jedit |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
9 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
10 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
11 |
import isabelle._ |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
12 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
13 |
import java.awt.Color |
46227
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
14 |
import javax.swing.Icon |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
15 |
|
43414 | 16 |
import org.gjt.sp.jedit.syntax.{Token => JEditToken} |
61175 | 17 |
import org.gjt.sp.jedit.jEdit |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
18 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
19 |
|
75393 | 20 |
object JEdit_Rendering { |
72718 | 21 |
/* make rendering */ |
22 |
||
66114 | 23 |
def apply(snapshot: Document.Snapshot, model: Document_Model, options: Options): JEdit_Rendering = |
24 |
new JEdit_Rendering(snapshot, model, options) |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
25 |
|
81432
85fc3b482924
clarified persistent values: Command.Results does not suitable for caching, because it contains all other messages;
wenzelm
parents:
81421
diff
changeset
|
26 |
def apply( |
85fc3b482924
clarified persistent values: Command.Results does not suitable for caching, because it contains all other messages;
wenzelm
parents:
81421
diff
changeset
|
27 |
snapshot: Document.Snapshot, |
85fc3b482924
clarified persistent values: Command.Results does not suitable for caching, because it contains all other messages;
wenzelm
parents:
81421
diff
changeset
|
28 |
rich_texts: List[Rich_Text.Formatted], |
85fc3b482924
clarified persistent values: Command.Results does not suitable for caching, because it contains all other messages;
wenzelm
parents:
81421
diff
changeset
|
29 |
results: Command.Results |
85fc3b482924
clarified persistent values: Command.Results does not suitable for caching, because it contains all other messages;
wenzelm
parents:
81421
diff
changeset
|
30 |
): JEdit_Rendering = { |
81414
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
81406
diff
changeset
|
31 |
val snapshot1 = |
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
81406
diff
changeset
|
32 |
if (rich_texts.isEmpty) snapshot |
81432
85fc3b482924
clarified persistent values: Command.Results does not suitable for caching, because it contains all other messages;
wenzelm
parents:
81421
diff
changeset
|
33 |
else snapshot.snippet(rich_texts.map(_.command(results)), Document.Blobs.empty) |
76783 | 34 |
val model = File_Model.init(PIDE.session) |
81414
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
81406
diff
changeset
|
35 |
apply(snapshot1, model, PIDE.options.value) |
72718 | 36 |
} |
37 |
||
49356 | 38 |
|
53230 | 39 |
/* popup window bounds */ |
40 |
||
41 |
def popup_bounds: Double = (PIDE.options.real("jedit_popup_bounds") max 0.2) min 0.8 |
|
42 |
||
43 |
||
55501 | 44 |
/* Isabelle/Isar token markup */ |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
45 |
|
75393 | 46 |
private val command_style: Map[String, Byte] = { |
43414 | 47 |
import JEditToken._ |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
48 |
Map[String, Byte]( |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
49 |
Keyword.THY_END -> KEYWORD2, |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
50 |
Keyword.PRF_ASM -> KEYWORD3, |
59125 | 51 |
Keyword.PRF_ASM_GOAL -> KEYWORD3 |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
52 |
).withDefaultValue(KEYWORD1) |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
53 |
} |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
54 |
|
75393 | 55 |
private val token_style: Map[Token.Kind.Value, Byte] = { |
43414 | 56 |
import JEditToken._ |
57 |
Map[Token.Kind.Value, Byte]( |
|
58 |
Token.Kind.KEYWORD -> KEYWORD2, |
|
59 |
Token.Kind.IDENT -> NULL, |
|
60 |
Token.Kind.LONG_IDENT -> NULL, |
|
61 |
Token.Kind.SYM_IDENT -> NULL, |
|
62 |
Token.Kind.VAR -> NULL, |
|
63 |
Token.Kind.TYPE_IDENT -> NULL, |
|
64 |
Token.Kind.TYPE_VAR -> NULL, |
|
65 |
Token.Kind.NAT -> NULL, |
|
66 |
Token.Kind.FLOAT -> NULL, |
|
59081 | 67 |
Token.Kind.SPACE -> NULL, |
43431 | 68 |
Token.Kind.STRING -> LITERAL1, |
69 |
Token.Kind.ALT_STRING -> LITERAL2, |
|
69963 | 70 |
Token.Kind.CARTOUCHE -> COMMENT3, |
74373
6e4093927dbb
outer syntax: support for control-cartouche tokens;
wenzelm
parents:
73358
diff
changeset
|
71 |
Token.Kind.CONTROL -> COMMENT3, |
67439
78759a7bd874
more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents:
67438
diff
changeset
|
72 |
Token.Kind.INFORMAL_COMMENT -> COMMENT1, |
78759a7bd874
more uniform support for formal comments in outer syntax, notably \<^cancel> and \<^latex>;
wenzelm
parents:
67438
diff
changeset
|
73 |
Token.Kind.FORMAL_COMMENT -> COMMENT1, |
48754
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
wenzelm
parents:
48751
diff
changeset
|
74 |
Token.Kind.ERROR -> INVALID |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
75 |
).withDefaultValue(NULL) |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
76 |
} |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
77 |
|
43414 | 78 |
def token_markup(syntax: Outer_Syntax, token: Token): Byte = |
63441 | 79 |
if (token.is_command) command_style(syntax.keywords.kinds.getOrElse(token.content, "")) |
55505 | 80 |
else if (token.is_delimiter) JEditToken.OPERATOR |
43414 | 81 |
else token_style(token.kind) |
55500 | 82 |
|
55501 | 83 |
|
84 |
/* Isabelle/ML token markup */ |
|
85 |
||
75393 | 86 |
private val ml_token_style: Map[ML_Lex.Kind.Value, Byte] = { |
55500 | 87 |
import JEditToken._ |
88 |
Map[ML_Lex.Kind.Value, Byte]( |
|
55505 | 89 |
ML_Lex.Kind.KEYWORD -> NULL, |
55500 | 90 |
ML_Lex.Kind.IDENT -> NULL, |
91 |
ML_Lex.Kind.LONG_IDENT -> NULL, |
|
92 |
ML_Lex.Kind.TYPE_VAR -> NULL, |
|
55503 | 93 |
ML_Lex.Kind.WORD -> DIGIT, |
94 |
ML_Lex.Kind.INT -> DIGIT, |
|
95 |
ML_Lex.Kind.REAL -> DIGIT, |
|
55500 | 96 |
ML_Lex.Kind.CHAR -> LITERAL2, |
97 |
ML_Lex.Kind.STRING -> LITERAL1, |
|
98 |
ML_Lex.Kind.SPACE -> NULL, |
|
67438 | 99 |
ML_Lex.Kind.INFORMAL_COMMENT -> COMMENT1, |
100 |
ML_Lex.Kind.FORMAL_COMMENT -> COMMENT1, |
|
55512 | 101 |
ML_Lex.Kind.ANTIQ -> NULL, |
102 |
ML_Lex.Kind.ANTIQ_START -> LITERAL4, |
|
103 |
ML_Lex.Kind.ANTIQ_STOP -> LITERAL4, |
|
104 |
ML_Lex.Kind.ANTIQ_OTHER -> NULL, |
|
55514
8ef781e282d9
more uniform rendering of text that is formally interpreted: avoid clash with inner markup;
wenzelm
parents:
55512
diff
changeset
|
105 |
ML_Lex.Kind.ANTIQ_STRING -> NULL, |
8ef781e282d9
more uniform rendering of text that is formally interpreted: avoid clash with inner markup;
wenzelm
parents:
55512
diff
changeset
|
106 |
ML_Lex.Kind.ANTIQ_ALT_STRING -> NULL, |
8ef781e282d9
more uniform rendering of text that is formally interpreted: avoid clash with inner markup;
wenzelm
parents:
55512
diff
changeset
|
107 |
ML_Lex.Kind.ANTIQ_CARTOUCHE -> NULL, |
55500 | 108 |
ML_Lex.Kind.ERROR -> INVALID |
109 |
).withDefaultValue(NULL) |
|
110 |
} |
|
111 |
||
112 |
def ml_token_markup(token: ML_Lex.Token): Byte = |
|
55501 | 113 |
if (!token.is_keyword) ml_token_style(token.kind) |
55505 | 114 |
else if (token.is_delimiter) JEditToken.OPERATOR |
115 |
else if (ML_Lex.keywords2(token.source)) JEditToken.KEYWORD2 |
|
116 |
else if (ML_Lex.keywords3(token.source)) JEditToken.KEYWORD3 |
|
55501 | 117 |
else JEditToken.KEYWORD1 |
55647 | 118 |
|
119 |
||
120 |
/* markup elements */ |
|
121 |
||
63474
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
122 |
private val indentation_elements = |
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
123 |
Markup.Elements(Markup.Command_Indent.name) |
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
124 |
|
60878
1f0d2bbcf38b
added action to toggle breakpoints (on editor side);
wenzelm
parents:
60876
diff
changeset
|
125 |
private val breakpoint_elements = Markup.Elements(Markup.ML_BREAKPOINT) |
1f0d2bbcf38b
added action to toggle breakpoints (on editor side);
wenzelm
parents:
60876
diff
changeset
|
126 |
|
55647 | 127 |
private val highlight_elements = |
81303
cee03fbcec0d
more rendering for Markup.COMMAND_SPAN, following Rendering.structure_elements;
wenzelm
parents:
80911
diff
changeset
|
128 |
Markup.Elements(Markup.NOTATION, Markup.EXPRESSION, Markup.LANGUAGE, Markup.COMMAND_SPAN, |
cee03fbcec0d
more rendering for Markup.COMMAND_SPAN, following Rendering.structure_elements;
wenzelm
parents:
80911
diff
changeset
|
129 |
Markup.ML_TYPING, Markup.TOKEN_RANGE, Markup.ENTITY, Markup.PATH, Markup.DOC, Markup.URL, |
69648 | 130 |
Markup.SORTING, Markup.TYPING, Markup.CLASS_PARAMETER, Markup.FREE, Markup.SKOLEM, |
131 |
Markup.BOUND, Markup.VAR, Markup.TFREE, Markup.TVAR, Markup.ML_BREAKPOINT, |
|
67323
d02208cefbdb
PIDE markup for Markdown items (which may consist of multiple paragraphs or lists);
wenzelm
parents:
66150
diff
changeset
|
132 |
Markup.MARKDOWN_PARAGRAPH, Markup.MARKDOWN_ITEM, Markup.Markdown_List.name) |
55647 | 133 |
|
134 |
private val hyperlink_elements = |
|
70016 | 135 |
Markup.Elements(Markup.ENTITY, Markup.PATH, Markup.EXPORT_PATH, Markup.DOC, Markup.URL, |
77029
1046a69fabaa
dismantle special treatment of citations in Isabelle/Scala;
wenzelm
parents:
76912
diff
changeset
|
136 |
Markup.POSITION) |
55647 | 137 |
|
138 |
private val gutter_elements = |
|
59203
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
139 |
Markup.Elements(Markup.WRITELN, Markup.INFORMATION, Markup.WARNING, Markup.LEGACY, Markup.ERROR) |
55647 | 140 |
|
141 |
private val squiggly_elements = |
|
59203
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
142 |
Markup.Elements(Markup.WRITELN, Markup.INFORMATION, Markup.WARNING, Markup.LEGACY, Markup.ERROR) |
55647 | 143 |
|
144 |
private val line_background_elements = |
|
59184
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59129
diff
changeset
|
145 |
Markup.Elements(Markup.WRITELN_MESSAGE, Markup.STATE_MESSAGE, Markup.INFORMATION_MESSAGE, |
59203
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
146 |
Markup.TRACING_MESSAGE, Markup.WARNING_MESSAGE, Markup.LEGACY_MESSAGE, |
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
147 |
Markup.ERROR_MESSAGE) |
55647 | 148 |
|
55820
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55790
diff
changeset
|
149 |
private val separator_elements = |
56743 | 150 |
Markup.Elements(Markup.SEPARATOR) |
55647 | 151 |
|
55820
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55790
diff
changeset
|
152 |
private val bullet_elements = |
60913 | 153 |
Markup.Elements(Markup.BULLET, Markup.ML_BREAKPOINT) |
55647 | 154 |
|
155 |
private val fold_depth_elements = |
|
56743 | 156 |
Markup.Elements(Markup.TEXT_FOLD, Markup.GOAL, Markup.SUBGOAL) |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
157 |
} |
49356 | 158 |
|
159 |
||
72856 | 160 |
class JEdit_Rendering(snapshot: Document.Snapshot, model: Document_Model, options: Options) |
75393 | 161 |
extends Rendering(snapshot, options, PIDE.session) { |
72856 | 162 |
override def get_text(range: Text.Range): Option[String] = model.get_text(range) |
66114 | 163 |
|
164 |
||
49356 | 165 |
/* colors */ |
166 |
||
65144 | 167 |
def color(s: String): Color = |
65145 | 168 |
if (s == "main_color") main_color |
65144 | 169 |
else Color_Value(options.string(s)) |
170 |
||
171 |
def color(c: Rendering.Color.Value): Color = _rendering_colors(c) |
|
49356 | 172 |
|
65101 | 173 |
lazy val _rendering_colors: Map[Rendering.Color.Value, Color] = |
65102 | 174 |
Rendering.Color.values.iterator.map(c => c -> color(c.toString + "_color")).toMap |
65101 | 175 |
|
65145 | 176 |
val main_color = jEdit.getColorProperty("view.fgColor") |
177 |
||
65102 | 178 |
val outdated_color = color("outdated_color") |
179 |
val bullet_color = color("bullet_color") |
|
180 |
val tooltip_color = color("tooltip_color") |
|
181 |
val spell_checker_color = color("spell_checker_color") |
|
182 |
val entity_ref_color = color("entity_ref_color") |
|
183 |
val breakpoint_disabled_color = color("breakpoint_disabled_color") |
|
184 |
val breakpoint_enabled_color = color("breakpoint_enabled_color") |
|
185 |
val caret_debugger_color = color("caret_debugger_color") |
|
186 |
val highlight_color = color("highlight_color") |
|
187 |
val hyperlink_color = color("hyperlink_color") |
|
188 |
val active_hover_color = color("active_hover_color") |
|
189 |
val caret_invisible_color = color("caret_invisible_color") |
|
190 |
val completion_color = color("completion_color") |
|
191 |
val search_color = color("search_color") |
|
49356 | 192 |
|
193 |
||
63474
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
194 |
/* indentation */ |
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
195 |
|
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
196 |
def indentation(range: Text.Range): Int = |
64621 | 197 |
snapshot.select(range, JEdit_Rendering.indentation_elements, _ => |
63474
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
198 |
{ |
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
199 |
case Text.Info(_, XML.Elem(Markup.Command_Indent(i), _)) => Some(i) |
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
200 |
case _ => None |
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
201 |
}).headOption.map(_.info).getOrElse(0) |
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
202 |
|
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
203 |
|
60878
1f0d2bbcf38b
added action to toggle breakpoints (on editor side);
wenzelm
parents:
60876
diff
changeset
|
204 |
/* breakpoints */ |
1f0d2bbcf38b
added action to toggle breakpoints (on editor side);
wenzelm
parents:
60876
diff
changeset
|
205 |
|
60880
fa958e24ff24
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents:
60878
diff
changeset
|
206 |
def breakpoint(range: Text.Range): Option[(Command, Long)] = |
fa958e24ff24
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents:
60878
diff
changeset
|
207 |
if (snapshot.is_outdated) None |
fa958e24ff24
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents:
60878
diff
changeset
|
208 |
else |
64621 | 209 |
snapshot.select(range, JEdit_Rendering.breakpoint_elements, command_states => |
60880
fa958e24ff24
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents:
60878
diff
changeset
|
210 |
{ |
60882 | 211 |
case Text.Info(_, Protocol.ML_Breakpoint(breakpoint)) => |
60880
fa958e24ff24
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents:
60878
diff
changeset
|
212 |
command_states match { |
60882 | 213 |
case st :: _ => Some((st.command, breakpoint)) |
60880
fa958e24ff24
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents:
60878
diff
changeset
|
214 |
case _ => None |
fa958e24ff24
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents:
60878
diff
changeset
|
215 |
} |
fa958e24ff24
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents:
60878
diff
changeset
|
216 |
case _ => None |
fa958e24ff24
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents:
60878
diff
changeset
|
217 |
}).headOption.map(_.info) |
60878
1f0d2bbcf38b
added action to toggle breakpoints (on editor side);
wenzelm
parents:
60876
diff
changeset
|
218 |
|
1f0d2bbcf38b
added action to toggle breakpoints (on editor side);
wenzelm
parents:
60876
diff
changeset
|
219 |
|
62986 | 220 |
/* caret focus */ |
221 |
||
72900 | 222 |
def entity_ref(range: Text.Range, focus: Rendering.Focus): List[Text.Info[Color]] = |
72901 | 223 |
snapshot.select(range, Rendering.entity_elements, _ => |
62988 | 224 |
{ |
74782 | 225 |
case Text.Info(_, XML.Elem(Markup.Entity.Ref(i), _)) if focus(i) => |
226 |
Some(entity_ref_color) |
|
62988 | 227 |
case _ => None |
228 |
}) |
|
229 |
||
62986 | 230 |
|
55626 | 231 |
/* highlighted area */ |
49356 | 232 |
|
49358 | 233 |
def highlight(range: Text.Range): Option[Text.Info[Color]] = |
64621 | 234 |
snapshot.select(range, JEdit_Rendering.highlight_elements, _ => |
55620 | 235 |
{ |
236 |
case info => Some(Text.Info(snapshot.convert(info.range), highlight_color)) |
|
55689 | 237 |
}).headOption.map(_.info) |
49356 | 238 |
|
239 |
||
55626 | 240 |
/* hyperlinks */ |
241 |
||
75393 | 242 |
def hyperlink(range: Text.Range): Option[Text.Info[PIDE.editor.Hyperlink]] = { |
66082 | 243 |
snapshot.cumulate[Vector[Text.Info[PIDE.editor.Hyperlink]]]( |
64621 | 244 |
range, Vector.empty, JEdit_Rendering.hyperlink_elements, _ => |
49356 | 245 |
{ |
56458
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56395
diff
changeset
|
246 |
case (links, Text.Info(info_range, XML.Elem(Markup.Path(name), _))) => |
65488 | 247 |
val file = perhaps_append_file(snapshot.node_name, name) |
66082 | 248 |
val link = PIDE.editor.hyperlink_file(true, file) |
55622
ce575c2212fc
clarified markup cumulation order (see also 25306d92f4ad and 0009a6ebc83b), e.g. relevant for completion_context;
wenzelm
parents:
55620
diff
changeset
|
249 |
Some(links :+ Text.Info(snapshot.convert(info_range), link)) |
49356 | 250 |
|
70016 | 251 |
case (links, Text.Info(info_range, XML.Elem(Markup.Export_Path(name), _))) => |
252 |
val link = PIDE.editor.hyperlink_file(true, Isabelle_Export.vfs_prefix + name) |
|
253 |
Some(links :+ Text.Info(snapshot.convert(info_range), link)) |
|
254 |
||
61660
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61603
diff
changeset
|
255 |
case (links, Text.Info(info_range, XML.Elem(Markup.Doc(name), _))) => |
66082 | 256 |
PIDE.editor.hyperlink_doc(name).map(link => |
61660
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61603
diff
changeset
|
257 |
(links :+ Text.Info(snapshot.convert(info_range), link))) |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61603
diff
changeset
|
258 |
|
54702
3daeba5130f0
added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
wenzelm
parents:
54515
diff
changeset
|
259 |
case (links, Text.Info(info_range, XML.Elem(Markup.Url(name), _))) => |
66082 | 260 |
val link = PIDE.editor.hyperlink_url(name) |
55622
ce575c2212fc
clarified markup cumulation order (see also 25306d92f4ad and 0009a6ebc83b), e.g. relevant for completion_context;
wenzelm
parents:
55620
diff
changeset
|
261 |
Some(links :+ Text.Info(snapshot.convert(info_range), link)) |
54702
3daeba5130f0
added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
wenzelm
parents:
54515
diff
changeset
|
262 |
|
64660 | 263 |
case (links, Text.Info(info_range, XML.Elem(Markup(Markup.ENTITY, props), _))) => |
66082 | 264 |
val opt_link = PIDE.editor.hyperlink_def_position(true, snapshot, props) |
60215 | 265 |
opt_link.map(link => links :+ Text.Info(snapshot.convert(info_range), link)) |
49356 | 266 |
|
55545 | 267 |
case (links, Text.Info(info_range, XML.Elem(Markup(Markup.POSITION, props), _))) => |
66082 | 268 |
val opt_link = PIDE.editor.hyperlink_position(true, snapshot, props) |
60215 | 269 |
opt_link.map(link => links :+ Text.Info(snapshot.convert(info_range), link)) |
52889
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents:
52873
diff
changeset
|
270 |
|
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents:
52873
diff
changeset
|
271 |
case _ => None |
55622
ce575c2212fc
clarified markup cumulation order (see also 25306d92f4ad and 0009a6ebc83b), e.g. relevant for completion_context;
wenzelm
parents:
55620
diff
changeset
|
272 |
}) match { case Text.Info(_, _ :+ info) :: _ => Some(info) case _ => None } |
49356 | 273 |
} |
274 |
||
75393 | 275 |
def hyperlink_entity(range: Text.Range): Option[Text.Info[PIDE.editor.Hyperlink]] = { |
72930
0cc298e29aff
added action isabelle.goto-entity to follow links in a narrow formal sense;
wenzelm
parents:
72902
diff
changeset
|
276 |
snapshot.cumulate[Vector[Text.Info[PIDE.editor.Hyperlink]]]( |
0cc298e29aff
added action isabelle.goto-entity to follow links in a narrow formal sense;
wenzelm
parents:
72902
diff
changeset
|
277 |
range, Vector.empty, Rendering.entity_elements, _ => |
0cc298e29aff
added action isabelle.goto-entity to follow links in a narrow formal sense;
wenzelm
parents:
72902
diff
changeset
|
278 |
{ |
0cc298e29aff
added action isabelle.goto-entity to follow links in a narrow formal sense;
wenzelm
parents:
72902
diff
changeset
|
279 |
case (links, Text.Info(info_range, XML.Elem(Markup(Markup.ENTITY, props), _))) => |
0cc298e29aff
added action isabelle.goto-entity to follow links in a narrow formal sense;
wenzelm
parents:
72902
diff
changeset
|
280 |
val opt_link = PIDE.editor.hyperlink_def_position(true, snapshot, props) |
0cc298e29aff
added action isabelle.goto-entity to follow links in a narrow formal sense;
wenzelm
parents:
72902
diff
changeset
|
281 |
opt_link.map(link => links :+ Text.Info(snapshot.convert(info_range), link)) |
0cc298e29aff
added action isabelle.goto-entity to follow links in a narrow formal sense;
wenzelm
parents:
72902
diff
changeset
|
282 |
case _ => None |
0cc298e29aff
added action isabelle.goto-entity to follow links in a narrow formal sense;
wenzelm
parents:
72902
diff
changeset
|
283 |
}) match { case Text.Info(_, _ :+ info) :: _ => Some(info) case _ => None } |
0cc298e29aff
added action isabelle.goto-entity to follow links in a narrow formal sense;
wenzelm
parents:
72902
diff
changeset
|
284 |
} |
0cc298e29aff
added action isabelle.goto-entity to follow links in a narrow formal sense;
wenzelm
parents:
72902
diff
changeset
|
285 |
|
49356 | 286 |
|
55626 | 287 |
/* active elements */ |
288 |
||
50450
358b6020f8b6
generalized notion of active area, where sendback is just one application;
wenzelm
parents:
50215
diff
changeset
|
289 |
def active(range: Text.Range): Option[Text.Info[XML.Elem]] = |
65101 | 290 |
snapshot.select(range, Rendering.active_elements, command_states => |
55620 | 291 |
{ |
292 |
case Text.Info(info_range, elem) => |
|
55623 | 293 |
if (elem.name == Markup.DIALOG) { |
294 |
elem match { |
|
295 |
case Protocol.Dialog(_, serial, _) |
|
56354
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
wenzelm
parents:
56352
diff
changeset
|
296 |
if !command_states.exists(st => st.results.defined(serial)) => |
55623 | 297 |
Some(Text.Info(snapshot.convert(info_range), elem)) |
298 |
case _ => None |
|
299 |
} |
|
300 |
} |
|
301 |
else Some(Text.Info(snapshot.convert(info_range), elem)) |
|
55689 | 302 |
}).headOption.map(_.info) |
49492 | 303 |
|
55626 | 304 |
|
305 |
/* tooltips */ |
|
306 |
||
55647 | 307 |
def tooltip_margin: Int = options.int("jedit_tooltip_margin") |
69898 | 308 |
override def timing_threshold: Double = options.real("jedit_timing_threshold") |
50554
0493efcc97e9
more general handling of graphics configurations, to increase chance of proper positioning of tooltips in multi-screen environment;
wenzelm
parents:
50547
diff
changeset
|
309 |
|
81398
f92ea68473f2
clarified signature with subtle change of semantics: output consists of individual messages that are formatted (and separated) internally;
wenzelm
parents:
81303
diff
changeset
|
310 |
def tooltip(range: Text.Range, control: Boolean): Option[Text.Info[List[XML.Elem]]] = |
f92ea68473f2
clarified signature with subtle change of semantics: output consists of individual messages that are formatted (and separated) internally;
wenzelm
parents:
81303
diff
changeset
|
311 |
tooltips(if (control) Rendering.tooltip_elements else Rendering.tooltip_message_elements, |
f92ea68473f2
clarified signature with subtle change of semantics: output consists of individual messages that are formatted (and separated) internally;
wenzelm
parents:
81303
diff
changeset
|
312 |
range) |
64748 | 313 |
|
71601 | 314 |
lazy val tooltip_close_icon: Icon = JEdit_Lib.load_icon(options.string("tooltip_close_icon")) |
315 |
lazy val tooltip_detach_icon: Icon = JEdit_Lib.load_icon(options.string("tooltip_detach_icon")) |
|
52472
3a43a8b1ecb0
load icons via options -- prefer IntelliJ IDEA for now;
wenzelm
parents:
52471
diff
changeset
|
316 |
|
3a43a8b1ecb0
load icons via options -- prefer IntelliJ IDEA for now;
wenzelm
parents:
52471
diff
changeset
|
317 |
|
56495 | 318 |
/* gutter */ |
319 |
||
320 |
private def gutter_message_pri(msg: XML.Tree): Int = |
|
64676 | 321 |
if (Protocol.is_error(msg)) Rendering.error_pri |
322 |
else if (Protocol.is_legacy(msg)) Rendering.legacy_pri |
|
323 |
else if (Protocol.is_warning(msg)) Rendering.warning_pri |
|
324 |
else if (Protocol.is_information(msg)) Rendering.information_pri |
|
56495 | 325 |
else 0 |
55626 | 326 |
|
59129
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
59125
diff
changeset
|
327 |
private lazy val gutter_message_content = Map( |
64676 | 328 |
Rendering.information_pri -> |
65127 | 329 |
(JEdit_Lib.load_icon(options.string("gutter_information_icon")), |
330 |
color(Rendering.Color.information_message)), |
|
64676 | 331 |
Rendering.warning_pri -> |
65127 | 332 |
(JEdit_Lib.load_icon(options.string("gutter_warning_icon")), |
333 |
color(Rendering.Color.warning_message)), |
|
64676 | 334 |
Rendering.legacy_pri -> |
65127 | 335 |
(JEdit_Lib.load_icon(options.string("gutter_legacy_icon")), |
336 |
color(Rendering.Color.legacy_message)), |
|
64676 | 337 |
Rendering.error_pri -> |
65127 | 338 |
(JEdit_Lib.load_icon(options.string("gutter_error_icon")), |
339 |
color(Rendering.Color.error_message))) |
|
49356 | 340 |
|
75393 | 341 |
def gutter_content(range: Text.Range): Option[(Icon, Color)] = { |
56495 | 342 |
val pris = |
64621 | 343 |
snapshot.cumulate[Int](range, 0, JEdit_Rendering.gutter_elements, _ => |
49356 | 344 |
{ |
72870
8c468d602db1
clarified: omit presumably pointless Markup.Serial (see also 0b9334adcf05);
wenzelm
parents:
72856
diff
changeset
|
345 |
case (pri, Text.Info(_, elem)) => Some(pri max gutter_message_pri(elem)) |
56495 | 346 |
}).map(_.info) |
347 |
||
73358 | 348 |
gutter_message_content.get(pris.foldLeft(0)(_ max _)) |
49356 | 349 |
} |
350 |
||
351 |
||
65128 | 352 |
/* message output */ |
55626 | 353 |
|
65121 | 354 |
def squiggly_underline(range: Text.Range): List[Text.Info[Rendering.Color.Value]] = |
355 |
message_underline_color(JEdit_Rendering.squiggly_elements, range) |
|
49356 | 356 |
|
81404 | 357 |
def line_background(range: Text.Range): Option[Rendering.Color.Value] = |
358 |
Rendering.message_background_color.get( |
|
359 |
snapshot.cumulate[Int](range, 0, JEdit_Rendering.line_background_elements, _ => { |
|
360 |
case (pri, Text.Info(_, elem)) => Some(pri max Rendering.message_pri(elem.name)) |
|
361 |
}).foldLeft(0) { case (p1, Text.Info(_, p2)) => p1 max p2 }) |
|
49474 | 362 |
|
81404 | 363 |
def line_separator(range: Text.Range): Boolean = |
364 |
snapshot.cumulate[Boolean](range, false, JEdit_Rendering.separator_elements, _ => { |
|
365 |
case _ => Some(true) |
|
366 |
}).exists(_.info) |
|
49356 | 367 |
|
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50499
diff
changeset
|
368 |
|
55626 | 369 |
/* text color */ |
370 |
||
75393 | 371 |
def text_color(range: Text.Range, current_color: Color): List[Text.Info[Color]] = { |
65258 | 372 |
if (current_color == Syntax_Style.hidden_color) List(Text.Info(range, current_color)) |
50196
94886ebf090f
retain hidden_color (i.e. transparent white) instead of replacing it by semantic text color, to make control symbols more hidden and avoid "dirty" lines with some fonts;
wenzelm
parents:
50164
diff
changeset
|
373 |
else |
65144 | 374 |
snapshot.cumulate(range, current_color, Rendering.text_color_elements, _ => |
50196
94886ebf090f
retain hidden_color (i.e. transparent white) instead of replacing it by semantic text color, to make control symbols more hidden and avoid "dirty" lines with some fonts;
wenzelm
parents:
50164
diff
changeset
|
375 |
{ |
81558
b57996a0688c
clarified term positions and markup: syntax = true means this is via concrete syntax;
wenzelm
parents:
81555
diff
changeset
|
376 |
case (_, Text.Info(_, elem)) => Rendering.get_text_color(elem.markup).map(color) |
50196
94886ebf090f
retain hidden_color (i.e. transparent white) instead of replacing it by semantic text color, to make control symbols more hidden and avoid "dirty" lines with some fonts;
wenzelm
parents:
50164
diff
changeset
|
377 |
}) |
49356 | 378 |
} |
50542
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50507
diff
changeset
|
379 |
|
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50507
diff
changeset
|
380 |
|
55626 | 381 |
/* virtual bullets */ |
382 |
||
383 |
def bullet(range: Text.Range): List[Text.Info[Color]] = |
|
64621 | 384 |
snapshot.select(range, JEdit_Rendering.bullet_elements, _ => |
60913 | 385 |
{ |
386 |
case Text.Info(_, Protocol.ML_Breakpoint(breakpoint)) => |
|
65247 | 387 |
PIDE.session.debugger.active_breakpoint_state(breakpoint).map(b => |
60913 | 388 |
if (b) breakpoint_enabled_color else breakpoint_disabled_color) |
389 |
case _ => Some(bullet_color) |
|
390 |
}) |
|
55626 | 391 |
|
392 |
||
393 |
/* text folds */ |
|
50542
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50507
diff
changeset
|
394 |
|
52900
d29bf6db8a2d
more elementary list structures for markup tree traversal;
wenzelm
parents:
52890
diff
changeset
|
395 |
def fold_depth(range: Text.Range): List[Text.Info[Int]] = |
64621 | 396 |
snapshot.cumulate[Int](range, 0, JEdit_Rendering.fold_depth_elements, _ => |
50542
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50507
diff
changeset
|
397 |
{ |
55620 | 398 |
case (depth, _) => Some(depth + 1) |
50542
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50507
diff
changeset
|
399 |
}) |
49356 | 400 |
} |