@@ -19,7 +19,7 @@ import { build } from "../../troll/src/builder.js";
1919
2020export default function Library ( { application } ) {
2121 const objects = build ( resource ) ;
22- const { window, picture_illustration } = objects ;
22+ const { window, picture_illustration, search_entry } = objects ;
2323 window . application = application ;
2424 picture_illustration . set_resource ( illustration ) ;
2525
@@ -32,6 +32,8 @@ export default function Library({ application }) {
3232 window . connect ( "close-request" , quitOnLastWindowClose ) ;
3333
3434 const demos = getDemos ( ) ;
35+ const widgets_map = new Map ( ) ;
36+ const category_map = new Map ( ) ;
3537 demos . forEach ( ( demo ) => {
3638 const widget = new EntryRow ( { demo : demo } ) ;
3739 if ( demo . name === "Welcome" ) last_selected = widget ;
@@ -45,10 +47,27 @@ export default function Library({ application }) {
4547 language,
4648 } ) . catch ( console . error ) ;
4749 } ) ;
48-
50+ if ( ! category_map . has ( demo . category ) ) {
51+ category_map . set ( demo . category , objects [ `library_${ demo . category } ` ] ) ;
52+ }
4953 objects [ `library_${ demo . category } ` ] . add ( widget ) ;
54+ widgets_map . set ( demo . name , { widget, category : demo . category } ) ;
5055 } ) ;
5156
57+ search_entry . connect ( "search-changed" , ( ) => {
58+ const search_term = search_entry . get_text ( ) . toLowerCase ( ) ;
59+ const visible_categories = new Set ( ) ;
60+
61+ widgets_map . forEach ( ( { widget, category } , demo_name ) => {
62+ const is_match = demo_name . toLowerCase ( ) . includes ( search_term ) ;
63+ widget . visible = is_match ;
64+ if ( is_match ) visible_categories . add ( category ) ;
65+ } ) ;
66+
67+ category_map . forEach ( ( category_widget , category_name ) => {
68+ category_widget . visible = visible_categories . has ( category_name ) ;
69+ } ) ;
70+ } ) ;
5271 const action_library = new Gio . SimpleAction ( {
5372 name : "library" ,
5473 parameter_type : null ,
@@ -86,9 +105,9 @@ async function openDemo({ application, demo_name, language }) {
86105 session . settings . set_int ( "code-language" , language . index ) ;
87106 global_settings . set_int ( "recent-code-language" , language . index ) ;
88107
89- // If the user explictely requested to open the demo
108+ // If the user explicitly requested to open the demo
90109 // in a specific language then that's probably what they are interested in
91- // therefor override the demo default and force show the code panel
110+ // therefore override the demo default and force show the code panel
92111 session . settings . set_boolean ( "show-code" , true ) ;
93112 }
94113
0 commit comments