src/Tools/jEdit/src/isabelle_logic.scala
author wenzelm
Sun, 14 Feb 2016 12:50:46 +0100
changeset 62305 fe01c4c7931a
parent 62296 b04a5ddd6121
child 62308 9b9547c9a6ed
permissions -rw-r--r--
tuned signature;
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
61288
9399860edb46 clarified modules;
wenzelm
parents: 60992
diff changeset
     4
Isabelle logic session.
49246
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
61288
9399860edb46 clarified modules;
wenzelm
parents: 60992
diff changeset
    20
  def session_name(): String =
50403
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
  {
57912
wenzelm
parents: 57612
diff changeset
    27
    override def toString: String = description
49246
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
  {
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 56890
diff changeset
    32
    GUI_Thread.require {}
49246
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 =
61288
9399860edb46 clarified modules;
wenzelm
parents: 60992
diff changeset
    35
      new Logic_Entry("", "default (" + session_name() + ")") ::
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
61288
9399860edb46 clarified modules;
wenzelm
parents: 60992
diff changeset
    61
  def session_build_mode(): String = Isabelle_System.getenv("JEDIT_BUILD_MODE")
9399860edb46 clarified modules;
wenzelm
parents: 60992
diff changeset
    62
9399860edb46 clarified modules;
wenzelm
parents: 60992
diff changeset
    63
  def session_build(progress: Progress = Ignore_Progress, no_build: Boolean = false): Int =
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    64
  {
61288
9399860edb46 clarified modules;
wenzelm
parents: 60992
diff changeset
    65
    val mode = session_build_mode()
9399860edb46 clarified modules;
wenzelm
parents: 60992
diff changeset
    66
9399860edb46 clarified modules;
wenzelm
parents: 60992
diff changeset
    67
    Build.build(options = PIDE.options.value, progress = progress,
9399860edb46 clarified modules;
wenzelm
parents: 60992
diff changeset
    68
      build_heap = true, no_build = no_build, system_mode = mode == "" || mode == "system",
9399860edb46 clarified modules;
wenzelm
parents: 60992
diff changeset
    69
      dirs = session_dirs(), sessions = List(session_name()))
9399860edb46 clarified modules;
wenzelm
parents: 60992
diff changeset
    70
  }
9399860edb46 clarified modules;
wenzelm
parents: 60992
diff changeset
    71
62305
fe01c4c7931a tuned signature;
wenzelm
parents: 62296
diff changeset
    72
  def session_args(): String =
61288
9399860edb46 clarified modules;
wenzelm
parents: 60992
diff changeset
    73
  {
9399860edb46 clarified modules;
wenzelm
parents: 60992
diff changeset
    74
    val print_modes =
62296
b04a5ddd6121 clarified bash process -- similar to ML version;
wenzelm
parents: 61288
diff changeset
    75
      (space_explode(',', PIDE.options.string("jedit_print_mode")) :::
b04a5ddd6121 clarified bash process -- similar to ML version;
wenzelm
parents: 61288
diff changeset
    76
       space_explode(',', Isabelle_System.getenv("JEDIT_PRINT_MODE"))).map("-m " + _)
62305
fe01c4c7931a tuned signature;
wenzelm
parents: 62296
diff changeset
    77
    (print_modes ::: List("-r", "-q", quote(session_name()))).mkString(" ")
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    78
  }
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    79
62305
fe01c4c7931a tuned signature;
wenzelm
parents: 62296
diff changeset
    80
  def session_start(): Unit = PIDE.session.start("Isabelle", session_args())
fe01c4c7931a tuned signature;
wenzelm
parents: 62296
diff changeset
    81
50380
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    82
  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
    83
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    84
  def session_list(): List[String] =
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    85
  {
56890
7f120d227ca5 tuned signature;
wenzelm
parents: 56801
diff changeset
    86
    val session_tree = Build.find_sessions(PIDE.options.value, dirs = session_dirs())
50574
0706797501a0 offer sessions of group "main" first to increase chances that the user makes a sensible choice;
wenzelm
parents: 50403
diff changeset
    87
    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
    88
      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
    89
    main_sessions.map(_._1).sorted ::: other_sessions.map(_._1).sorted
50380
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    90
  }
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    91
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    92
  def session_content(inlined_files: Boolean): Build.Session_Content =
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    93
  {
61288
9399860edb46 clarified modules;
wenzelm
parents: 60992
diff changeset
    94
    val content =
9399860edb46 clarified modules;
wenzelm
parents: 60992
diff changeset
    95
      Build.session_content(PIDE.options.value, inlined_files, session_dirs(), session_name())
56801
8dd9df88f647 some support for session-qualified theories: allow to refer to resources via qualified name instead of odd file-system path;
wenzelm
parents: 56662
diff changeset
    96
    content.copy(known_theories =
60992
89effcb342df clarified modules, like ML version;
wenzelm
parents: 57912
diff changeset
    97
      content.known_theories.mapValues(name => name.map(File.platform_path(_))))
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    98
  }
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    99
}