src/Tools/jEdit/src/symbols_dockable.scala
changeset 63877 b4051d3f4e94
parent 63874 e2393cfde472
child 63926 70973a1b4ec0
equal deleted inserted replaced
63876:fd73c5dbaad2 63877:b4051d3f4e94
    20 {
    20 {
    21   private def font_size: Int =
    21   private def font_size: Int =
    22     Font_Info.main_size(PIDE.options.real("jedit_font_scale")).round
    22     Font_Info.main_size(PIDE.options.real("jedit_font_scale")).round
    23 
    23 
    24 
    24 
    25   /* abbreviations */
    25   /* abbrevs */
    26 
    26 
    27   private val abbrevs_panel = new Abbrevs_Panel
    27   private val abbrevs_panel = new Abbrevs_Panel
    28 
    28 
    29   private val abbrevs_refresh_delay =
    29   private val abbrevs_refresh_delay =
    30     GUI_Thread.delay_last(PIDE.options.seconds("editor_update_delay")) { abbrevs_panel.refresh }
    30     GUI_Thread.delay_last(PIDE.options.seconds("editor_update_delay")) { abbrevs_panel.refresh }
   116     }
   116     }
   117     tooltip = "Reset control symbols within text"
   117     tooltip = "Reset control symbols within text"
   118   }
   118   }
   119 
   119 
   120 
   120 
       
   121   /* search */
       
   122 
       
   123   private class Search_Panel extends BorderPanel {
       
   124     val search_field = new TextField(10)
       
   125     val results_panel = new Wrap_Panel
       
   126     layout(search_field) = BorderPanel.Position.North
       
   127     layout(new ScrollPane(results_panel)) = BorderPanel.Position.Center
       
   128 
       
   129     val search_space =
       
   130       (for (sym <- Symbol.names.keysIterator) yield (sym, Word.lowercase(sym))).toList
       
   131     val search_delay =
       
   132       GUI_Thread.delay_last(PIDE.options.seconds("editor_input_delay")) {
       
   133         val search_words = Word.explode(Word.lowercase(search_field.text))
       
   134         val search_limit = PIDE.options.int("jedit_symbols_search_limit") max 0
       
   135         val results =
       
   136           for ((sym, s) <- search_space; if search_words.forall(s.contains(_))) yield sym
       
   137 
       
   138         results_panel.contents.clear
       
   139         for (sym <- results.take(search_limit))
       
   140           results_panel.contents += new Symbol_Component(sym, false)
       
   141         if (results.length > search_limit)
       
   142           results_panel.contents +=
       
   143             new Label("...") { tooltip = "(" + (results.length - search_limit) + " more)" }
       
   144         revalidate
       
   145         repaint
       
   146       }
       
   147       search_field.reactions += { case ValueChanged(_) => search_delay.invoke() }
       
   148   }
       
   149 
       
   150 
   121   /* tabs */
   151   /* tabs */
   122 
   152 
   123   private val group_tabs: TabbedPane = new TabbedPane {
   153   private val group_tabs: TabbedPane = new TabbedPane {
   124     pages += new TabbedPane.Page("abbrevs", abbrevs_panel)
   154     pages += new TabbedPane.Page("abbrevs", abbrevs_panel)
   125 
   155 
   131             contents ++= symbols.map(new Symbol_Component(_, control))
   161             contents ++= symbols.map(new Symbol_Component(_, control))
   132             if (control) contents += new Reset_Component
   162             if (control) contents += new Reset_Component
   133           }), null)
   163           }), null)
   134       })
   164       })
   135 
   165 
   136     val search_field = new TextField(10)
   166     val search_panel = new Search_Panel
   137     val search_page =
   167     val search_page = new TabbedPane.Page("search", search_panel, "Search Symbols")
   138       new TabbedPane.Page("search", new BorderPanel {
       
   139         val results_panel = new Wrap_Panel
       
   140         layout(search_field) = BorderPanel.Position.North
       
   141         layout(new ScrollPane(results_panel)) = BorderPanel.Position.Center
       
   142 
       
   143         val search_space =
       
   144           (for (sym <- Symbol.names.keysIterator) yield (sym, Word.lowercase(sym))).toList
       
   145         val search_delay =
       
   146           GUI_Thread.delay_last(PIDE.options.seconds("editor_input_delay")) {
       
   147             val search_words = Word.explode(Word.lowercase(search_field.text))
       
   148             val search_limit = PIDE.options.int("jedit_symbols_search_limit") max 0
       
   149             val results =
       
   150               for ((sym, s) <- search_space; if search_words.forall(s.contains(_))) yield sym
       
   151 
       
   152             results_panel.contents.clear
       
   153             for (sym <- results.take(search_limit))
       
   154               results_panel.contents += new Symbol_Component(sym, false)
       
   155             if (results.length > search_limit)
       
   156               results_panel.contents +=
       
   157                 new Label("...") { tooltip = "(" + (results.length - search_limit) + " more)" }
       
   158             revalidate
       
   159             repaint
       
   160           }
       
   161           search_field.reactions += { case ValueChanged(_) => search_delay.invoke() }
       
   162       }, "Search Symbols")
       
   163     pages += search_page
   168     pages += search_page
   164 
   169 
   165     listenTo(selection)
   170     listenTo(selection)
   166     reactions += {
   171     reactions += {
   167       case SelectionChanged(_) if selection.page == search_page => search_field.requestFocus
   172       case SelectionChanged(_) if selection.page == search_page =>
       
   173         search_panel.search_field.requestFocus
   168     }
   174     }
   169 
   175 
   170     for (page <- pages)
   176     for (page <- pages)
   171       page.title = Word.implode(Word.explode('_', page.title).map(Word.perhaps_capitalize(_)))
   177       page.title = Word.implode(Word.explode('_', page.title).map(Word.perhaps_capitalize(_)))
   172   }
   178   }