author | wenzelm |
Thu, 21 Nov 2013 21:55:29 +0100 | |
changeset 54640 | bbd2fa353809 |
parent 54368 | 36dc6aa4fe87 |
child 55618 | 995162143ef4 |
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 |
||
12 |
import scala.actors.Actor._ |
|
13 |
||
53711
8ce7795256e1
improved FlowLayout for wrapping of components over multiple lines;
wenzelm
parents:
53177
diff
changeset
|
14 |
import scala.swing.{Button, Component, TextField, CheckBox, Label, ComboBox} |
52846 | 15 |
import scala.swing.event.ButtonClicked |
16 |
||
17 |
import java.awt.BorderLayout |
|
52886 | 18 |
import java.awt.event.{ComponentEvent, ComponentAdapter, KeyEvent} |
52846 | 19 |
|
20 |
import org.gjt.sp.jedit.View |
|
21 |
||
22 |
||
23 |
class Find_Dockable(view: View, position: String) extends Dockable(view, position) |
|
24 |
{ |
|
25 |
val pretty_text_area = new Pretty_Text_Area(view) |
|
26 |
set_content(pretty_text_area) |
|
27 |
||
28 |
||
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
29 |
/* 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
|
30 |
|
52935 | 31 |
private val process_indicator = new Process_Indicator |
32 |
||
33 |
private def consume_status(status: Query_Operation.Status.Value) |
|
34 |
{ |
|
35 |
status match { |
|
36 |
case Query_Operation.Status.WAITING => |
|
37 |
process_indicator.update("Waiting for evaluation of context ...", 5) |
|
38 |
case Query_Operation.Status.RUNNING => |
|
39 |
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
|
40 |
case Query_Operation.Status.FINISHED => |
52935 | 41 |
process_indicator.update(null, 0) |
42 |
} |
|
43 |
} |
|
44 |
||
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 |
private val find_theorems = |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
52951
diff
changeset
|
46 |
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
|
47 |
(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
|
48 |
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
|
49 |
|
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 |
/* resize */ |
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
52 |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
53 |
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
|
54 |
|
52846 | 55 |
private def handle_resize() |
56 |
{ |
|
57 |
Swing_Thread.require() |
|
58 |
||
59 |
pretty_text_area.resize(Rendering.font_family(), |
|
60 |
(Rendering.font_size("jedit_font_scale") * zoom_factor / 100).round) |
|
61 |
} |
|
62 |
||
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
63 |
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
|
64 |
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
|
65 |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
66 |
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
|
67 |
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
|
68 |
}) |
52846 | 69 |
|
70 |
||
71 |
/* main actor */ |
|
72 |
||
73 |
private val main_actor = actor { |
|
74 |
loop { |
|
75 |
react { |
|
76 |
case _: Session.Global_Options => |
|
77 |
Swing_Thread.later { handle_resize() } |
|
53177
dcac8d837b9c
more uniform treatment of Swing_Thread context switch: prefer asynchronous Swing_Thread.later from actor;
wenzelm
parents:
52971
diff
changeset
|
78 |
|
52846 | 79 |
case bad => |
80 |
java.lang.System.err.println("Find_Dockable: ignoring bad message " + bad) |
|
81 |
} |
|
82 |
} |
|
83 |
} |
|
84 |
||
85 |
override def init() |
|
86 |
{ |
|
87 |
PIDE.session.global_options += main_actor |
|
52848 | 88 |
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
|
89 |
find_theorems.activate() |
52846 | 90 |
} |
91 |
||
92 |
override def exit() |
|
93 |
{ |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
94 |
find_theorems.deactivate() |
52846 | 95 |
PIDE.session.global_options -= main_actor |
96 |
delay_resize.revoke() |
|
97 |
} |
|
98 |
||
99 |
||
100 |
/* controls */ |
|
101 |
||
52942 | 102 |
private def clicked { |
52943 | 103 |
find_theorems.apply_query( |
104 |
List(limit.text, allow_dups.selected.toString, context.selection.item.name, query.getText)) |
|
52942 | 105 |
} |
106 |
||
52946 | 107 |
private val query_label = new Label("Search criteria:") { |
54367 | 108 |
tooltip = |
109 |
GUI.tooltip_lines(List( |
|
110 |
"Search criteria for find operation, e.g.", |
|
111 |
"", |
|
112 |
" \"_ = _\" \"op +\" name: Group -name: monoid")) |
|
52946 | 113 |
} |
52886 | 114 |
|
53784 | 115 |
private val query = new Completion_Popup.History_Text_Field("isabelle-find-theorems") { |
52886 | 116 |
override def processKeyEvent(evt: KeyEvent) |
117 |
{ |
|
118 |
if (evt.getID == KeyEvent.KEY_PRESSED && evt.getKeyCode == KeyEvent.VK_ENTER) clicked |
|
119 |
super.processKeyEvent(evt) |
|
120 |
} |
|
52846 | 121 |
{ val max = getPreferredSize; max.width = Integer.MAX_VALUE; setMaximumSize(max) } |
52885 | 122 |
setColumns(40) |
52946 | 123 |
setToolTipText(query_label.tooltip) |
54368 | 124 |
setFont(GUI.imitate_font(Rendering.font_family(), getFont, 1.2)) |
52846 | 125 |
} |
126 |
||
52943 | 127 |
private case class Context_Entry(val name: String, val description: String) |
128 |
{ |
|
129 |
override def toString = description |
|
130 |
} |
|
131 |
||
132 |
private val context_entries = |
|
52946 | 133 |
new Context_Entry("", "current context") :: |
52943 | 134 |
PIDE.thy_load.loaded_theories.toList.sorted.map(name => Context_Entry(name, name)) |
135 |
||
136 |
private val context = new ComboBox[Context_Entry](context_entries) { |
|
137 |
tooltip = "Search in pre-loaded theory (default: context of current command)" |
|
138 |
} |
|
139 |
||
52942 | 140 |
private val limit = new TextField(PIDE.options.int("find_theorems_limit").toString, 5) { |
141 |
tooltip = "Limit of displayed results" |
|
142 |
verifier = (s: String) => |
|
143 |
s match { case Properties.Value.Int(x) => x >= 0 case _ => false } |
|
144 |
} |
|
145 |
||
146 |
private val allow_dups = new CheckBox("Duplicates") { |
|
52951 | 147 |
tooltip = "Show all versions of matching theorems" |
52942 | 148 |
selected = false |
149 |
} |
|
52846 | 150 |
|
52880 | 151 |
private val apply_query = new Button("Apply") { |
52846 | 152 |
tooltip = "Find theorems meeting specified criteria" |
52886 | 153 |
reactions += { case ButtonClicked(_) => clicked } |
52846 | 154 |
} |
155 |
||
156 |
private val zoom = new GUI.Zoom_Box(factor => { zoom_factor = factor; handle_resize() }) { |
|
157 |
tooltip = "Zoom factor for output font size" |
|
158 |
} |
|
159 |
||
160 |
private val controls = |
|
53711
8ce7795256e1
improved FlowLayout for wrapping of components over multiple lines;
wenzelm
parents:
53177
diff
changeset
|
161 |
new Wrap_Panel(Wrap_Panel.Alignment.Right)( |
52943 | 162 |
query_label, Component.wrap(query), context, 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
|
163 |
process_indicator.component, apply_query, zoom) |
52846 | 164 |
add(controls.peer, BorderLayout.NORTH) |
53787
e64389fe2d2c
focus on default component according to jEdit window management;
wenzelm
parents:
53785
diff
changeset
|
165 |
|
e64389fe2d2c
focus on default component according to jEdit window management;
wenzelm
parents:
53785
diff
changeset
|
166 |
override def focusOnDefaultComponent { query.requestFocus } |
52846 | 167 |
} |