src/Tools/jEdit/src/plugin.scala
changeset 44573 51f8895b9ad9
parent 44434 3b9b684bfa6f
child 44574 24444588fddd
equal deleted inserted replaced
44572:63d460db4919 44573:51f8895b9ad9
    10 import isabelle._
    10 import isabelle._
    11 
    11 
    12 import java.lang.System
    12 import java.lang.System
    13 import java.io.{File, FileInputStream, IOException}
    13 import java.io.{File, FileInputStream, IOException}
    14 import java.awt.Font
    14 import java.awt.Font
       
    15 import javax.swing.JOptionPane
    15 
    16 
    16 import scala.collection.mutable
    17 import scala.collection.mutable
    17 import scala.swing.ComboBox
    18 import scala.swing.ComboBox
    18 
    19 
    19 import org.gjt.sp.jedit.{jEdit, GUIUtilities, EBMessage, EBPlugin,
    20 import org.gjt.sp.jedit.{jEdit, GUIUtilities, EBMessage, EBPlugin,
   373   }
   374   }
   374 
   375 
   375 
   376 
   376   /* session manager */
   377   /* session manager */
   377 
   378 
       
   379   private lazy val delay_load =
       
   380     Swing_Thread.delay_last(Isabelle.session.load_delay) {
       
   381       def ask(files: List[String]): Boolean = Swing_Thread.now
       
   382         {
       
   383           val file_list = new scala.swing.TextArea(files.mkString("\n"))
       
   384           file_list.editable = false
       
   385           val answer =
       
   386             Library.confirm_dialog(jEdit.getActiveView(),
       
   387             "Auto loading of required files",
       
   388             JOptionPane.YES_NO_OPTION,
       
   389             "The following files are required to resolve theory imports.",
       
   390             "Reload now?",
       
   391             file_list)
       
   392           answer == 0
       
   393         }
       
   394 
       
   395       Isabelle.session.check_loaded_files(ask _)
       
   396     }
       
   397 
   378   private val session_manager = actor {
   398   private val session_manager = actor {
   379     loop {
   399     loop {
   380       react {
   400       react {
   381         case phase: Session.Phase =>
   401         case phase: Session.Phase =>
   382           phase match {
   402           phase match {
   385                 val text = new scala.swing.TextArea(Isabelle.session.syslog())
   405                 val text = new scala.swing.TextArea(Isabelle.session.syslog())
   386                 text.editable = false
   406                 text.editable = false
   387                 Library.error_dialog(jEdit.getActiveView, "Failed to start Isabelle process", text)
   407                 Library.error_dialog(jEdit.getActiveView, "Failed to start Isabelle process", text)
   388               }
   408               }
   389 
   409 
   390             case Session.Ready => Isabelle.jedit_buffers.foreach(Isabelle.init_model)
   410             case Session.Ready =>
       
   411               Isabelle.jedit_buffers.foreach(Isabelle.init_model)
       
   412               delay_load()
       
   413 
   391             case Session.Shutdown => Isabelle.jedit_buffers.foreach(Isabelle.exit_model)
   414             case Session.Shutdown => Isabelle.jedit_buffers.foreach(Isabelle.exit_model)
   392             case _ =>
   415             case _ =>
   393           }
   416           }
   394         case bad => System.err.println("session_manager: ignoring bad message " + bad)
   417         case bad => System.err.println("session_manager: ignoring bad message " + bad)
   395       }
   418       }
   408         if (Isabelle.Boolean_Property("auto-start"))
   431         if (Isabelle.Boolean_Property("auto-start"))
   409           Isabelle.start_session()
   432           Isabelle.start_session()
   410 
   433 
   411       case msg: BufferUpdate
   434       case msg: BufferUpdate
   412       if msg.getWhat == BufferUpdate.LOADED =>
   435       if msg.getWhat == BufferUpdate.LOADED =>
   413 
   436         if (Isabelle.session.is_ready) {
   414         val buffer = msg.getBuffer
   437           val buffer = msg.getBuffer
   415         if (buffer != null && Isabelle.session.is_ready)
   438           if (buffer != null) Isabelle.init_model(buffer)
   416           Isabelle.init_model(buffer)
   439           delay_load()
       
   440         }
   417 
   441 
   418       case msg: EditPaneUpdate
   442       case msg: EditPaneUpdate
   419       if (msg.getWhat == EditPaneUpdate.BUFFER_CHANGING ||
   443       if (msg.getWhat == EditPaneUpdate.BUFFER_CHANGING ||
   420           msg.getWhat == EditPaneUpdate.BUFFER_CHANGED ||
   444           msg.getWhat == EditPaneUpdate.BUFFER_CHANGED ||
   421           msg.getWhat == EditPaneUpdate.CREATED ||
   445           msg.getWhat == EditPaneUpdate.CREATED ||
   422           msg.getWhat == EditPaneUpdate.DESTROYED) =>
   446           msg.getWhat == EditPaneUpdate.DESTROYED) =>
   423 
       
   424         val edit_pane = msg.getEditPane
   447         val edit_pane = msg.getEditPane
   425         val buffer = edit_pane.getBuffer
   448         val buffer = edit_pane.getBuffer
   426         val text_area = edit_pane.getTextArea
   449         val text_area = edit_pane.getTextArea
   427 
   450 
   428         if (buffer != null && text_area != null) {
   451         if (buffer != null && text_area != null) {