author | wenzelm |
Thu, 07 Nov 2024 12:08:32 +0100 | |
changeset 81382 | 5e8287d34295 |
parent 78595 | b0abf5a9dada |
child 81387 | c677755779f5 |
permissions | -rw-r--r-- |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/sledgehammer_dockable.scala |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
3 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
4 |
Dockable window for Sledgehammer. |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
6 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle.jedit |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
8 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
9 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
10 |
import isabelle._ |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
11 |
|
75853 | 12 |
import scala.swing.{Component, Label} |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
13 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
14 |
import java.awt.BorderLayout |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
15 |
import java.awt.event.{ComponentEvent, ComponentAdapter, KeyEvent} |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
16 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
17 |
import org.gjt.sp.jedit.View |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
18 |
import org.gjt.sp.jedit.gui.HistoryTextField |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
19 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
20 |
|
75393 | 21 |
class Sledgehammer_Dockable(view: View, position: String) extends Dockable(view, position) { |
61207 | 22 |
GUI_Thread.require {} |
23 |
||
24 |
||
25 |
/* text area */ |
|
26 |
||
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
27 |
val pretty_text_area = new Pretty_Text_Area(view) |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
28 |
set_content(pretty_text_area) |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
29 |
|
71601 | 30 |
override def detach_operation: Option[() => Unit] = pretty_text_area.detach_operation |
56918 | 31 |
|
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
32 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
33 |
/* query operation */ |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
34 |
|
52935 | 35 |
private val process_indicator = new Process_Indicator |
36 |
||
78595 | 37 |
private def consume_status(status: Query_Operation.Status): Unit = { |
52935 | 38 |
status match { |
78595 | 39 |
case Query_Operation.Status.waiting => |
52935 | 40 |
process_indicator.update("Waiting for evaluation of context ...", 5) |
78595 | 41 |
case Query_Operation.Status.running => |
52935 | 42 |
process_indicator.update("Sledgehammering ...", 15) |
78595 | 43 |
case Query_Operation.Status.finished => |
52935 | 44 |
process_indicator.update(null, 0) |
45 |
} |
|
46 |
} |
|
47 |
||
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
48 |
private val sledgehammer = |
71601 | 49 |
new Query_Operation(PIDE.editor, view, "sledgehammer", consume_status, |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
50 |
(snapshot, results, body) => |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
51 |
pretty_text_area.update(snapshot, results, Pretty.separate(body))) |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
52 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
53 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
54 |
/* resize */ |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
55 |
|
61207 | 56 |
private val delay_resize = |
76610 | 57 |
Delay.first(PIDE.session.update_delay, gui = true) { handle_resize() } |
61207 | 58 |
|
59 |
addComponentListener(new ComponentAdapter { |
|
73340 | 60 |
override def componentResized(e: ComponentEvent): Unit = delay_resize.invoke() |
61 |
override def componentShown(e: ComponentEvent): Unit = delay_resize.invoke() |
|
61207 | 62 |
}) |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
63 |
|
75812 | 64 |
private def handle_resize(): Unit = |
75839 | 65 |
GUI_Thread.require { pretty_text_area.zoom(zoom) } |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
66 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
67 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
68 |
/* controls */ |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
69 |
|
75853 | 70 |
private def hammer(): Unit = { |
60861 | 71 |
provers.addCurrentToHistory() |
56623
4675df68450e
more elementary option sledgehammer_provers, avoiding complications of defaults from ML side (NB: guessing at number of cores does not make sense in PIDE);
wenzelm
parents:
56622
diff
changeset
|
72 |
PIDE.options.string("sledgehammer_provers") = provers.getText |
60202 | 73 |
sledgehammer.apply_query( |
74 |
List(provers.getText, isar_proofs.selected.toString, try0.selected.toString)) |
|
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
75 |
} |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
76 |
|
52939 | 77 |
private val provers_label = new Label("Provers:") { |
54367 | 78 |
tooltip = |
56622
891d1b8b64fb
clarified tooltip_lines: HTML.encode already takes care of newline (but not space);
wenzelm
parents:
55825
diff
changeset
|
79 |
GUI.tooltip_lines( |
60278 | 80 |
"Automatic provers as space-separated list, e.g.\n" + |
81 |
PIDE.options.value.check_name("sledgehammer_provers").default_value) |
|
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
82 |
} |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
83 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
84 |
private val provers = new HistoryTextField("isabelle-sledgehammer-provers") { |
75393 | 85 |
override def processKeyEvent(evt: KeyEvent): Unit = { |
75853 | 86 |
if (evt.getID == KeyEvent.KEY_PRESSED && evt.getKeyCode == KeyEvent.VK_ENTER) hammer() |
52933
08bbd321ac4c
more active "provers" field, which increases chances that its history is stored;
wenzelm
parents:
52931
diff
changeset
|
87 |
super.processKeyEvent(evt) |
08bbd321ac4c
more active "provers" field, which increases chances that its history is stored;
wenzelm
parents:
52931
diff
changeset
|
88 |
} |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
89 |
setToolTipText(provers_label.tooltip) |
53055
0fe8a9972eda
some protocol to determine provers according to ML;
wenzelm
parents:
53049
diff
changeset
|
90 |
setColumns(30) |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
91 |
} |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
92 |
|
75393 | 93 |
private def update_provers(): Unit = { |
56623
4675df68450e
more elementary option sledgehammer_provers, avoiding complications of defaults from ML side (NB: guessing at number of cores does not make sense in PIDE);
wenzelm
parents:
56622
diff
changeset
|
94 |
val new_provers = PIDE.options.string("sledgehammer_provers") |
4675df68450e
more elementary option sledgehammer_provers, avoiding complications of defaults from ML side (NB: guessing at number of cores does not make sense in PIDE);
wenzelm
parents:
56622
diff
changeset
|
95 |
if (new_provers != provers.getText) { |
4675df68450e
more elementary option sledgehammer_provers, avoiding complications of defaults from ML side (NB: guessing at number of cores does not make sense in PIDE);
wenzelm
parents:
56622
diff
changeset
|
96 |
provers.setText(new_provers) |
4675df68450e
more elementary option sledgehammer_provers, avoiding complications of defaults from ML side (NB: guessing at number of cores does not make sense in PIDE);
wenzelm
parents:
56622
diff
changeset
|
97 |
if (provers.getCaret != null) |
4675df68450e
more elementary option sledgehammer_provers, avoiding complications of defaults from ML side (NB: guessing at number of cores does not make sense in PIDE);
wenzelm
parents:
56622
diff
changeset
|
98 |
provers.getCaret.setDot(0) |
4675df68450e
more elementary option sledgehammer_provers, avoiding complications of defaults from ML side (NB: guessing at number of cores does not make sense in PIDE);
wenzelm
parents:
56622
diff
changeset
|
99 |
} |
4675df68450e
more elementary option sledgehammer_provers, avoiding complications of defaults from ML side (NB: guessing at number of cores does not make sense in PIDE);
wenzelm
parents:
56622
diff
changeset
|
100 |
} |
4675df68450e
more elementary option sledgehammer_provers, avoiding complications of defaults from ML side (NB: guessing at number of cores does not make sense in PIDE);
wenzelm
parents:
56622
diff
changeset
|
101 |
|
75854 | 102 |
private val isar_proofs = new GUI.Check("Isar proofs") { |
60202 | 103 |
tooltip = "Specify whether Isar proofs should be output in addition to \"by\" one-liner" |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
104 |
} |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
105 |
|
75854 | 106 |
private val try0 = new GUI.Check("Try methods", init = true) { |
60202 | 107 |
tooltip = "Try standard proof methods like \"auto\" and \"blast\" as alternatives to \"metis\"" |
108 |
} |
|
109 |
||
75853 | 110 |
private val apply_query = new GUI.Button("<html><b>Apply</b></html>") { |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
111 |
tooltip = "Search for first-order proof using automatic theorem provers" |
75853 | 112 |
override def clicked(): Unit = hammer() |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
113 |
} |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
114 |
|
75853 | 115 |
private val cancel_query = new GUI.Button("Cancel") { |
52939 | 116 |
tooltip = "Interrupt unfinished sledgehammering" |
75853 | 117 |
override def clicked(): Unit = sledgehammer.cancel_query() |
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52908
diff
changeset
|
118 |
} |
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52908
diff
changeset
|
119 |
|
75853 | 120 |
private val locate_query = new GUI.Button("Locate") { |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
121 |
tooltip = "Locate context of current query within source text" |
75853 | 122 |
override def clicked(): Unit = sledgehammer.locate_query() |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
123 |
} |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
124 |
|
75839 | 125 |
private val zoom = new Font_Info.Zoom { override def changed(): Unit = handle_resize() } |
61207 | 126 |
|
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
127 |
private val controls = |
66205 | 128 |
Wrap_Panel( |
129 |
List(provers_label, Component.wrap(provers), isar_proofs, try0, |
|
66206 | 130 |
process_indicator.component, apply_query, cancel_query, locate_query, zoom)) |
66205 | 131 |
|
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
132 |
add(controls.peer, BorderLayout.NORTH) |
53787
e64389fe2d2c
focus on default component according to jEdit window management;
wenzelm
parents:
53711
diff
changeset
|
133 |
|
73367 | 134 |
override def focusOnDefaultComponent(): Unit = provers.requestFocus() |
56624 | 135 |
|
136 |
||
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
137 |
/* main */ |
56624 | 138 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
139 |
private val main = |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
140 |
Session.Consumer[Session.Global_Options](getClass.getName) { |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
141 |
case _: Session.Global_Options => GUI_Thread.later { update_provers(); handle_resize() } |
56624 | 142 |
} |
143 |
||
75393 | 144 |
override def init(): Unit = { |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
145 |
PIDE.session.global_options += main |
56624 | 146 |
update_provers() |
147 |
handle_resize() |
|
148 |
sledgehammer.activate() |
|
149 |
} |
|
150 |
||
75393 | 151 |
override def exit(): Unit = { |
56624 | 152 |
sledgehammer.deactivate() |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
153 |
PIDE.session.global_options -= main |
56624 | 154 |
delay_resize.revoke() |
155 |
} |
|
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
156 |
} |