@@ -43,7 +43,27 @@ export default function Library({ application }) {
4343
4444 const demos = getDemos ( ) ;
4545 const widgets_map = new Map ( ) ;
46- const category_map = new Map ( ) ;
46+ // const category_map = new Map(
47+
48+ // );
49+
50+ // if (!category_map.has(demo.category)) {
51+ // category_map.set(demo.category, objects[`library_${demo.category}`]);
52+ // }
53+ const categories = [
54+ { id : "uncategorized" , label : _ ( "Uncategorized" ) , index : 1 } ,
55+ { id : "tools" , label : _ ( "Tools" ) , index : 2 } ,
56+ { id : "network" , label : _ ( "Network" ) , index : 3 } ,
57+ { id : "controls" , label : _ ( "Controls" ) , index : 4 } ,
58+ { id : "layout" , label : _ ( "Layout" ) , index : 5 } ,
59+ { id : "feedback" , label : _ ( "Feedback" ) , index : 6 } ,
60+ { id : "navigation" , label : _ ( "Navigation" ) , index : 7 } ,
61+ { id : "user_interface" , label : _ ( "User Interface" ) , index : 8 } ,
62+ { id : "platform" , label : _ ( "Platform APIs" ) , index : 9 } ,
63+ ] ;
64+ categories . forEach ( ( category ) => {
65+ category . widget = objects [ `library_${ category . id } ` ] ;
66+ } ) ;
4767
4868 const language_model = new Gtk . StringList ( ) ;
4969 language_model . append ( _ ( "Any Language" ) ) ;
@@ -60,20 +80,8 @@ export default function Library({ application }) {
6080
6181 const category_model = new Gtk . StringList ( ) ;
6282 category_model . append ( _ ( "Any Category" ) ) ;
83+ categories . forEach ( ( category ) => category_model . append ( category . label ) ) ;
6384 dropdown_category . set_model ( category_model ) ;
64- const category_check = [ _ ( "Any Category" ) ] ;
65- const category_labels = {
66- uncategorized : _ ( "Uncategorized" ) ,
67- tools : _ ( "Tools" ) ,
68- network : _ ( "Network" ) ,
69- controls : _ ( "Controls" ) ,
70- layout : _ ( "Layout" ) ,
71- feedback : _ ( "Feedback" ) ,
72- navigation : _ ( "Navigation" ) ,
73- user_interface : _ ( "User Interface" ) ,
74- platform : _ ( "Platform APIs" ) ,
75- } ;
76- Object . values ( category_labels ) . forEach ( ( str ) => category_model . append ( str ) ) ;
7785
7886 demos . forEach ( ( demo ) => {
7987 demo . languages . forEach ( ( lang ) => {
@@ -82,10 +90,6 @@ export default function Library({ application }) {
8290 }
8391 } ) ;
8492
85- if ( ! category_check . includes ( demo . category ) ) {
86- category_check . push ( demo . category ) ;
87- }
88-
8993 const entry_row = new EntryRow ( { demo : demo } ) ;
9094 if ( demo . name === "Welcome" ) last_triggered = entry_row ;
9195
@@ -98,13 +102,13 @@ export default function Library({ application }) {
98102 language,
99103 } ) . catch ( console . error ) ;
100104 } ) ;
101- if ( ! category_map . has ( demo . category ) ) {
102- category_map . set ( demo . category , objects [ `library_ ${ demo . category } ` ] ) ;
103- }
104- objects [ `library_ ${ demo . category } ` ] . append ( entry_row ) ;
105+ const category = categories . find (
106+ ( category ) => category . id === demo . category ,
107+ ) ;
108+ category . widget . append ( entry_row ) ;
105109 widgets_map . set ( demo . name , {
106110 entry_row,
107- category_index : category_check . indexOf ( demo . category ) ,
111+ category_index : category . index ,
108112 languages_index : demo . languages . map ( ( lang ) =>
109113 language_check . indexOf ( lang ) ,
110114 ) ,
@@ -132,19 +136,21 @@ export default function Library({ application }) {
132136 entry_row . visible = is_match ;
133137 if ( is_match ) {
134138 results_found = true ;
135- visible_categories . add ( category_check [ category_index ] ) ;
139+ visible_categories . add (
140+ categories . find ( ( cat ) => cat . index === category_index ) . id ,
141+ ) ;
136142 }
137143 } ,
138144 ) ;
139145
140- category_map . forEach ( ( category_widget , category_name ) => {
141- const label = objects [ `label_${ category_name } ` ] ;
146+ categories . forEach ( ( category ) => {
147+ const label = objects [ `label_${ category . id } ` ] ;
142148 if ( label )
143149 label . visible =
144150 current_category === 0 &&
145151 current_language === 0 &&
146152 search_term === "" ;
147- category_widget . visible = visible_categories . has ( category_name ) ;
153+ category . widget . visible = visible_categories . has ( category . id ) ;
148154 } ) ;
149155 results_empty . set_visible ( ! results_found ) ;
150156 }
0 commit comments