author | wenzelm |
Sat, 04 Apr 2020 19:18:19 +0200 | |
changeset 71685 | d5773922358d |
parent 71601 | 97ccf48c2f0c |
child 71692 | f8e52c0152fe |
permissions | -rw-r--r-- |
61288 | 1 |
/* Title: Tools/jEdit/src/session_build.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Session build management. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle.jedit |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
11 |
||
12 |
import java.awt.event.{WindowEvent, WindowAdapter} |
|
13 |
import javax.swing.{WindowConstants, JDialog} |
|
14 |
||
15 |
import scala.swing.{ScrollPane, Button, CheckBox, FlowPanel, |
|
16 |
BorderPanel, TextArea, Component, Label} |
|
17 |
import scala.swing.event.ButtonClicked |
|
18 |
||
19 |
import org.gjt.sp.jedit.View |
|
20 |
||
21 |
||
22 |
object Session_Build |
|
23 |
{ |
|
65256 | 24 |
def check_dialog(view: View) |
61288 | 25 |
{ |
26 |
GUI_Thread.require {} |
|
27 |
||
65256 | 28 |
val options = PIDE.options.value |
61288 | 29 |
try { |
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
68957
diff
changeset
|
30 |
if (JEdit_Sessions.session_no_build || |
65256 | 31 |
JEdit_Sessions.session_build(options, no_build = true) == 0) |
32 |
JEdit_Sessions.session_start(options) |
|
61288 | 33 |
else new Dialog(view) |
34 |
} |
|
35 |
catch { |
|
36 |
case exn: Throwable => |
|
37 |
GUI.dialog(view, "Isabelle", GUI.scrollable_text(Exn.message(exn))) |
|
38 |
} |
|
39 |
} |
|
40 |
||
41 |
private class Dialog(view: View) extends JDialog(view) |
|
42 |
{ |
|
71601 | 43 |
val options: Options = PIDE.options.value |
65256 | 44 |
|
45 |
||
61288 | 46 |
/* text */ |
47 |
||
48 |
private val text = new TextArea { |
|
49 |
editable = false |
|
50 |
columns = 65 |
|
51 |
rows = 24 |
|
52 |
} |
|
61742
fd3b214b0979
clarified font: GUI defaults might change dynamically;
wenzelm
parents:
61680
diff
changeset
|
53 |
text.font = GUI.copy_font((new Label).font) |
61288 | 54 |
|
55 |
private val scroll_text = new ScrollPane(text) |
|
56 |
||
57 |
||
58 |
/* progress */ |
|
59 |
||
60 |
@volatile private var is_stopped = false |
|
61 |
||
62 |
private val progress = new Progress { |
|
63 |
override def echo(txt: String): Unit = |
|
64 |
GUI_Thread.later { |
|
65 |
text.append(txt + "\n") |
|
66 |
val vertical = scroll_text.peer.getVerticalScrollBar |
|
67 |
vertical.setValue(vertical.getMaximum) |
|
68 |
} |
|
69 |
||
68957 | 70 |
override def theory(theory: Progress.Theory): Unit = echo(theory.message) |
61288 | 71 |
|
72 |
override def stopped: Boolean = is_stopped |
|
73 |
} |
|
74 |
||
75 |
||
76 |
/* layout panel with dynamic actions */ |
|
77 |
||
78 |
private val action_panel = new FlowPanel(FlowPanel.Alignment.Center)() |
|
79 |
private val layout_panel = new BorderPanel |
|
80 |
layout_panel.layout(scroll_text) = BorderPanel.Position.Center |
|
81 |
layout_panel.layout(action_panel) = BorderPanel.Position.South |
|
82 |
||
83 |
setContentPane(layout_panel.peer) |
|
84 |
||
85 |
private def set_actions(cs: Component*) |
|
86 |
{ |
|
87 |
action_panel.contents.clear |
|
88 |
action_panel.contents ++= cs |
|
89 |
layout_panel.revalidate |
|
90 |
layout_panel.repaint |
|
91 |
} |
|
92 |
||
93 |
||
94 |
/* return code and exit */ |
|
95 |
||
96 |
private var _return_code: Option[Int] = None |
|
97 |
||
98 |
private def return_code(rc: Int): Unit = |
|
99 |
GUI_Thread.later { |
|
100 |
_return_code = Some(rc) |
|
101 |
delay_exit.invoke |
|
102 |
} |
|
103 |
||
104 |
private val delay_exit = |
|
105 |
GUI_Thread.delay_first(Time.seconds(1.0)) |
|
106 |
{ |
|
107 |
if (can_auto_close) conclude() |
|
108 |
else { |
|
61299 | 109 |
val button = new Button("Close") { reactions += { case ButtonClicked(_) => conclude() } } |
61288 | 110 |
set_actions(button) |
111 |
button.peer.getRootPane.setDefaultButton(button.peer) |
|
112 |
} |
|
113 |
} |
|
114 |
||
115 |
private def conclude() |
|
116 |
{ |
|
117 |
setVisible(false) |
|
118 |
dispose() |
|
119 |
} |
|
120 |
||
121 |
||
122 |
/* close */ |
|
123 |
||
124 |
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE) |
|
125 |
||
126 |
addWindowListener(new WindowAdapter { |
|
127 |
override def windowClosing(e: WindowEvent) { |
|
128 |
if (_return_code.isDefined) conclude() |
|
129 |
else stopping() |
|
130 |
} |
|
131 |
}) |
|
132 |
||
133 |
private def stopping() |
|
134 |
{ |
|
135 |
is_stopped = true |
|
136 |
set_actions(new Label("Stopping ...")) |
|
137 |
} |
|
138 |
||
139 |
private val stop_button = new Button("Stop") { |
|
140 |
reactions += { case ButtonClicked(_) => stopping() } |
|
141 |
} |
|
142 |
||
143 |
private var do_auto_close = true |
|
144 |
private def can_auto_close: Boolean = do_auto_close && _return_code == Some(0) |
|
145 |
||
146 |
private val auto_close = new CheckBox("Auto close") { |
|
147 |
reactions += { |
|
148 |
case ButtonClicked(_) => do_auto_close = this.selected |
|
149 |
if (can_auto_close) conclude() |
|
150 |
} |
|
151 |
} |
|
152 |
auto_close.selected = do_auto_close |
|
153 |
auto_close.tooltip = "Automatically close dialog when finished" |
|
154 |
||
155 |
set_actions(stop_button, auto_close) |
|
156 |
||
157 |
||
158 |
/* main */ |
|
159 |
||
160 |
setTitle("Isabelle build (" + |
|
161 |
Isabelle_System.getenv("ML_IDENTIFIER") + " / " + |
|
162 |
"jdk-" + Platform.jvm_version + "_" + Platform.jvm_platform + ")") |
|
163 |
||
164 |
pack() |
|
165 |
setLocationRelativeTo(view) |
|
166 |
setVisible(true) |
|
167 |
||
71685 | 168 |
Standard_Thread.fork(name = "session_build") { |
66973
829c3133c4ca
added isabelle jedit options -B, -P, clarified -R;
wenzelm
parents:
65828
diff
changeset
|
169 |
progress.echo("Build started for Isabelle/" + PIDE.resources.session_name + " ...") |
61288 | 170 |
|
171 |
val (out, rc) = |
|
65256 | 172 |
try { ("", JEdit_Sessions.session_build(options, progress = progress)) } |
61288 | 173 |
catch { |
174 |
case exn: Throwable => |
|
65828 | 175 |
(Output.error_message_text(Exn.message(exn)) + "\n", Exn.return_code(exn, 2)) |
61288 | 176 |
} |
177 |
||
178 |
progress.echo(out + (if (rc == 0) "OK\n" else "Return code: " + rc + "\n")) |
|
61289 | 179 |
|
65256 | 180 |
if (rc == 0) JEdit_Sessions.session_start(options) |
61680 | 181 |
else progress.echo("Session build failed -- prover process remains inactive!") |
61288 | 182 |
|
183 |
return_code(rc) |
|
184 |
} |
|
185 |
} |
|
186 |
} |