src/Tools/jEdit/src/isabelle_logic.scala
author wenzelm
Mon Jun 24 23:33:14 2013 +0200 (2013-06-24)
changeset 52439 4cf3f6153eb8
parent 51297 d9f3d91208af
child 52834 a3f8c9f16d26
permissions -rw-r--r--
improved "isabelle keywords" and "isabelle update_keywords" based on Isabelle/Scala, without requiring to build sessions first;
tuned signature;
wenzelm@49246
     1
/*  Title:      Tools/jEdit/src/isabelle_logic.scala
wenzelm@49246
     2
    Author:     Makarius
wenzelm@49246
     3
wenzelm@49246
     4
Isabellel logic session.
wenzelm@49246
     5
*/
wenzelm@49246
     6
wenzelm@49246
     7
package isabelle.jedit
wenzelm@49246
     8
wenzelm@49246
     9
wenzelm@49246
    10
import isabelle._
wenzelm@49246
    11
wenzelm@49246
    12
import scala.swing.ComboBox
wenzelm@49246
    13
import scala.swing.event.SelectionChanged
wenzelm@49246
    14
wenzelm@49246
    15
wenzelm@49246
    16
object Isabelle_Logic
wenzelm@49246
    17
{
wenzelm@50403
    18
  private val option_name = "jedit_logic"
wenzelm@50403
    19
wenzelm@50403
    20
  private def jedit_logic(): String =
wenzelm@50403
    21
    Isabelle_System.default_logic(
wenzelm@50403
    22
      Isabelle_System.getenv("JEDIT_LOGIC"),
wenzelm@50403
    23
      PIDE.options.string(option_name))
wenzelm@49246
    24
wenzelm@49246
    25
  private class Logic_Entry(val name: String, val description: String)
wenzelm@49246
    26
  {
wenzelm@49246
    27
    override def toString = description
wenzelm@49246
    28
  }
wenzelm@49246
    29
wenzelm@49246
    30
  def logic_selector(autosave: Boolean): Option_Component =
wenzelm@49246
    31
  {
wenzelm@49246
    32
    Swing_Thread.require()
wenzelm@49246
    33
wenzelm@49246
    34
    val entries =
wenzelm@50403
    35
      new Logic_Entry("", "default (" + jedit_logic() + ")") ::
wenzelm@50380
    36
        Isabelle_Logic.session_list().map(name => new Logic_Entry(name, name))
wenzelm@49246
    37
wenzelm@49246
    38
    val component = new ComboBox(entries) with Option_Component {
wenzelm@50375
    39
      name = option_name
wenzelm@49270
    40
      val title = "Logic"
wenzelm@49247
    41
      def load: Unit =
wenzelm@49247
    42
      {
wenzelm@50375
    43
        val logic = PIDE.options.string(option_name)
wenzelm@49247
    44
        entries.find(_.name == logic) match {
wenzelm@49247
    45
          case Some(entry) => selection.item = entry
wenzelm@49247
    46
          case None =>
wenzelm@49247
    47
        }
wenzelm@49247
    48
      }
wenzelm@50375
    49
      def save: Unit = PIDE.options.string(option_name) = selection.item.name
wenzelm@49246
    50
    }
wenzelm@49246
    51
wenzelm@49247
    52
    component.load()
wenzelm@49246
    53
    if (autosave) {
wenzelm@49246
    54
      component.listenTo(component.selection)
wenzelm@49246
    55
      component.reactions += { case SelectionChanged(_) => component.save() }
wenzelm@49246
    56
    }
wenzelm@50380
    57
    component.tooltip = "Logic session name (change requires restart)"
wenzelm@49246
    58
    component
wenzelm@49246
    59
  }
wenzelm@49246
    60
wenzelm@49246
    61
  def session_args(): List[String] =
wenzelm@49246
    62
  {
wenzelm@49246
    63
    val modes = space_explode(',', Isabelle_System.getenv("JEDIT_PRINT_MODE")).map("-m" + _)
wenzelm@50403
    64
    modes ::: List(jedit_logic())
wenzelm@49246
    65
  }
wenzelm@49246
    66
wenzelm@50380
    67
  def session_dirs(): List[Path] = Path.split(Isabelle_System.getenv("JEDIT_SESSION_DIRS"))
wenzelm@50380
    68
wenzelm@50380
    69
  def session_list(): List[String] =
wenzelm@50380
    70
  {
wenzelm@50380
    71
    val dirs = session_dirs().map((false, _))
wenzelm@50574
    72
    val session_tree = Build.find_sessions(PIDE.options.value, dirs)
wenzelm@50574
    73
    val (main_sessions, other_sessions) =
wenzelm@50574
    74
      session_tree.topological_order.partition(p => p._2.groups.contains("main"))
wenzelm@50574
    75
    main_sessions.map(_._1).sorted ::: other_sessions.map(_._1).sorted
wenzelm@50380
    76
  }
wenzelm@50380
    77
wenzelm@49246
    78
  def session_content(inlined_files: Boolean): Build.Session_Content =
wenzelm@49246
    79
  {
wenzelm@50380
    80
    val dirs = session_dirs()
wenzelm@50375
    81
    val name = session_args().last
wenzelm@52439
    82
    Build.session_content(PIDE.options.value, inlined_files, dirs, name)
wenzelm@49246
    83
  }
wenzelm@49246
    84
}
wenzelm@49246
    85