author | wenzelm |
Fri, 12 Aug 2022 11:47:12 +0200 | |
changeset 75810 | 51867c8ad109 |
parent 75809 | 1dd5d4f4b69e |
child 75812 | d6e8d12494be |
permissions | -rw-r--r-- |
56879
ee2b61f37ad9
renamed "Find" to "Query", with more general operations;
wenzelm
parents:
56872
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/query_dockable.scala |
52846 | 2 |
Author: Makarius |
3 |
||
56879
ee2b61f37ad9
renamed "Find" to "Query", with more general operations;
wenzelm
parents:
56872
diff
changeset
|
4 |
Dockable window for query operations. |
52846 | 5 |
*/ |
6 |
||
7 |
package isabelle.jedit |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
11 |
||
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
12 |
import java.awt.event.{ComponentEvent, ComponentAdapter, KeyEvent} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
13 |
import javax.swing.{JComponent, JTextField} |
52846 | 14 |
|
56872
1435f0c771dc
some complication with ListView.Renderer to get tooltips;
wenzelm
parents:
56866
diff
changeset
|
15 |
import scala.swing.{Button, Component, TextField, CheckBox, Label, ListView, |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
16 |
ComboBox, TabbedPane, BorderPanel} |
56759
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
17 |
import scala.swing.event.{SelectionChanged, ButtonClicked, Key, KeyPressed} |
52846 | 18 |
|
19 |
import org.gjt.sp.jedit.View |
|
20 |
||
21 |
||
75393 | 22 |
object Query_Dockable { |
23 |
private abstract class Operation(view: View) { |
|
56758 | 24 |
val pretty_text_area = new Pretty_Text_Area(view) |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
25 |
def query_operation: Query_Operation[View] |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
26 |
def query: JComponent |
75809 | 27 |
def select(): Unit |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
28 |
def page: TabbedPane.Page |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
29 |
} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
30 |
} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
31 |
|
75393 | 32 |
class Query_Dockable(view: View, position: String) extends Dockable(view, position) { |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
33 |
/* common GUI components */ |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
34 |
|
75810 | 35 |
private val zoom = new Font_Info.Zoom_Box { def changed(): Unit = handle_resize() } |
52846 | 36 |
|
75393 | 37 |
private def make_query( |
38 |
property: String, |
|
39 |
tooltip: String, |
|
40 |
apply_query: () => Unit |
|
41 |
): Completion_Popup.History_Text_Field = { |
|
42 |
new Completion_Popup.History_Text_Field(property) { |
|
43 |
override def processKeyEvent(evt: KeyEvent): Unit = { |
|
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
44 |
if (evt.getID == KeyEvent.KEY_PRESSED && evt.getKeyCode == KeyEvent.VK_ENTER) apply_query() |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
45 |
super.processKeyEvent(evt) |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
46 |
} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
47 |
{ val max = getPreferredSize; max.width = Integer.MAX_VALUE; setMaximumSize(max) } |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
48 |
setColumns(40) |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
49 |
setToolTipText(tooltip) |
69358
71ef6e6da3dc
prefer Isabelle_Fonts.sans (not mono) as derived GUI font;
wenzelm
parents:
66591
diff
changeset
|
50 |
setFont(GUI.imitate_font(getFont, scale = 1.2)) |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
51 |
} |
75393 | 52 |
} |
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
53 |
|
52935 | 54 |
|
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
55 |
/* consume status */ |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
56 |
|
73340 | 57 |
def consume_status( |
75393 | 58 |
process_indicator: Process_Indicator, |
59 |
status: Query_Operation.Status.Value |
|
60 |
): Unit = { |
|
52935 | 61 |
status match { |
62 |
case Query_Operation.Status.WAITING => |
|
63 |
process_indicator.update("Waiting for evaluation of context ...", 5) |
|
64 |
case Query_Operation.Status.RUNNING => |
|
65 |
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
|
66 |
case Query_Operation.Status.FINISHED => |
52935 | 67 |
process_indicator.update(null, 0) |
68 |
} |
|
69 |
} |
|
70 |
||
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
71 |
|
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
72 |
/* find theorems */ |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
73 |
|
75810 | 74 |
private val find_theorems: Query_Dockable.Operation = new Query_Dockable.Operation(view) { |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
75 |
/* query */ |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
76 |
|
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
77 |
private val process_indicator = new Process_Indicator |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
78 |
|
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
79 |
val query_operation = |
66082 | 80 |
new Query_Operation(PIDE.editor, view, "find_theorems", |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
81 |
consume_status(process_indicator, _), |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
82 |
(snapshot, results, body) => |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
83 |
pretty_text_area.update(snapshot, results, Pretty.separate(body))) |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
84 |
|
75393 | 85 |
private def apply_query(): Unit = { |
60861 | 86 |
query.addCurrentToHistory() |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
87 |
query_operation.apply_query(List(limit.text, allow_dups.selected.toString, query.getText)) |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
88 |
} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
89 |
|
56909 | 90 |
private val query_label = new Label("Find:") { |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
91 |
tooltip = |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
92 |
GUI.tooltip_lines( |
70278 | 93 |
"Search criteria for find operation, e.g.\n\"_ = _\" \"(+)\" name: Group -name: monoid") |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
94 |
} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
95 |
|
75404 | 96 |
val query: Completion_Popup.History_Text_Field = |
97 |
make_query("isabelle-find-theorems", query_label.tooltip, apply_query _) |
|
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
98 |
|
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
99 |
|
56758 | 100 |
/* GUI page */ |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
101 |
|
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
102 |
private val limit = new TextField(PIDE.options.int("find_theorems_limit").toString, 5) { |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
103 |
tooltip = "Limit of displayed results" |
75810 | 104 |
verifier = { case Value.Int(x) => x >= 0 case _ => false } |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
105 |
listenTo(keys) |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
106 |
reactions += { case KeyPressed(_, Key.Enter, 0, _) => apply_query() } |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
107 |
} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
108 |
|
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
109 |
private val allow_dups = new CheckBox("Duplicates") { |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
110 |
tooltip = "Show all versions of matching theorems" |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
111 |
selected = false |
56911 | 112 |
reactions += { case ButtonClicked(_) => apply_query() } |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
113 |
} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
114 |
|
56910 | 115 |
private val apply_button = new Button("<html><b>Apply</b></html>") { |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
116 |
tooltip = "Find theorems meeting specified criteria" |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
117 |
reactions += { case ButtonClicked(_) => apply_query() } |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
118 |
} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
119 |
|
56759
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
120 |
private val control_panel = |
66205 | 121 |
Wrap_Panel( |
122 |
List(query_label, Component.wrap(query), limit, allow_dups, |
|
123 |
process_indicator.component, apply_button, |
|
66206 | 124 |
pretty_text_area.search_label, pretty_text_area.search_field)) |
56759
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
125 |
|
75809 | 126 |
def select(): Unit = { control_panel.contents += zoom } |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
127 |
|
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
128 |
val page = |
56879
ee2b61f37ad9
renamed "Find" to "Query", with more general operations;
wenzelm
parents:
56872
diff
changeset
|
129 |
new TabbedPane.Page("Find Theorems", new BorderPanel { |
59391 | 130 |
layout(control_panel) = BorderPanel.Position.North |
131 |
layout(Component.wrap(pretty_text_area)) = BorderPanel.Position.Center |
|
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
132 |
}, apply_button.tooltip) |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
133 |
} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
134 |
|
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
135 |
|
56758 | 136 |
/* find consts */ |
137 |
||
75810 | 138 |
private val find_consts: Query_Dockable.Operation = new Query_Dockable.Operation(view) { |
56758 | 139 |
/* query */ |
140 |
||
141 |
private val process_indicator = new Process_Indicator |
|
142 |
||
143 |
val query_operation = |
|
66082 | 144 |
new Query_Operation(PIDE.editor, view, "find_consts", |
56758 | 145 |
consume_status(process_indicator, _), |
146 |
(snapshot, results, body) => |
|
147 |
pretty_text_area.update(snapshot, results, Pretty.separate(body))) |
|
148 |
||
75404 | 149 |
private val query_label = new Label("Find:") { |
150 |
tooltip = GUI.tooltip_lines("Name / type patterns for constants") |
|
151 |
} |
|
152 |
||
153 |
val query: Completion_Popup.History_Text_Field = |
|
154 |
make_query("isabelle-find-consts", query_label.tooltip, apply_query _) |
|
155 |
||
75393 | 156 |
private def apply_query(): Unit = { |
60861 | 157 |
query.addCurrentToHistory() |
56758 | 158 |
query_operation.apply_query(List(query.getText)) |
159 |
} |
|
160 |
||
161 |
||
162 |
/* GUI page */ |
|
163 |
||
56910 | 164 |
private val apply_button = new Button("<html><b>Apply</b></html>") { |
56758 | 165 |
tooltip = "Find constants by name / type patterns" |
166 |
reactions += { case ButtonClicked(_) => apply_query() } |
|
167 |
} |
|
168 |
||
56759
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
169 |
private val control_panel = |
66205 | 170 |
Wrap_Panel( |
171 |
List( |
|
172 |
query_label, Component.wrap(query), process_indicator.component, apply_button, |
|
66206 | 173 |
pretty_text_area.search_label, pretty_text_area.search_field)) |
56759
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
174 |
|
75809 | 175 |
def select(): Unit = { control_panel.contents += zoom } |
56758 | 176 |
|
177 |
val page = |
|
56879
ee2b61f37ad9
renamed "Find" to "Query", with more general operations;
wenzelm
parents:
56872
diff
changeset
|
178 |
new TabbedPane.Page("Find Constants", new BorderPanel { |
59391 | 179 |
layout(control_panel) = BorderPanel.Position.North |
180 |
layout(Component.wrap(pretty_text_area)) = BorderPanel.Position.Center |
|
56758 | 181 |
}, apply_button.tooltip) |
182 |
} |
|
183 |
||
184 |
||
56864 | 185 |
/* print operation */ |
186 |
||
75393 | 187 |
private val print_operation = new Query_Dockable.Operation(view) { |
57604
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
188 |
/* items */ |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
189 |
|
75393 | 190 |
private class Item(val name: String, description: String, sel: Boolean) { |
75810 | 191 |
val checkbox: CheckBox = new CheckBox(name) { |
57604
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
192 |
tooltip = "Print " + description |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
193 |
selected = sel |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
194 |
reactions += { case ButtonClicked(_) => apply_query() } |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
195 |
} |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
196 |
} |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
197 |
|
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
198 |
private var _items: List[Item] = Nil |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
199 |
|
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
200 |
private def selected_items(): List[String] = |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
201 |
for (item <- _items if item.checkbox.selected) yield item.name |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
202 |
|
75393 | 203 |
private def update_items(): List[Item] = { |
57604
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
204 |
val old_items = _items |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
205 |
def was_selected(name: String): Boolean = |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
206 |
old_items.find(item => item.name == name) match { |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
207 |
case None => false |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
208 |
case Some(item) => item.checkbox.selected |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
209 |
} |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
210 |
|
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
211 |
_items = |
72215 | 212 |
for ((name, description) <- Print_Operation.get(PIDE.session)) |
213 |
yield new Item(name, description, was_selected(name)) |
|
57604
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
214 |
_items |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
215 |
} |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
216 |
|
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
217 |
|
56864 | 218 |
/* query */ |
219 |
||
56909 | 220 |
private val process_indicator = new Process_Indicator |
221 |
||
56864 | 222 |
val query_operation = |
66082 | 223 |
new Query_Operation(PIDE.editor, view, "print_operation", |
56909 | 224 |
consume_status(process_indicator, _), |
56864 | 225 |
(snapshot, results, body) => |
226 |
pretty_text_area.update(snapshot, results, Pretty.separate(body))) |
|
227 |
||
73340 | 228 |
private def apply_query(): Unit = |
57604
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
229 |
query_operation.apply_query(selected_items()) |
56864 | 230 |
|
56866 | 231 |
private val query_label = new Label("Print:") |
56882 | 232 |
def query: JComponent = apply_button.peer |
56864 | 233 |
|
57604
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
234 |
update_items() |
56872
1435f0c771dc
some complication with ListView.Renderer to get tooltips;
wenzelm
parents:
56866
diff
changeset
|
235 |
|
1435f0c771dc
some complication with ListView.Renderer to get tooltips;
wenzelm
parents:
56866
diff
changeset
|
236 |
|
1435f0c771dc
some complication with ListView.Renderer to get tooltips;
wenzelm
parents:
56866
diff
changeset
|
237 |
/* GUI page */ |
56864 | 238 |
|
56910 | 239 |
private val apply_button = new Button("<html><b>Apply</b></html>") { |
56865 | 240 |
tooltip = "Apply to current context" |
57000
c914618feef8
some adhoc event handling to unify L&F button focus behavior, e.g. Mac OS X vs. Nimbus;
wenzelm
parents:
56918
diff
changeset
|
241 |
listenTo(keys) |
c914618feef8
some adhoc event handling to unify L&F button focus behavior, e.g. Mac OS X vs. Nimbus;
wenzelm
parents:
56918
diff
changeset
|
242 |
reactions += { |
c914618feef8
some adhoc event handling to unify L&F button focus behavior, e.g. Mac OS X vs. Nimbus;
wenzelm
parents:
56918
diff
changeset
|
243 |
case ButtonClicked(_) => apply_query() |
c914618feef8
some adhoc event handling to unify L&F button focus behavior, e.g. Mac OS X vs. Nimbus;
wenzelm
parents:
56918
diff
changeset
|
244 |
case evt @ KeyPressed(_, Key.Enter, 0, _) => |
75807
b0394e7d43ea
tuned signature, following hints by IntelliJ IDEA;
wenzelm
parents:
75404
diff
changeset
|
245 |
evt.peer.consume() |
57000
c914618feef8
some adhoc event handling to unify L&F button focus behavior, e.g. Mac OS X vs. Nimbus;
wenzelm
parents:
56918
diff
changeset
|
246 |
apply_query() |
c914618feef8
some adhoc event handling to unify L&F button focus behavior, e.g. Mac OS X vs. Nimbus;
wenzelm
parents:
56918
diff
changeset
|
247 |
} |
56865 | 248 |
} |
249 |
||
66206 | 250 |
private val control_panel = Wrap_Panel() |
56864 | 251 |
|
75809 | 252 |
def select(): Unit = { |
73367 | 253 |
control_panel.contents.clear() |
57604
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
254 |
control_panel.contents += query_label |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
255 |
update_items().foreach(item => control_panel.contents += item.checkbox) |
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56882
diff
changeset
|
256 |
control_panel.contents ++= |
57604
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
257 |
List(process_indicator.component, apply_button, |
57042 | 258 |
pretty_text_area.search_label, pretty_text_area.search_field, zoom) |
56864 | 259 |
} |
260 |
||
261 |
val page = |
|
56879
ee2b61f37ad9
renamed "Find" to "Query", with more general operations;
wenzelm
parents:
56872
diff
changeset
|
262 |
new TabbedPane.Page("Print Context", new BorderPanel { |
59391 | 263 |
layout(control_panel) = BorderPanel.Position.North |
264 |
layout(Component.wrap(pretty_text_area)) = BorderPanel.Position.Center |
|
56864 | 265 |
}, "Print information from context") |
266 |
} |
|
267 |
||
268 |
||
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
269 |
/* operations */ |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
270 |
|
56864 | 271 |
private val operations = List(find_theorems, find_consts, print_operation) |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
272 |
|
75393 | 273 |
private val operations_pane = new TabbedPane { |
56759
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
274 |
pages ++= operations.map(_.page) |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
275 |
listenTo(selection) |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
276 |
reactions += { case SelectionChanged(_) => select_operation() } |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
277 |
} |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
278 |
|
56879
ee2b61f37ad9
renamed "Find" to "Query", with more general operations;
wenzelm
parents:
56872
diff
changeset
|
279 |
private def get_operation(): Option[Query_Dockable.Operation] = |
56759
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
280 |
try { Some(operations(operations_pane.selection.index)) } |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
281 |
catch { case _: IndexOutOfBoundsException => None } |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
282 |
|
75393 | 283 |
private def select_operation(): Unit = { |
75809 | 284 |
for (op <- get_operation()) { op.select(); op.query.requestFocus() } |
73367 | 285 |
operations_pane.revalidate() |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
286 |
} |
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
287 |
|
75393 | 288 |
override def focusOnDefaultComponent(): Unit = { |
73367 | 289 |
for (op <- get_operation()) op.query.requestFocus() |
73340 | 290 |
} |
56759
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
291 |
|
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
292 |
select_operation() |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
293 |
set_content(operations_pane) |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
294 |
|
71601 | 295 |
override def detach_operation: Option[() => Unit] = |
56918 | 296 |
get_operation() match { |
297 |
case None => None |
|
298 |
case Some(op) => op.pretty_text_area.detach_operation |
|
299 |
} |
|
56906
408b526911f7
some odd tricks to provide "Detach" menu item, via "PIDE" docking framework;
wenzelm
parents:
56886
diff
changeset
|
300 |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
301 |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
302 |
/* resize */ |
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
303 |
|
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
304 |
private def handle_resize(): Unit = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57604
diff
changeset
|
305 |
GUI_Thread.require { |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
306 |
for (op <- operations) { |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
307 |
op.pretty_text_area.resize( |
57044 | 308 |
Font_Info.main(PIDE.options.real("jedit_font_scale") * zoom.factor / 100)) |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
309 |
} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
310 |
} |
52846 | 311 |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
312 |
private val delay_resize = |
71704 | 313 |
Delay.first(PIDE.options.seconds("editor_update_delay"), gui = true) { handle_resize() } |
52854
92932931bd82
more general Output.result: allow to update arbitrary properties;
wenzelm
parents:
52851
diff
changeset
|
314 |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
315 |
addComponentListener(new ComponentAdapter { |
73340 | 316 |
override def componentResized(e: ComponentEvent): Unit = delay_resize.invoke() |
317 |
override def componentShown(e: ComponentEvent): Unit = delay_resize.invoke() |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
318 |
}) |
52846 | 319 |
|
320 |
||
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
321 |
/* main */ |
52846 | 322 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
323 |
private val main = |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
324 |
Session.Consumer[Session.Global_Options](getClass.getName) { |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57604
diff
changeset
|
325 |
case _: Session.Global_Options => GUI_Thread.later { handle_resize() } |
52846 | 326 |
} |
327 |
||
75393 | 328 |
override def init(): Unit = { |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
329 |
PIDE.session.global_options += main |
52848 | 330 |
handle_resize() |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
331 |
operations.foreach(op => op.query_operation.activate()) |
52846 | 332 |
} |
333 |
||
75393 | 334 |
override def exit(): Unit = { |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
335 |
operations.foreach(op => op.query_operation.deactivate()) |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
336 |
PIDE.session.global_options -= main |
52846 | 337 |
delay_resize.revoke() |
338 |
} |
|
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
339 |
} |
52846 | 340 |