author | wenzelm |
Sat, 26 Apr 2014 13:07:20 +0200 | |
changeset 56743 | 81370dfadb1d |
parent 56715 | 52125652e82a |
child 56751 | 2080e752ed40 |
permissions | -rw-r--r-- |
52846 | 1 |
/* Title: Tools/jEdit/src/find_dockable.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Dockable window for "find" dialog. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle.jedit |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
11 |
||
53711
8ce7795256e1
improved FlowLayout for wrapping of components over multiple lines;
wenzelm
parents:
53177
diff
changeset
|
12 |
import scala.swing.{Button, Component, TextField, CheckBox, Label, ComboBox} |
52846 | 13 |
import scala.swing.event.ButtonClicked |
14 |
||
15 |
import java.awt.BorderLayout |
|
52886 | 16 |
import java.awt.event.{ComponentEvent, ComponentAdapter, KeyEvent} |
52846 | 17 |
|
18 |
import org.gjt.sp.jedit.View |
|
19 |
||
20 |
||
21 |
class Find_Dockable(view: View, position: String) extends Dockable(view, position) |
|
22 |
{ |
|
23 |
val pretty_text_area = new Pretty_Text_Area(view) |
|
24 |
set_content(pretty_text_area) |
|
25 |
||
26 |
||
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
27 |
/* query operation */ |
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
28 |
|
52935 | 29 |
private val process_indicator = new Process_Indicator |
30 |
||
31 |
private def consume_status(status: Query_Operation.Status.Value) |
|
32 |
{ |
|
33 |
status match { |
|
34 |
case Query_Operation.Status.WAITING => |
|
35 |
process_indicator.update("Waiting for evaluation of context ...", 5) |
|
36 |
case Query_Operation.Status.RUNNING => |
|
37 |
process_indicator.update("Running find operation ...", 15) |
|
54640
bbd2fa353809
back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents:
54368
diff
changeset
|
38 |
case Query_Operation.Status.FINISHED => |
52935 | 39 |
process_indicator.update(null, 0) |
40 |
} |
|
41 |
} |
|
42 |
||
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
43 |
private val find_theorems = |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
52951
diff
changeset
|
44 |
new Query_Operation(PIDE.editor, view, "find_theorems", consume_status _, |
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
45 |
(snapshot, results, body) => |
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
46 |
pretty_text_area.update(snapshot, results, Pretty.separate(body))) |
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
47 |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
48 |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
49 |
/* resize */ |
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
50 |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
51 |
private var zoom_factor = 100 |
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
52 |
|
52846 | 53 |
private def handle_resize() |
54 |
{ |
|
56662
f373fb77e0a4
avoid "Adaptation of argument list by inserting ()" -- deprecated in scala-2.11.0;
wenzelm
parents:
56622
diff
changeset
|
55 |
Swing_Thread.require {} |
52846 | 56 |
|
55825 | 57 |
pretty_text_area.resize( |
58 |
Font_Info.main(PIDE.options.real("jedit_font_scale") * zoom_factor / 100)) |
|
52846 | 59 |
} |
60 |
||
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
61 |
private val delay_resize = |
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
62 |
Swing_Thread.delay_first(PIDE.options.seconds("editor_update_delay")) { handle_resize() } |
52854
92932931bd82
more general Output.result: allow to update arbitrary properties;
wenzelm
parents:
52851
diff
changeset
|
63 |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
64 |
addComponentListener(new ComponentAdapter { |
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
65 |
override def componentResized(e: ComponentEvent) { delay_resize.invoke() } |
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
66 |
}) |
52846 | 67 |
|
68 |
||
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
69 |
/* main */ |
52846 | 70 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
71 |
private val main = |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
72 |
Session.Consumer[Session.Global_Options](getClass.getName) { |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
73 |
case _: Session.Global_Options => Swing_Thread.later { handle_resize() } |
52846 | 74 |
} |
75 |
||
76 |
override def init() |
|
77 |
{ |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
78 |
PIDE.session.global_options += main |
52848 | 79 |
handle_resize() |
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
80 |
find_theorems.activate() |
52846 | 81 |
} |
82 |
||
83 |
override def exit() |
|
84 |
{ |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
85 |
find_theorems.deactivate() |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
86 |
PIDE.session.global_options -= main |
52846 | 87 |
delay_resize.revoke() |
88 |
} |
|
89 |
||
90 |
||
91 |
/* controls */ |
|
92 |
||
56621
798ba1c2da12
removed odd context argument: Thy_Info.get_theory does not fit into PIDE document model;
wenzelm
parents:
56208
diff
changeset
|
93 |
private def clicked |
798ba1c2da12
removed odd context argument: Thy_Info.get_theory does not fit into PIDE document model;
wenzelm
parents:
56208
diff
changeset
|
94 |
{ |
798ba1c2da12
removed odd context argument: Thy_Info.get_theory does not fit into PIDE document model;
wenzelm
parents:
56208
diff
changeset
|
95 |
find_theorems.apply_query(List(limit.text, allow_dups.selected.toString, query.getText)) |
52942 | 96 |
} |
97 |
||
52946 | 98 |
private val query_label = new Label("Search criteria:") { |
54367 | 99 |
tooltip = |
56622
891d1b8b64fb
clarified tooltip_lines: HTML.encode already takes care of newline (but not space);
wenzelm
parents:
56621
diff
changeset
|
100 |
GUI.tooltip_lines( |
891d1b8b64fb
clarified tooltip_lines: HTML.encode already takes care of newline (but not space);
wenzelm
parents:
56621
diff
changeset
|
101 |
"Search criteria for find operation, e.g.\n\"_ = _\" \"op +\" name: Group -name: monoid") |
52946 | 102 |
} |
52886 | 103 |
|
53784 | 104 |
private val query = new Completion_Popup.History_Text_Field("isabelle-find-theorems") { |
52886 | 105 |
override def processKeyEvent(evt: KeyEvent) |
106 |
{ |
|
107 |
if (evt.getID == KeyEvent.KEY_PRESSED && evt.getKeyCode == KeyEvent.VK_ENTER) clicked |
|
108 |
super.processKeyEvent(evt) |
|
109 |
} |
|
52846 | 110 |
{ val max = getPreferredSize; max.width = Integer.MAX_VALUE; setMaximumSize(max) } |
52885 | 111 |
setColumns(40) |
52946 | 112 |
setToolTipText(query_label.tooltip) |
55825 | 113 |
setFont(GUI.imitate_font(Font_Info.main_family(), getFont, 1.2)) |
52846 | 114 |
} |
115 |
||
52942 | 116 |
private val limit = new TextField(PIDE.options.int("find_theorems_limit").toString, 5) { |
117 |
tooltip = "Limit of displayed results" |
|
118 |
verifier = (s: String) => |
|
119 |
s match { case Properties.Value.Int(x) => x >= 0 case _ => false } |
|
120 |
} |
|
121 |
||
122 |
private val allow_dups = new CheckBox("Duplicates") { |
|
52951 | 123 |
tooltip = "Show all versions of matching theorems" |
52942 | 124 |
selected = false |
125 |
} |
|
52846 | 126 |
|
52880 | 127 |
private val apply_query = new Button("Apply") { |
52846 | 128 |
tooltip = "Find theorems meeting specified criteria" |
52886 | 129 |
reactions += { case ButtonClicked(_) => clicked } |
52846 | 130 |
} |
131 |
||
132 |
private val zoom = new GUI.Zoom_Box(factor => { zoom_factor = factor; handle_resize() }) { |
|
133 |
tooltip = "Zoom factor for output font size" |
|
134 |
} |
|
135 |
||
136 |
private val controls = |
|
53711
8ce7795256e1
improved FlowLayout for wrapping of components over multiple lines;
wenzelm
parents:
53177
diff
changeset
|
137 |
new Wrap_Panel(Wrap_Panel.Alignment.Right)( |
56621
798ba1c2da12
removed odd context argument: Thy_Info.get_theory does not fit into PIDE document model;
wenzelm
parents:
56208
diff
changeset
|
138 |
query_label, Component.wrap(query), limit, allow_dups, |
52944
4b053d8d0e7e
removed "Locate" button, to avoid confusion about the slightly odd meaning of current_command with explicit theory context;
wenzelm
parents:
52943
diff
changeset
|
139 |
process_indicator.component, apply_query, zoom) |
52846 | 140 |
add(controls.peer, BorderLayout.NORTH) |
53787
e64389fe2d2c
focus on default component according to jEdit window management;
wenzelm
parents:
53785
diff
changeset
|
141 |
|
e64389fe2d2c
focus on default component according to jEdit window management;
wenzelm
parents:
53785
diff
changeset
|
142 |
override def focusOnDefaultComponent { query.requestFocus } |
52846 | 143 |
} |