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