src/Tools/jEdit/src/isabelle_logic.scala
author wenzelm
Mon Dec 30 20:35:17 2013 +0100 (2013-12-30)
changeset 54881 dff57132cf18
parent 52834 a3f8c9f16d26
child 56662 f373fb77e0a4
permissions -rw-r--r--
added system option "jedit_print_mode";
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@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@50380
    74
    val dirs = session_dirs().map((false, _))
wenzelm@50574
    75
    val session_tree = Build.find_sessions(PIDE.options.value, dirs)
wenzelm@50574
    76
    val (main_sessions, other_sessions) =
wenzelm@50574
    77
      session_tree.topological_order.partition(p => p._2.groups.contains("main"))
wenzelm@50574
    78
    main_sessions.map(_._1).sorted ::: other_sessions.map(_._1).sorted
wenzelm@50380
    79
  }
wenzelm@50380
    80
wenzelm@49246
    81
  def session_content(inlined_files: Boolean): Build.Session_Content =
wenzelm@49246
    82
  {
wenzelm@50380
    83
    val dirs = session_dirs()
wenzelm@50375
    84
    val name = session_args().last
wenzelm@52439
    85
    Build.session_content(PIDE.options.value, inlined_files, dirs, name)
wenzelm@49246
    86
  }
wenzelm@49246
    87
}
wenzelm@49246
    88