author | wenzelm |
Thu, 31 Aug 2017 16:35:09 +0200 | |
changeset 66572 | 1e5ae735e026 |
parent 66460 | f7b0d6fb417a |
child 66574 | e16b27bd3f76 |
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 |
{ |
62972 | 19 |
/* session info */ |
20 |
||
50403
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50380
diff
changeset
|
21 |
private val option_name = "jedit_logic" |
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50380
diff
changeset
|
22 |
|
64602 | 23 |
sealed case class Info(name: String, open_root: Position.T) |
49246 | 24 |
|
62972 | 25 |
def session_dirs(): List[Path] = Path.split(Isabelle_System.getenv("JEDIT_SESSION_DIRS")) |
26 |
||
65256 | 27 |
def session_options(options: Options): Options = |
63986
c7a4b03727ae
options for process policy, notably for multiprocessor machines;
wenzelm
parents:
62974
diff
changeset
|
28 |
Isabelle_System.getenv("JEDIT_ML_PROCESS_POLICY") match { |
65256 | 29 |
case "" => options |
30 |
case s => options.string("ML_process_policy") = s |
|
63986
c7a4b03727ae
options for process policy, notably for multiprocessor machines;
wenzelm
parents:
62974
diff
changeset
|
31 |
} |
c7a4b03727ae
options for process policy, notably for multiprocessor machines;
wenzelm
parents:
62974
diff
changeset
|
32 |
|
65572
6acb28e5ba41
clarified meaning of "isabelle jedit -R": avoid potential problems with all_known = true;
wenzelm
parents:
65571
diff
changeset
|
33 |
def session_restricted(): Boolean = |
6acb28e5ba41
clarified meaning of "isabelle jedit -R": avoid potential problems with all_known = true;
wenzelm
parents:
65571
diff
changeset
|
34 |
Isabelle_System.getenv("JEDIT_LOGIC_RESTRICT") == "true" |
6acb28e5ba41
clarified meaning of "isabelle jedit -R": avoid potential problems with all_known = true;
wenzelm
parents:
65571
diff
changeset
|
35 |
|
65256 | 36 |
def session_info(options: Options): Info = |
64602 | 37 |
{ |
38 |
val logic = |
|
39 |
Isabelle_System.default_logic( |
|
40 |
Isabelle_System.getenv("JEDIT_LOGIC"), |
|
65256 | 41 |
options.string(option_name)) |
64602 | 42 |
|
43 |
(for { |
|
65421 | 44 |
sessions <- |
65256 | 45 |
try { Some(Sessions.load(session_options(options), dirs = session_dirs())) } |
64602 | 46 |
catch { case ERROR(_) => None } |
65421 | 47 |
info <- sessions.get(logic) |
64602 | 48 |
parent <- info.parent |
65572
6acb28e5ba41
clarified meaning of "isabelle jedit -R": avoid potential problems with all_known = true;
wenzelm
parents:
65571
diff
changeset
|
49 |
if session_restricted() |
64602 | 50 |
} yield Info(parent, info.pos)) getOrElse Info(logic, Position.none) |
51 |
} |
|
52 |
||
65256 | 53 |
def session_name(options: Options): String = session_info(options).name |
64602 | 54 |
|
66572
1e5ae735e026
tolerate errors in session structure, although this may lead to confusion about theory imports later on;
wenzelm
parents:
66460
diff
changeset
|
55 |
def session_base(options: Options): (List[String], Sessions.Base) = |
65572
6acb28e5ba41
clarified meaning of "isabelle jedit -R": avoid potential problems with all_known = true;
wenzelm
parents:
65571
diff
changeset
|
56 |
{ |
6acb28e5ba41
clarified meaning of "isabelle jedit -R": avoid potential problems with all_known = true;
wenzelm
parents:
65571
diff
changeset
|
57 |
val all_known = !session_restricted() |
66572
1e5ae735e026
tolerate errors in session structure, although this may lead to confusion about theory imports later on;
wenzelm
parents:
66460
diff
changeset
|
58 |
val (errs, base) = |
1e5ae735e026
tolerate errors in session structure, although this may lead to confusion about theory imports later on;
wenzelm
parents:
66460
diff
changeset
|
59 |
Sessions.session_base_errors( |
1e5ae735e026
tolerate errors in session structure, although this may lead to confusion about theory imports later on;
wenzelm
parents:
66460
diff
changeset
|
60 |
options, session_name(options), dirs = JEdit_Sessions.session_dirs(), all_known = all_known) |
1e5ae735e026
tolerate errors in session structure, although this may lead to confusion about theory imports later on;
wenzelm
parents:
66460
diff
changeset
|
61 |
(errs, base.platform_path) |
65572
6acb28e5ba41
clarified meaning of "isabelle jedit -R": avoid potential problems with all_known = true;
wenzelm
parents:
65571
diff
changeset
|
62 |
} |
65571 | 63 |
|
62972 | 64 |
def session_build_mode(): String = Isabelle_System.getenv("JEDIT_BUILD_MODE") |
65 |
||
65256 | 66 |
def session_build( |
67 |
options: Options, progress: Progress = No_Progress, no_build: Boolean = false): Int = |
|
62972 | 68 |
{ |
69 |
val mode = session_build_mode() |
|
70 |
||
65256 | 71 |
Build.build(options = session_options(options), progress = progress, |
62972 | 72 |
build_heap = true, no_build = no_build, system_mode = mode == "" || mode == "system", |
65256 | 73 |
dirs = session_dirs(), sessions = List(session_name(options))).rc |
62972 | 74 |
} |
75 |
||
65256 | 76 |
def session_start(options: Options) |
62972 | 77 |
{ |
78 |
val modes = |
|
65256 | 79 |
(space_explode(',', options.string("jedit_print_mode")) ::: |
62972 | 80 |
space_explode(',', Isabelle_System.getenv("JEDIT_PRINT_MODE"))).reverse |
63986
c7a4b03727ae
options for process policy, notably for multiprocessor machines;
wenzelm
parents:
62974
diff
changeset
|
81 |
|
65256 | 82 |
Isabelle_Process.start(PIDE.session, session_options(options), |
83 |
logic = session_name(options), dirs = session_dirs(), modes = modes, |
|
65226 | 84 |
store = Sessions.store(session_build_mode() == "system"), |
85 |
phase_changed = PIDE.plugin.session_phase_changed) |
|
62972 | 86 |
} |
87 |
||
65256 | 88 |
def session_list(options: Options): List[String] = |
62972 | 89 |
{ |
65421 | 90 |
val sessions = Sessions.load(options, dirs = session_dirs()) |
62972 | 91 |
val (main_sessions, other_sessions) = |
65519 | 92 |
sessions.imports_topological_order.partition(info => info.groups.contains("main")) |
93 |
main_sessions.map(_.name).sorted ::: other_sessions.map(_.name).sorted |
|
62972 | 94 |
} |
95 |
||
96 |
||
97 |
/* logic selector */ |
|
98 |
||
49246 | 99 |
private class Logic_Entry(val name: String, val description: String) |
100 |
{ |
|
57912 | 101 |
override def toString: String = description |
49246 | 102 |
} |
103 |
||
66460
f7b0d6fb417a
proper update of options (amending c3d6dd17d626);
wenzelm
parents:
65572
diff
changeset
|
104 |
def logic_selector(options: Options_Variable, autosave: Boolean): Option_Component = |
49246 | 105 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56890
diff
changeset
|
106 |
GUI_Thread.require {} |
49246 | 107 |
|
108 |
val entries = |
|
66460
f7b0d6fb417a
proper update of options (amending c3d6dd17d626);
wenzelm
parents:
65572
diff
changeset
|
109 |
new Logic_Entry("", "default (" + session_name(options.value) + ")") :: |
f7b0d6fb417a
proper update of options (amending c3d6dd17d626);
wenzelm
parents:
65572
diff
changeset
|
110 |
session_list(options.value).map(name => new Logic_Entry(name, name)) |
49246 | 111 |
|
112 |
val component = new ComboBox(entries) with Option_Component { |
|
50375
c101127a7f37
clarified logic argument: session name, not path name;
wenzelm
parents:
50205
diff
changeset
|
113 |
name = option_name |
49270 | 114 |
val title = "Logic" |
49247 | 115 |
def load: Unit = |
116 |
{ |
|
65256 | 117 |
val logic = options.string(option_name) |
49247 | 118 |
entries.find(_.name == logic) match { |
119 |
case Some(entry) => selection.item = entry |
|
120 |
case None => |
|
121 |
} |
|
122 |
} |
|
65256 | 123 |
def save: Unit = options.string(option_name) = selection.item.name |
49246 | 124 |
} |
125 |
||
49247 | 126 |
component.load() |
49246 | 127 |
if (autosave) { |
128 |
component.listenTo(component.selection) |
|
129 |
component.reactions += { case SelectionChanged(_) => component.save() } |
|
130 |
} |
|
50380 | 131 |
component.tooltip = "Logic session name (change requires restart)" |
49246 | 132 |
component |
133 |
} |
|
134 |
} |