src/Tools/jEdit/src/plugin.scala
author wenzelm
Mon Sep 10 17:13:17 2012 +0200 (2012-09-10)
changeset 49246 248e66e8321f
parent 49245 cb70157293c0
child 49250 332ab3748350
permissions -rw-r--r--
more systematic JEdit_Options.make_component;
separate module Isabelle_Logic;
wenzelm@43282
     1
/*  Title:      Tools/jEdit/src/plugin.scala
wenzelm@36760
     2
    Author:     Makarius
wenzelm@36760
     3
wenzelm@36760
     4
Main Isabelle/jEdit plugin setup.
wenzelm@36760
     5
*/
wenzelm@34407
     6
wenzelm@34318
     7
package isabelle.jedit
wenzelm@34318
     8
wenzelm@34429
     9
wenzelm@36015
    10
import isabelle._
wenzelm@36015
    11
wenzelm@43520
    12
import java.lang.System
wenzelm@34318
    13
import java.awt.Font
wenzelm@44573
    14
import javax.swing.JOptionPane
wenzelm@34318
    15
wenzelm@34497
    16
import scala.collection.mutable
wenzelm@49246
    17
import scala.swing.{ListView, ScrollPane}
immler@34406
    18
wenzelm@39241
    19
import org.gjt.sp.jedit.{jEdit, GUIUtilities, EBMessage, EBPlugin,
wenzelm@44577
    20
  Buffer, EditPane, ServiceManager, View}
immler@34406
    21
import org.gjt.sp.jedit.buffer.JEditBuffer
wenzelm@39043
    22
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea}
wenzelm@43452
    23
import org.gjt.sp.jedit.syntax.{Token => JEditToken, ModeProvider}
wenzelm@49100
    24
import org.gjt.sp.jedit.msg.{EditorStarted, BufferUpdate, EditPaneUpdate, PropertiesChanged}
wenzelm@37068
    25
import org.gjt.sp.jedit.gui.DockableWindowManager
wenzelm@34429
    26
wenzelm@43443
    27
import org.gjt.sp.util.SyntaxUtilities
wenzelm@39241
    28
import org.gjt.sp.util.Log
wenzelm@39241
    29
wenzelm@44721
    30
import scala.actors.Actor._
wenzelm@39630
    31
wenzelm@34318
    32
wenzelm@34618
    33
object Isabelle
wenzelm@34618
    34
{
wenzelm@34784
    35
  /* plugin instance */
wenzelm@34784
    36
wenzelm@49245
    37
  val options = new JEdit_Options
wenzelm@49245
    38
wenzelm@49099
    39
  @volatile var startup_failure: Option[Throwable] = None
wenzelm@49099
    40
  @volatile var startup_notified = false
wenzelm@34784
    41
wenzelm@49101
    42
  @volatile var plugin: Plugin = null
wenzelm@49101
    43
  @volatile var session: Session = new Session(new JEdit_Thy_Load(Set.empty, Outer_Syntax.empty))
wenzelm@49101
    44
wenzelm@48870
    45
  def thy_load(): JEdit_Thy_Load =
wenzelm@48870
    46
    session.thy_load.asInstanceOf[JEdit_Thy_Load]
wenzelm@44955
    47
wenzelm@48884
    48
  def get_recent_syntax(): Option[Outer_Syntax] =
wenzelm@48884
    49
  {
wenzelm@48884
    50
    val current_session = session
wenzelm@49101
    51
    if (current_session.recent_syntax == Outer_Syntax.empty) None
wenzelm@49101
    52
    else Some(current_session.recent_syntax)
wenzelm@48884
    53
  }
wenzelm@48884
    54
wenzelm@34784
    55
wenzelm@37164
    56
  /* font */
wenzelm@37164
    57
wenzelm@37164
    58
  def font_family(): String = jEdit.getProperty("view.font")
wenzelm@37164
    59
wenzelm@37019
    60
  def font_size(): Float =
wenzelm@37019
    61
    (jEdit.getIntegerProperty("view.fontsize", 16) *
wenzelm@49245
    62
      options.int("jedit_relative_font_size")).toFloat / 100
wenzelm@36814
    63
wenzelm@34618
    64
wenzelm@37201
    65
  /* tooltip markup */
wenzelm@37201
    66
wenzelm@37201
    67
  def tooltip(text: String): String =
wenzelm@37203
    68
    "<html><pre style=\"font-family: " + font_family() + "; font-size: " +
wenzelm@49245
    69
        options.int("jedit_tooltip_font_size").toString + "px; \">" +  // FIXME proper scaling (!?)
wenzelm@37203
    70
      HTML.encode(text) + "</pre></html>"
wenzelm@37201
    71
wenzelm@44699
    72
  private val tooltip_lb = Time.seconds(0.5)
wenzelm@44699
    73
  private val tooltip_ub = Time.seconds(60.0)
wenzelm@40849
    74
  def tooltip_dismiss_delay(): Time =
wenzelm@49245
    75
    Time.seconds(options.real("jedit_tooltip_dismiss_delay")) max tooltip_lb min tooltip_ub
wenzelm@38854
    76
wenzelm@38854
    77
  def setup_tooltips()
wenzelm@38854
    78
  {
wenzelm@38854
    79
    Swing_Thread.now {
wenzelm@38854
    80
      val manager = javax.swing.ToolTipManager.sharedInstance
wenzelm@40849
    81
      manager.setDismissDelay(tooltip_dismiss_delay().ms.toInt)
wenzelm@38854
    82
    }
wenzelm@38854
    83
  }
wenzelm@38854
    84
wenzelm@37201
    85
wenzelm@39241
    86
  /* icons */
wenzelm@39241
    87
wenzelm@39241
    88
  def load_icon(name: String): javax.swing.Icon =
wenzelm@39241
    89
  {
wenzelm@39241
    90
    val icon = GUIUtilities.loadIcon(name)
wenzelm@39241
    91
    if (icon.getIconWidth < 0 || icon.getIconHeight < 0)
wenzelm@39630
    92
      Log.log(Log.ERROR, icon, "Bad icon: " + name)
wenzelm@39241
    93
    icon
wenzelm@39241
    94
  }
wenzelm@39241
    95
wenzelm@39241
    96
wenzelm@44580
    97
  /* buffers */
wenzelm@44580
    98
wenzelm@44580
    99
  def swing_buffer_lock[A](buffer: JEditBuffer)(body: => A): A =
wenzelm@44580
   100
    Swing_Thread.now { buffer_lock(buffer) { body } }
wenzelm@44580
   101
wenzelm@44580
   102
  def buffer_text(buffer: JEditBuffer): String =
wenzelm@44580
   103
    buffer_lock(buffer) { buffer.getText(0, buffer.getLength) }
wenzelm@44580
   104
wenzelm@44580
   105
  def buffer_name(buffer: Buffer): String = buffer.getSymlinkPath
wenzelm@44580
   106
wenzelm@48718
   107
  def buffer_node_dummy(buffer: Buffer): Option[Document.Node.Name] =
wenzelm@48718
   108
    Some(Document.Node.Name(buffer_name(buffer), buffer.getDirectory, buffer.getName))
wenzelm@48718
   109
wenzelm@48718
   110
  def buffer_node_name(buffer: Buffer): Option[Document.Node.Name] =
wenzelm@48718
   111
  {
wenzelm@48718
   112
    val name = buffer_name(buffer)
wenzelm@48718
   113
    Thy_Header.thy_name(name).map(theory => Document.Node.Name(name, buffer.getDirectory, theory))
wenzelm@48718
   114
  }
wenzelm@48718
   115
wenzelm@44580
   116
wenzelm@38221
   117
  /* main jEdit components */
wenzelm@34784
   118
wenzelm@37177
   119
  def jedit_buffers(): Iterator[Buffer] = jEdit.getBuffers().iterator
wenzelm@34784
   120
wenzelm@44580
   121
  def jedit_buffer(name: String): Option[Buffer] =
wenzelm@44580
   122
    jedit_buffers().find(buffer => buffer_name(buffer) == name)
wenzelm@44580
   123
wenzelm@37177
   124
  def jedit_views(): Iterator[View] = jEdit.getViews().iterator
wenzelm@34784
   125
wenzelm@34784
   126
  def jedit_text_areas(view: View): Iterator[JEditTextArea] =
wenzelm@37177
   127
    view.getEditPanes().iterator.map(_.getTextArea)
wenzelm@34784
   128
wenzelm@34784
   129
  def jedit_text_areas(): Iterator[JEditTextArea] =
wenzelm@34784
   130
    jedit_views().flatMap(jedit_text_areas(_))
wenzelm@34784
   131
wenzelm@34784
   132
  def jedit_text_areas(buffer: JEditBuffer): Iterator[JEditTextArea] =
wenzelm@34784
   133
    jedit_text_areas().filter(_.getBuffer == buffer)
wenzelm@34784
   134
wenzelm@38843
   135
  def buffer_lock[A](buffer: JEditBuffer)(body: => A): A =
wenzelm@38640
   136
  {
wenzelm@38640
   137
    try { buffer.readLock(); body }
wenzelm@38640
   138
    finally { buffer.readUnlock() }
wenzelm@38640
   139
  }
wenzelm@38640
   140
wenzelm@34784
   141
wenzelm@43449
   142
  /* document model and view */
wenzelm@43449
   143
wenzelm@43449
   144
  def document_model(buffer: Buffer): Option[Document_Model] = Document_Model(buffer)
wenzelm@43449
   145
  def document_view(text_area: JEditTextArea): Option[Document_View] = Document_View(text_area)
wenzelm@43449
   146
wenzelm@44379
   147
  def document_views(buffer: Buffer): List[Document_View] =
wenzelm@44379
   148
    for {
wenzelm@44379
   149
      text_area <- jedit_text_areas(buffer).toList
wenzelm@46997
   150
      doc_view = document_view(text_area)
wenzelm@44379
   151
      if doc_view.isDefined
wenzelm@44379
   152
    } yield doc_view.get
wenzelm@44379
   153
wenzelm@47058
   154
  def exit_model(buffer: Buffer)
wenzelm@47058
   155
  {
wenzelm@47058
   156
    swing_buffer_lock(buffer) {
wenzelm@47058
   157
      jedit_text_areas(buffer).foreach(Document_View.exit)
wenzelm@47058
   158
      Document_Model.exit(buffer)
wenzelm@47058
   159
    }
wenzelm@47058
   160
  }
wenzelm@47058
   161
wenzelm@43510
   162
  def init_model(buffer: Buffer)
wenzelm@43510
   163
  {
wenzelm@43510
   164
    swing_buffer_lock(buffer) {
wenzelm@43510
   165
      val opt_model =
wenzelm@48717
   166
        buffer_node_name(buffer) match {
wenzelm@48717
   167
          case Some(node_name) =>
wenzelm@47058
   168
            document_model(buffer) match {
wenzelm@47058
   169
              case Some(model) if model.name == node_name => Some(model)
wenzelm@47058
   170
              case _ => Some(Document_Model.init(session, buffer, node_name))
wenzelm@43510
   171
            }
wenzelm@47058
   172
          case None => None
wenzelm@43510
   173
        }
wenzelm@43510
   174
      if (opt_model.isDefined) {
wenzelm@43510
   175
        for (text_area <- jedit_text_areas(buffer)) {
wenzelm@43510
   176
          if (document_view(text_area).map(_.model) != opt_model)
wenzelm@43510
   177
            Document_View.init(opt_model.get, text_area)
wenzelm@43510
   178
        }
wenzelm@43510
   179
      }
wenzelm@43510
   180
    }
wenzelm@43510
   181
  }
wenzelm@43510
   182
wenzelm@43510
   183
  def init_view(buffer: Buffer, text_area: JEditTextArea)
wenzelm@43510
   184
  {
wenzelm@43510
   185
    swing_buffer_lock(buffer) {
wenzelm@43510
   186
      document_model(buffer) match {
wenzelm@43510
   187
        case Some(model) => Document_View.init(model, text_area)
wenzelm@43510
   188
        case None =>
wenzelm@43510
   189
      }
wenzelm@43510
   190
    }
wenzelm@43510
   191
  }
wenzelm@43510
   192
wenzelm@43510
   193
  def exit_view(buffer: Buffer, text_area: JEditTextArea)
wenzelm@43510
   194
  {
wenzelm@43510
   195
    swing_buffer_lock(buffer) {
wenzelm@43510
   196
      Document_View.exit(text_area)
wenzelm@43510
   197
    }
wenzelm@43510
   198
  }
wenzelm@43510
   199
wenzelm@43449
   200
wenzelm@37068
   201
  /* dockable windows */
wenzelm@37068
   202
wenzelm@37068
   203
  private def wm(view: View): DockableWindowManager = view.getDockableWindowManager
wenzelm@37068
   204
wenzelm@39515
   205
  def docked_session(view: View): Option[Session_Dockable] =
wenzelm@39515
   206
    wm(view).getDockableWindow("isabelle-session") match {
wenzelm@39515
   207
      case dockable: Session_Dockable => Some(dockable)
wenzelm@39515
   208
      case _ => None
wenzelm@39515
   209
    }
wenzelm@39515
   210
wenzelm@37068
   211
  def docked_output(view: View): Option[Output_Dockable] =
wenzelm@37068
   212
    wm(view).getDockableWindow("isabelle-output") match {
wenzelm@37068
   213
      case dockable: Output_Dockable => Some(dockable)
wenzelm@37068
   214
      case _ => None
wenzelm@37068
   215
    }
wenzelm@37068
   216
wenzelm@37068
   217
  def docked_raw_output(view: View): Option[Raw_Output_Dockable] =
wenzelm@37068
   218
    wm(view).getDockableWindow("isabelle-raw-output") match {
wenzelm@37068
   219
      case dockable: Raw_Output_Dockable => Some(dockable)
wenzelm@37068
   220
      case _ => None
wenzelm@37068
   221
    }
wenzelm@37068
   222
wenzelm@37068
   223
  def docked_protocol(view: View): Option[Protocol_Dockable] =
wenzelm@37068
   224
    wm(view).getDockableWindow("isabelle-protocol") match {
wenzelm@37068
   225
      case dockable: Protocol_Dockable => Some(dockable)
wenzelm@37068
   226
      case _ => None
wenzelm@37068
   227
    }
wenzelm@37068
   228
wenzelm@37068
   229
wenzelm@44238
   230
  /* convenience actions */
wenzelm@44238
   231
wenzelm@44238
   232
  private def user_input(text_area: JEditTextArea, s1: String, s2: String = "")
wenzelm@44238
   233
  {
wenzelm@44238
   234
    s1.foreach(text_area.userInput(_))
wenzelm@44238
   235
    s2.foreach(text_area.userInput(_))
wenzelm@44238
   236
    s2.foreach(_ => text_area.goToPrevCharacter(false))
wenzelm@44238
   237
  }
wenzelm@44238
   238
wenzelm@44238
   239
  def input_sub(text_area: JEditTextArea): Unit = user_input(text_area, Symbol.sub_decoded)
wenzelm@44238
   240
  def input_sup(text_area: JEditTextArea): Unit = user_input(text_area, Symbol.sup_decoded)
wenzelm@44238
   241
  def input_isub(text_area: JEditTextArea): Unit = user_input(text_area, Symbol.isub_decoded)
wenzelm@44238
   242
  def input_isup(text_area: JEditTextArea): Unit = user_input(text_area, Symbol.isup_decoded)
wenzelm@44238
   243
  def input_bsub(text_area: JEditTextArea): Unit = user_input(text_area, Symbol.bsub_decoded, Symbol.esub_decoded)
wenzelm@44238
   244
  def input_bsup(text_area: JEditTextArea): Unit = user_input(text_area, Symbol.bsup_decoded, Symbol.esup_decoded)
wenzelm@44238
   245
  def input_bold(text_area: JEditTextArea): Unit = user_input(text_area, Symbol.bold_decoded)
wenzelm@44864
   246
wenzelm@44864
   247
  def check_buffer(buffer: Buffer)
wenzelm@44864
   248
  {
wenzelm@44864
   249
    document_model(buffer) match {
wenzelm@44864
   250
      case None =>
wenzelm@44864
   251
      case Some(model) => model.full_perspective()
wenzelm@44864
   252
    }
wenzelm@44864
   253
  }
wenzelm@44864
   254
wenzelm@44864
   255
  def cancel_execution() { session.cancel_execution() }
wenzelm@34318
   256
}
wenzelm@34318
   257
wenzelm@34429
   258
wenzelm@34618
   259
class Plugin extends EBPlugin
wenzelm@34618
   260
{
wenzelm@44577
   261
  /* theory files */
wenzelm@44574
   262
wenzelm@44573
   263
  private lazy val delay_load =
wenzelm@44574
   264
    Swing_Thread.delay_last(Isabelle.session.load_delay)
wenzelm@44574
   265
    {
wenzelm@44963
   266
      val view = jEdit.getActiveView()
wenzelm@44963
   267
wenzelm@44574
   268
      val buffers = Isabelle.jedit_buffers().toList
wenzelm@46761
   269
      if (buffers.forall(_.isLoaded)) {
wenzelm@46761
   270
        def loaded_buffer(name: String): Boolean =
wenzelm@46761
   271
          buffers.exists(buffer => Isabelle.buffer_name(buffer) == name)
wenzelm@44574
   272
wenzelm@46761
   273
        val thys =
wenzelm@46761
   274
          for (buffer <- buffers; model <- Isabelle.document_model(buffer))
wenzelm@46761
   275
            yield model.name
wenzelm@46761
   276
wenzelm@48870
   277
        val thy_info = new Thy_Info(Isabelle.thy_load)
wenzelm@46761
   278
        // FIXME avoid I/O in Swing thread!?!
wenzelm@49098
   279
        val files = thy_info.dependencies(true, thys).deps.map(_._1.node).
wenzelm@46761
   280
          filter(file => !loaded_buffer(file) && Isabelle.thy_load.check_file(view, file))
wenzelm@44574
   281
wenzelm@46761
   282
        if (!files.isEmpty) {
wenzelm@46761
   283
          val files_list = new ListView(files.sorted)
wenzelm@46761
   284
          for (i <- 0 until files.length)
wenzelm@46761
   285
            files_list.selection.indices += i
wenzelm@44606
   286
wenzelm@46761
   287
          val answer =
wenzelm@46761
   288
            Library.confirm_dialog(view,
wenzelm@46761
   289
              "Auto loading of required files",
wenzelm@46761
   290
              JOptionPane.YES_NO_OPTION,
wenzelm@46761
   291
              "The following files are required to resolve theory imports.",
wenzelm@46761
   292
              "Reload selected files now?",
wenzelm@46761
   293
              new ScrollPane(files_list))
wenzelm@46761
   294
          if (answer == 0) {
wenzelm@46761
   295
            files.foreach(file =>
wenzelm@46761
   296
              if (files_list.selection.items.contains(file))
wenzelm@46761
   297
                jEdit.openFile(null: View, file))
wenzelm@46761
   298
          }
wenzelm@46761
   299
        }
wenzelm@44606
   300
      }
wenzelm@44574
   301
    }
wenzelm@44573
   302
wenzelm@44574
   303
wenzelm@44574
   304
  /* session manager */
wenzelm@44573
   305
wenzelm@39633
   306
  private val session_manager = actor {
wenzelm@39633
   307
    loop {
wenzelm@39633
   308
      react {
wenzelm@39735
   309
        case phase: Session.Phase =>
wenzelm@39735
   310
          phase match {
wenzelm@39735
   311
            case Session.Failed =>
wenzelm@46918
   312
              Swing_Thread.later {
wenzelm@48022
   313
                Library.error_dialog(jEdit.getActiveView, "Prover process failure",
wenzelm@48022
   314
                    "Isabelle Syslog", Library.scrollable_text(Isabelle.session.current_syslog()))
wenzelm@39735
   315
              }
wenzelm@39735
   316
wenzelm@44573
   317
            case Session.Ready =>
wenzelm@44573
   318
              Isabelle.jedit_buffers.foreach(Isabelle.init_model)
wenzelm@49195
   319
              Swing_Thread.later { delay_load.invoke() }
wenzelm@44573
   320
wenzelm@46740
   321
            case Session.Shutdown =>
wenzelm@46740
   322
              Isabelle.jedit_buffers.foreach(Isabelle.exit_model)
wenzelm@49195
   323
              Swing_Thread.later { delay_load.revoke() }
wenzelm@46740
   324
wenzelm@39735
   325
            case _ =>
wenzelm@39735
   326
          }
wenzelm@39735
   327
        case bad => System.err.println("session_manager: ignoring bad message " + bad)
wenzelm@39630
   328
      }
wenzelm@39630
   329
    }
wenzelm@39630
   330
  }
wenzelm@39630
   331
wenzelm@39630
   332
wenzelm@34618
   333
  /* main plugin plumbing */
wenzelm@34433
   334
wenzelm@34767
   335
  override def handleMessage(message: EBMessage)
wenzelm@34618
   336
  {
wenzelm@43510
   337
    Swing_Thread.assert()
wenzelm@39630
   338
wenzelm@49099
   339
    if (Isabelle.startup_failure.isDefined && !Isabelle.startup_notified) {
wenzelm@49099
   340
      message match {
wenzelm@49100
   341
        case msg: EditorStarted =>
wenzelm@49100
   342
          Library.error_dialog(null, "Isabelle plugin startup failure",
wenzelm@49099
   343
            Library.scrollable_text(Exn.message(Isabelle.startup_failure.get)),
wenzelm@49099
   344
            "Prover IDE inactive!")
wenzelm@49099
   345
          Isabelle.startup_notified = true
wenzelm@49099
   346
        case _ =>
wenzelm@49099
   347
      }
wenzelm@49099
   348
    }
wenzelm@49099
   349
wenzelm@49099
   350
    if (Isabelle.startup_failure.isEmpty) {
wenzelm@49099
   351
      message match {
wenzelm@49099
   352
        case msg: EditorStarted =>
wenzelm@49245
   353
          if (Isabelle.options.bool("jedit_auto_start"))
wenzelm@49246
   354
            Isabelle.session.start(Isabelle_Logic.session_args())
wenzelm@37557
   355
wenzelm@49099
   356
        case msg: BufferUpdate
wenzelm@49099
   357
        if msg.getWhat == BufferUpdate.LOADED || msg.getWhat == BufferUpdate.PROPERTIES_CHANGED =>
wenzelm@49099
   358
          if (Isabelle.session.is_ready) {
wenzelm@49099
   359
            val buffer = msg.getBuffer
wenzelm@49099
   360
            if (buffer != null && !buffer.isLoading) Isabelle.init_model(buffer)
wenzelm@49195
   361
            Swing_Thread.later { delay_load.invoke() }
wenzelm@49099
   362
          }
wenzelm@34784
   363
wenzelm@49099
   364
        case msg: EditPaneUpdate
wenzelm@49099
   365
        if (msg.getWhat == EditPaneUpdate.BUFFER_CHANGING ||
wenzelm@49099
   366
            msg.getWhat == EditPaneUpdate.BUFFER_CHANGED ||
wenzelm@49099
   367
            msg.getWhat == EditPaneUpdate.CREATED ||
wenzelm@49099
   368
            msg.getWhat == EditPaneUpdate.DESTROYED) =>
wenzelm@49099
   369
          val edit_pane = msg.getEditPane
wenzelm@49099
   370
          val buffer = edit_pane.getBuffer
wenzelm@49099
   371
          val text_area = edit_pane.getTextArea
wenzelm@49099
   372
wenzelm@49099
   373
          if (buffer != null && text_area != null) {
wenzelm@49099
   374
            if (msg.getWhat == EditPaneUpdate.BUFFER_CHANGED ||
wenzelm@49099
   375
                msg.getWhat == EditPaneUpdate.CREATED) {
wenzelm@49099
   376
              if (Isabelle.session.is_ready)
wenzelm@49099
   377
                Isabelle.init_view(buffer, text_area)
wenzelm@49099
   378
            }
wenzelm@49099
   379
            else Isabelle.exit_view(buffer, text_area)
wenzelm@43510
   380
          }
wenzelm@34784
   381
wenzelm@49099
   382
        case msg: PropertiesChanged =>
wenzelm@49099
   383
          Isabelle.setup_tooltips()
wenzelm@49099
   384
          Isabelle.session.global_settings.event(Session.Global_Settings)
wenzelm@34784
   385
wenzelm@49099
   386
        case _ =>
wenzelm@49099
   387
      }
wenzelm@34318
   388
    }
wenzelm@34318
   389
  }
wenzelm@34318
   390
wenzelm@34618
   391
  override def start()
wenzelm@49099
   392
  {
wenzelm@49099
   393
    try {
wenzelm@49099
   394
      Isabelle.plugin = this
wenzelm@49099
   395
      Isabelle_System.init()
wenzelm@49099
   396
      Isabelle_System.install_fonts()
wenzelm@49099
   397
wenzelm@49245
   398
      val init_options = Options.init()
wenzelm@49245
   399
      Swing_Thread.now {
wenzelm@49245
   400
        Isabelle.options.update(init_options)
wenzelm@49245
   401
        Isabelle.setup_tooltips()
wenzelm@49245
   402
      }
wenzelm@49245
   403
wenzelm@49099
   404
      SyntaxUtilities.setStyleExtender(new Token_Markup.Style_Extender)
wenzelm@49099
   405
      if (ModeProvider.instance.isInstanceOf[ModeProvider])
wenzelm@49099
   406
        ModeProvider.instance = new Token_Markup.Mode_Provider(ModeProvider.instance)
wenzelm@48870
   407
wenzelm@49246
   408
      val content = Isabelle_Logic.session_content(false)
wenzelm@49099
   409
      val thy_load = new JEdit_Thy_Load(content.loaded_theories, content.syntax)
wenzelm@49099
   410
      Isabelle.session = new Session(thy_load)
wenzelm@48870
   411
wenzelm@49099
   412
      Isabelle.session.phase_changed += session_manager
wenzelm@49099
   413
      Isabelle.startup_failure = None
wenzelm@49099
   414
    }
wenzelm@49099
   415
    catch {
wenzelm@49099
   416
      case exn: Throwable =>
wenzelm@49099
   417
        Isabelle.startup_failure = Some(exn)
wenzelm@49099
   418
        Isabelle.startup_notified = false
wenzelm@49099
   419
    }
wenzelm@34318
   420
  }
wenzelm@34618
   421
wenzelm@39628
   422
  override def stop()
wenzelm@34618
   423
  {
wenzelm@49245
   424
    if (Isabelle.startup_failure.isEmpty)
wenzelm@49245
   425
      Isabelle.options.value.save_prefs()
wenzelm@49245
   426
wenzelm@49101
   427
    Isabelle.session.phase_changed -= session_manager
wenzelm@49101
   428
    Isabelle.jedit_buffers.foreach(Isabelle.exit_model)
wenzelm@49101
   429
    Isabelle.session.stop()
wenzelm@34318
   430
  }
wenzelm@34318
   431
}