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