author | wenzelm |
Fri, 08 Jan 2016 18:18:40 +0100 | |
changeset 62104 | fb73c0d7bb37 |
parent 62024 | e3e22a5e85f2 |
child 63870 | 6db1aac936db |
permissions | -rw-r--r-- |
50143
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/symbols_dockable.scala |
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
2 |
Author: Fabian Immler |
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
3 |
|
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
4 |
Dockable window for Symbol Palette. |
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
5 |
*/ |
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
6 |
|
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
7 |
package isabelle.jedit |
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
8 |
|
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
9 |
|
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
10 |
import isabelle._ |
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
11 |
|
56755 | 12 |
import scala.swing.event.{SelectionChanged, ValueChanged} |
53713
bb15972a644d
improved layout, with special treatment for ScrollPane;
wenzelm
parents:
53316
diff
changeset
|
13 |
import scala.swing.{Action, Button, TabbedPane, TextField, BorderPanel, Label, ScrollPane} |
50143
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
14 |
|
50299 | 15 |
import org.gjt.sp.jedit.View |
16 |
||
17 |
||
50143
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
18 |
class Symbols_Dockable(view: View, position: String) extends Dockable(view, position) |
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
19 |
{ |
62104
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
62024
diff
changeset
|
20 |
private class Symbol_Component(val symbol: String, is_control: Boolean) extends Button |
50143
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
21 |
{ |
55825 | 22 |
private val font_size = Font_Info.main_size(PIDE.options.real("jedit_font_scale")).round |
50191
8b5a256859af
more robust default font -- user might have switched jEdit TextArea to another font that lacks glyphs;
wenzelm
parents:
50190
diff
changeset
|
23 |
|
50143
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
24 |
font = |
50191
8b5a256859af
more robust default font -- user might have switched jEdit TextArea to another font that lacks glyphs;
wenzelm
parents:
50190
diff
changeset
|
25 |
Symbol.fonts.get(symbol) match { |
57908
1937603dbdf2
separate Java FX modules -- no need to include jfxrt.jar by default;
wenzelm
parents:
57612
diff
changeset
|
26 |
case None => GUI.font(size = font_size) |
1937603dbdf2
separate Java FX modules -- no need to include jfxrt.jar by default;
wenzelm
parents:
57612
diff
changeset
|
27 |
case Some(font_family) => GUI.font(family = font_family, size = font_size) |
50191
8b5a256859af
more robust default font -- user might have switched jEdit TextArea to another font that lacks glyphs;
wenzelm
parents:
50190
diff
changeset
|
28 |
} |
50187
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50186
diff
changeset
|
29 |
action = |
62104
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
62024
diff
changeset
|
30 |
Action(Symbol.decode(symbol)) { |
50187
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50186
diff
changeset
|
31 |
val text_area = view.getTextArea |
62104
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
62024
diff
changeset
|
32 |
if (is_control && HTML.control.isDefinedAt(symbol)) |
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
62024
diff
changeset
|
33 |
Token_Markup.edit_control_style(text_area, symbol) |
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
62024
diff
changeset
|
34 |
else |
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
62024
diff
changeset
|
35 |
text_area.setSelectedText(Isabelle_Encoding.maybe_decode(text_area.getBuffer, symbol)) |
50187
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50186
diff
changeset
|
36 |
text_area.requestFocus |
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50186
diff
changeset
|
37 |
} |
56622
891d1b8b64fb
clarified tooltip_lines: HTML.encode already takes care of newline (but not space);
wenzelm
parents:
56609
diff
changeset
|
38 |
tooltip = |
891d1b8b64fb
clarified tooltip_lines: HTML.encode already takes care of newline (but not space);
wenzelm
parents:
56609
diff
changeset
|
39 |
GUI.tooltip_lines( |
891d1b8b64fb
clarified tooltip_lines: HTML.encode already takes care of newline (but not space);
wenzelm
parents:
56609
diff
changeset
|
40 |
cat_lines(symbol :: Symbol.abbrevs.get_list(symbol).map(a => "abbrev: " + a))) |
50143
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
41 |
} |
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
42 |
|
50187
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50186
diff
changeset
|
43 |
private class Reset_Component extends Button |
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50186
diff
changeset
|
44 |
{ |
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50186
diff
changeset
|
45 |
action = Action("Reset") { |
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50186
diff
changeset
|
46 |
val text_area = view.getTextArea |
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50186
diff
changeset
|
47 |
Token_Markup.edit_control_style(text_area, "") |
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50186
diff
changeset
|
48 |
text_area.requestFocus |
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50186
diff
changeset
|
49 |
} |
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50186
diff
changeset
|
50 |
tooltip = "Reset control symbols within text" |
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50186
diff
changeset
|
51 |
} |
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50186
diff
changeset
|
52 |
|
56756 | 53 |
private val group_tabs: TabbedPane = new TabbedPane { |
50192 | 54 |
pages ++= |
56753 | 55 |
Symbol.groups.map({ case (group, symbols) => |
50151 | 56 |
new TabbedPane.Page(group, |
53713
bb15972a644d
improved layout, with special treatment for ScrollPane;
wenzelm
parents:
53316
diff
changeset
|
57 |
new ScrollPane(new Wrap_Panel { |
62024
e3e22a5e85f2
clarified meaning of \<^bold> action, depending on group;
wenzelm
parents:
59391
diff
changeset
|
58 |
val control = group == "control" |
e3e22a5e85f2
clarified meaning of \<^bold> action, depending on group;
wenzelm
parents:
59391
diff
changeset
|
59 |
contents ++= symbols.map(new Symbol_Component(_, control)) |
e3e22a5e85f2
clarified meaning of \<^bold> action, depending on group;
wenzelm
parents:
59391
diff
changeset
|
60 |
if (control) contents += new Reset_Component |
53713
bb15972a644d
improved layout, with special treatment for ScrollPane;
wenzelm
parents:
53316
diff
changeset
|
61 |
}), null) |
56753 | 62 |
}) |
63 |
||
56755 | 64 |
val search_field = new TextField(10) |
65 |
val search_page = |
|
66 |
new TabbedPane.Page("search", new BorderPanel { |
|
67 |
val results_panel = new Wrap_Panel |
|
59391 | 68 |
layout(search_field) = BorderPanel.Position.North |
69 |
layout(new ScrollPane(results_panel)) = BorderPanel.Position.Center |
|
56755 | 70 |
|
71 |
val search_space = |
|
72 |
(for (sym <- Symbol.names.keysIterator) yield (sym, Word.lowercase(sym))).toList |
|
56769 | 73 |
val search_delay = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56769
diff
changeset
|
74 |
GUI_Thread.delay_last(PIDE.options.seconds("editor_input_delay")) { |
56756 | 75 |
val search_words = Word.explode(Word.lowercase(search_field.text)) |
56755 | 76 |
val search_limit = PIDE.options.int("jedit_symbols_search_limit") max 0 |
56756 | 77 |
val results = |
78 |
for ((sym, s) <- search_space; if search_words.forall(s.contains(_))) yield sym |
|
79 |
||
56755 | 80 |
results_panel.contents.clear |
81 |
for (sym <- results.take(search_limit)) |
|
62024
e3e22a5e85f2
clarified meaning of \<^bold> action, depending on group;
wenzelm
parents:
59391
diff
changeset
|
82 |
results_panel.contents += new Symbol_Component(sym, false) |
56755 | 83 |
if (results.length > search_limit) |
56756 | 84 |
results_panel.contents += |
85 |
new Label("...") { tooltip = "(" + (results.length - search_limit) + " more)" } |
|
56755 | 86 |
revalidate |
87 |
repaint |
|
88 |
} |
|
56769 | 89 |
search_field.reactions += { case ValueChanged(_) => search_delay.invoke() } |
56755 | 90 |
}, "Search Symbols") |
91 |
pages += search_page |
|
92 |
||
93 |
listenTo(selection) |
|
94 |
reactions += { |
|
95 |
case SelectionChanged(_) if selection.page == search_page => search_field.requestFocus |
|
96 |
} |
|
97 |
||
56756 | 98 |
for (page <- pages) |
99 |
page.title = Word.implode(Word.explode('_', page.title).map(Word.perhaps_capitalize(_))) |
|
50143
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
100 |
} |
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
101 |
set_content(group_tabs) |
4ff5d795ed08
dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff
changeset
|
102 |
} |