src/Tools/jEdit/src/rendering.scala
changeset 55651 fa42cf3fe79b
parent 55649 1532ab0dc67b
child 55666 cc350eb1087e
equal deleted inserted replaced
55650:349afd0fa0c4 55651:fa42cf3fe79b
   272   /* completion context */
   272   /* completion context */
   273 
   273 
   274   def completion_context(caret: Text.Offset): Option[Completion.Context] =
   274   def completion_context(caret: Text.Offset): Option[Completion.Context] =
   275     if (caret > 0) {
   275     if (caret > 0) {
   276       val result =
   276       val result =
   277         snapshot.select_markup(Text.Range(caret - 1, caret + 1), Rendering.completion_elements, _ =>
   277         snapshot.select(Text.Range(caret - 1, caret + 1), Rendering.completion_elements, _ =>
   278           {
   278           {
   279             case Text.Info(_, elem)
   279             case Text.Info(_, elem)
   280             if elem.name == Markup.ML_STRING || elem.name == Markup.ML_COMMENT =>
   280             if elem.name == Markup.ML_STRING || elem.name == Markup.ML_COMMENT =>
   281               Some(Completion.Context(Markup.Language.ML, true))
   281               Some(Completion.Context(Markup.Language.ML, true))
   282             case Text.Info(_, XML.Elem(Markup.Language(language, symbols), _)) =>
   282             case Text.Info(_, XML.Elem(Markup.Language(language, symbols), _)) =>
   299   def overview_color(range: Text.Range): Option[Color] =
   299   def overview_color(range: Text.Range): Option[Color] =
   300   {
   300   {
   301     if (snapshot.is_outdated) None
   301     if (snapshot.is_outdated) None
   302     else {
   302     else {
   303       val results =
   303       val results =
   304         snapshot.cumulate_status[(Protocol.Status, Int)](
   304         snapshot.cumulate[(Protocol.Status, Int)](
   305           range, (Protocol.Status.init, 0), Protocol.status_elements, _ =>
   305           range, (Protocol.Status.init, 0), Protocol.status_elements, _ =>
   306           {
   306           {
   307             case ((status, pri), Text.Info(_, elem)) =>
   307             case ((status, pri), Text.Info(_, elem)) =>
   308               if (Protocol.command_status_elements(elem.name))
   308               if (Protocol.command_status_elements(elem.name))
   309                 Some((Protocol.command_status(status, elem.markup), pri))
   309                 Some((Protocol.command_status(status, elem.markup), pri))
   310               else
   310               else
   311                 Some((status, pri max Rendering.message_pri(elem.name)))
   311                 Some((status, pri max Rendering.message_pri(elem.name)))
   312           })
   312           }, status = true)
   313       if (results.isEmpty) None
   313       if (results.isEmpty) None
   314       else {
   314       else {
   315         val (status, pri) =
   315         val (status, pri) =
   316           ((Protocol.Status.init, 0) /: results) {
   316           ((Protocol.Status.init, 0) /: results) {
   317             case ((s1, p1), Text.Info(_, (s2, p2))) => (s1 + s2, p1 max p2) }
   317             case ((s1, p1), Text.Info(_, (s2, p2))) => (s1 + s2, p1 max p2) }
   329 
   329 
   330   /* highlighted area */
   330   /* highlighted area */
   331 
   331 
   332   def highlight(range: Text.Range): Option[Text.Info[Color]] =
   332   def highlight(range: Text.Range): Option[Text.Info[Color]] =
   333   {
   333   {
   334     snapshot.select_markup(range, Rendering.highlight_elements, _ =>
   334     snapshot.select(range, Rendering.highlight_elements, _ =>
   335       {
   335       {
   336         case info => Some(Text.Info(snapshot.convert(info.range), highlight_color))
   336         case info => Some(Text.Info(snapshot.convert(info.range), highlight_color))
   337       }) match { case Text.Info(_, info) :: _ => Some(info) case _ => None }
   337       }) match { case Text.Info(_, info) :: _ => Some(info) case _ => None }
   338   }
   338   }
   339 
   339 
   354       case None => None
   354       case None => None
   355     }
   355     }
   356 
   356 
   357   def hyperlink(range: Text.Range): Option[Text.Info[PIDE.editor.Hyperlink]] =
   357   def hyperlink(range: Text.Range): Option[Text.Info[PIDE.editor.Hyperlink]] =
   358   {
   358   {
   359     snapshot.cumulate_markup[Vector[Text.Info[PIDE.editor.Hyperlink]]](
   359     snapshot.cumulate[Vector[Text.Info[PIDE.editor.Hyperlink]]](
   360       range, Vector.empty, Rendering.hyperlink_elements, _ =>
   360       range, Vector.empty, Rendering.hyperlink_elements, _ =>
   361         {
   361         {
   362           case (links, Text.Info(info_range, XML.Elem(Markup.Path(name), _)))
   362           case (links, Text.Info(info_range, XML.Elem(Markup.Path(name), _)))
   363           if Path.is_ok(name) =>
   363           if Path.is_ok(name) =>
   364             val jedit_file = PIDE.thy_load.append(snapshot.node_name.master_dir, Path.explode(name))
   364             val jedit_file = PIDE.thy_load.append(snapshot.node_name.master_dir, Path.explode(name))
   398 
   398 
   399 
   399 
   400   /* active elements */
   400   /* active elements */
   401 
   401 
   402   def active(range: Text.Range): Option[Text.Info[XML.Elem]] =
   402   def active(range: Text.Range): Option[Text.Info[XML.Elem]] =
   403     snapshot.select_markup(range, Rendering.active_elements, command_state =>
   403     snapshot.select(range, Rendering.active_elements, command_state =>
   404       {
   404       {
   405         case Text.Info(info_range, elem) =>
   405         case Text.Info(info_range, elem) =>
   406           if (elem.name == Markup.DIALOG) {
   406           if (elem.name == Markup.DIALOG) {
   407             elem match {
   407             elem match {
   408               case Protocol.Dialog(_, serial, _)
   408               case Protocol.Dialog(_, serial, _)
   416 
   416 
   417 
   417 
   418   def command_results(range: Text.Range): Command.Results =
   418   def command_results(range: Text.Range): Command.Results =
   419   {
   419   {
   420     val results =
   420     val results =
   421       snapshot.select_markup[Command.Results](range, _ => true, command_state =>
   421       snapshot.select[Command.Results](range, _ => true, command_state =>
   422         { case _ => Some(command_state.results) }).map(_.info)
   422         { case _ => Some(command_state.results) }).map(_.info)
   423     (Command.Results.empty /: results)(_ ++ _)
   423     (Command.Results.empty /: results)(_ ++ _)
   424   }
   424   }
   425 
   425 
   426 
   426 
   427   /* tooltip messages */
   427   /* tooltip messages */
   428 
   428 
   429   def tooltip_message(range: Text.Range): Option[Text.Info[XML.Body]] =
   429   def tooltip_message(range: Text.Range): Option[Text.Info[XML.Body]] =
   430   {
   430   {
   431     val results =
   431     val results =
   432       snapshot.cumulate_markup[List[Text.Info[Command.Results.Entry]]](
   432       snapshot.cumulate[List[Text.Info[Command.Results.Entry]]](
   433         range, Nil, Rendering.tooltip_message_elements, _ =>
   433         range, Nil, Rendering.tooltip_message_elements, _ =>
   434         {
   434         {
   435           case (msgs, Text.Info(info_range,
   435           case (msgs, Text.Info(info_range,
   436             XML.Elem(Markup(name, props @ Markup.Serial(serial)), body)))
   436             XML.Elem(Markup(name, props @ Markup.Serial(serial)), body)))
   437           if name == Markup.WRITELN || name == Markup.WARNING || name == Markup.ERROR =>
   437           if name == Markup.WRITELN || name == Markup.WARNING || name == Markup.ERROR =>
   473         Text.Info(r, (t, info :+ p))
   473         Text.Info(r, (t, info :+ p))
   474       else Text.Info(r, (t, Vector(p)))
   474       else Text.Info(r, (t, Vector(p)))
   475     }
   475     }
   476 
   476 
   477     val results =
   477     val results =
   478       snapshot.cumulate_markup[Text.Info[(Timing, Vector[(Boolean, XML.Tree)])]](
   478       snapshot.cumulate[Text.Info[(Timing, Vector[(Boolean, XML.Tree)])]](
   479         range, Text.Info(range, (Timing.zero, Vector.empty)), Rendering.tooltip_elements, _ =>
   479         range, Text.Info(range, (Timing.zero, Vector.empty)), Rendering.tooltip_elements, _ =>
   480         {
   480         {
   481           case (Text.Info(r, (t1, info)), Text.Info(_, XML.Elem(Markup.Timing(t2), _))) =>
   481           case (Text.Info(r, (t1, info)), Text.Info(_, XML.Elem(Markup.Timing(t2), _))) =>
   482             Some(Text.Info(r, (t1 + t2, info)))
   482             Some(Text.Info(r, (t1 + t2, info)))
   483           case (prev, Text.Info(r, XML.Elem(Markup.Entity(kind, name), _))) =>
   483           case (prev, Text.Info(r, XML.Elem(Markup.Entity(kind, name), _))) =>
   531     Rendering.error_pri -> JEdit_Lib.load_icon(options.string("gutter_error_icon")))
   531     Rendering.error_pri -> JEdit_Lib.load_icon(options.string("gutter_error_icon")))
   532 
   532 
   533   def gutter_message(range: Text.Range): Option[Icon] =
   533   def gutter_message(range: Text.Range): Option[Icon] =
   534   {
   534   {
   535     val results =
   535     val results =
   536       snapshot.cumulate_markup[Int](range, 0, Rendering.gutter_elements, _ =>
   536       snapshot.cumulate[Int](range, 0, Rendering.gutter_elements, _ =>
   537         {
   537         {
   538           case (pri, Text.Info(_, XML.Elem(Markup(Markup.WRITELN, _),
   538           case (pri, Text.Info(_, XML.Elem(Markup(Markup.WRITELN, _),
   539               List(XML.Elem(Markup(Markup.INFORMATION, _), _))))) =>
   539               List(XML.Elem(Markup(Markup.INFORMATION, _), _))))) =>
   540             Some(pri max Rendering.information_pri)
   540             Some(pri max Rendering.information_pri)
   541           case (pri, Text.Info(_, XML.Elem(Markup(Markup.WARNING, _), body))) =>
   541           case (pri, Text.Info(_, XML.Elem(Markup(Markup.WARNING, _), body))) =>
   563     Rendering.error_pri -> error_color)
   563     Rendering.error_pri -> error_color)
   564 
   564 
   565   def squiggly_underline(range: Text.Range): List[Text.Info[Color]] =
   565   def squiggly_underline(range: Text.Range): List[Text.Info[Color]] =
   566   {
   566   {
   567     val results =
   567     val results =
   568       snapshot.cumulate_markup[Int](range, 0, Rendering.squiggly_elements, _ =>
   568       snapshot.cumulate[Int](range, 0, Rendering.squiggly_elements, _ =>
   569         {
   569         {
   570           case (pri, Text.Info(_, elem)) =>
   570           case (pri, Text.Info(_, elem)) =>
   571             if (Protocol.is_information(elem))
   571             if (Protocol.is_information(elem))
   572               Some(pri max Rendering.information_pri)
   572               Some(pri max Rendering.information_pri)
   573             else
   573             else
   590     Rendering.error_pri -> error_message_color)
   590     Rendering.error_pri -> error_message_color)
   591 
   591 
   592   def line_background(range: Text.Range): Option[(Color, Boolean)] =
   592   def line_background(range: Text.Range): Option[(Color, Boolean)] =
   593   {
   593   {
   594     val results =
   594     val results =
   595       snapshot.cumulate_markup[Int](range, 0, Rendering.line_background_elements, _ =>
   595       snapshot.cumulate[Int](range, 0, Rendering.line_background_elements, _ =>
   596         {
   596         {
   597           case (pri, Text.Info(_, elem)) =>
   597           case (pri, Text.Info(_, elem)) =>
   598             if (elem.name == Markup.INFORMATION)
   598             if (elem.name == Markup.INFORMATION)
   599               Some(pri max Rendering.information_pri)
   599               Some(pri max Rendering.information_pri)
   600             else
   600             else
   602         })
   602         })
   603     val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 }
   603     val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 }
   604 
   604 
   605     val is_separator =
   605     val is_separator =
   606       pri > 0 &&
   606       pri > 0 &&
   607       snapshot.cumulate_markup[Boolean](range, false, Rendering.separator_elements, _ =>
   607       snapshot.cumulate[Boolean](range, false, Rendering.separator_elements, _ =>
   608         {
   608         {
   609           case _ => Some(true)
   609           case _ => Some(true)
   610         }).exists(_.info)
   610         }).exists(_.info)
   611 
   611 
   612     message_colors.get(pri).map((_, is_separator))
   612     message_colors.get(pri).map((_, is_separator))
   622   {
   622   {
   623     if (snapshot.is_outdated) List(Text.Info(range, outdated_color))
   623     if (snapshot.is_outdated) List(Text.Info(range, outdated_color))
   624     else
   624     else
   625       for {
   625       for {
   626         Text.Info(r, result) <-
   626         Text.Info(r, result) <-
   627           snapshot.cumulate_markup[(Option[Protocol.Status], Option[Color])](
   627           snapshot.cumulate[(Option[Protocol.Status], Option[Color])](
   628             range, (Some(Protocol.Status.init), None), Rendering.background1_elements,
   628             range, (Some(Protocol.Status.init), None), Rendering.background1_elements,
   629             command_state =>
   629             command_state =>
   630               {
   630               {
   631                 case (((Some(status), color), Text.Info(_, XML.Elem(markup, _))))
   631                 case (((Some(status), color), Text.Info(_, XML.Elem(markup, _))))
   632                 if (Protocol.command_status_elements(markup.name)) =>
   632                 if (Protocol.command_status_elements(markup.name)) =>
   656           })
   656           })
   657       } yield Text.Info(r, color)
   657       } yield Text.Info(r, color)
   658   }
   658   }
   659 
   659 
   660   def background2(range: Text.Range): List[Text.Info[Color]] =
   660   def background2(range: Text.Range): List[Text.Info[Color]] =
   661     snapshot.select_markup(range, Rendering.background2_elements, _ => _ => Some(light_color))
   661     snapshot.select(range, Rendering.background2_elements, _ => _ => Some(light_color))
   662 
   662 
   663 
   663 
   664   /* text foreground */
   664   /* text foreground */
   665 
   665 
   666   def foreground(range: Text.Range): List[Text.Info[Color]] =
   666   def foreground(range: Text.Range): List[Text.Info[Color]] =
   667     snapshot.select_markup(range, Rendering.foreground_elements, _ =>
   667     snapshot.select(range, Rendering.foreground_elements, _ =>
   668       {
   668       {
   669         case Text.Info(_, elem) =>
   669         case Text.Info(_, elem) =>
   670           if (elem.name == Markup.ANTIQUOTED) Some(antiquoted_color) else Some(quoted_color)
   670           if (elem.name == Markup.ANTIQUOTED) Some(antiquoted_color) else Some(quoted_color)
   671       })
   671       })
   672 
   672 
   706 
   706 
   707   def text_color(range: Text.Range, color: Color): List[Text.Info[Color]] =
   707   def text_color(range: Text.Range, color: Color): List[Text.Info[Color]] =
   708   {
   708   {
   709     if (color == Token_Markup.hidden_color) List(Text.Info(range, color))
   709     if (color == Token_Markup.hidden_color) List(Text.Info(range, color))
   710     else
   710     else
   711       snapshot.cumulate_markup(range, color, text_color_elements, _ =>
   711       snapshot.cumulate(range, color, text_color_elements, _ =>
   712         {
   712         {
   713           case (_, Text.Info(_, elem)) => text_colors.get(elem.name)
   713           case (_, Text.Info(_, elem)) => text_colors.get(elem.name)
   714         })
   714         })
   715   }
   715   }
   716 
   716 
   717 
   717 
   718   /* virtual bullets */
   718   /* virtual bullets */
   719 
   719 
   720   def bullet(range: Text.Range): List[Text.Info[Color]] =
   720   def bullet(range: Text.Range): List[Text.Info[Color]] =
   721     snapshot.select_markup(range, Rendering.bullet_elements, _ => _ => Some(bullet_color))
   721     snapshot.select(range, Rendering.bullet_elements, _ => _ => Some(bullet_color))
   722 
   722 
   723 
   723 
   724   /* text folds */
   724   /* text folds */
   725 
   725 
   726   def fold_depth(range: Text.Range): List[Text.Info[Int]] =
   726   def fold_depth(range: Text.Range): List[Text.Info[Int]] =
   727     snapshot.cumulate_markup[Int](range, 0, Rendering.fold_depth_elements, _ =>
   727     snapshot.cumulate[Int](range, 0, Rendering.fold_depth_elements, _ =>
   728       {
   728       {
   729         case (depth, _) => Some(depth + 1)
   729         case (depth, _) => Some(depth + 1)
   730       })
   730       })
   731 }
   731 }