author | wenzelm |
Fri, 15 Nov 2024 13:31:36 +0100 | |
changeset 81448 | 9b2e13b3ee43 |
parent 81398 | f92ea68473f2 |
child 81492 | 480dffe5741f |
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 = |
81398
f92ea68473f2
clarified signature with subtle change of semantics: output consists of individual messages that are formatted (and separated) internally;
wenzelm
parents:
81394
diff
changeset
|
49 |
new Query_Operation(PIDE.editor, view, "sledgehammer", consume_status, pretty_text_area.update) |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
50 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
51 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
52 |
/* resize */ |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
53 |
|
61207 | 54 |
private val delay_resize = |
76610 | 55 |
Delay.first(PIDE.session.update_delay, gui = true) { handle_resize() } |
61207 | 56 |
|
57 |
addComponentListener(new ComponentAdapter { |
|
73340 | 58 |
override def componentResized(e: ComponentEvent): Unit = delay_resize.invoke() |
59 |
override def componentShown(e: ComponentEvent): Unit = delay_resize.invoke() |
|
61207 | 60 |
}) |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
61 |
|
81387
c677755779f5
more uniform pretty_text_area.zoom via its zoom_component;
wenzelm
parents:
78595
diff
changeset
|
62 |
private def handle_resize(): Unit = pretty_text_area.zoom() |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
63 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
64 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
65 |
/* controls */ |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
66 |
|
75853 | 67 |
private def hammer(): Unit = { |
60861 | 68 |
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
|
69 |
PIDE.options.string("sledgehammer_provers") = provers.getText |
60202 | 70 |
sledgehammer.apply_query( |
71 |
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
|
72 |
} |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
73 |
|
52939 | 74 |
private val provers_label = new Label("Provers:") { |
54367 | 75 |
tooltip = |
56622
891d1b8b64fb
clarified tooltip_lines: HTML.encode already takes care of newline (but not space);
wenzelm
parents:
55825
diff
changeset
|
76 |
GUI.tooltip_lines( |
60278 | 77 |
"Automatic provers as space-separated list, e.g.\n" + |
78 |
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
|
79 |
} |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
80 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
81 |
private val provers = new HistoryTextField("isabelle-sledgehammer-provers") { |
75393 | 82 |
override def processKeyEvent(evt: KeyEvent): Unit = { |
75853 | 83 |
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
|
84 |
super.processKeyEvent(evt) |
08bbd321ac4c
more active "provers" field, which increases chances that its history is stored;
wenzelm
parents:
52931
diff
changeset
|
85 |
} |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
86 |
setToolTipText(provers_label.tooltip) |
53055
0fe8a9972eda
some protocol to determine provers according to ML;
wenzelm
parents:
53049
diff
changeset
|
87 |
setColumns(30) |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
88 |
} |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
89 |
|
75393 | 90 |
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
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
} |
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 |
} |
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 |
|
75854 | 99 |
private val isar_proofs = new GUI.Check("Isar proofs") { |
60202 | 100 |
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
|
101 |
} |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
102 |
|
75854 | 103 |
private val try0 = new GUI.Check("Try methods", init = true) { |
60202 | 104 |
tooltip = "Try standard proof methods like \"auto\" and \"blast\" as alternatives to \"metis\"" |
105 |
} |
|
106 |
||
75853 | 107 |
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
|
108 |
tooltip = "Search for first-order proof using automatic theorem provers" |
75853 | 109 |
override def clicked(): Unit = hammer() |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
110 |
} |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
111 |
|
75853 | 112 |
private val cancel_query = new GUI.Button("Cancel") { |
52939 | 113 |
tooltip = "Interrupt unfinished sledgehammering" |
75853 | 114 |
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
|
115 |
} |
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52908
diff
changeset
|
116 |
|
75853 | 117 |
private val locate_query = new GUI.Button("Locate") { |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
118 |
tooltip = "Locate context of current query within source text" |
75853 | 119 |
override def clicked(): Unit = sledgehammer.locate_query() |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
120 |
} |
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
121 |
|
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
122 |
private val controls = |
66205 | 123 |
Wrap_Panel( |
124 |
List(provers_label, Component.wrap(provers), isar_proofs, try0, |
|
81387
c677755779f5
more uniform pretty_text_area.zoom via its zoom_component;
wenzelm
parents:
78595
diff
changeset
|
125 |
process_indicator.component, apply_query, cancel_query, locate_query, |
c677755779f5
more uniform pretty_text_area.zoom via its zoom_component;
wenzelm
parents:
78595
diff
changeset
|
126 |
pretty_text_area.zoom_component)) |
66205 | 127 |
|
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
128 |
add(controls.peer, BorderLayout.NORTH) |
53787
e64389fe2d2c
focus on default component according to jEdit window management;
wenzelm
parents:
53711
diff
changeset
|
129 |
|
73367 | 130 |
override def focusOnDefaultComponent(): Unit = provers.requestFocus() |
56624 | 131 |
|
132 |
||
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
133 |
/* main */ |
56624 | 134 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
135 |
private val main = |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
136 |
Session.Consumer[Session.Global_Options](getClass.getName) { |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
137 |
case _: Session.Global_Options => GUI_Thread.later { update_provers(); handle_resize() } |
56624 | 138 |
} |
139 |
||
75393 | 140 |
override def init(): Unit = { |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
141 |
PIDE.session.global_options += main |
56624 | 142 |
update_provers() |
143 |
handle_resize() |
|
144 |
sledgehammer.activate() |
|
145 |
} |
|
146 |
||
75393 | 147 |
override def exit(): Unit = { |
56624 | 148 |
sledgehammer.deactivate() |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
149 |
PIDE.session.global_options -= main |
56624 | 150 |
delay_resize.revoke() |
151 |
} |
|
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
diff
changeset
|
152 |
} |