avoid delay_load overrun;
authorwenzelm
Sun Jul 20 19:36:46 2014 +0200 (2014-07-20)
changeset 57582b79b75f92604
parent 57581 74bbe9317aa4
child 57583 a52e06f11e41
avoid delay_load overrun;
src/Tools/jEdit/src/plugin.scala
     1.1 --- a/src/Tools/jEdit/src/plugin.scala	Sun Jul 20 17:54:01 2014 +0200
     1.2 +++ b/src/Tools/jEdit/src/plugin.scala	Sun Jul 20 19:36:46 2014 +0200
     1.3 @@ -191,54 +191,61 @@
     1.4        PIDE.init_models()
     1.5      }
     1.6  
     1.7 +  private val delay_load_active = Synchronized(false)
     1.8 +  private def delay_load_activated(): Boolean =
     1.9 +    delay_load_active.guarded_access(a => Some((!a, true)))
    1.10 +
    1.11    private lazy val delay_load =
    1.12      Swing_Thread.delay_last(PIDE.options.seconds("editor_load_delay"))
    1.13      {
    1.14 -      if (Isabelle.continuous_checking) {
    1.15 -        val view = jEdit.getActiveView()
    1.16 +      if (Isabelle.continuous_checking && delay_load_activated()) {
    1.17 +        try {
    1.18 +          val view = jEdit.getActiveView()
    1.19  
    1.20 -        val buffers = JEdit_Lib.jedit_buffers().toList
    1.21 -        if (buffers.forall(_.isLoaded)) {
    1.22 -          def loaded_buffer(name: String): Boolean =
    1.23 -            buffers.exists(buffer => JEdit_Lib.buffer_name(buffer) == name)
    1.24 +          val buffers = JEdit_Lib.jedit_buffers().toList
    1.25 +          if (buffers.forall(_.isLoaded)) {
    1.26 +            def loaded_buffer(name: String): Boolean =
    1.27 +              buffers.exists(buffer => JEdit_Lib.buffer_name(buffer) == name)
    1.28  
    1.29 -          val thys =
    1.30 -            for {
    1.31 -              buffer <- buffers
    1.32 -              model <- PIDE.document_model(buffer)
    1.33 -              if model.is_theory
    1.34 -            } yield (model.node_name, Position.none)
    1.35 +            val thys =
    1.36 +              for {
    1.37 +                buffer <- buffers
    1.38 +                model <- PIDE.document_model(buffer)
    1.39 +                if model.is_theory
    1.40 +              } yield (model.node_name, Position.none)
    1.41  
    1.42 -          val thy_info = new Thy_Info(PIDE.resources)
    1.43 -          // FIXME avoid I/O in Swing thread!?!
    1.44 -          val files = thy_info.dependencies("", thys).deps.map(_.name.node).
    1.45 -            filter(file => !loaded_buffer(file) && PIDE.resources.check_file(view, file))
    1.46 +            val thy_info = new Thy_Info(PIDE.resources)
    1.47 +            // FIXME avoid I/O in Swing thread!?!
    1.48 +            val files = thy_info.dependencies("", thys).deps.map(_.name.node).
    1.49 +              filter(file => !loaded_buffer(file) && PIDE.resources.check_file(view, file))
    1.50  
    1.51 -          if (!files.isEmpty) {
    1.52 -            if (PIDE.options.bool("jedit_auto_load")) {
    1.53 -              files.foreach(file => jEdit.openFile(null: View, file))
    1.54 -            }
    1.55 -            else {
    1.56 -              val files_list = new ListView(files.sorted)
    1.57 -              for (i <- 0 until files.length)
    1.58 -                files_list.selection.indices += i
    1.59 +            if (!files.isEmpty) {
    1.60 +              if (PIDE.options.bool("jedit_auto_load")) {
    1.61 +                files.foreach(file => jEdit.openFile(null: View, file))
    1.62 +              }
    1.63 +              else {
    1.64 +                val files_list = new ListView(files.sorted)
    1.65 +                for (i <- 0 until files.length)
    1.66 +                  files_list.selection.indices += i
    1.67  
    1.68 -              val answer =
    1.69 -                GUI.confirm_dialog(view,
    1.70 -                  "Auto loading of required files",
    1.71 -                  JOptionPane.YES_NO_OPTION,
    1.72 -                  "The following files are required to resolve theory imports.",
    1.73 -                  "Reload selected files now?",
    1.74 -                  new ScrollPane(files_list),
    1.75 -                  new Isabelle.Continuous_Checking)
    1.76 -              if (answer == 0) {
    1.77 -                files.foreach(file =>
    1.78 -                  if (files_list.selection.items.contains(file))
    1.79 -                    jEdit.openFile(null: View, file))
    1.80 +                val answer =
    1.81 +                  GUI.confirm_dialog(view,
    1.82 +                    "Auto loading of required files",
    1.83 +                    JOptionPane.YES_NO_OPTION,
    1.84 +                    "The following files are required to resolve theory imports.",
    1.85 +                    "Reload selected files now?",
    1.86 +                    new ScrollPane(files_list),
    1.87 +                    new Isabelle.Continuous_Checking)
    1.88 +                if (answer == 0) {
    1.89 +                  files.foreach(file =>
    1.90 +                    if (files_list.selection.items.contains(file))
    1.91 +                      jEdit.openFile(null: View, file))
    1.92 +                }
    1.93                }
    1.94              }
    1.95            }
    1.96          }
    1.97 +        finally { delay_load_active.change(_ => false) }
    1.98        }
    1.99      }
   1.100