author | wenzelm |
Thu, 02 Nov 2017 10:16:22 +0100 | |
changeset 66987 | 352b23c97ac8 |
parent 66979 | 58b166fd8447 |
child 66988 | 7f8c1dd7576a |
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 |
|
66987
352b23c97ac8
support focus_session, for much faster startup of Isabelle/jEdit;
wenzelm
parents:
66979
diff
changeset
|
42 |
def logic_focus: Boolean = Isabelle_System.getenv("JEDIT_LOGIC_FOCUS") == "true" |
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
43 |
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
|
44 |
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
|
45 |
|
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
46 |
def logic_info(options: Options): Option[Sessions.Info] = |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
47 |
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
|
48 |
catch { case ERROR(_) => None } |
64602 | 49 |
|
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
50 |
def logic_root(options: Options): Position.T = |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
51 |
if (Isabelle_System.getenv("JEDIT_LOGIC_ROOT") == "true") { |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
52 |
logic_info(options).map(_.pos) getOrElse Position.none |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
53 |
} |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
54 |
else Position.none |
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 |
|
66979 | 57 |
/* logic selector */ |
58 |
||
59 |
private class Logic_Entry(val name: String, val description: String) |
|
60 |
{ |
|
61 |
override def toString: String = description |
|
62 |
} |
|
63 |
||
64 |
def logic_selector(options: Options_Variable, autosave: Boolean): Option_Component = |
|
65 |
{ |
|
66 |
GUI_Thread.require {} |
|
67 |
||
68 |
val session_list = |
|
69 |
{ |
|
70 |
val sessions = Sessions.load(options.value, dirs = session_dirs()) |
|
71 |
val (main_sessions, other_sessions) = |
|
72 |
sessions.imports_topological_order.partition(info => info.groups.contains("main")) |
|
73 |
main_sessions.map(_.name).sorted ::: other_sessions.map(_.name).sorted |
|
74 |
} |
|
75 |
||
76 |
val entries = |
|
77 |
new Logic_Entry("", "default (" + logic_name(options.value) + ")") :: |
|
78 |
session_list.map(name => new Logic_Entry(name, name)) |
|
79 |
||
80 |
val component = new ComboBox(entries) with Option_Component { |
|
81 |
name = jedit_logic_option |
|
82 |
val title = "Logic" |
|
83 |
def load: Unit = |
|
84 |
{ |
|
85 |
val logic = options.string(jedit_logic_option) |
|
86 |
entries.find(_.name == logic) match { |
|
87 |
case Some(entry) => selection.item = entry |
|
88 |
case None => |
|
89 |
} |
|
90 |
} |
|
91 |
def save: Unit = options.string(jedit_logic_option) = selection.item.name |
|
92 |
} |
|
93 |
||
94 |
component.load() |
|
95 |
if (autosave) { |
|
96 |
component.listenTo(component.selection) |
|
97 |
component.reactions += { case SelectionChanged(_) => component.save() } |
|
98 |
} |
|
99 |
component.tooltip = "Logic session name (change requires restart)" |
|
100 |
component |
|
101 |
} |
|
102 |
||
103 |
||
104 |
/* session build process */ |
|
64602 | 105 |
|
66963 | 106 |
def session_base_info(options: Options): Sessions.Base_Info = |
66976 | 107 |
Sessions.base_info(options, |
66987
352b23c97ac8
support focus_session, for much faster startup of Isabelle/jEdit;
wenzelm
parents:
66979
diff
changeset
|
108 |
session = |
352b23c97ac8
support focus_session, for much faster startup of Isabelle/jEdit;
wenzelm
parents:
66979
diff
changeset
|
109 |
if (logic_parent) logic_info(options).flatMap(_.parent) getOrElse logic_name(options) |
352b23c97ac8
support focus_session, for much faster startup of Isabelle/jEdit;
wenzelm
parents:
66979
diff
changeset
|
110 |
else logic_name(options), |
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
111 |
dirs = JEdit_Sessions.session_dirs(), |
66987
352b23c97ac8
support focus_session, for much faster startup of Isabelle/jEdit;
wenzelm
parents:
66979
diff
changeset
|
112 |
all_known = !logic_focus, |
352b23c97ac8
support focus_session, for much faster startup of Isabelle/jEdit;
wenzelm
parents:
66979
diff
changeset
|
113 |
focus_session = logic_focus, |
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
114 |
required_session = logic_base) |
65571 | 115 |
|
65256 | 116 |
def session_build( |
117 |
options: Options, progress: Progress = No_Progress, no_build: Boolean = false): Int = |
|
62972 | 118 |
{ |
119 |
val mode = session_build_mode() |
|
120 |
||
65256 | 121 |
Build.build(options = session_options(options), progress = progress, |
62972 | 122 |
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
|
123 |
dirs = session_dirs(), infos = PIDE.resources.session_base_info.infos, |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
124 |
sessions = List(PIDE.resources.session_name)).rc |
62972 | 125 |
} |
126 |
||
65256 | 127 |
def session_start(options: Options) |
62972 | 128 |
{ |
65256 | 129 |
Isabelle_Process.start(PIDE.session, session_options(options), |
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
130 |
sessions = Some(PIDE.resources.session_base_info.sessions), |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
131 |
logic = PIDE.resources.session_name, |
65226 | 132 |
store = Sessions.store(session_build_mode() == "system"), |
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
133 |
modes = |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
134 |
(space_explode(',', options.string("jedit_print_mode")) ::: |
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
66965
diff
changeset
|
135 |
space_explode(',', Isabelle_System.getenv("JEDIT_PRINT_MODE"))).reverse, |
65226 | 136 |
phase_changed = PIDE.plugin.session_phase_changed) |
62972 | 137 |
} |
49246 | 138 |
} |