author | wenzelm |
Fri, 10 Aug 2012 13:33:07 +0200 | |
changeset 48754 | c2c1e5944536 |
parent 48751 | dc3bbdda4bc8 |
child 48756 | 1c843142758e |
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 |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
14 |
|
43386
4e78dd88c64f
more foreground markup, using actual CSS color names;
wenzelm
parents:
43377
diff
changeset
|
15 |
import org.lobobrowser.util.gui.ColorFactory |
43414 | 16 |
import org.gjt.sp.jedit.syntax.{Token => JEditToken} |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
17 |
|
45460 | 18 |
import scala.collection.immutable.SortedMap |
19 |
||
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
20 |
|
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
|
21 |
object Isabelle_Rendering |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
22 |
{ |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
23 |
/* physical rendering */ |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
24 |
|
48751 | 25 |
// see http://www.w3schools.com/cssref/css_colornames.asp |
43377 | 26 |
|
43386
4e78dd88c64f
more foreground markup, using actual CSS color names;
wenzelm
parents:
43377
diff
changeset
|
27 |
def get_color(s: String): Color = ColorFactory.getInstance.getColor(s) |
4e78dd88c64f
more foreground markup, using actual CSS color names;
wenzelm
parents:
43377
diff
changeset
|
28 |
|
44579
a9cf2380377d
tuned colors -- more distance between outdated_color and quoted_color;
wenzelm
parents:
44549
diff
changeset
|
29 |
val outdated_color = new Color(238, 227, 227) |
46166 | 30 |
val unprocessed_color = new Color(255, 160, 160) |
31 |
val unprocessed1_color = new Color(255, 160, 160, 50) |
|
44611 | 32 |
val running_color = new Color(97, 0, 97) |
33 |
val running1_color = new Color(97, 0, 97, 100) |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
34 |
|
39690
6c6164b37fef
some attempts to improve visual appearance of bad text;
wenzelm
parents:
39512
diff
changeset
|
35 |
val light_color = new Color(240, 240, 240) |
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
|
36 |
val writeln_color = new Color(192, 192, 192) |
39692 | 37 |
val warning_color = new Color(255, 140, 0) |
39691 | 38 |
val error_color = new Color(178, 34, 34) |
44866 | 39 |
val error1_color = new Color(178, 34, 34, 50) |
39690
6c6164b37fef
some attempts to improve visual appearance of bad text;
wenzelm
parents:
39512
diff
changeset
|
40 |
val bad_color = new Color(255, 106, 106, 100) |
42171 | 41 |
val hilite_color = new Color(255, 204, 102, 100) |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
42 |
|
44546 | 43 |
val quoted_color = new Color(139, 139, 139, 25) |
44545
3c40007aa031
transparent foreground color for quoted entities;
wenzelm
parents:
44181
diff
changeset
|
44 |
val subexp_color = new Color(80, 80, 80, 50) |
43435
ae6b0c3e58a8
highlight via foreground painter, using alpha channel;
wenzelm
parents:
43434
diff
changeset
|
45 |
|
43388 | 46 |
val keyword1_color = get_color("#006699") |
47 |
val keyword2_color = get_color("#009966") |
|
48 |
||
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
|
49 |
private val writeln_pri = 1 |
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
|
50 |
private val warning_pri = 2 |
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
|
51 |
private val legacy_pri = 3 |
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
|
52 |
private val error_pri = 4 |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
53 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
54 |
|
46166 | 55 |
/* command overview */ |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
56 |
|
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
|
57 |
def overview_color(snapshot: Document.Snapshot, range: Text.Range): Option[Color] = |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
58 |
{ |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
59 |
if (snapshot.is_outdated) None |
46166 | 60 |
else { |
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
|
61 |
val results = |
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
|
62 |
snapshot.cumulate_markup[(Protocol.Status, Int)]( |
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
|
63 |
range, (Protocol.Status.init, 0), |
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
|
64 |
Some(Protocol.command_status_markup + Isabelle_Markup.WARNING + Isabelle_Markup.ERROR), |
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
|
65 |
{ |
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
|
66 |
case ((status, pri), Text.Info(_, XML.Elem(markup, _))) => |
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
|
67 |
if (markup.name == Isabelle_Markup.WARNING) (status, pri max warning_pri) |
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
|
68 |
else if (markup.name == Isabelle_Markup.ERROR) (status, pri max error_pri) |
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
|
69 |
else (Protocol.command_status(status, markup), pri) |
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
|
70 |
}) |
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
|
71 |
if (results.isEmpty) None |
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
|
72 |
else { |
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
|
73 |
val (status, pri) = |
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
|
74 |
((Protocol.Status.init, 0) /: results) { |
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
|
75 |
case ((s1, p1), Text.Info(_, (s2, p2))) => (s1 + s2, p1 max p2) } |
46166 | 76 |
|
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
|
77 |
if (pri == warning_pri) Some(warning_color) |
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
|
78 |
else if (pri == error_pri) Some(error_color) |
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
|
79 |
else if (status.is_unprocessed) Some(unprocessed_color) |
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
|
80 |
else if (status.is_running) Some(running_color) |
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
|
81 |
else if (status.is_failed) Some(error_color) |
46166 | 82 |
else None |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
83 |
} |
46166 | 84 |
} |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
85 |
} |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
86 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
87 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
88 |
/* markup selectors */ |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
89 |
|
46234 | 90 |
private val subexp_include = |
91 |
Set(Isabelle_Markup.SORT, Isabelle_Markup.TYP, Isabelle_Markup.TERM, Isabelle_Markup.PROP, |
|
92 |
Isabelle_Markup.ML_TYPING, Isabelle_Markup.TOKEN_RANGE, Isabelle_Markup.ENTITY, |
|
93 |
Isabelle_Markup.TYPING, Isabelle_Markup.FREE, Isabelle_Markup.SKOLEM, Isabelle_Markup.BOUND, |
|
94 |
Isabelle_Markup.VAR, Isabelle_Markup.TFREE, Isabelle_Markup.TVAR, Isabelle_Markup.ML_SOURCE, |
|
95 |
Isabelle_Markup.DOC_SOURCE) |
|
96 |
||
97 |
def subexp(snapshot: Document.Snapshot, range: Text.Range): Option[Text.Info[Color]] = |
|
98 |
{ |
|
99 |
snapshot.select_markup(range, Some(subexp_include), |
|
100 |
{ |
|
101 |
case Text.Info(range, XML.Elem(Markup(name, _), _)) if subexp_include(name) => |
|
102 |
Text.Info(snapshot.convert(range), subexp_color) |
|
103 |
}) match { case Text.Info(_, info) #:: _ => Some(info) case _ => None } |
|
104 |
} |
|
105 |
||
106 |
||
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46166
diff
changeset
|
107 |
def tooltip_message(snapshot: Document.Snapshot, range: Text.Range): Option[String] = |
46199 | 108 |
{ |
109 |
val msgs = |
|
110 |
snapshot.cumulate_markup[SortedMap[Long, String]](range, SortedMap.empty, |
|
111 |
Some(Set(Isabelle_Markup.WRITELN, Isabelle_Markup.WARNING, Isabelle_Markup.ERROR)), |
|
112 |
{ |
|
113 |
case (msgs, Text.Info(_, msg @ XML.Elem(Markup(markup, Isabelle_Markup.Serial(serial)), _))) |
|
114 |
if markup == Isabelle_Markup.WRITELN || |
|
115 |
markup == Isabelle_Markup.WARNING || |
|
116 |
markup == Isabelle_Markup.ERROR => |
|
117 |
msgs + (serial -> |
|
118 |
Pretty.string_of(List(msg), margin = Isabelle.Int_Property("tooltip-margin"))) |
|
119 |
}).toList.flatMap(_.info) |
|
120 |
if (msgs.isEmpty) None else Some(cat_lines(msgs.iterator.map(_._2))) |
|
121 |
} |
|
39740 | 122 |
|
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43282
diff
changeset
|
123 |
|
43431 | 124 |
private val tooltips: Map[String, String] = |
125 |
Map( |
|
45666 | 126 |
Isabelle_Markup.SORT -> "sort", |
127 |
Isabelle_Markup.TYP -> "type", |
|
128 |
Isabelle_Markup.TERM -> "term", |
|
129 |
Isabelle_Markup.PROP -> "proposition", |
|
130 |
Isabelle_Markup.TOKEN_RANGE -> "inner syntax token", |
|
131 |
Isabelle_Markup.FREE -> "free variable", |
|
132 |
Isabelle_Markup.SKOLEM -> "skolem variable", |
|
133 |
Isabelle_Markup.BOUND -> "bound variable", |
|
134 |
Isabelle_Markup.VAR -> "schematic variable", |
|
135 |
Isabelle_Markup.TFREE -> "free type variable", |
|
136 |
Isabelle_Markup.TVAR -> "schematic type variable", |
|
137 |
Isabelle_Markup.ML_SOURCE -> "ML source", |
|
138 |
Isabelle_Markup.DOC_SOURCE -> "document source") |
|
43431 | 139 |
|
46235
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
140 |
private val tooltip_elements = |
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
141 |
Set(Isabelle_Markup.ENTITY, Isabelle_Markup.TYPING, Isabelle_Markup.ML_TYPING) ++ |
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
142 |
tooltips.keys |
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
143 |
|
45445
41e641a870de
pass term positions into check phase, where resulting types are reported accordingly, and eventually shown as tooltips;
wenzelm
parents:
44866
diff
changeset
|
144 |
private def string_of_typing(kind: String, body: XML.Body): String = |
41e641a870de
pass term positions into check phase, where resulting types are reported accordingly, and eventually shown as tooltips;
wenzelm
parents:
44866
diff
changeset
|
145 |
Pretty.string_of(List(Pretty.block(XML.Text(kind) :: Pretty.Break(1) :: body)), |
41e641a870de
pass term positions into check phase, where resulting types are reported accordingly, and eventually shown as tooltips;
wenzelm
parents:
44866
diff
changeset
|
146 |
margin = Isabelle.Int_Property("tooltip-margin")) |
41e641a870de
pass term positions into check phase, where resulting types are reported accordingly, and eventually shown as tooltips;
wenzelm
parents:
44866
diff
changeset
|
147 |
|
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46166
diff
changeset
|
148 |
def tooltip(snapshot: Document.Snapshot, range: Text.Range): Option[String] = |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46166
diff
changeset
|
149 |
{ |
47540
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
150 |
def add(prev: Text.Info[List[(Boolean, String)]], r: Text.Range, p: (Boolean, String)) = |
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
151 |
if (prev.range == r) Text.Info(r, p :: prev.info) else Text.Info(r, List(p)) |
42302 | 152 |
|
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46166
diff
changeset
|
153 |
val tips = |
47540
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
154 |
snapshot.cumulate_markup[Text.Info[(List[(Boolean, String)])]]( |
46235
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
155 |
range, Text.Info(range, Nil), Some(tooltip_elements), |
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
156 |
{ |
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
157 |
case (prev, Text.Info(r, XML.Elem(Isabelle_Markup.Entity(kind, name), _))) => |
47540
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
158 |
add(prev, r, (true, kind + " " + quote(name))) |
46235
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
159 |
case (prev, Text.Info(r, XML.Elem(Markup(Isabelle_Markup.TYPING, _), body))) => |
47540
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
160 |
add(prev, r, (true, string_of_typing("::", body))) |
46235
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
161 |
case (prev, Text.Info(r, XML.Elem(Markup(Isabelle_Markup.ML_TYPING, _), body))) => |
47540
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
162 |
add(prev, r, (false, string_of_typing("ML:", body))) |
46235
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
163 |
case (prev, Text.Info(r, XML.Elem(Markup(name, _), _))) |
47540
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
164 |
if tooltips.isDefinedAt(name) => add(prev, r, (true, tooltips(name))) |
46235
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
165 |
}).toList.flatMap(_.info.info) |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46166
diff
changeset
|
166 |
|
47540
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
167 |
val all_tips = |
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
168 |
(tips.filter(_._1) ++ tips.filter(!_._1).lastOption.toList).map(_._2) |
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
169 |
if (all_tips.isEmpty) None else Some(cat_lines(all_tips)) |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46166
diff
changeset
|
170 |
} |
45460 | 171 |
|
46234 | 172 |
|
173 |
private val gutter_icons = Map( |
|
174 |
warning_pri -> Isabelle.load_icon("16x16/status/dialog-information.png"), |
|
175 |
legacy_pri -> Isabelle.load_icon("16x16/status/dialog-warning.png"), |
|
176 |
error_pri -> Isabelle.load_icon("16x16/status/dialog-error.png")) |
|
177 |
||
178 |
def gutter_message(snapshot: Document.Snapshot, range: Text.Range): Option[Icon] = |
|
179 |
{ |
|
180 |
val results = |
|
181 |
snapshot.cumulate_markup[Int](range, 0, |
|
182 |
Some(Set(Isabelle_Markup.WARNING, Isabelle_Markup.ERROR)), |
|
183 |
{ |
|
184 |
case (pri, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.WARNING, _), body))) => |
|
185 |
body match { |
|
186 |
case List(XML.Elem(Markup(Isabelle_Markup.LEGACY, _), _)) => pri max legacy_pri |
|
187 |
case _ => pri max warning_pri |
|
188 |
} |
|
189 |
case (pri, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.ERROR, _), _))) => |
|
190 |
pri max error_pri |
|
191 |
}) |
|
192 |
val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 } |
|
193 |
gutter_icons.get(pri) |
|
194 |
} |
|
195 |
||
196 |
||
197 |
private val squiggly_colors = Map( |
|
198 |
writeln_pri -> writeln_color, |
|
199 |
warning_pri -> warning_color, |
|
200 |
error_pri -> error_color) |
|
201 |
||
202 |
def squiggly_underline(snapshot: Document.Snapshot, range: Text.Range): Stream[Text.Info[Color]] = |
|
203 |
{ |
|
204 |
val results = |
|
205 |
snapshot.cumulate_markup[Int](range, 0, |
|
206 |
Some(Set(Isabelle_Markup.WRITELN, Isabelle_Markup.WARNING, Isabelle_Markup.ERROR)), |
|
207 |
{ |
|
208 |
case (pri, Text.Info(_, XML.Elem(Markup(name, _), _))) => |
|
209 |
name match { |
|
210 |
case Isabelle_Markup.WRITELN => pri max writeln_pri |
|
211 |
case Isabelle_Markup.WARNING => pri max warning_pri |
|
212 |
case Isabelle_Markup.ERROR => pri max error_pri |
|
213 |
case _ => pri |
|
214 |
} |
|
215 |
}) |
|
216 |
for { |
|
217 |
Text.Info(r, pri) <- results |
|
218 |
color <- squiggly_colors.get(pri) |
|
219 |
} yield Text.Info(r, color) |
|
220 |
} |
|
221 |
||
42302 | 222 |
|
46234 | 223 |
def background1(snapshot: Document.Snapshot, range: Text.Range): Stream[Text.Info[Color]] = |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46166
diff
changeset
|
224 |
{ |
46234 | 225 |
if (snapshot.is_outdated) Stream(Text.Info(range, outdated_color)) |
226 |
else |
|
227 |
for { |
|
228 |
Text.Info(r, result) <- |
|
229 |
snapshot.cumulate_markup[(Option[Protocol.Status], Option[Color])]( |
|
230 |
range, (Some(Protocol.Status.init), None), |
|
231 |
Some(Protocol.command_status_markup + Isabelle_Markup.BAD + Isabelle_Markup.HILITE), |
|
232 |
{ |
|
233 |
case (((Some(status), color), Text.Info(_, XML.Elem(markup, _)))) |
|
234 |
if (Protocol.command_status_markup(markup.name)) => |
|
235 |
(Some(Protocol.command_status(status, markup)), color) |
|
236 |
case (_, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.BAD, _), _))) => |
|
237 |
(None, Some(bad_color)) |
|
238 |
case (_, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.HILITE, _), _))) => |
|
239 |
(None, Some(hilite_color)) |
|
240 |
}) |
|
241 |
color <- |
|
242 |
(result match { |
|
243 |
case (Some(status), _) => |
|
244 |
if (status.is_running) Some(running1_color) |
|
245 |
else if (status.is_unprocessed) Some(unprocessed1_color) |
|
246 |
else None |
|
247 |
case (_, opt_color) => opt_color |
|
248 |
}) |
|
249 |
} yield Text.Info(r, color) |
|
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46166
diff
changeset
|
250 |
} |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
251 |
|
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
252 |
|
46234 | 253 |
def background2(snapshot: Document.Snapshot, range: Text.Range): Stream[Text.Info[Color]] = |
254 |
snapshot.select_markup(range, |
|
255 |
Some(Set(Isabelle_Markup.TOKEN_RANGE)), |
|
256 |
{ |
|
257 |
case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.TOKEN_RANGE, _), _)) => light_color |
|
258 |
}) |
|
259 |
||
260 |
||
261 |
def foreground(snapshot: Document.Snapshot, range: Text.Range): Stream[Text.Info[Color]] = |
|
262 |
snapshot.select_markup(range, |
|
263 |
Some(Set(Isabelle_Markup.STRING, Isabelle_Markup.ALTSTRING, Isabelle_Markup.VERBATIM)), |
|
264 |
{ |
|
265 |
case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.STRING, _), _)) => quoted_color |
|
266 |
case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.ALTSTRING, _), _)) => quoted_color |
|
267 |
case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.VERBATIM, _), _)) => quoted_color |
|
268 |
}) |
|
269 |
||
270 |
||
271 |
private val text_colors: Map[String, Color] = |
|
272 |
Map( |
|
273 |
Isabelle_Markup.STRING -> get_color("black"), |
|
274 |
Isabelle_Markup.ALTSTRING -> get_color("black"), |
|
275 |
Isabelle_Markup.VERBATIM -> get_color("black"), |
|
276 |
Isabelle_Markup.LITERAL -> keyword1_color, |
|
277 |
Isabelle_Markup.DELIMITER -> get_color("black"), |
|
278 |
Isabelle_Markup.TFREE -> get_color("#A020F0"), |
|
279 |
Isabelle_Markup.TVAR -> get_color("#A020F0"), |
|
280 |
Isabelle_Markup.FREE -> get_color("blue"), |
|
281 |
Isabelle_Markup.SKOLEM -> get_color("#D2691E"), |
|
282 |
Isabelle_Markup.BOUND -> get_color("green"), |
|
283 |
Isabelle_Markup.VAR -> get_color("#00009B"), |
|
284 |
Isabelle_Markup.INNER_STRING -> get_color("#D2691E"), |
|
285 |
Isabelle_Markup.INNER_COMMENT -> get_color("#8B0000"), |
|
286 |
Isabelle_Markup.DYNAMIC_FACT -> get_color("#7BA428"), |
|
287 |
Isabelle_Markup.ML_KEYWORD -> keyword1_color, |
|
288 |
Isabelle_Markup.ML_DELIMITER -> get_color("black"), |
|
289 |
Isabelle_Markup.ML_NUMERAL -> get_color("red"), |
|
290 |
Isabelle_Markup.ML_CHAR -> get_color("#D2691E"), |
|
291 |
Isabelle_Markup.ML_STRING -> get_color("#D2691E"), |
|
292 |
Isabelle_Markup.ML_COMMENT -> get_color("#8B0000"), |
|
293 |
Isabelle_Markup.ANTIQ -> get_color("blue")) |
|
294 |
||
295 |
private val text_color_elements = Set.empty[String] ++ text_colors.keys |
|
296 |
||
297 |
def text_color(snapshot: Document.Snapshot, range: Text.Range, color: Color) |
|
298 |
: Stream[Text.Info[Color]] = |
|
299 |
snapshot.cumulate_markup(range, color, Some(text_color_elements), |
|
300 |
{ |
|
301 |
case (_, Text.Info(_, XML.Elem(Markup(m, _), _))) |
|
302 |
if text_colors.isDefinedAt(m) => text_colors(m) |
|
303 |
}) |
|
304 |
||
305 |
||
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
306 |
/* token markup -- text styles */ |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
307 |
|
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
308 |
private val command_style: Map[String, Byte] = |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
309 |
{ |
43414 | 310 |
import JEditToken._ |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
311 |
Map[String, Byte]( |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
312 |
Keyword.THY_END -> KEYWORD2, |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
313 |
Keyword.THY_SCRIPT -> LABEL, |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
314 |
Keyword.PRF_SCRIPT -> LABEL, |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
315 |
Keyword.PRF_ASM -> KEYWORD3, |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
316 |
Keyword.PRF_ASM_GOAL -> KEYWORD3 |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
317 |
).withDefaultValue(KEYWORD1) |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
318 |
} |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
319 |
|
43414 | 320 |
private val token_style: Map[Token.Kind.Value, Byte] = |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
321 |
{ |
43414 | 322 |
import JEditToken._ |
323 |
Map[Token.Kind.Value, Byte]( |
|
324 |
Token.Kind.KEYWORD -> KEYWORD2, |
|
325 |
Token.Kind.IDENT -> NULL, |
|
326 |
Token.Kind.LONG_IDENT -> NULL, |
|
327 |
Token.Kind.SYM_IDENT -> NULL, |
|
328 |
Token.Kind.VAR -> NULL, |
|
329 |
Token.Kind.TYPE_IDENT -> NULL, |
|
330 |
Token.Kind.TYPE_VAR -> NULL, |
|
331 |
Token.Kind.NAT -> NULL, |
|
332 |
Token.Kind.FLOAT -> NULL, |
|
43431 | 333 |
Token.Kind.STRING -> LITERAL1, |
334 |
Token.Kind.ALT_STRING -> LITERAL2, |
|
43414 | 335 |
Token.Kind.VERBATIM -> COMMENT3, |
336 |
Token.Kind.SPACE -> NULL, |
|
337 |
Token.Kind.COMMENT -> COMMENT1, |
|
48754
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
wenzelm
parents:
48751
diff
changeset
|
338 |
Token.Kind.ERROR -> INVALID |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
339 |
).withDefaultValue(NULL) |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
340 |
} |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
341 |
|
43414 | 342 |
def token_markup(syntax: Outer_Syntax, token: Token): Byte = |
43430
1ed88ddf1268
more uniform treatment of "keyword" vs. "operator";
wenzelm
parents:
43418
diff
changeset
|
343 |
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
|
344 |
else if (token.is_operator) JEditToken.OPERATOR |
43414 | 345 |
else token_style(token.kind) |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
346 |
} |