author | wenzelm |
Fri, 07 Aug 2015 11:44:11 +0200 | |
changeset 60861 | fa77faa87d5f |
parent 60750 | 7694aa52ad56 |
child 63805 | c272680df665 |
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 |
||
56879
ee2b61f37ad9
renamed "Find" to "Query", with more general operations;
wenzelm
parents:
56872
diff
changeset
|
22 |
object Query_Dockable |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
23 |
{ |
56758 | 24 |
private abstract class Operation(view: View) |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
25 |
{ |
56758 | 26 |
val pretty_text_area = new Pretty_Text_Area(view) |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
27 |
def query_operation: Query_Operation[View] |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
28 |
def query: JComponent |
56759
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
29 |
def select: Unit |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
30 |
def page: TabbedPane.Page |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
31 |
} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
32 |
} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
33 |
|
56879
ee2b61f37ad9
renamed "Find" to "Query", with more general operations;
wenzelm
parents:
56872
diff
changeset
|
34 |
class Query_Dockable(view: View, position: String) extends Dockable(view, position) |
52846 | 35 |
{ |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
36 |
/* common GUI components */ |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
37 |
|
57044 | 38 |
private val zoom = new Font_Info.Zoom_Box { def changed = handle_resize() } |
52846 | 39 |
|
60861 | 40 |
private def make_query(property: String, tooltip: String, apply_query: () => Unit) |
41 |
: Completion_Popup.History_Text_Field = |
|
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
42 |
new Completion_Popup.History_Text_Field(property) |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
43 |
{ |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
44 |
override def processKeyEvent(evt: KeyEvent) |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
45 |
{ |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
46 |
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
|
47 |
super.processKeyEvent(evt) |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
48 |
} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
49 |
{ val max = getPreferredSize; max.width = Integer.MAX_VALUE; setMaximumSize(max) } |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
50 |
setColumns(40) |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
51 |
setToolTipText(tooltip) |
59286
ac74eedb910a
GUI.imitate_font: more explicit result size, e.g. relevant for caching;
wenzelm
parents:
57612
diff
changeset
|
52 |
setFont(GUI.imitate_font(getFont, Font_Info.main_family(), 1.2)) |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
53 |
} |
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
54 |
|
52935 | 55 |
|
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
56 |
/* consume status */ |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
57 |
|
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
58 |
def consume_status(process_indicator: Process_Indicator, status: Query_Operation.Status.Value) |
52935 | 59 |
{ |
60 |
status match { |
|
61 |
case Query_Operation.Status.WAITING => |
|
62 |
process_indicator.update("Waiting for evaluation of context ...", 5) |
|
63 |
case Query_Operation.Status.RUNNING => |
|
64 |
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
|
65 |
case Query_Operation.Status.FINISHED => |
52935 | 66 |
process_indicator.update(null, 0) |
67 |
} |
|
68 |
} |
|
69 |
||
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
70 |
|
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
71 |
/* find theorems */ |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
72 |
|
56879
ee2b61f37ad9
renamed "Find" to "Query", with more general operations;
wenzelm
parents:
56872
diff
changeset
|
73 |
private val find_theorems = new Query_Dockable.Operation(view) |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
74 |
{ |
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 = |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
80 |
new Query_Operation(PIDE.editor, view, "find_theorems", |
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 |
|
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
85 |
private def apply_query() |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
86 |
{ |
60861 | 87 |
query.addCurrentToHistory() |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
88 |
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
|
89 |
} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
90 |
|
56909 | 91 |
private val query_label = new Label("Find:") { |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
92 |
tooltip = |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
93 |
GUI.tooltip_lines( |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
94 |
"Search criteria for find operation, e.g.\n\"_ = _\" \"op +\" name: Group -name: monoid") |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
95 |
} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
96 |
|
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
97 |
val query = make_query("isabelle-find-theorems", query_label.tooltip, apply_query _) |
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" |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
104 |
verifier = (s: String) => |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
105 |
s match { case Properties.Value.Int(x) => x >= 0 case _ => false } |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
106 |
listenTo(keys) |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
107 |
reactions += { case KeyPressed(_, Key.Enter, 0, _) => apply_query() } |
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 |
|
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
110 |
private val allow_dups = new CheckBox("Duplicates") { |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
111 |
tooltip = "Show all versions of matching theorems" |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
112 |
selected = false |
56911 | 113 |
reactions += { case ButtonClicked(_) => apply_query() } |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
114 |
} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
115 |
|
56910 | 116 |
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
|
117 |
tooltip = "Find theorems meeting specified criteria" |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
118 |
reactions += { case ButtonClicked(_) => apply_query() } |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
119 |
} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
120 |
|
56759
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
121 |
private val control_panel = |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
122 |
new Wrap_Panel(Wrap_Panel.Alignment.Right)( |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
123 |
query_label, Component.wrap(query), limit, allow_dups, |
56907
0f3c375fd27c
enable "PIDE" docking framework by default, and rely on its "Detach" menu item;
wenzelm
parents:
56906
diff
changeset
|
124 |
process_indicator.component, apply_button, |
57042 | 125 |
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
|
126 |
|
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
127 |
def select { control_panel.contents += zoom } |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
128 |
|
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
129 |
val page = |
56879
ee2b61f37ad9
renamed "Find" to "Query", with more general operations;
wenzelm
parents:
56872
diff
changeset
|
130 |
new TabbedPane.Page("Find Theorems", new BorderPanel { |
59391 | 131 |
layout(control_panel) = BorderPanel.Position.North |
132 |
layout(Component.wrap(pretty_text_area)) = BorderPanel.Position.Center |
|
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
133 |
}, apply_button.tooltip) |
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 |
|
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
136 |
|
56758 | 137 |
/* find consts */ |
138 |
||
56879
ee2b61f37ad9
renamed "Find" to "Query", with more general operations;
wenzelm
parents:
56872
diff
changeset
|
139 |
private val find_consts = new Query_Dockable.Operation(view) |
56758 | 140 |
{ |
141 |
/* query */ |
|
142 |
||
143 |
private val process_indicator = new Process_Indicator |
|
144 |
||
145 |
val query_operation = |
|
146 |
new Query_Operation(PIDE.editor, view, "find_consts", |
|
147 |
consume_status(process_indicator, _), |
|
148 |
(snapshot, results, body) => |
|
149 |
pretty_text_area.update(snapshot, results, Pretty.separate(body))) |
|
150 |
||
151 |
private def apply_query() |
|
152 |
{ |
|
60861 | 153 |
query.addCurrentToHistory() |
56758 | 154 |
query_operation.apply_query(List(query.getText)) |
155 |
} |
|
156 |
||
56909 | 157 |
private val query_label = new Label("Find:") { |
56758 | 158 |
tooltip = GUI.tooltip_lines("Name / type patterns for constants") |
159 |
} |
|
160 |
||
161 |
val query = make_query("isabelle-find-consts", query_label.tooltip, apply_query _) |
|
162 |
||
163 |
||
164 |
/* GUI page */ |
|
165 |
||
56910 | 166 |
private val apply_button = new Button("<html><b>Apply</b></html>") { |
56758 | 167 |
tooltip = "Find constants by name / type patterns" |
168 |
reactions += { case ButtonClicked(_) => apply_query() } |
|
169 |
} |
|
170 |
||
56759
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
171 |
private val control_panel = |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
172 |
new Wrap_Panel(Wrap_Panel.Alignment.Right)( |
56907
0f3c375fd27c
enable "PIDE" docking framework by default, and rely on its "Detach" menu item;
wenzelm
parents:
56906
diff
changeset
|
173 |
query_label, Component.wrap(query), process_indicator.component, apply_button, |
57042 | 174 |
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
|
175 |
|
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
176 |
def select { control_panel.contents += zoom } |
56758 | 177 |
|
178 |
val page = |
|
56879
ee2b61f37ad9
renamed "Find" to "Query", with more general operations;
wenzelm
parents:
56872
diff
changeset
|
179 |
new TabbedPane.Page("Find Constants", new BorderPanel { |
59391 | 180 |
layout(control_panel) = BorderPanel.Position.North |
181 |
layout(Component.wrap(pretty_text_area)) = BorderPanel.Position.Center |
|
56758 | 182 |
}, apply_button.tooltip) |
183 |
} |
|
184 |
||
185 |
||
56864 | 186 |
/* print operation */ |
187 |
||
56879
ee2b61f37ad9
renamed "Find" to "Query", with more general operations;
wenzelm
parents:
56872
diff
changeset
|
188 |
private val print_operation = new Query_Dockable.Operation(view) |
56864 | 189 |
{ |
57604
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
190 |
/* items */ |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
191 |
|
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
192 |
private class Item(val name: String, description: String, sel: Boolean) |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
193 |
{ |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
194 |
val checkbox = new CheckBox(name) { |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
195 |
tooltip = "Print " + description |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
196 |
selected = sel |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
197 |
reactions += { case ButtonClicked(_) => apply_query() } |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
198 |
} |
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 |
|
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
201 |
private var _items: List[Item] = Nil |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
202 |
|
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
203 |
private def selected_items(): List[String] = |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
204 |
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
|
205 |
|
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
206 |
private def update_items(): List[Item] = |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
207 |
{ |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
208 |
val old_items = _items |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
209 |
def was_selected(name: String): Boolean = |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
210 |
old_items.find(item => item.name == name) match { |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
211 |
case None => false |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
212 |
case Some(item) => item.checkbox.selected |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
213 |
} |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
214 |
|
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
215 |
_items = |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
216 |
Print_Operation.print_operations(PIDE.session).map( |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
217 |
{ |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
218 |
case (name, description) => new Item(name, description, was_selected(name)) |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
219 |
}) |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
220 |
_items |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
221 |
} |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
222 |
|
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
223 |
|
56864 | 224 |
/* query */ |
225 |
||
56909 | 226 |
private val process_indicator = new Process_Indicator |
227 |
||
56864 | 228 |
val query_operation = |
56909 | 229 |
new Query_Operation(PIDE.editor, view, "print_operation", |
230 |
consume_status(process_indicator, _), |
|
56864 | 231 |
(snapshot, results, body) => |
232 |
pretty_text_area.update(snapshot, results, Pretty.separate(body))) |
|
233 |
||
234 |
private def apply_query() |
|
235 |
{ |
|
57604
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
236 |
query_operation.apply_query(selected_items()) |
56864 | 237 |
} |
238 |
||
56866 | 239 |
private val query_label = new Label("Print:") |
56882 | 240 |
def query: JComponent = apply_button.peer |
56864 | 241 |
|
57604
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
242 |
update_items() |
56872
1435f0c771dc
some complication with ListView.Renderer to get tooltips;
wenzelm
parents:
56866
diff
changeset
|
243 |
|
1435f0c771dc
some complication with ListView.Renderer to get tooltips;
wenzelm
parents:
56866
diff
changeset
|
244 |
|
1435f0c771dc
some complication with ListView.Renderer to get tooltips;
wenzelm
parents:
56866
diff
changeset
|
245 |
/* GUI page */ |
56864 | 246 |
|
56910 | 247 |
private val apply_button = new Button("<html><b>Apply</b></html>") { |
56865 | 248 |
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
|
249 |
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
|
250 |
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
|
251 |
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
|
252 |
case evt @ KeyPressed(_, Key.Enter, 0, _) => |
c914618feef8
some adhoc event handling to unify L&F button focus behavior, e.g. Mac OS X vs. Nimbus;
wenzelm
parents:
56918
diff
changeset
|
253 |
evt.peer.consume |
c914618feef8
some adhoc event handling to unify L&F button focus behavior, e.g. Mac OS X vs. Nimbus;
wenzelm
parents:
56918
diff
changeset
|
254 |
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
|
255 |
} |
56865 | 256 |
} |
257 |
||
56864 | 258 |
private val control_panel = new Wrap_Panel(Wrap_Panel.Alignment.Right)() |
259 |
||
260 |
def select |
|
261 |
{ |
|
262 |
control_panel.contents.clear |
|
57604
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
263 |
control_panel.contents += query_label |
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
264 |
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
|
265 |
control_panel.contents ++= |
57604
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57044
diff
changeset
|
266 |
List(process_indicator.component, apply_button, |
57042 | 267 |
pretty_text_area.search_label, pretty_text_area.search_field, zoom) |
56864 | 268 |
} |
269 |
||
270 |
val page = |
|
56879
ee2b61f37ad9
renamed "Find" to "Query", with more general operations;
wenzelm
parents:
56872
diff
changeset
|
271 |
new TabbedPane.Page("Print Context", new BorderPanel { |
59391 | 272 |
layout(control_panel) = BorderPanel.Position.North |
273 |
layout(Component.wrap(pretty_text_area)) = BorderPanel.Position.Center |
|
56864 | 274 |
}, "Print information from context") |
275 |
} |
|
276 |
||
277 |
||
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
278 |
/* operations */ |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
279 |
|
56864 | 280 |
private val operations = List(find_theorems, find_consts, print_operation) |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
281 |
|
56759
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
282 |
private val operations_pane = new TabbedPane |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
283 |
{ |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
284 |
pages ++= operations.map(_.page) |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
285 |
listenTo(selection) |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
286 |
reactions += { case SelectionChanged(_) => select_operation() } |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
287 |
} |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
288 |
|
56879
ee2b61f37ad9
renamed "Find" to "Query", with more general operations;
wenzelm
parents:
56872
diff
changeset
|
289 |
private def get_operation(): Option[Query_Dockable.Operation] = |
56759
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
290 |
try { Some(operations(operations_pane.selection.index)) } |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
291 |
catch { case _: IndexOutOfBoundsException => None } |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
292 |
|
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
293 |
private def select_operation() { |
56865 | 294 |
for (op <- get_operation()) { op.select; op.query.requestFocus } |
56759
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
295 |
operations_pane.revalidate |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
296 |
} |
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
297 |
|
56759
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
298 |
override def focusOnDefaultComponent { for (op <- get_operation()) op.query.requestFocus } |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
299 |
|
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
300 |
select_operation() |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
301 |
set_content(operations_pane) |
790f7562cd0e
proper handling of shared zoom component: update layout dynamically;
wenzelm
parents:
56758
diff
changeset
|
302 |
|
56918 | 303 |
override def detach_operation = |
304 |
get_operation() match { |
|
305 |
case None => None |
|
306 |
case Some(op) => op.pretty_text_area.detach_operation |
|
307 |
} |
|
56906
408b526911f7
some odd tricks to provide "Detach" menu item, via "PIDE" docking framework;
wenzelm
parents:
56886
diff
changeset
|
308 |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
309 |
|
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
310 |
/* resize */ |
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
311 |
|
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
312 |
private def handle_resize(): Unit = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57604
diff
changeset
|
313 |
GUI_Thread.require { |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
314 |
for (op <- operations) { |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
315 |
op.pretty_text_area.resize( |
57044 | 316 |
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
|
317 |
} |
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
318 |
} |
52846 | 319 |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
320 |
private val delay_resize = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57604
diff
changeset
|
321 |
GUI_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
|
322 |
|
52865
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents:
52864
diff
changeset
|
323 |
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
|
324 |
override def componentResized(e: ComponentEvent) { delay_resize.invoke() } |
60750 | 325 |
override def componentShown(e: ComponentEvent) { 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
|
326 |
}) |
52846 | 327 |
|
328 |
||
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
329 |
/* main */ |
52846 | 330 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
331 |
private val main = |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
332 |
Session.Consumer[Session.Global_Options](getClass.getName) { |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57604
diff
changeset
|
333 |
case _: Session.Global_Options => GUI_Thread.later { handle_resize() } |
52846 | 334 |
} |
335 |
||
336 |
override def init() |
|
337 |
{ |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
338 |
PIDE.session.global_options += main |
52848 | 339 |
handle_resize() |
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
340 |
operations.foreach(op => op.query_operation.activate()) |
52846 | 341 |
} |
342 |
||
343 |
override def exit() |
|
344 |
{ |
|
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
345 |
operations.foreach(op => op.query_operation.deactivate()) |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
346 |
PIDE.session.global_options -= main |
52846 | 347 |
delay_resize.revoke() |
348 |
} |
|
56757
d6fdf08282f3
some rearrangements to support multiple find operations;
wenzelm
parents:
56751
diff
changeset
|
349 |
} |
52846 | 350 |