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