src/Tools/jEdit/src/symbols_dockable.scala
author wenzelm
Wed, 30 Sep 2015 20:48:59 +0200
changeset 61292 ca76026ed7cc
parent 59391 39a38657d16b
child 62024 e3e22a5e85f2
permissions -rw-r--r--
tuned GUI;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    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
f70b3712040f renamed dockable "Prover Session" to "Theories";
wenzelm
parents: 50207
diff changeset
    15
import org.gjt.sp.jedit.View
f70b3712040f renamed dockable "Prover Session" to "Theories";
wenzelm
parents: 50207
diff changeset
    16
f70b3712040f renamed dockable "Prover Session" to "Theories";
wenzelm
parents: 50207
diff changeset
    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
{
4ff5d795ed08 dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff changeset
    20
  private class Symbol_Component(val symbol: String) extends Button
4ff5d795ed08 dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff changeset
    21
  {
50187
b5a09812abc4 special handling of control symbols in Symbols dockable;
wenzelm
parents: 50186
diff changeset
    22
    private val decoded = Symbol.decode(symbol)
55825
694833e3e4a0 tuned signature -- separate module Font_Info;
wenzelm
parents: 53786
diff changeset
    23
    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
    24
50143
4ff5d795ed08 dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff changeset
    25
    font =
50191
8b5a256859af more robust default font -- user might have switched jEdit TextArea to another font that lacks glyphs;
wenzelm
parents: 50190
diff changeset
    26
      Symbol.fonts.get(symbol) match {
57908
1937603dbdf2 separate Java FX modules -- no need to include jfxrt.jar by default;
wenzelm
parents: 57612
diff changeset
    27
        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
    28
        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
    29
      }
50187
b5a09812abc4 special handling of control symbols in Symbols dockable;
wenzelm
parents: 50186
diff changeset
    30
    action =
b5a09812abc4 special handling of control symbols in Symbols dockable;
wenzelm
parents: 50186
diff changeset
    31
      Action(decoded) {
b5a09812abc4 special handling of control symbols in Symbols dockable;
wenzelm
parents: 50186
diff changeset
    32
        val text_area = view.getTextArea
59063
b3c45d0e4fe1 encode text with control symbols;
wenzelm
parents: 57908
diff changeset
    33
        if (HTML.control_decoded.isDefinedAt(decoded))
50187
b5a09812abc4 special handling of control symbols in Symbols dockable;
wenzelm
parents: 50186
diff changeset
    34
          Token_Markup.edit_control_style(text_area, decoded)
b5a09812abc4 special handling of control symbols in Symbols dockable;
wenzelm
parents: 50186
diff changeset
    35
        else text_area.setSelectedText(decoded)
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
wenzelm
parents: 56755
diff changeset
    53
  private val group_tabs: TabbedPane = new TabbedPane {
50192
22d0f64362a5 tuned -- Symbol.groups already sorted;
wenzelm
parents: 50191
diff changeset
    54
    pages ++=
56753
40f8822d6bef misc tuning;
wenzelm
parents: 56622
diff changeset
    55
      Symbol.groups.map({ case (group, symbols) =>
50151
5f5e74365f14 capitalize lowercase groups;
immler
parents: 50146
diff changeset
    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 {
50187
b5a09812abc4 special handling of control symbols in Symbols dockable;
wenzelm
parents: 50186
diff changeset
    58
            contents ++= symbols.map(new Symbol_Component(_))
b5a09812abc4 special handling of control symbols in Symbols dockable;
wenzelm
parents: 50186
diff changeset
    59
            if (group == "control") contents += new Reset_Component
53713
bb15972a644d improved layout, with special treatment for ScrollPane;
wenzelm
parents: 53316
diff changeset
    60
          }), null)
56753
40f8822d6bef misc tuning;
wenzelm
parents: 56622
diff changeset
    61
      })
40f8822d6bef misc tuning;
wenzelm
parents: 56622
diff changeset
    62
56755
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    63
    val search_field = new TextField(10)
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    64
    val search_page =
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    65
      new TabbedPane.Page("search", new BorderPanel {
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    66
        val results_panel = new Wrap_Panel
59391
wenzelm
parents: 59063
diff changeset
    67
        layout(search_field) = BorderPanel.Position.North
wenzelm
parents: 59063
diff changeset
    68
        layout(new ScrollPane(results_panel)) = BorderPanel.Position.Center
56755
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    69
  
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    70
        val search_space =
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    71
          (for (sym <- Symbol.names.keysIterator) yield (sym, Word.lowercase(sym))).toList
56769
wenzelm
parents: 56756
diff changeset
    72
        val search_delay =
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 56769
diff changeset
    73
          GUI_Thread.delay_last(PIDE.options.seconds("editor_input_delay")) {
56756
wenzelm
parents: 56755
diff changeset
    74
            val search_words = Word.explode(Word.lowercase(search_field.text))
56755
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    75
            val search_limit = PIDE.options.int("jedit_symbols_search_limit") max 0
56756
wenzelm
parents: 56755
diff changeset
    76
            val results =
wenzelm
parents: 56755
diff changeset
    77
              for ((sym, s) <- search_space; if search_words.forall(s.contains(_))) yield sym
wenzelm
parents: 56755
diff changeset
    78
56755
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    79
            results_panel.contents.clear
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    80
            for (sym <- results.take(search_limit))
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    81
              results_panel.contents += new Symbol_Component(sym)
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    82
            if (results.length > search_limit)
56756
wenzelm
parents: 56755
diff changeset
    83
              results_panel.contents +=
wenzelm
parents: 56755
diff changeset
    84
                new Label("...") { tooltip = "(" + (results.length - search_limit) + " more)" }
56755
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    85
            revalidate
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    86
            repaint
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    87
          }
56769
wenzelm
parents: 56756
diff changeset
    88
          search_field.reactions += { case ValueChanged(_) => search_delay.invoke() }
56755
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    89
      }, "Search Symbols")
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    90
    pages += search_page
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    91
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    92
    listenTo(selection)
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    93
    reactions += {
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    94
      case SelectionChanged(_) if selection.page == search_page => search_field.requestFocus
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    95
    }
f29c9e7a3a80 clarified GUI focus;
wenzelm
parents: 56754
diff changeset
    96
56756
wenzelm
parents: 56755
diff changeset
    97
    for (page <- pages)
wenzelm
parents: 56755
diff changeset
    98
      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
    99
  }
4ff5d795ed08 dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff changeset
   100
  set_content(group_tabs)
4ff5d795ed08 dockable with buttons for symbols, grouped and sorted in tabs according to ~~/etc/symbols;
immler
parents:
diff changeset
   101
}