author | wenzelm |
Sun, 07 Oct 2012 16:05:31 +0200 | |
changeset 49726 | 2074197dc274 |
parent 49725 | f8eeff667076 |
child 49727 | 2fe56b600698 |
permissions | -rw-r--r-- |
45665
129db1416717
renamed Isabelle_Markup to Isabelle_Rendering to emphasize its meaning and make room for Pure Isabelle_Markup module;
wenzelm
parents:
45489
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/isabelle_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 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
4 |
Isabelle specific physical rendering and markup selection. |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
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 |
package isabelle.jedit |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
8 |
|
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 |
import isabelle._ |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
11 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
12 |
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
|
13 |
import javax.swing.Icon |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
14 |
import java.io.{File => JFile} |
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} |
49406 | 17 |
import org.gjt.sp.jedit.GUIUtilities |
18 |
import org.gjt.sp.util.Log |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
19 |
|
45460 | 20 |
import scala.collection.immutable.SortedMap |
21 |
||
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
22 |
|
45665
129db1416717
renamed Isabelle_Markup to Isabelle_Rendering to emphasize its meaning and make room for Pure Isabelle_Markup module;
wenzelm
parents:
45489
diff
changeset
|
23 |
object Isabelle_Rendering |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
24 |
{ |
49356 | 25 |
def apply(snapshot: Document.Snapshot, options: Options): Isabelle_Rendering = |
26 |
new Isabelle_Rendering(snapshot, options) |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
27 |
|
49356 | 28 |
|
49406 | 29 |
/* message priorities */ |
43388 | 30 |
|
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
|
31 |
private val writeln_pri = 1 |
49474 | 32 |
private val tracing_pri = 2 |
33 |
private val warning_pri = 3 |
|
34 |
private val legacy_pri = 4 |
|
35 |
private val error_pri = 5 |
|
36 |
||
37 |
private val message_pri = Map( |
|
38 |
Isabelle_Markup.WRITELN -> writeln_pri, Isabelle_Markup.WRITELN_MESSAGE -> writeln_pri, |
|
39 |
Isabelle_Markup.TRACING -> tracing_pri, Isabelle_Markup.TRACING_MESSAGE -> tracing_pri, |
|
40 |
Isabelle_Markup.WARNING -> warning_pri, Isabelle_Markup.WARNING_MESSAGE -> warning_pri, |
|
41 |
Isabelle_Markup.ERROR -> error_pri, Isabelle_Markup.ERROR_MESSAGE -> error_pri) |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
42 |
|
49406 | 43 |
|
44 |
/* icons */ |
|
45 |
||
46 |
private def load_icon(name: String): Icon = |
|
47 |
{ |
|
48 |
val icon = GUIUtilities.loadIcon(name) |
|
49 |
if (icon.getIconWidth < 0 || icon.getIconHeight < 0) |
|
50 |
Log.log(Log.ERROR, icon, "Bad icon: " + name) |
|
51 |
icon |
|
52 |
} |
|
53 |
||
46234 | 54 |
private val gutter_icons = Map( |
49406 | 55 |
warning_pri -> load_icon("16x16/status/dialog-information.png"), |
56 |
legacy_pri -> load_icon("16x16/status/dialog-warning.png"), |
|
57 |
error_pri -> load_icon("16x16/status/dialog-error.png")) |
|
46234 | 58 |
|
49726 | 59 |
val tooltip_detach_icon = load_icon("16x16/actions/window-new.png") |
49725 | 60 |
val tooltip_close_icon = load_icon("16x16/actions/document-close.png") |
61 |
||
46234 | 62 |
|
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
63 |
/* token markup -- text styles */ |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
64 |
|
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
65 |
private val command_style: Map[String, Byte] = |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
66 |
{ |
43414 | 67 |
import JEditToken._ |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
68 |
Map[String, Byte]( |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
69 |
Keyword.THY_END -> KEYWORD2, |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
70 |
Keyword.THY_SCRIPT -> LABEL, |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
71 |
Keyword.PRF_SCRIPT -> LABEL, |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
72 |
Keyword.PRF_ASM -> KEYWORD3, |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
73 |
Keyword.PRF_ASM_GOAL -> KEYWORD3 |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
74 |
).withDefaultValue(KEYWORD1) |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
75 |
} |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
76 |
|
43414 | 77 |
private val token_style: Map[Token.Kind.Value, Byte] = |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
78 |
{ |
43414 | 79 |
import JEditToken._ |
80 |
Map[Token.Kind.Value, Byte]( |
|
81 |
Token.Kind.KEYWORD -> KEYWORD2, |
|
82 |
Token.Kind.IDENT -> NULL, |
|
83 |
Token.Kind.LONG_IDENT -> NULL, |
|
84 |
Token.Kind.SYM_IDENT -> NULL, |
|
85 |
Token.Kind.VAR -> NULL, |
|
86 |
Token.Kind.TYPE_IDENT -> NULL, |
|
87 |
Token.Kind.TYPE_VAR -> NULL, |
|
88 |
Token.Kind.NAT -> NULL, |
|
89 |
Token.Kind.FLOAT -> NULL, |
|
43431 | 90 |
Token.Kind.STRING -> LITERAL1, |
91 |
Token.Kind.ALT_STRING -> LITERAL2, |
|
43414 | 92 |
Token.Kind.VERBATIM -> COMMENT3, |
93 |
Token.Kind.SPACE -> NULL, |
|
94 |
Token.Kind.COMMENT -> COMMENT1, |
|
48754
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
wenzelm
parents:
48751
diff
changeset
|
95 |
Token.Kind.ERROR -> INVALID |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
96 |
).withDefaultValue(NULL) |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
97 |
} |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
98 |
|
43414 | 99 |
def token_markup(syntax: Outer_Syntax, token: Token): Byte = |
43430
1ed88ddf1268
more uniform treatment of "keyword" vs. "operator";
wenzelm
parents:
43418
diff
changeset
|
100 |
if (token.is_command) command_style(syntax.keyword_kind(token.content).getOrElse("")) |
1ed88ddf1268
more uniform treatment of "keyword" vs. "operator";
wenzelm
parents:
43418
diff
changeset
|
101 |
else if (token.is_operator) JEditToken.OPERATOR |
43414 | 102 |
else token_style(token.kind) |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
103 |
} |
49356 | 104 |
|
105 |
||
106 |
class Isabelle_Rendering private(val snapshot: Document.Snapshot, val options: Options) |
|
107 |
{ |
|
108 |
/* colors */ |
|
109 |
||
110 |
def color_value(s: String): Color = Color_Value(options.string(s)) |
|
111 |
||
112 |
val outdated_color = color_value("outdated_color") |
|
113 |
val unprocessed_color = color_value("unprocessed_color") |
|
114 |
val unprocessed1_color = color_value("unprocessed1_color") |
|
115 |
val running_color = color_value("running_color") |
|
116 |
val running1_color = color_value("running1_color") |
|
117 |
val light_color = color_value("light_color") |
|
49706 | 118 |
val tooltip_color = color_value("tooltip_color") |
49356 | 119 |
val writeln_color = color_value("writeln_color") |
120 |
val warning_color = color_value("warning_color") |
|
121 |
val error_color = color_value("error_color") |
|
122 |
val error1_color = color_value("error1_color") |
|
49418 | 123 |
val writeln_message_color = color_value("writeln_message_color") |
124 |
val tracing_message_color = color_value("tracing_message_color") |
|
125 |
val warning_message_color = color_value("warning_message_color") |
|
126 |
val error_message_color = color_value("error_message_color") |
|
49356 | 127 |
val bad_color = color_value("bad_color") |
49358 | 128 |
val intensify_color = color_value("intensify_color") |
49356 | 129 |
val quoted_color = color_value("quoted_color") |
49358 | 130 |
val highlight_color = color_value("highlight_color") |
49356 | 131 |
val hyperlink_color = color_value("hyperlink_color") |
49492 | 132 |
val sendback_color = color_value("sendback_color") |
133 |
val sendback_active_color = color_value("sendback_active_color") |
|
49356 | 134 |
val keyword1_color = color_value("keyword1_color") |
135 |
val keyword2_color = color_value("keyword2_color") |
|
136 |
||
137 |
val tfree_color = color_value("tfree_color") |
|
138 |
val tvar_color = color_value("tvar_color") |
|
139 |
val free_color = color_value("free_color") |
|
140 |
val skolem_color = color_value("skolem_color") |
|
141 |
val bound_color = color_value("bound_color") |
|
142 |
val var_color = color_value("var_color") |
|
143 |
val inner_numeral_color = color_value("inner_numeral_color") |
|
144 |
val inner_quoted_color = color_value("inner_quoted_color") |
|
145 |
val inner_comment_color = color_value("inner_comment_color") |
|
146 |
val antiquotation_color = color_value("antiquotation_color") |
|
147 |
val dynamic_color = color_value("dynamic_color") |
|
148 |
||
149 |
||
150 |
/* command overview */ |
|
151 |
||
152 |
def overview_color(range: Text.Range): Option[Color] = |
|
153 |
{ |
|
154 |
if (snapshot.is_outdated) None |
|
155 |
else { |
|
156 |
val results = |
|
157 |
snapshot.cumulate_markup[(Protocol.Status, Int)]( |
|
158 |
range, (Protocol.Status.init, 0), |
|
159 |
Some(Protocol.command_status_markup + Isabelle_Markup.WARNING + Isabelle_Markup.ERROR), |
|
160 |
{ |
|
161 |
case ((status, pri), Text.Info(_, XML.Elem(markup, _))) => |
|
49474 | 162 |
if (markup.name == Isabelle_Markup.WARNING || markup.name == Isabelle_Markup.ERROR) |
163 |
(status, pri max Isabelle_Rendering.message_pri(markup.name)) |
|
49356 | 164 |
else (Protocol.command_status(status, markup), pri) |
165 |
}) |
|
166 |
if (results.isEmpty) None |
|
167 |
else { |
|
168 |
val (status, pri) = |
|
169 |
((Protocol.Status.init, 0) /: results) { |
|
170 |
case ((s1, p1), Text.Info(_, (s2, p2))) => (s1 + s2, p1 max p2) } |
|
171 |
||
172 |
if (pri == Isabelle_Rendering.warning_pri) Some(warning_color) |
|
173 |
else if (pri == Isabelle_Rendering.error_pri) Some(error_color) |
|
174 |
else if (status.is_unprocessed) Some(unprocessed_color) |
|
175 |
else if (status.is_running) Some(running_color) |
|
176 |
else if (status.is_failed) Some(error_color) |
|
177 |
else None |
|
178 |
} |
|
179 |
} |
|
180 |
} |
|
181 |
||
182 |
||
183 |
/* markup selectors */ |
|
184 |
||
49358 | 185 |
private val highlight_include = |
49356 | 186 |
Set(Isabelle_Markup.SORT, Isabelle_Markup.TYP, Isabelle_Markup.TERM, Isabelle_Markup.PROP, |
187 |
Isabelle_Markup.ML_TYPING, Isabelle_Markup.TOKEN_RANGE, Isabelle_Markup.ENTITY, |
|
49674
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
49554
diff
changeset
|
188 |
Isabelle_Markup.PATH, Isabelle_Markup.SORTING, Isabelle_Markup.TYPING, Isabelle_Markup.FREE, |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
49554
diff
changeset
|
189 |
Isabelle_Markup.SKOLEM, Isabelle_Markup.BOUND, Isabelle_Markup.VAR, Isabelle_Markup.TFREE, |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
49554
diff
changeset
|
190 |
Isabelle_Markup.TVAR, Isabelle_Markup.ML_SOURCE, Isabelle_Markup.DOCUMENT_SOURCE) |
49356 | 191 |
|
49358 | 192 |
def highlight(range: Text.Range): Option[Text.Info[Color]] = |
49356 | 193 |
{ |
49358 | 194 |
snapshot.select_markup(range, Some(highlight_include), |
49356 | 195 |
{ |
49358 | 196 |
case Text.Info(info_range, XML.Elem(Markup(name, _), _)) if highlight_include(name) => |
197 |
Text.Info(snapshot.convert(info_range), highlight_color) |
|
49356 | 198 |
}) match { case Text.Info(_, info) #:: _ => Some(info) case _ => None } |
199 |
} |
|
200 |
||
201 |
||
202 |
private val hyperlink_include = Set(Isabelle_Markup.ENTITY, Isabelle_Markup.PATH) |
|
203 |
||
204 |
def hyperlink(range: Text.Range): Option[Text.Info[Hyperlink]] = |
|
205 |
{ |
|
206 |
snapshot.cumulate_markup[List[Text.Info[Hyperlink]]](range, Nil, Some(hyperlink_include), |
|
207 |
{ |
|
208 |
case (links, Text.Info(info_range, XML.Elem(Isabelle_Markup.Path(name), _))) |
|
209 |
if Path.is_ok(name) => |
|
210 |
val jedit_file = Isabelle.thy_load.append(snapshot.node_name.dir, Path.explode(name)) |
|
211 |
Text.Info(snapshot.convert(info_range), Hyperlink(jedit_file, 0, 0)) :: links |
|
212 |
||
213 |
case (links, Text.Info(info_range, XML.Elem(Markup(Isabelle_Markup.ENTITY, props), _))) |
|
214 |
if (props.find( |
|
215 |
{ case (Markup.KIND, Isabelle_Markup.ML_OPEN) => true |
|
216 |
case (Markup.KIND, Isabelle_Markup.ML_STRUCT) => true |
|
217 |
case _ => false }).isEmpty) => |
|
218 |
||
219 |
props match { |
|
49419
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
49418
diff
changeset
|
220 |
case Position.Def_Line_File(line, name) if Path.is_ok(name) => |
49356 | 221 |
Isabelle_System.source_file(Path.explode(name)) match { |
222 |
case Some(path) => |
|
223 |
val jedit_file = Isabelle_System.platform_path(path) |
|
224 |
Text.Info(snapshot.convert(info_range), Hyperlink(jedit_file, line, 0)) :: links |
|
225 |
case None => links |
|
226 |
} |
|
227 |
||
49419
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
49418
diff
changeset
|
228 |
case Position.Def_Id_Offset(id, offset) => |
49356 | 229 |
snapshot.state.find_command(snapshot.version, id) match { |
230 |
case Some((node, command)) => |
|
231 |
val sources = |
|
232 |
node.commands.iterator.takeWhile(_ != command).map(_.source) ++ |
|
233 |
Iterator.single(command.source(Text.Range(0, command.decode(offset)))) |
|
234 |
val (line, column) = ((1, 1) /: sources)(Symbol.advance_line_column) |
|
235 |
Text.Info(snapshot.convert(info_range), |
|
236 |
Hyperlink(command.node_name.node, line, column)) :: links |
|
237 |
case None => links |
|
238 |
} |
|
239 |
||
240 |
case _ => links |
|
241 |
} |
|
242 |
}) match { case Text.Info(_, info :: _) #:: _ => Some(info) case _ => None } |
|
243 |
} |
|
244 |
||
245 |
||
49493
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
246 |
def sendback(range: Text.Range): Option[Text.Info[Document.Exec_ID]] = |
49492 | 247 |
{ |
49493
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
248 |
val results = |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
249 |
snapshot.cumulate_markup[(Option[Document.Exec_ID], Option[Text.Range])](range, |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
250 |
(None, None), Some(messages_include + Isabelle_Markup.SENDBACK), |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
251 |
{ |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
252 |
case ((_, info), Text.Info(_, XML.Elem(Markup(name, Position.Id(id)), _))) |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
253 |
if messages_include(name) => (Some(id), info) |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
254 |
|
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
255 |
case ((id, _), Text.Info(info_range, XML.Elem(Markup(Isabelle_Markup.SENDBACK, _), _))) => |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
256 |
(id, Some(snapshot.convert(info_range))) |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
257 |
}) |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
258 |
|
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
259 |
(for (Text.Info(_, (Some(id), Some(r))) <- results) yield Text.Info(r, id)) match { |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
260 |
case res #:: _ => Some(res) |
49492 | 261 |
case _ => None |
262 |
} |
|
263 |
} |
|
264 |
||
265 |
||
49700
2d1cbdf6a68b
Rich_Text_Area tooltips via nested Pretty_Text_Area, based on some techniques of FoldViewer plugin;
wenzelm
parents:
49674
diff
changeset
|
266 |
def tooltip_message(range: Text.Range): XML.Body = |
49356 | 267 |
{ |
268 |
val msgs = |
|
49700
2d1cbdf6a68b
Rich_Text_Area tooltips via nested Pretty_Text_Area, based on some techniques of FoldViewer plugin;
wenzelm
parents:
49674
diff
changeset
|
269 |
snapshot.cumulate_markup[SortedMap[Long, XML.Tree]](range, SortedMap.empty, |
49356 | 270 |
Some(Set(Isabelle_Markup.WRITELN, Isabelle_Markup.WARNING, Isabelle_Markup.ERROR, |
271 |
Isabelle_Markup.BAD)), |
|
272 |
{ |
|
49704 | 273 |
case (msgs, Text.Info(_, |
274 |
XML.Elem(Markup(name, props @ Isabelle_Markup.Serial(serial)), body))) |
|
275 |
if name == Isabelle_Markup.WRITELN || |
|
276 |
name == Isabelle_Markup.WARNING || |
|
277 |
name == Isabelle_Markup.ERROR => |
|
278 |
msgs + (serial -> XML.Elem(Markup(Isabelle_Markup.message(name), props), body)) |
|
49356 | 279 |
case (msgs, Text.Info(_, msg @ XML.Elem(Markup(Isabelle_Markup.BAD, _), body))) |
49700
2d1cbdf6a68b
Rich_Text_Area tooltips via nested Pretty_Text_Area, based on some techniques of FoldViewer plugin;
wenzelm
parents:
49674
diff
changeset
|
280 |
if !body.isEmpty => msgs + (Document.new_id() -> msg) |
49356 | 281 |
}).toList.flatMap(_.info) |
49700
2d1cbdf6a68b
Rich_Text_Area tooltips via nested Pretty_Text_Area, based on some techniques of FoldViewer plugin;
wenzelm
parents:
49674
diff
changeset
|
282 |
Library.separate(Pretty.Separator, msgs.iterator.map(_._2).toList) |
49356 | 283 |
} |
284 |
||
285 |
||
286 |
private val tooltips: Map[String, String] = |
|
287 |
Map( |
|
288 |
Isabelle_Markup.SORT -> "sort", |
|
289 |
Isabelle_Markup.TYP -> "type", |
|
290 |
Isabelle_Markup.TERM -> "term", |
|
291 |
Isabelle_Markup.PROP -> "proposition", |
|
292 |
Isabelle_Markup.TOKEN_RANGE -> "inner syntax token", |
|
293 |
Isabelle_Markup.FREE -> "free variable", |
|
294 |
Isabelle_Markup.SKOLEM -> "skolem variable", |
|
295 |
Isabelle_Markup.BOUND -> "bound variable", |
|
296 |
Isabelle_Markup.VAR -> "schematic variable", |
|
297 |
Isabelle_Markup.TFREE -> "free type variable", |
|
298 |
Isabelle_Markup.TVAR -> "schematic type variable", |
|
299 |
Isabelle_Markup.ML_SOURCE -> "ML source", |
|
300 |
Isabelle_Markup.DOCUMENT_SOURCE -> "document source") |
|
301 |
||
302 |
private val tooltip_elements = |
|
49674
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
49554
diff
changeset
|
303 |
Set(Isabelle_Markup.ENTITY, Isabelle_Markup.SORTING, Isabelle_Markup.TYPING, |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
49554
diff
changeset
|
304 |
Isabelle_Markup.ML_TYPING, Isabelle_Markup.PATH) ++ tooltips.keys |
49356 | 305 |
|
49700
2d1cbdf6a68b
Rich_Text_Area tooltips via nested Pretty_Text_Area, based on some techniques of FoldViewer plugin;
wenzelm
parents:
49674
diff
changeset
|
306 |
private def pretty_typing(kind: String, body: XML.Body): XML.Tree = |
2d1cbdf6a68b
Rich_Text_Area tooltips via nested Pretty_Text_Area, based on some techniques of FoldViewer plugin;
wenzelm
parents:
49674
diff
changeset
|
307 |
Pretty.block(XML.Text(kind) :: Pretty.Break(1) :: body) |
49356 | 308 |
|
49700
2d1cbdf6a68b
Rich_Text_Area tooltips via nested Pretty_Text_Area, based on some techniques of FoldViewer plugin;
wenzelm
parents:
49674
diff
changeset
|
309 |
def tooltip(range: Text.Range): XML.Body = |
49356 | 310 |
{ |
49700
2d1cbdf6a68b
Rich_Text_Area tooltips via nested Pretty_Text_Area, based on some techniques of FoldViewer plugin;
wenzelm
parents:
49674
diff
changeset
|
311 |
def add(prev: Text.Info[List[(Boolean, XML.Tree)]], r: Text.Range, p: (Boolean, XML.Tree)) = |
49356 | 312 |
if (prev.range == r) Text.Info(r, p :: prev.info) else Text.Info(r, List(p)) |
313 |
||
314 |
val tips = |
|
49700
2d1cbdf6a68b
Rich_Text_Area tooltips via nested Pretty_Text_Area, based on some techniques of FoldViewer plugin;
wenzelm
parents:
49674
diff
changeset
|
315 |
snapshot.cumulate_markup[Text.Info[(List[(Boolean, XML.Tree)])]]( |
49356 | 316 |
range, Text.Info(range, Nil), Some(tooltip_elements), |
317 |
{ |
|
318 |
case (prev, Text.Info(r, XML.Elem(Isabelle_Markup.Entity(kind, name), _))) => |
|
319 |
val kind1 = space_explode('_', kind).mkString(" ") |
|
49700
2d1cbdf6a68b
Rich_Text_Area tooltips via nested Pretty_Text_Area, based on some techniques of FoldViewer plugin;
wenzelm
parents:
49674
diff
changeset
|
320 |
add(prev, r, (true, XML.Text(kind1 + " " + quote(name)))) |
49356 | 321 |
case (prev, Text.Info(r, XML.Elem(Isabelle_Markup.Path(name), _))) |
322 |
if Path.is_ok(name) => |
|
323 |
val jedit_file = Isabelle.thy_load.append(snapshot.node_name.dir, Path.explode(name)) |
|
49700
2d1cbdf6a68b
Rich_Text_Area tooltips via nested Pretty_Text_Area, based on some techniques of FoldViewer plugin;
wenzelm
parents:
49674
diff
changeset
|
324 |
add(prev, r, (true, XML.Text("file " + quote(jedit_file)))) |
49674
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
49554
diff
changeset
|
325 |
case (prev, Text.Info(r, XML.Elem(Markup(name, _), body))) |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
49554
diff
changeset
|
326 |
if name == Isabelle_Markup.SORTING || name == Isabelle_Markup.TYPING => |
49700
2d1cbdf6a68b
Rich_Text_Area tooltips via nested Pretty_Text_Area, based on some techniques of FoldViewer plugin;
wenzelm
parents:
49674
diff
changeset
|
327 |
add(prev, r, (true, pretty_typing("::", body))) |
49356 | 328 |
case (prev, Text.Info(r, XML.Elem(Markup(Isabelle_Markup.ML_TYPING, _), body))) => |
49700
2d1cbdf6a68b
Rich_Text_Area tooltips via nested Pretty_Text_Area, based on some techniques of FoldViewer plugin;
wenzelm
parents:
49674
diff
changeset
|
329 |
add(prev, r, (false, pretty_typing("ML:", body))) |
49356 | 330 |
case (prev, Text.Info(r, XML.Elem(Markup(name, _), _))) |
49700
2d1cbdf6a68b
Rich_Text_Area tooltips via nested Pretty_Text_Area, based on some techniques of FoldViewer plugin;
wenzelm
parents:
49674
diff
changeset
|
331 |
if tooltips.isDefinedAt(name) => add(prev, r, (true, XML.Text(tooltips(name)))) |
49356 | 332 |
}).toList.flatMap(_.info.info) |
333 |
||
334 |
val all_tips = |
|
335 |
(tips.filter(_._1) ++ tips.filter(!_._1).lastOption.toList).map(_._2) |
|
49700
2d1cbdf6a68b
Rich_Text_Area tooltips via nested Pretty_Text_Area, based on some techniques of FoldViewer plugin;
wenzelm
parents:
49674
diff
changeset
|
336 |
Library.separate(Pretty.FBreak, all_tips.toList) |
49356 | 337 |
} |
338 |
||
339 |
||
340 |
def gutter_message(range: Text.Range): Option[Icon] = |
|
341 |
{ |
|
342 |
val results = |
|
343 |
snapshot.cumulate_markup[Int](range, 0, |
|
344 |
Some(Set(Isabelle_Markup.WARNING, Isabelle_Markup.ERROR)), |
|
345 |
{ |
|
346 |
case (pri, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.WARNING, _), body))) => |
|
347 |
body match { |
|
348 |
case List(XML.Elem(Markup(Isabelle_Markup.LEGACY, _), _)) => |
|
349 |
pri max Isabelle_Rendering.legacy_pri |
|
350 |
case _ => pri max Isabelle_Rendering.warning_pri |
|
351 |
} |
|
352 |
case (pri, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.ERROR, _), _))) => |
|
353 |
pri max Isabelle_Rendering.error_pri |
|
354 |
}) |
|
355 |
val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 } |
|
356 |
Isabelle_Rendering.gutter_icons.get(pri) |
|
357 |
} |
|
358 |
||
359 |
||
360 |
private val squiggly_colors = Map( |
|
361 |
Isabelle_Rendering.writeln_pri -> writeln_color, |
|
362 |
Isabelle_Rendering.warning_pri -> warning_color, |
|
363 |
Isabelle_Rendering.error_pri -> error_color) |
|
364 |
||
365 |
def squiggly_underline(range: Text.Range): Stream[Text.Info[Color]] = |
|
366 |
{ |
|
367 |
val results = |
|
368 |
snapshot.cumulate_markup[Int](range, 0, |
|
369 |
Some(Set(Isabelle_Markup.WRITELN, Isabelle_Markup.WARNING, Isabelle_Markup.ERROR)), |
|
370 |
{ |
|
49474 | 371 |
case (pri, Text.Info(_, XML.Elem(Markup(name, _), _))) |
372 |
if name == Isabelle_Markup.WRITELN || |
|
373 |
name == Isabelle_Markup.WARNING || |
|
374 |
name == Isabelle_Markup.ERROR => pri max Isabelle_Rendering.message_pri(name) |
|
49356 | 375 |
}) |
376 |
for { |
|
377 |
Text.Info(r, pri) <- results |
|
378 |
color <- squiggly_colors.get(pri) |
|
379 |
} yield Text.Info(r, color) |
|
380 |
} |
|
381 |
||
49474 | 382 |
|
49493
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
383 |
private val messages_include = |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
384 |
Set(Isabelle_Markup.WRITELN_MESSAGE, Isabelle_Markup.TRACING_MESSAGE, |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
385 |
Isabelle_Markup.WARNING_MESSAGE, Isabelle_Markup.ERROR_MESSAGE) |
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
386 |
|
49474 | 387 |
private val message_colors = Map( |
388 |
Isabelle_Rendering.writeln_pri -> writeln_message_color, |
|
389 |
Isabelle_Rendering.tracing_pri -> tracing_message_color, |
|
390 |
Isabelle_Rendering.warning_pri -> warning_message_color, |
|
391 |
Isabelle_Rendering.error_pri -> error_message_color) |
|
392 |
||
49473 | 393 |
def line_background(range: Text.Range): Option[(Color, Boolean)] = |
394 |
{ |
|
49474 | 395 |
val results = |
49493
db58490a68ac
more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents:
49492
diff
changeset
|
396 |
snapshot.cumulate_markup[Int](range, 0, Some(messages_include), |
49473 | 397 |
{ |
49474 | 398 |
case (pri, Text.Info(_, XML.Elem(Markup(name, _), _))) |
399 |
if name == Isabelle_Markup.WRITELN_MESSAGE || |
|
400 |
name == Isabelle_Markup.TRACING_MESSAGE || |
|
401 |
name == Isabelle_Markup.WARNING_MESSAGE || |
|
402 |
name == Isabelle_Markup.ERROR_MESSAGE => pri max Isabelle_Rendering.message_pri(name) |
|
403 |
}) |
|
404 |
val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 } |
|
405 |
||
406 |
val is_separator = pri > 0 && |
|
407 |
snapshot.cumulate_markup[Boolean](range, false, Some(Set(Isabelle_Markup.SEPARATOR)), |
|
49473 | 408 |
{ |
409 |
case (_, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.SEPARATOR, _), _))) => true |
|
410 |
}).exists(_.info) |
|
411 |
||
49474 | 412 |
message_colors.get(pri).map((_, is_separator)) |
49473 | 413 |
} |
49356 | 414 |
|
49492 | 415 |
|
416 |
private val background1_include = |
|
417 |
Protocol.command_status_markup + Isabelle_Markup.WRITELN_MESSAGE + |
|
418 |
Isabelle_Markup.TRACING_MESSAGE + Isabelle_Markup.WARNING_MESSAGE + |
|
419 |
Isabelle_Markup.ERROR_MESSAGE + Isabelle_Markup.BAD + Isabelle_Markup.INTENSIFY + |
|
420 |
Isabelle_Markup.SENDBACK |
|
421 |
||
49356 | 422 |
def background1(range: Text.Range): Stream[Text.Info[Color]] = |
423 |
{ |
|
424 |
if (snapshot.is_outdated) Stream(Text.Info(range, outdated_color)) |
|
425 |
else |
|
426 |
for { |
|
427 |
Text.Info(r, result) <- |
|
428 |
snapshot.cumulate_markup[(Option[Protocol.Status], Option[Color])]( |
|
49492 | 429 |
range, (Some(Protocol.Status.init), None), Some(background1_include), |
49356 | 430 |
{ |
431 |
case (((Some(status), color), Text.Info(_, XML.Elem(markup, _)))) |
|
432 |
if (Protocol.command_status_markup(markup.name)) => |
|
433 |
(Some(Protocol.command_status(status, markup)), color) |
|
434 |
case (_, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.BAD, _), _))) => |
|
435 |
(None, Some(bad_color)) |
|
49358 | 436 |
case (_, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.INTENSIFY, _), _))) => |
437 |
(None, Some(intensify_color)) |
|
49492 | 438 |
case (_, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.SENDBACK, _), _))) => |
439 |
(None, Some(sendback_color)) |
|
49356 | 440 |
}) |
441 |
color <- |
|
442 |
(result match { |
|
443 |
case (Some(status), opt_color) => |
|
444 |
if (status.is_unprocessed) Some(unprocessed1_color) |
|
445 |
else if (status.is_running) Some(running1_color) |
|
446 |
else opt_color |
|
447 |
case (_, opt_color) => opt_color |
|
448 |
}) |
|
449 |
} yield Text.Info(r, color) |
|
450 |
} |
|
451 |
||
452 |
||
453 |
def background2(range: Text.Range): Stream[Text.Info[Color]] = |
|
454 |
snapshot.select_markup(range, |
|
455 |
Some(Set(Isabelle_Markup.TOKEN_RANGE)), |
|
456 |
{ |
|
457 |
case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.TOKEN_RANGE, _), _)) => light_color |
|
458 |
}) |
|
459 |
||
460 |
||
461 |
def foreground(range: Text.Range): Stream[Text.Info[Color]] = |
|
462 |
snapshot.select_markup(range, |
|
463 |
Some(Set(Isabelle_Markup.STRING, Isabelle_Markup.ALTSTRING, Isabelle_Markup.VERBATIM)), |
|
464 |
{ |
|
465 |
case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.STRING, _), _)) => quoted_color |
|
466 |
case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.ALTSTRING, _), _)) => quoted_color |
|
467 |
case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.VERBATIM, _), _)) => quoted_color |
|
468 |
}) |
|
469 |
||
470 |
||
471 |
private val text_colors: Map[String, Color] = Map( |
|
49554
7b7bd2d7661d
more explicit keyword1/keyword2 markup -- avoid potential conflict with input token markup produced by Token_Marker;
wenzelm
parents:
49493
diff
changeset
|
472 |
Isabelle_Markup.KEYWORD1 -> keyword1_color, |
7b7bd2d7661d
more explicit keyword1/keyword2 markup -- avoid potential conflict with input token markup produced by Token_Marker;
wenzelm
parents:
49493
diff
changeset
|
473 |
Isabelle_Markup.KEYWORD2 -> keyword2_color, |
49356 | 474 |
Isabelle_Markup.STRING -> Color.BLACK, |
475 |
Isabelle_Markup.ALTSTRING -> Color.BLACK, |
|
476 |
Isabelle_Markup.VERBATIM -> Color.BLACK, |
|
477 |
Isabelle_Markup.LITERAL -> keyword1_color, |
|
478 |
Isabelle_Markup.DELIMITER -> Color.BLACK, |
|
479 |
Isabelle_Markup.TFREE -> tfree_color, |
|
480 |
Isabelle_Markup.TVAR -> tvar_color, |
|
481 |
Isabelle_Markup.FREE -> free_color, |
|
482 |
Isabelle_Markup.SKOLEM -> skolem_color, |
|
483 |
Isabelle_Markup.BOUND -> bound_color, |
|
484 |
Isabelle_Markup.VAR -> var_color, |
|
485 |
Isabelle_Markup.INNER_STRING -> inner_quoted_color, |
|
486 |
Isabelle_Markup.INNER_COMMENT -> inner_comment_color, |
|
487 |
Isabelle_Markup.DYNAMIC_FACT -> dynamic_color, |
|
488 |
Isabelle_Markup.ML_KEYWORD -> keyword1_color, |
|
489 |
Isabelle_Markup.ML_DELIMITER -> Color.BLACK, |
|
490 |
Isabelle_Markup.ML_NUMERAL -> inner_numeral_color, |
|
491 |
Isabelle_Markup.ML_CHAR -> inner_quoted_color, |
|
492 |
Isabelle_Markup.ML_STRING -> inner_quoted_color, |
|
493 |
Isabelle_Markup.ML_COMMENT -> inner_comment_color, |
|
494 |
Isabelle_Markup.ANTIQ -> antiquotation_color) |
|
495 |
||
496 |
private val text_color_elements = Set.empty[String] ++ text_colors.keys |
|
497 |
||
498 |
def text_color(range: Text.Range, color: Color) |
|
499 |
: Stream[Text.Info[Color]] = |
|
500 |
{ |
|
501 |
snapshot.cumulate_markup(range, color, Some(text_color_elements), |
|
502 |
{ |
|
503 |
case (_, Text.Info(_, XML.Elem(Markup(m, _), _))) |
|
504 |
if text_colors.isDefinedAt(m) => text_colors(m) |
|
505 |
}) |
|
506 |
} |
|
507 |
} |