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