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