src/Tools/jEdit/src/isabelle_logic.scala
author wenzelm
Tue Aug 12 15:46:20 2014 +0200 (2014-08-12)
changeset 57912 dd9550f84106
parent 57612 990ffb84489b
child 60992 89effcb342df
permissions -rw-r--r--
tuned;
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@57912
    27
    override def toString: String = description
wenzelm@49246
    28
  }
wenzelm@49246
    29
wenzelm@49246
    30
  def logic_selector(autosave: Boolean): Option_Component =
wenzelm@49246
    31
  {
wenzelm@57612
    32
    GUI_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@54881
    63
    val modes =
wenzelm@54881
    64
      space_explode(',', PIDE.options.string("jedit_print_mode")) :::
wenzelm@54881
    65
      space_explode(',', Isabelle_System.getenv("JEDIT_PRINT_MODE"))
wenzelm@54881
    66
wenzelm@54881
    67
    modes.map("-m" + _) ::: List("-r", "-q", jedit_logic())
wenzelm@49246
    68
  }
wenzelm@49246
    69
wenzelm@50380
    70
  def session_dirs(): List[Path] = Path.split(Isabelle_System.getenv("JEDIT_SESSION_DIRS"))
wenzelm@50380
    71
wenzelm@50380
    72
  def session_list(): List[String] =
wenzelm@50380
    73
  {
wenzelm@56890
    74
    val session_tree = Build.find_sessions(PIDE.options.value, dirs = session_dirs())
wenzelm@50574
    75
    val (main_sessions, other_sessions) =
wenzelm@50574
    76
      session_tree.topological_order.partition(p => p._2.groups.contains("main"))
wenzelm@50574
    77
    main_sessions.map(_._1).sorted ::: other_sessions.map(_._1).sorted
wenzelm@50380
    78
  }
wenzelm@50380
    79
wenzelm@49246
    80
  def session_content(inlined_files: Boolean): Build.Session_Content =
wenzelm@49246
    81
  {
wenzelm@50380
    82
    val dirs = session_dirs()
wenzelm@50375
    83
    val name = session_args().last
wenzelm@56801
    84
    val content = Build.session_content(PIDE.options.value, inlined_files, dirs, name)
wenzelm@56801
    85
    content.copy(known_theories =
wenzelm@56801
    86
      content.known_theories.mapValues(name => name.map(Isabelle_System.jvm_path(_))))
wenzelm@49246
    87
  }
wenzelm@49246
    88
}
wenzelm@49246
    89