author | wenzelm |
Wed, 01 Nov 2017 15:32:07 +0100 | |
changeset 66973 | 829c3133c4ca |
parent 66965 | 9cec50354099 |
child 66976 | 806bc39550a5 |
permissions | -rw-r--r-- |
62973 | 1 |
/* Title: Tools/jEdit/src/jedit_sessions.scala |
49246 | 2 |
Author: Makarius |
3 |
||
65256 | 4 |
Isabelle/jEdit session information, based on implicit process environment |
5 |
and explicit options. |
|
49246 | 6 |
*/ |
7 |
||
8 |
package isabelle.jedit |
|
9 |
||
10 |
||
11 |
import isabelle._ |
|
12 |
||
13 |
import scala.swing.ComboBox |
|
14 |
import scala.swing.event.SelectionChanged |
|
15 |
||
16 |
||
62973 | 17 |
object JEdit_Sessions |
49246 | 18 |
{ |
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
19 |
/* session options */ |
62972 | 20 |
|
65256 | 21 |
def session_options(options: Options): Options = |
63986
c7a4b03727ae
options for process policy, notably for multiprocessor machines;
wenzelm
parents:
62974
diff
changeset
|
22 |
Isabelle_System.getenv("JEDIT_ML_PROCESS_POLICY") match { |
65256 | 23 |
case "" => options |
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
24 |
case s => options.string.update("ML_process_policy", s) |
63986
c7a4b03727ae
options for process policy, notably for multiprocessor machines;
wenzelm
parents:
62974
diff
changeset
|
25 |
} |
c7a4b03727ae
options for process policy, notably for multiprocessor machines;
wenzelm
parents:
62974
diff
changeset
|
26 |
|
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
27 |
def session_dirs(): List[Path] = |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
28 |
Path.split(Isabelle_System.getenv("JEDIT_SESSION_DIRS")) |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
29 |
|
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
30 |
def session_build_mode(): String = Isabelle_System.getenv("JEDIT_BUILD_MODE") |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
31 |
|
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
32 |
|
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
33 |
/* raw logic info */ |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
34 |
|
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
35 |
private val jedit_logic_option = "jedit_logic" |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
36 |
|
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
37 |
def logic_name(options: Options): String = |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
38 |
Isabelle_System.default_logic( |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
39 |
Isabelle_System.getenv("JEDIT_LOGIC"), |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
40 |
options.string(jedit_logic_option)) |
64602 | 41 |
|
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
42 |
def logic_base: Boolean = Isabelle_System.getenv("JEDIT_LOGIC_BASE") == "true" |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
43 |
def logic_parent: Boolean = Isabelle_System.getenv("JEDIT_LOGIC_PARENT") == "true" |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
44 |
|
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
45 |
def logic_info(options: Options): Option[Sessions.Info] = |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
46 |
try { Sessions.load(session_options(options), dirs = session_dirs()).get(logic_name(options)) } |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
47 |
catch { case ERROR(_) => None } |
64602 | 48 |
|
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
49 |
def logic_root(options: Options): Position.T = |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
50 |
if (Isabelle_System.getenv("JEDIT_LOGIC_ROOT") == "true") { |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
51 |
logic_info(options).map(_.pos) getOrElse Position.none |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
52 |
} |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
53 |
else Position.none |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
54 |
|
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
55 |
|
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
56 |
/* session base info */ |
64602 | 57 |
|
66963 | 58 |
def session_base_info(options: Options): Sessions.Base_Info = |
65572
6acb28e5ba41
clarified meaning of "isabelle jedit -R": avoid potential problems with all_known = true;
wenzelm
parents:
65571
diff
changeset
|
59 |
{ |
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
60 |
val logic = logic_name(options) |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
61 |
|
66963 | 62 |
Sessions.session_base_info(options, |
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
63 |
if (logic_parent) logic_info(options).flatMap(_.parent) getOrElse logic else logic, |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
64 |
dirs = JEdit_Sessions.session_dirs(), |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
65 |
all_known = true, |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
66 |
required_session = logic_base) |
65572
6acb28e5ba41
clarified meaning of "isabelle jedit -R": avoid potential problems with all_known = true;
wenzelm
parents:
65571
diff
changeset
|
67 |
} |
65571 | 68 |
|
65256 | 69 |
def session_build( |
70 |
options: Options, progress: Progress = No_Progress, no_build: Boolean = false): Int = |
|
62972 | 71 |
{ |
72 |
val mode = session_build_mode() |
|
73 |
||
65256 | 74 |
Build.build(options = session_options(options), progress = progress, |
62972 | 75 |
build_heap = true, no_build = no_build, system_mode = mode == "" || mode == "system", |
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
76 |
dirs = session_dirs(), infos = PIDE.resources.session_base_info.infos, |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
77 |
sessions = List(PIDE.resources.session_name)).rc |
62972 | 78 |
} |
79 |
||
65256 | 80 |
def session_start(options: Options) |
62972 | 81 |
{ |
65256 | 82 |
Isabelle_Process.start(PIDE.session, session_options(options), |
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
83 |
sessions = Some(PIDE.resources.session_base_info.sessions), |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
84 |
logic = PIDE.resources.session_name, |
65226 | 85 |
store = Sessions.store(session_build_mode() == "system"), |
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
86 |
modes = |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
87 |
(space_explode(',', options.string("jedit_print_mode")) ::: |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
88 |
space_explode(',', Isabelle_System.getenv("JEDIT_PRINT_MODE"))).reverse, |
65226 | 89 |
phase_changed = PIDE.plugin.session_phase_changed) |
62972 | 90 |
} |
91 |
||
65256 | 92 |
def session_list(options: Options): List[String] = |
62972 | 93 |
{ |
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
94 |
val sessions = |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
95 |
Sessions.load(options, dirs = session_dirs(), infos = PIDE.resources.session_base_info.infos) |
62972 | 96 |
val (main_sessions, other_sessions) = |
65519 | 97 |
sessions.imports_topological_order.partition(info => info.groups.contains("main")) |
98 |
main_sessions.map(_.name).sorted ::: other_sessions.map(_.name).sorted |
|
62972 | 99 |
} |
100 |
||
101 |
||
102 |
/* logic selector */ |
|
103 |
||
49246 | 104 |
private class Logic_Entry(val name: String, val description: String) |
105 |
{ |
|
57912 | 106 |
override def toString: String = description |
49246 | 107 |
} |
108 |
||
66460
f7b0d6fb417a
proper update of options (amending c3d6dd17d626);
wenzelm
parents:
65572
diff
changeset
|
109 |
def logic_selector(options: Options_Variable, autosave: Boolean): Option_Component = |
49246 | 110 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56890
diff
changeset
|
111 |
GUI_Thread.require {} |
49246 | 112 |
|
113 |
val entries = |
|
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
114 |
new Logic_Entry("", "default (" + PIDE.resources.session_name + ")") :: |
66460
f7b0d6fb417a
proper update of options (amending c3d6dd17d626);
wenzelm
parents:
65572
diff
changeset
|
115 |
session_list(options.value).map(name => new Logic_Entry(name, name)) |
49246 | 116 |
|
117 |
val component = new ComboBox(entries) with Option_Component { |
|
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
118 |
name = jedit_logic_option |
49270 | 119 |
val title = "Logic" |
49247 | 120 |
def load: Unit = |
121 |
{ |
|
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
122 |
val logic = options.string(jedit_logic_option) |
49247 | 123 |
entries.find(_.name == logic) match { |
124 |
case Some(entry) => selection.item = entry |
|
125 |
case None => |
|
126 |
} |
|
127 |
} |
|
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
128 |
def save: Unit = options.string(jedit_logic_option) = selection.item.name |
49246 | 129 |
} |
130 |
||
49247 | 131 |
component.load() |
49246 | 132 |
if (autosave) { |
133 |
component.listenTo(component.selection) |
|
134 |
component.reactions += { case SelectionChanged(_) => component.save() } |
|
135 |
} |
|
50380 | 136 |
component.tooltip = "Logic session name (change requires restart)" |
49246 | 137 |
component |
138 |
} |
|
139 |
} |