src/Tools/jEdit/src/plugin.scala
author wenzelm
Sat Jan 07 15:16:36 2017 +0100 (2017-01-07)
changeset 64818 67a0a563d2b3
parent 64817 0bb6b582bb4f
child 64835 fd1efd6dd385
permissions -rw-r--r--
clarified buffer events: exit model while loading;
misc tuning;
wenzelm@43282
     1
/*  Title:      Tools/jEdit/src/plugin.scala
wenzelm@36760
     2
    Author:     Makarius
wenzelm@36760
     3
wenzelm@50362
     4
Main plumbing for PIDE infrastructure as jEdit plugin.
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@44573
    12
import javax.swing.JOptionPane
wenzelm@34318
    13
wenzelm@49246
    14
import scala.swing.{ListView, ScrollPane}
immler@34406
    15
wenzelm@60205
    16
import org.gjt.sp.jedit.{jEdit, EBMessage, EBPlugin, Buffer, View, Debug, PerspectiveManager}
wenzelm@53487
    17
import org.gjt.sp.jedit.gui.AboutDialog
wenzelm@39043
    18
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea}
wenzelm@59077
    19
import org.gjt.sp.jedit.buffer.JEditBuffer
wenzelm@50362
    20
import org.gjt.sp.jedit.syntax.ModeProvider
wenzelm@49100
    21
import org.gjt.sp.jedit.msg.{EditorStarted, BufferUpdate, EditPaneUpdate, PropertiesChanged}
wenzelm@43443
    22
import org.gjt.sp.util.SyntaxUtilities
wenzelm@62228
    23
import org.gjt.sp.util.Log
wenzelm@39241
    24
wenzelm@34318
    25
wenzelm@50205
    26
object PIDE
wenzelm@34618
    27
{
wenzelm@34784
    28
  /* plugin instance */
wenzelm@34784
    29
wenzelm@49245
    30
  val options = new JEdit_Options
wenzelm@53337
    31
  val completion_history = new Completion.History_Variable
wenzelm@56558
    32
  val spell_checker = new Spell_Checker_Variable
wenzelm@49245
    33
wenzelm@49099
    34
  @volatile var startup_failure: Option[Throwable] = None
wenzelm@49099
    35
  @volatile var startup_notified = false
wenzelm@34784
    36
wenzelm@49101
    37
  @volatile var plugin: Plugin = null
wenzelm@60835
    38
  @volatile var session: Session = new Session(JEdit_Resources.empty)
wenzelm@49101
    39
wenzelm@62068
    40
  def options_changed() { if (plugin != null) plugin.options_changed() }
wenzelm@62068
    41
  def deps_changed() { if (plugin != null) plugin.deps_changed() }
wenzelm@52815
    42
wenzelm@56208
    43
  def resources(): JEdit_Resources =
wenzelm@56208
    44
    session.resources.asInstanceOf[JEdit_Resources]
wenzelm@44955
    45
wenzelm@52971
    46
  lazy val editor = new JEdit_Editor
wenzelm@52971
    47
wenzelm@34784
    48
wenzelm@53244
    49
  /* popups */
wenzelm@53244
    50
wenzelm@53244
    51
  def dismissed_popups(view: View): Boolean =
wenzelm@53244
    52
  {
wenzelm@53272
    53
    var dismissed = false
wenzelm@53272
    54
wenzelm@53274
    55
    JEdit_Lib.jedit_text_areas(view).foreach(text_area =>
wenzelm@53274
    56
      if (Completion_Popup.Text_Area.dismissed(text_area)) dismissed = true)
wenzelm@53272
    57
wenzelm@53272
    58
    if (Pretty_Tooltip.dismissed_all()) dismissed = true
wenzelm@53272
    59
wenzelm@53272
    60
    dismissed
wenzelm@53244
    61
  }
wenzelm@53244
    62
wenzelm@53244
    63
wenzelm@43449
    64
  /* document model and view */
wenzelm@43449
    65
wenzelm@55712
    66
  def document_view(text_area: TextArea): Option[Document_View] = Document_View(text_area)
wenzelm@43449
    67
wenzelm@44379
    68
  def document_views(buffer: Buffer): List[Document_View] =
wenzelm@44379
    69
    for {
wenzelm@49406
    70
      text_area <- JEdit_Lib.jedit_text_areas(buffer).toList
wenzelm@54529
    71
      doc_view <- document_view(text_area)
wenzelm@54529
    72
    } yield doc_view
wenzelm@44379
    73
wenzelm@50344
    74
  def exit_models(buffers: List[Buffer])
wenzelm@47058
    75
  {
wenzelm@57612
    76
    GUI_Thread.now {
wenzelm@54461
    77
      PIDE.editor.flush()
wenzelm@50344
    78
      buffers.foreach(buffer =>
wenzelm@50344
    79
        JEdit_Lib.buffer_lock(buffer) {
wenzelm@50344
    80
          JEdit_Lib.jedit_text_areas(buffer).foreach(Document_View.exit)
wenzelm@50344
    81
          Document_Model.exit(buffer)
wenzelm@50344
    82
        })
wenzelm@50344
    83
      }
wenzelm@47058
    84
  }
wenzelm@47058
    85
wenzelm@55791
    86
  def init_models()
wenzelm@43510
    87
  {
wenzelm@57612
    88
    GUI_Thread.now {
wenzelm@54461
    89
      PIDE.editor.flush()
wenzelm@55791
    90
wenzelm@55791
    91
      for {
wenzelm@55791
    92
        buffer <- JEdit_Lib.jedit_buffers()
wenzelm@62068
    93
        if buffer != null && !buffer.getBooleanProperty(Buffer.GZIPPED)
wenzelm@55791
    94
      } {
wenzelm@62068
    95
        if (buffer.isLoaded) {
wenzelm@62068
    96
          JEdit_Lib.buffer_lock(buffer) {
wenzelm@62068
    97
            val node_name = resources.node_name(buffer)
wenzelm@64817
    98
            val model = Document_Model.init(session, node_name, buffer)
wenzelm@62068
    99
            for {
wenzelm@62068
   100
              text_area <- JEdit_Lib.jedit_text_areas(buffer)
wenzelm@62068
   101
              if document_view(text_area).map(_.model) != Some(model)
wenzelm@62068
   102
            } Document_View.init(model, text_area)
wenzelm@62068
   103
          }
wenzelm@43510
   104
        }
wenzelm@62068
   105
        else if (plugin != null) plugin.delay_init.invoke()
wenzelm@55791
   106
      }
wenzelm@55791
   107
wenzelm@64524
   108
      PIDE.editor.invoke_generated()
wenzelm@43510
   109
    }
wenzelm@43510
   110
  }
wenzelm@43510
   111
wenzelm@56774
   112
  def init_view(buffer: Buffer, text_area: JEditTextArea): Unit =
wenzelm@57612
   113
    GUI_Thread.now {
wenzelm@56774
   114
      JEdit_Lib.buffer_lock(buffer) {
wenzelm@64813
   115
        Document_Model.get(buffer) match {
wenzelm@56774
   116
          case Some(model) => Document_View.init(model, text_area)
wenzelm@56774
   117
          case None =>
wenzelm@56774
   118
        }
wenzelm@43510
   119
      }
wenzelm@43510
   120
    }
wenzelm@43510
   121
wenzelm@56774
   122
  def exit_view(buffer: Buffer, text_area: JEditTextArea): Unit =
wenzelm@57612
   123
    GUI_Thread.now {
wenzelm@56774
   124
      JEdit_Lib.buffer_lock(buffer) {
wenzelm@56774
   125
        Document_View.exit(text_area)
wenzelm@56774
   126
      }
wenzelm@43510
   127
    }
wenzelm@55621
   128
wenzelm@55621
   129
wenzelm@55621
   130
  /* current document content */
wenzelm@55621
   131
wenzelm@62062
   132
  def snapshot(view: View): Document.Snapshot = GUI_Thread.now
wenzelm@55621
   133
  {
wenzelm@64813
   134
    Document_Model.get(view.getBuffer) match {
wenzelm@55621
   135
      case Some(model) => model.snapshot
wenzelm@55621
   136
      case None => error("No document model for current buffer")
wenzelm@55621
   137
    }
wenzelm@55621
   138
  }
wenzelm@55621
   139
wenzelm@64621
   140
  def rendering(view: View): JEdit_Rendering = GUI_Thread.now
wenzelm@55621
   141
  {
wenzelm@55621
   142
    val text_area = view.getTextArea
wenzelm@55621
   143
    document_view(text_area) match {
wenzelm@55621
   144
      case Some(doc_view) => doc_view.get_rendering()
wenzelm@55621
   145
      case None => error("No document view for current text area")
wenzelm@55621
   146
    }
wenzelm@55621
   147
  }
wenzelm@34318
   148
}
wenzelm@34318
   149
wenzelm@34429
   150
wenzelm@34618
   151
class Plugin extends EBPlugin
wenzelm@34618
   152
{
wenzelm@56316
   153
  /* global changes */
wenzelm@55791
   154
wenzelm@56316
   155
  def options_changed()
wenzelm@56316
   156
  {
wenzelm@56715
   157
    PIDE.session.global_options.post(Session.Global_Options(PIDE.options.value))
wenzelm@56770
   158
    delay_load.invoke()
wenzelm@55791
   159
  }
wenzelm@55791
   160
wenzelm@56316
   161
  def deps_changed()
wenzelm@56316
   162
  {
wenzelm@56770
   163
    delay_load.invoke()
wenzelm@56316
   164
  }
wenzelm@56316
   165
wenzelm@55791
   166
wenzelm@44577
   167
  /* theory files */
wenzelm@44574
   168
wenzelm@62068
   169
  lazy val delay_init =
wenzelm@57612
   170
    GUI_Thread.delay_last(PIDE.options.seconds("editor_load_delay"))
wenzelm@50344
   171
    {
wenzelm@55791
   172
      PIDE.init_models()
wenzelm@50344
   173
    }
wenzelm@50344
   174
wenzelm@57582
   175
  private val delay_load_active = Synchronized(false)
wenzelm@57582
   176
  private def delay_load_activated(): Boolean =
wenzelm@57582
   177
    delay_load_active.guarded_access(a => Some((!a, true)))
wenzelm@62068
   178
  private def delay_load_action()
wenzelm@62068
   179
  {
wenzelm@62068
   180
    if (Isabelle.continuous_checking && delay_load_activated() &&
wenzelm@62068
   181
        PerspectiveManager.isPerspectiveEnabled)
wenzelm@44574
   182
    {
wenzelm@62068
   183
      try {
wenzelm@62068
   184
        val view = jEdit.getActiveView()
wenzelm@44963
   185
wenzelm@62068
   186
        val buffers = JEdit_Lib.jedit_buffers().toList
wenzelm@62068
   187
        if (buffers.forall(_.isLoaded)) {
wenzelm@62068
   188
          def loaded_buffer(name: String): Boolean =
wenzelm@62068
   189
            buffers.exists(buffer => JEdit_Lib.buffer_name(buffer) == name)
wenzelm@44574
   190
wenzelm@62068
   191
          val thys =
wenzelm@62068
   192
            for {
wenzelm@62068
   193
              buffer <- buffers
wenzelm@64813
   194
              model <- Document_Model.get(buffer)
wenzelm@62068
   195
              if model.is_theory
wenzelm@62068
   196
            } yield (model.node_name, Position.none)
wenzelm@46761
   197
wenzelm@62068
   198
          val thy_info = new Thy_Info(PIDE.resources)
wenzelm@62068
   199
          val thy_files = thy_info.dependencies("", thys).deps.map(_.name.node)
wenzelm@60916
   200
wenzelm@62068
   201
          val aux_files =
wenzelm@62068
   202
            if (PIDE.options.bool("jedit_auto_resolve")) {
wenzelm@62068
   203
              PIDE.editor.stable_tip_version() match {
wenzelm@62068
   204
                case Some(version) => PIDE.resources.undefined_blobs(version.nodes).map(_.node)
wenzelm@64478
   205
                case None => delay_load.invoke(); Nil
wenzelm@57582
   206
              }
wenzelm@62068
   207
            }
wenzelm@62068
   208
            else Nil
wenzelm@62068
   209
wenzelm@62068
   210
          val files =
wenzelm@62068
   211
            (thy_files ::: aux_files).filter(file =>
wenzelm@62068
   212
              !loaded_buffer(file) && PIDE.resources.check_file(file))
wenzelm@44606
   213
wenzelm@62068
   214
          if (files.nonEmpty) {
wenzelm@62068
   215
            if (PIDE.options.bool("jedit_auto_load")) {
wenzelm@62068
   216
              files.foreach(file => jEdit.openFile(null: View, file))
wenzelm@62068
   217
            }
wenzelm@62068
   218
            else {
wenzelm@62068
   219
              val files_list = new ListView(files.sorted)
wenzelm@62068
   220
              for (i <- 0 until files.length)
wenzelm@62068
   221
                files_list.selection.indices += i
wenzelm@62068
   222
wenzelm@62068
   223
              val answer =
wenzelm@62068
   224
                GUI.confirm_dialog(view,
wenzelm@62068
   225
                  "Auto loading of required files",
wenzelm@62068
   226
                  JOptionPane.YES_NO_OPTION,
wenzelm@62068
   227
                  "The following files are required to resolve theory imports.",
wenzelm@62068
   228
                  "Reload selected files now?",
wenzelm@62068
   229
                  new ScrollPane(files_list),
wenzelm@62068
   230
                  new Isabelle.Continuous_Checking)
wenzelm@62068
   231
              if (answer == 0) {
wenzelm@62068
   232
                files.foreach(file =>
wenzelm@62068
   233
                  if (files_list.selection.items.contains(file))
wenzelm@62068
   234
                    jEdit.openFile(null: View, file))
wenzelm@53715
   235
              }
wenzelm@53074
   236
            }
wenzelm@46761
   237
          }
wenzelm@46761
   238
        }
wenzelm@62068
   239
        else delay_load.invoke()
wenzelm@44606
   240
      }
wenzelm@62068
   241
      finally { delay_load_active.change(_ => false) }
wenzelm@44574
   242
    }
wenzelm@62068
   243
  }
wenzelm@62068
   244
wenzelm@64478
   245
  private lazy val delay_load =
wenzelm@62068
   246
    GUI_Thread.delay_last(PIDE.options.seconds("editor_load_delay")) { delay_load_action() }
wenzelm@44573
   247
wenzelm@44574
   248
wenzelm@56715
   249
  /* session phase */
wenzelm@44573
   250
wenzelm@56715
   251
  private val session_phase =
wenzelm@56715
   252
    Session.Consumer[Session.Phase](getClass.getName) {
wenzelm@56715
   253
      case Session.Inactive | Session.Failed =>
wenzelm@57612
   254
        GUI_Thread.later {
wenzelm@56715
   255
          GUI.error_dialog(jEdit.getActiveView, "Prover process terminated",
wenzelm@56775
   256
            "Isabelle Syslog", GUI.scrollable_text(PIDE.session.syslog_content()))
wenzelm@56715
   257
        }
wenzelm@39735
   258
wenzelm@56715
   259
      case Session.Ready =>
wenzelm@60910
   260
        Debugger.init_session(PIDE.session)
wenzelm@60075
   261
        PIDE.session.update_options(PIDE.options.value)
wenzelm@56715
   262
        PIDE.init_models()
wenzelm@57640
   263
wenzelm@57640
   264
        if (!Isabelle.continuous_checking) {
wenzelm@57640
   265
          GUI_Thread.later {
wenzelm@57640
   266
            val answer =
wenzelm@57640
   267
              GUI.confirm_dialog(jEdit.getActiveView,
wenzelm@57640
   268
                "Continuous checking of PIDE document",
wenzelm@57640
   269
                JOptionPane.YES_NO_OPTION,
wenzelm@57640
   270
                "Continuous checking is presently disabled:",
wenzelm@57640
   271
                "editor buffers will remain inactive!",
wenzelm@57640
   272
                "Enable continuous checking now?")
wenzelm@57640
   273
            if (answer == 0) Isabelle.continuous_checking = true
wenzelm@57640
   274
          }
wenzelm@57640
   275
        }
wenzelm@57640
   276
wenzelm@56770
   277
        delay_load.invoke()
wenzelm@44573
   278
wenzelm@56715
   279
      case Session.Shutdown =>
wenzelm@62062
   280
        GUI_Thread.later {
wenzelm@62062
   281
          delay_load.revoke()
wenzelm@62062
   282
          PIDE.exit_models(JEdit_Lib.jedit_buffers().toList)
wenzelm@62062
   283
        }
wenzelm@46740
   284
wenzelm@56715
   285
      case _ =>
wenzelm@39630
   286
    }
wenzelm@39630
   287
wenzelm@39630
   288
wenzelm@34618
   289
  /* main plugin plumbing */
wenzelm@34433
   290
wenzelm@34767
   291
  override def handleMessage(message: EBMessage)
wenzelm@34618
   292
  {
wenzelm@57612
   293
    GUI_Thread.assert {}
wenzelm@39630
   294
wenzelm@50205
   295
    if (PIDE.startup_failure.isDefined && !PIDE.startup_notified) {
wenzelm@49099
   296
      message match {
wenzelm@49100
   297
        case msg: EditorStarted =>
wenzelm@51616
   298
          GUI.error_dialog(null, "Isabelle plugin startup failure",
wenzelm@51616
   299
            GUI.scrollable_text(Exn.message(PIDE.startup_failure.get)),
wenzelm@49099
   300
            "Prover IDE inactive!")
wenzelm@50205
   301
          PIDE.startup_notified = true
wenzelm@49099
   302
        case _ =>
wenzelm@49099
   303
      }
wenzelm@49099
   304
    }
wenzelm@49099
   305
wenzelm@50205
   306
    if (PIDE.startup_failure.isEmpty) {
wenzelm@49099
   307
      message match {
wenzelm@49099
   308
        case msg: EditorStarted =>
wenzelm@57649
   309
          if (Distribution.is_identified && !Distribution.is_official) {
wenzelm@57680
   310
            GUI.warning_dialog(jEdit.getActiveView, "Isabelle version for testing",
wenzelm@60206
   311
              "This is " + Distribution.version + ".",
wenzelm@57649
   312
              "It is for testing only, not for production use.")
wenzelm@57649
   313
          }
wenzelm@57649
   314
wenzelm@64602
   315
          val view = jEdit.getActiveView()
wenzelm@64602
   316
wenzelm@64602
   317
          Session_Build.session_build(view)
wenzelm@63747
   318
wenzelm@64602
   319
          Keymap_Merge.check_dialog(view)
wenzelm@64602
   320
wenzelm@64602
   321
          PIDE.editor.hyperlink_position(true, Document.Snapshot.init,
wenzelm@64602
   322
            JEdit_Sessions.session_info().open_root).foreach(_.follow(view))
wenzelm@61277
   323
wenzelm@49099
   324
        case msg: BufferUpdate
wenzelm@64818
   325
        if msg.getWhat == BufferUpdate.LOAD_STARTED || msg.getWhat == BufferUpdate.CLOSING =>
wenzelm@64818
   326
          if (msg.getBuffer != null) PIDE.exit_models(List(msg.getBuffer))
wenzelm@57611
   327
wenzelm@64818
   328
        case msg: BufferUpdate
wenzelm@64818
   329
        if msg.getWhat == BufferUpdate.PROPERTIES_CHANGED || msg.getWhat == BufferUpdate.LOADED =>
wenzelm@50205
   330
          if (PIDE.session.is_ready) {
wenzelm@55791
   331
            delay_init.invoke()
wenzelm@55791
   332
            delay_load.invoke()
wenzelm@49099
   333
          }
wenzelm@34784
   334
wenzelm@49099
   335
        case msg: EditPaneUpdate
wenzelm@60215
   336
        if msg.getWhat == EditPaneUpdate.BUFFER_CHANGING ||
wenzelm@49099
   337
            msg.getWhat == EditPaneUpdate.BUFFER_CHANGED ||
wenzelm@49099
   338
            msg.getWhat == EditPaneUpdate.CREATED ||
wenzelm@60215
   339
            msg.getWhat == EditPaneUpdate.DESTROYED =>
wenzelm@49099
   340
          val edit_pane = msg.getEditPane
wenzelm@49099
   341
          val buffer = edit_pane.getBuffer
wenzelm@49099
   342
          val text_area = edit_pane.getTextArea
wenzelm@49099
   343
wenzelm@49099
   344
          if (buffer != null && text_area != null) {
wenzelm@49099
   345
            if (msg.getWhat == EditPaneUpdate.BUFFER_CHANGED ||
wenzelm@49099
   346
                msg.getWhat == EditPaneUpdate.CREATED) {
wenzelm@50205
   347
              if (PIDE.session.is_ready)
wenzelm@50205
   348
                PIDE.init_view(buffer, text_area)
wenzelm@49099
   349
            }
wenzelm@52867
   350
            else {
wenzelm@53244
   351
              PIDE.dismissed_popups(text_area.getView)
wenzelm@52867
   352
              PIDE.exit_view(buffer, text_area)
wenzelm@52867
   353
            }
wenzelm@53274
   354
wenzelm@53274
   355
            if (msg.getWhat == EditPaneUpdate.CREATED)
wenzelm@53274
   356
              Completion_Popup.Text_Area.init(text_area)
wenzelm@53274
   357
wenzelm@53274
   358
            if (msg.getWhat == EditPaneUpdate.DESTROYED)
wenzelm@53274
   359
              Completion_Popup.Text_Area.exit(text_area)
wenzelm@43510
   360
          }
wenzelm@34784
   361
wenzelm@49099
   362
        case msg: PropertiesChanged =>
wenzelm@62264
   363
          for {
wenzelm@62264
   364
            view <- JEdit_Lib.jedit_views
wenzelm@62264
   365
            edit_pane <- JEdit_Lib.jedit_edit_panes(view)
wenzelm@62264
   366
          } {
wenzelm@62264
   367
            val buffer = edit_pane.getBuffer
wenzelm@62264
   368
            val text_area = edit_pane.getTextArea
wenzelm@62264
   369
            if (buffer != null && text_area != null) PIDE.init_view(buffer, text_area)
wenzelm@62264
   370
          }
wenzelm@62264
   371
wenzelm@56558
   372
          PIDE.spell_checker.update(PIDE.options.value)
wenzelm@52084
   373
          PIDE.session.update_options(PIDE.options.value)
wenzelm@34784
   374
wenzelm@49099
   375
        case _ =>
wenzelm@49099
   376
      }
wenzelm@34318
   377
    }
wenzelm@34318
   378
  }
wenzelm@34318
   379
wenzelm@34618
   380
  override def start()
wenzelm@49099
   381
  {
wenzelm@49099
   382
    try {
wenzelm@50709
   383
      Debug.DISABLE_SEARCH_DIALOG_POOL = true
wenzelm@50709
   384
wenzelm@50205
   385
      PIDE.plugin = this
wenzelm@62917
   386
      PIDE.options.store(Options.init())
wenzelm@53337
   387
      PIDE.completion_history.load()
wenzelm@56558
   388
      PIDE.spell_checker.update(PIDE.options.value)
wenzelm@49245
   389
wenzelm@49099
   390
      SyntaxUtilities.setStyleExtender(new Token_Markup.Style_Extender)
wenzelm@49099
   391
      if (ModeProvider.instance.isInstanceOf[ModeProvider])
wenzelm@49099
   392
        ModeProvider.instance = new Token_Markup.Mode_Provider(ModeProvider.instance)
wenzelm@48870
   393
wenzelm@53274
   394
      JEdit_Lib.jedit_text_areas.foreach(Completion_Popup.Text_Area.init _)
wenzelm@53274
   395
wenzelm@62973
   396
      val content = JEdit_Sessions.session_content(false)
wenzelm@56801
   397
      val resources =
wenzelm@56801
   398
        new JEdit_Resources(content.loaded_theories, content.known_theories, content.syntax)
wenzelm@49524
   399
wenzelm@62051
   400
      PIDE.session.stop()
wenzelm@56208
   401
      PIDE.session = new Session(resources) {
wenzelm@50207
   402
        override def output_delay = PIDE.options.seconds("editor_output_delay")
wenzelm@57867
   403
        override def prune_delay = PIDE.options.seconds("editor_prune_delay")
wenzelm@57974
   404
        override def syslog_limit = PIDE.options.int("editor_syslog_limit")
wenzelm@50205
   405
        override def reparse_limit = PIDE.options.int("editor_reparse_limit")
wenzelm@49288
   406
      }
wenzelm@48870
   407
wenzelm@56715
   408
      PIDE.session.phase_changed += session_phase
wenzelm@50205
   409
      PIDE.startup_failure = None
wenzelm@49099
   410
    }
wenzelm@49099
   411
    catch {
wenzelm@49099
   412
      case exn: Throwable =>
wenzelm@50205
   413
        PIDE.startup_failure = Some(exn)
wenzelm@50205
   414
        PIDE.startup_notified = false
wenzelm@62228
   415
        Log.log(Log.ERROR, this, exn)
wenzelm@49099
   416
    }
wenzelm@34318
   417
  }
wenzelm@34618
   418
wenzelm@39628
   419
  override def stop()
wenzelm@34618
   420
  {
wenzelm@53274
   421
    JEdit_Lib.jedit_text_areas.foreach(Completion_Popup.Text_Area.exit _)
wenzelm@53274
   422
wenzelm@53337
   423
    if (PIDE.startup_failure.isEmpty) {
wenzelm@50205
   424
      PIDE.options.value.save_prefs()
wenzelm@53337
   425
      PIDE.completion_history.value.save()
wenzelm@53337
   426
    }
wenzelm@49245
   427
wenzelm@56715
   428
    PIDE.session.phase_changed -= session_phase
wenzelm@50344
   429
    PIDE.exit_models(JEdit_Lib.jedit_buffers().toList)
wenzelm@50205
   430
    PIDE.session.stop()
wenzelm@34318
   431
  }
wenzelm@34318
   432
}