src/Tools/jEdit/src/plugin.scala
changeset 43443 5d9693c2337e
parent 43390 7ee98a3802af
child 43449 591598bc52bc
equal deleted inserted replaced
43442:e1fff67b23ac 43443:5d9693c2337e
    17 
    17 
    18 import org.gjt.sp.jedit.{jEdit, GUIUtilities, EBMessage, EBPlugin,
    18 import org.gjt.sp.jedit.{jEdit, GUIUtilities, EBMessage, EBPlugin,
    19   Buffer, EditPane, ServiceManager, View}
    19   Buffer, EditPane, ServiceManager, View}
    20 import org.gjt.sp.jedit.buffer.JEditBuffer
    20 import org.gjt.sp.jedit.buffer.JEditBuffer
    21 import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea}
    21 import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea}
       
    22 import org.gjt.sp.jedit.syntax.{Token => JEditToken}
    22 import org.gjt.sp.jedit.msg.{EditorStarted, BufferUpdate, EditPaneUpdate, PropertiesChanged}
    23 import org.gjt.sp.jedit.msg.{EditorStarted, BufferUpdate, EditPaneUpdate, PropertiesChanged}
    23 import org.gjt.sp.jedit.gui.DockableWindowManager
    24 import org.gjt.sp.jedit.gui.DockableWindowManager
    24 
    25 
       
    26 import org.gjt.sp.util.SyntaxUtilities
    25 import org.gjt.sp.util.Log
    27 import org.gjt.sp.util.Log
    26 
    28 
    27 import scala.actors.Actor
    29 import scala.actors.Actor
    28 import Actor._
    30 import Actor._
    29 
    31 
    30 
    32 
    31 object Isabelle
    33 object Isabelle
    32 {
    34 {
    33   /* plugin instance */
    35   /* plugin instance */
    34 
    36 
       
    37   var plugin: Plugin = null
    35   var system: Isabelle_System = null
    38   var system: Isabelle_System = null
    36   var session: Session = null
    39   var session: Session = null
       
    40 
       
    41 
       
    42   /* extended syntax styles */
       
    43 
       
    44   def extended_styles: Boolean = plugin != null && plugin._extended_styles
    37 
    45 
    38 
    46 
    39   /* properties */
    47   /* properties */
    40 
    48 
    41   val OPTION_PREFIX = "options.isabelle."
    49   val OPTION_PREFIX = "options.isabelle."
   254 }
   262 }
   255 
   263 
   256 
   264 
   257 class Plugin extends EBPlugin
   265 class Plugin extends EBPlugin
   258 {
   266 {
       
   267   /* extended syntax styles */
       
   268 
       
   269   @volatile var _extended_styles: Boolean = false
       
   270 
       
   271   private def check_extended_styles()
       
   272   {
       
   273     val family = jEdit.getProperty("view.font")
       
   274     val size = jEdit.getIntegerProperty("view.fontsize", 12)
       
   275     val styles = SyntaxUtilities.loadStyles(family, size)
       
   276     _extended_styles = (styles.length == JEditToken.ID_COUNT * 3 + 1)
       
   277   }
       
   278 
       
   279 
   259   /* session management */
   280   /* session management */
   260 
   281 
   261   private def init_model(buffer: Buffer)
   282   private def init_model(buffer: Buffer)
   262   {
   283   {
   263     Isabelle.swing_buffer_lock(buffer) {
   284     Isabelle.swing_buffer_lock(buffer) {
   344   override def handleMessage(message: EBMessage)
   365   override def handleMessage(message: EBMessage)
   345   {
   366   {
   346     message match {
   367     message match {
   347       case msg: EditorStarted =>
   368       case msg: EditorStarted =>
   348       Isabelle.check_jvm()
   369       Isabelle.check_jvm()
       
   370       check_extended_styles()
   349       if (Isabelle.Boolean_Property("auto-start")) Isabelle.start_session()
   371       if (Isabelle.Boolean_Property("auto-start")) Isabelle.start_session()
   350 
   372 
   351       case msg: BufferUpdate
   373       case msg: BufferUpdate
   352       if msg.getWhat == BufferUpdate.PROPERTIES_CHANGED =>
   374       if msg.getWhat == BufferUpdate.PROPERTIES_CHANGED =>
   353 
   375 
   380     }
   402     }
   381   }
   403   }
   382 
   404 
   383   override def start()
   405   override def start()
   384   {
   406   {
       
   407     Isabelle.plugin = this
   385     Isabelle.setup_tooltips()
   408     Isabelle.setup_tooltips()
   386     Isabelle.system = new Isabelle_System
   409     Isabelle.system = new Isabelle_System
   387     Isabelle.system.install_fonts()
   410     Isabelle.system.install_fonts()
   388     Isabelle.session = new Session(Isabelle.system)
   411     Isabelle.session = new Session(Isabelle.system)
   389     Isabelle.session.phase_changed += session_manager
   412     Isabelle.session.phase_changed += session_manager