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