src/Tools/jEdit/src/isabelle.scala
author wenzelm
Tue Mar 26 11:26:13 2013 +0100 (2013-03-26)
changeset 51533 3f6280aedbcc
parent 50775 8c1cda8ad833
child 52815 eaad5fe7bb1b
permissions -rw-r--r--
dockable window for timing information;
     1 /*  Title:      Tools/jEdit/src/isabelle.scala
     2     Author:     Makarius
     3 
     4 Convenience operations for Isabelle/jEdit.
     5 */
     6 
     7 package isabelle.jedit
     8 
     9 
    10 import isabelle._
    11 
    12 import org.gjt.sp.jedit.{jEdit, View, Buffer}
    13 import org.gjt.sp.jedit.textarea.JEditTextArea
    14 import org.gjt.sp.jedit.gui.DockableWindowManager
    15 
    16 
    17 object Isabelle
    18 {
    19   /* dockable windows */
    20 
    21   private def wm(view: View): DockableWindowManager = view.getDockableWindowManager
    22 
    23   def docked_theories(view: View): Option[Theories_Dockable] =
    24     wm(view).getDockableWindow("isabelle-theories") match {
    25       case dockable: Theories_Dockable => Some(dockable)
    26       case _ => None
    27     }
    28 
    29   def docked_timing(view: View): Option[Timing_Dockable] =
    30     wm(view).getDockableWindow("isabelle-timing") match {
    31       case dockable: Timing_Dockable => Some(dockable)
    32       case _ => None
    33     }
    34 
    35   def docked_output(view: View): Option[Output_Dockable] =
    36     wm(view).getDockableWindow("isabelle-output") match {
    37       case dockable: Output_Dockable => Some(dockable)
    38       case _ => None
    39     }
    40 
    41   def docked_raw_output(view: View): Option[Raw_Output_Dockable] =
    42     wm(view).getDockableWindow("isabelle-raw-output") match {
    43       case dockable: Raw_Output_Dockable => Some(dockable)
    44       case _ => None
    45     }
    46 
    47   def docked_protocol(view: View): Option[Protocol_Dockable] =
    48     wm(view).getDockableWindow("isabelle-protocol") match {
    49       case dockable: Protocol_Dockable => Some(dockable)
    50       case _ => None
    51     }
    52 
    53   def docked_monitor(view: View): Option[Monitor_Dockable] =
    54     wm(view).getDockableWindow("isabelle-monitor") match {
    55       case dockable: Monitor_Dockable => Some(dockable)
    56       case _ => None
    57     }
    58 
    59 
    60   /* font size */
    61 
    62   def change_font_size(view: View, change: Int => Int)
    63   {
    64     val size = change(jEdit.getIntegerProperty("view.fontsize", 16)) max 5 min 250
    65     jEdit.setIntegerProperty("view.fontsize", size)
    66     jEdit.propertiesChanged()
    67     jEdit.saveSettings()
    68     view.getStatus.setMessageAndClear("Text font size: " + size)
    69   }
    70 
    71   def increase_font_size(view: View): Unit = change_font_size(view, i => i + ((i / 10) max 1))
    72   def decrease_font_size(view: View): Unit = change_font_size(view, i => i - ((i / 10) max 1))
    73 
    74 
    75   /* structured insert */
    76 
    77   def insert_line_padding(text_area: JEditTextArea, text: String)
    78   {
    79     val buffer = text_area.getBuffer
    80     JEdit_Lib.buffer_edit(buffer) {
    81       val text1 =
    82         if (text_area.getSelectionCount == 0) {
    83           def pad(range: Text.Range): String =
    84             if (JEdit_Lib.try_get_text(buffer, range) == Some("\n")) "" else "\n"
    85 
    86           val caret = JEdit_Lib.point_range(buffer, text_area.getCaretPosition)
    87           val before_caret = JEdit_Lib.point_range(buffer, caret.start - 1)
    88           pad(before_caret) + text + pad(caret)
    89         }
    90         else text
    91       text_area.setSelectedText(text1)
    92     }
    93   }
    94 
    95 
    96   /* control styles */
    97 
    98   def control_sub(text_area: JEditTextArea)
    99   { Token_Markup.edit_control_style(text_area, Symbol.sub_decoded) }
   100 
   101   def control_sup(text_area: JEditTextArea)
   102   { Token_Markup.edit_control_style(text_area, Symbol.sup_decoded) }
   103 
   104   def control_isub(text_area: JEditTextArea)
   105   { Token_Markup.edit_control_style(text_area, Symbol.isub_decoded) }
   106 
   107   def control_isup(text_area: JEditTextArea)
   108   { Token_Markup.edit_control_style(text_area, Symbol.isup_decoded) }
   109 
   110   def control_bold(text_area: JEditTextArea)
   111   { Token_Markup.edit_control_style(text_area, Symbol.bold_decoded) }
   112 
   113   def control_reset(text_area: JEditTextArea)
   114   { Token_Markup.edit_control_style(text_area, "") }
   115 
   116 
   117   /* block styles */
   118 
   119   private def enclose_input(text_area: JEditTextArea, s1: String, s2: String)
   120   {
   121     s1.foreach(text_area.userInput(_))
   122     s2.foreach(text_area.userInput(_))
   123     s2.foreach(_ => text_area.goToPrevCharacter(false))
   124   }
   125 
   126   def input_bsub(text_area: JEditTextArea)
   127   { enclose_input(text_area, Symbol.bsub_decoded, Symbol.esub_decoded) }
   128 
   129   def input_bsup(text_area: JEditTextArea)
   130   { enclose_input(text_area, Symbol.bsup_decoded, Symbol.esup_decoded) }
   131 }
   132