src/Tools/jEdit/src/isabelle_logic.scala
author wenzelm
Wed, 23 Jul 2014 11:19:24 +0200
changeset 57612 990ffb84489b
parent 56890 7f120d227ca5
child 57912 dd9550f84106
permissions -rw-r--r--
clarified module name: facilitate alternative GUI frameworks;
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
  {
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 =
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
  {
54881
dff57132cf18 added system option "jedit_print_mode";
wenzelm
parents: 52834
diff changeset
    63
    val modes =
dff57132cf18 added system option "jedit_print_mode";
wenzelm
parents: 52834
diff changeset
    64
      space_explode(',', PIDE.options.string("jedit_print_mode")) :::
dff57132cf18 added system option "jedit_print_mode";
wenzelm
parents: 52834
diff changeset
    65
      space_explode(',', Isabelle_System.getenv("JEDIT_PRINT_MODE"))
dff57132cf18 added system option "jedit_print_mode";
wenzelm
parents: 52834
diff changeset
    66
dff57132cf18 added system option "jedit_print_mode";
wenzelm
parents: 52834
diff changeset
    67
    modes.map("-m" + _) ::: List("-r", "-q", jedit_logic())
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    68
  }
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    69
50380
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    70
  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
    71
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    72
  def session_list(): List[String] =
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    73
  {
56890
7f120d227ca5 tuned signature;
wenzelm
parents: 56801
diff changeset
    74
    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
    75
    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
    76
      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
    77
    main_sessions.map(_._1).sorted ::: other_sessions.map(_._1).sorted
50380
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    78
  }
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    79
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    80
  def session_content(inlined_files: Boolean): Build.Session_Content =
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    81
  {
50380
b1cb76418760 select logic session names, not paths;
wenzelm
parents: 50375
diff changeset
    82
    val dirs = session_dirs()
50375
c101127a7f37 clarified logic argument: session name, not path name;
wenzelm
parents: 50205
diff changeset
    83
    val name = session_args().last
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
    84
    val content = Build.session_content(PIDE.options.value, inlined_files, dirs, name)
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
    85
    content.copy(known_theories =
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
    86
      content.known_theories.mapValues(name => name.map(Isabelle_System.jvm_path(_))))
49246
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    87
  }
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    88
}
248e66e8321f more systematic JEdit_Options.make_component;
wenzelm
parents:
diff changeset
    89