src/Tools/jEdit/src/isabelle_logic.scala
author wenzelm
Mon, 17 Dec 2012 11:07:20 +0100
changeset 50574 0706797501a0
parent 50403 87868964733c
child 51297 d9f3d91208af
permissions -rw-r--r--
offer sessions of group "main" first to increase chances that the user makes a sensible choice;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
     1
/*  Title:      Tools/jEdit/src/isabelle_logic.scala
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
     3
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
     4
Isabellel logic session.
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
     5
*/
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
     6
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
     7
package isabelle.jedit
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
     8
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
     9
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    10
import isabelle._
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    11
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    12
import scala.swing.ComboBox
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    13
import scala.swing.event.SelectionChanged
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    14
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    15
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    16
object Isabelle_Logic
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    17
{
50403
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50380
diff changeset
    18
  private val option_name = "jedit_logic"
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50380
diff changeset
    19
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50380
diff changeset
    20
  private def jedit_logic(): String =
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50380
diff changeset
    21
    Isabelle_System.default_logic(
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50380
diff changeset
    22
      Isabelle_System.getenv("JEDIT_LOGIC"),
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50380
diff changeset
    23
      PIDE.options.string(option_name))
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    24
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    25
  private class Logic_Entry(val name: String, val description: String)
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    26
  {
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    27
    override def toString = description
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    28
  }
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    29
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    30
  def logic_selector(autosave: Boolean): Option_Component =
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    31
  {
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    32
    Swing_Thread.require()
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    33
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    34
    val entries =
50403
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50380
diff changeset
    35
      new Logic_Entry("", "default (" + jedit_logic() + ")") ::
50380
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    36
        Isabelle_Logic.session_list().map(name => new Logic_Entry(name, name))
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    37
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    38
    val component = new ComboBox(entries) with Option_Component {
50375
c101127a7f37 clarified logic argument: session name, not path name;
wenzelm
parents: 50205
diff changeset
    39
      name = option_name
49270
e5d162d15867 some support to organize options in sections;
wenzelm
parents: 49248
diff changeset
    40
      val title = "Logic"
49247
ffd9ad9dc35b more detailed option tooltip;
wenzelm
parents: 49246
diff changeset
    41
      def load: Unit =
ffd9ad9dc35b more detailed option tooltip;
wenzelm
parents: 49246
diff changeset
    42
      {
50375
c101127a7f37 clarified logic argument: session name, not path name;
wenzelm
parents: 50205
diff changeset
    43
        val logic = PIDE.options.string(option_name)
49247
ffd9ad9dc35b more detailed option tooltip;
wenzelm
parents: 49246
diff changeset
    44
        entries.find(_.name == logic) match {
ffd9ad9dc35b more detailed option tooltip;
wenzelm
parents: 49246
diff changeset
    45
          case Some(entry) => selection.item = entry
ffd9ad9dc35b more detailed option tooltip;
wenzelm
parents: 49246
diff changeset
    46
          case None =>
ffd9ad9dc35b more detailed option tooltip;
wenzelm
parents: 49246
diff changeset
    47
        }
ffd9ad9dc35b more detailed option tooltip;
wenzelm
parents: 49246
diff changeset
    48
      }
50375
c101127a7f37 clarified logic argument: session name, not path name;
wenzelm
parents: 50205
diff changeset
    49
      def save: Unit = PIDE.options.string(option_name) = selection.item.name
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    50
    }
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    51
49247
ffd9ad9dc35b more detailed option tooltip;
wenzelm
parents: 49246
diff changeset
    52
    component.load()
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    53
    if (autosave) {
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    54
      component.listenTo(component.selection)
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    55
      component.reactions += { case SelectionChanged(_) => component.save() }
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    56
    }
50380
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    57
    component.tooltip = "Logic session name (change requires restart)"
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    58
    component
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    59
  }
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    60
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    61
  def session_args(): List[String] =
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    62
  {
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    63
    val modes = space_explode(',', Isabelle_System.getenv("JEDIT_PRINT_MODE")).map("-m" + _)
50403
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50380
diff changeset
    64
    modes ::: List(jedit_logic())
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    65
  }
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    66
50380
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    67
  def session_dirs(): List[Path] = Path.split(Isabelle_System.getenv("JEDIT_SESSION_DIRS"))
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    68
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    69
  def session_list(): List[String] =
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    70
  {
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    71
    val dirs = session_dirs().map((false, _))
50574
0706797501a0 offer sessions of group "main" first to increase chances that the user makes a sensible choice;
wenzelm
parents: 50403
diff changeset
    72
    val session_tree = Build.find_sessions(PIDE.options.value, dirs)
0706797501a0 offer sessions of group "main" first to increase chances that the user makes a sensible choice;
wenzelm
parents: 50403
diff changeset
    73
    val (main_sessions, other_sessions) =
0706797501a0 offer sessions of group "main" first to increase chances that the user makes a sensible choice;
wenzelm
parents: 50403
diff changeset
    74
      session_tree.topological_order.partition(p => p._2.groups.contains("main"))
0706797501a0 offer sessions of group "main" first to increase chances that the user makes a sensible choice;
wenzelm
parents: 50403
diff changeset
    75
    main_sessions.map(_._1).sorted ::: other_sessions.map(_._1).sorted
50380
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    76
  }
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    77
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    78
  def session_content(inlined_files: Boolean): Build.Session_Content =
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    79
  {
50380
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    80
    val dirs = session_dirs()
50375
c101127a7f37 clarified logic argument: session name, not path name;
wenzelm
parents: 50205
diff changeset
    81
    val name = session_args().last
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    82
    Build.session_content(inlined_files, dirs, name).check_errors
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    83
  }
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    84
}
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    85