| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of client_live_nav; |
| 6 |
| 5 List libraryList; | 7 List libraryList; |
| 6 InputElement searchInput; | 8 InputElement searchInput; |
| 7 DivElement dropdown; | 9 DivElement dropdown; |
| 8 | 10 |
| 9 /** | 11 /** |
| 10 * Update the search drop down based on the current search text. | 12 * Update the search drop down based on the current search text. |
| 11 */ | 13 */ |
| 12 updateDropDown(Event event) { | 14 updateDropDown(Event event) { |
| 13 if (libraryList == null) return; | 15 if (libraryList == null) return; |
| 14 if (searchInput == null) return; | 16 if (searchInput == null) return; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 37 } else if (memberText.isEmpty) { | 39 } else if (memberText.isEmpty) { |
| 38 // Search text is of the form 'Type.' => Look up members in 'Type'. | 40 // Search text is of the form 'Type.' => Look up members in 'Type'. |
| 39 matchAllMembersInType(results, typeText, memberText); | 41 matchAllMembersInType(results, typeText, memberText); |
| 40 } else { | 42 } else { |
| 41 // Search text is of the form 'Type.id' => Look up member 'id' in 'Type'. | 43 // Search text is of the form 'Type.id' => Look up member 'id' in 'Type'. |
| 42 matchMembersInType(results, text, typeText, memberText); | 44 matchMembersInType(results, text, typeText, memberText); |
| 43 } | 45 } |
| 44 } else { | 46 } else { |
| 45 // Search all entities. | 47 // Search all entities. |
| 46 var searchText = new SearchText(text); | 48 var searchText = new SearchText(text); |
| 47 for (Map<String,Dynamic> library in libraryList) { | 49 for (Map<String,dynamic> library in libraryList) { |
| 48 matchLibrary(results, searchText, library); | 50 matchLibrary(results, searchText, library); |
| 49 matchLibraryMembers(results, searchText, library); | 51 matchLibraryMembers(results, searchText, library); |
| 50 matchTypes(results, searchText, library); | 52 matchTypes(results, searchText, library); |
| 51 } | 53 } |
| 52 } | 54 } |
| 53 var elements = <Element>[]; | 55 var elements = <Element>[]; |
| 54 var table = new TableElement(); | 56 var table = new TableElement(); |
| 55 table.classes.add('drop-down-table'); | 57 table.classes.add('drop-down-table'); |
| 56 elements.add(table); | 58 elements.add(table); |
| 57 | 59 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 74 results = results.getRange(0, 10); | 76 results = results.getRange(0, 10); |
| 75 } | 77 } |
| 76 } | 78 } |
| 77 dropdown.elements = elements; | 79 dropdown.elements = elements; |
| 78 updateResults(text, results); | 80 updateResults(text, results); |
| 79 showDropDown(); | 81 showDropDown(); |
| 80 } | 82 } |
| 81 | 83 |
| 82 void matchAllMembers(List<Result> results, String memberText) { | 84 void matchAllMembers(List<Result> results, String memberText) { |
| 83 var searchText = new SearchText(memberText); | 85 var searchText = new SearchText(memberText); |
| 84 for (Map<String,Dynamic> library in libraryList) { | 86 for (Map<String,dynamic> library in libraryList) { |
| 85 String libraryName = library[NAME]; | 87 String libraryName = library[NAME]; |
| 86 if (library.containsKey(TYPES)) { | 88 if (library.containsKey(TYPES)) { |
| 87 for (Map<String,Dynamic> type in library[TYPES]) { | 89 for (Map<String,dynamic> type in library[TYPES]) { |
| 88 String typeName = type[NAME]; | 90 String typeName = type[NAME]; |
| 89 if (type.containsKey(MEMBERS)) { | 91 if (type.containsKey(MEMBERS)) { |
| 90 for (Map<String,Dynamic> member in type[MEMBERS]) { | 92 for (Map<String,dynamic> member in type[MEMBERS]) { |
| 91 StringMatch memberMatch = obtainMatch(searchText, member[NAME]); | 93 StringMatch memberMatch = obtainMatch(searchText, member[NAME]); |
| 92 if (memberMatch != null) { | 94 if (memberMatch != null) { |
| 93 results.add(new Result(memberMatch, member[KIND], | 95 results.add(new Result(memberMatch, member[KIND], |
| 94 getTypeMemberUrl(libraryName, typeName, member), | 96 getTypeMemberUrl(libraryName, typeName, member), |
| 95 library: libraryName, type: typeName, args: type[ARGS], | 97 library: libraryName, type: typeName, args: type[ARGS], |
| 96 noargs: member[NO_PARAMS])); | 98 noargs: member[NO_PARAMS])); |
| 97 } | 99 } |
| 98 } | 100 } |
| 99 } | 101 } |
| 100 } | 102 } |
| 101 } | 103 } |
| 102 } | 104 } |
| 103 } | 105 } |
| 104 | 106 |
| 105 void matchAllMembersInType(List<Result> results, | 107 void matchAllMembersInType(List<Result> results, |
| 106 String typeText, String memberText) { | 108 String typeText, String memberText) { |
| 107 var searchText = new SearchText(typeText); | 109 var searchText = new SearchText(typeText); |
| 108 var emptyText = new SearchText(memberText); | 110 var emptyText = new SearchText(memberText); |
| 109 for (Map<String,Dynamic> library in libraryList) { | 111 for (Map<String,dynamic> library in libraryList) { |
| 110 String libraryName = library[NAME]; | 112 String libraryName = library[NAME]; |
| 111 if (library.containsKey(TYPES)) { | 113 if (library.containsKey(TYPES)) { |
| 112 for (Map<String,Dynamic> type in library[TYPES]) { | 114 for (Map<String,dynamic> type in library[TYPES]) { |
| 113 String typeName = type[NAME]; | 115 String typeName = type[NAME]; |
| 114 StringMatch typeMatch = obtainMatch(searchText, typeName); | 116 StringMatch typeMatch = obtainMatch(searchText, typeName); |
| 115 if (typeMatch != null) { | 117 if (typeMatch != null) { |
| 116 if (type.containsKey(MEMBERS)) { | 118 if (type.containsKey(MEMBERS)) { |
| 117 for (Map<String,Dynamic> member in type[MEMBERS]) { | 119 for (Map<String,dynamic> member in type[MEMBERS]) { |
| 118 StringMatch memberMatch = obtainMatch(emptyText, | 120 StringMatch memberMatch = obtainMatch(emptyText, |
| 119 member[NAME]); | 121 member[NAME]); |
| 120 results.add(new Result(memberMatch, member[KIND], | 122 results.add(new Result(memberMatch, member[KIND], |
| 121 getTypeMemberUrl(libraryName, typeName, member), | 123 getTypeMemberUrl(libraryName, typeName, member), |
| 122 library: libraryName, prefix: typeMatch, | 124 library: libraryName, prefix: typeMatch, |
| 123 noargs: member[NO_PARAMS])); | 125 noargs: member[NO_PARAMS])); |
| 124 } | 126 } |
| 125 } | 127 } |
| 126 } | 128 } |
| 127 } | 129 } |
| 128 } | 130 } |
| 129 } | 131 } |
| 130 } | 132 } |
| 131 | 133 |
| 132 void matchMembersInType(List<Result> results, | 134 void matchMembersInType(List<Result> results, |
| 133 String text, String typeText, String memberText) { | 135 String text, String typeText, String memberText) { |
| 134 var searchText = new SearchText(text); | 136 var searchText = new SearchText(text); |
| 135 var typeSearchText = new SearchText(typeText); | 137 var typeSearchText = new SearchText(typeText); |
| 136 var memberSearchText = new SearchText(memberText); | 138 var memberSearchText = new SearchText(memberText); |
| 137 for (Map<String,Dynamic> library in libraryList) { | 139 for (Map<String,dynamic> library in libraryList) { |
| 138 String libraryName = library[NAME]; | 140 String libraryName = library[NAME]; |
| 139 if (library.containsKey(TYPES)) { | 141 if (library.containsKey(TYPES)) { |
| 140 for (Map<String,Dynamic> type in library[TYPES]) { | 142 for (Map<String,dynamic> type in library[TYPES]) { |
| 141 String typeName = type[NAME]; | 143 String typeName = type[NAME]; |
| 142 StringMatch typeMatch = obtainMatch(typeSearchText, typeName); | 144 StringMatch typeMatch = obtainMatch(typeSearchText, typeName); |
| 143 if (typeMatch != null) { | 145 if (typeMatch != null) { |
| 144 if (type.containsKey(MEMBERS)) { | 146 if (type.containsKey(MEMBERS)) { |
| 145 for (Map<String,Dynamic> member in type[MEMBERS]) { | 147 for (Map<String,dynamic> member in type[MEMBERS]) { |
| 146 // Check for constructor match. | 148 // Check for constructor match. |
| 147 StringMatch constructorMatch = obtainMatch(searchText, | 149 StringMatch constructorMatch = obtainMatch(searchText, |
| 148 member[NAME]); | 150 member[NAME]); |
| 149 if (constructorMatch != null) { | 151 if (constructorMatch != null) { |
| 150 results.add(new Result(constructorMatch, member[KIND], | 152 results.add(new Result(constructorMatch, member[KIND], |
| 151 getTypeMemberUrl(libraryName, typeName, member), | 153 getTypeMemberUrl(libraryName, typeName, member), |
| 152 library: libraryName, noargs: member[NO_PARAMS])); | 154 library: libraryName, noargs: member[NO_PARAMS])); |
| 153 } else { | 155 } else { |
| 154 // Try member match. | 156 // Try member match. |
| 155 StringMatch memberMatch = obtainMatch(memberSearchText, | 157 StringMatch memberMatch = obtainMatch(memberSearchText, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 175 if (libraryMatch != null) { | 177 if (libraryMatch != null) { |
| 176 results.add(new Result(libraryMatch, LIBRARY, | 178 results.add(new Result(libraryMatch, LIBRARY, |
| 177 getLibraryUrl(libraryName))); | 179 getLibraryUrl(libraryName))); |
| 178 } | 180 } |
| 179 } | 181 } |
| 180 | 182 |
| 181 void matchLibraryMembers(List<Result> results, SearchText searchText, | 183 void matchLibraryMembers(List<Result> results, SearchText searchText, |
| 182 Map library) { | 184 Map library) { |
| 183 if (library.containsKey(MEMBERS)) { | 185 if (library.containsKey(MEMBERS)) { |
| 184 String libraryName = library[NAME]; | 186 String libraryName = library[NAME]; |
| 185 for (Map<String,Dynamic> member in library[MEMBERS]) { | 187 for (Map<String,dynamic> member in library[MEMBERS]) { |
| 186 StringMatch memberMatch = obtainMatch(searchText, member[NAME]); | 188 StringMatch memberMatch = obtainMatch(searchText, member[NAME]); |
| 187 if (memberMatch != null) { | 189 if (memberMatch != null) { |
| 188 results.add(new Result(memberMatch, member[KIND], | 190 results.add(new Result(memberMatch, member[KIND], |
| 189 getLibraryMemberUrl(libraryName, member), | 191 getLibraryMemberUrl(libraryName, member), |
| 190 library: libraryName, noargs: member[NO_PARAMS]))
; | 192 library: libraryName, noargs: member[NO_PARAMS]))
; |
| 191 } | 193 } |
| 192 } | 194 } |
| 193 } | 195 } |
| 194 } | 196 } |
| 195 | 197 |
| 196 void matchTypes(List<Result> results, SearchText searchText, | 198 void matchTypes(List<Result> results, SearchText searchText, |
| 197 Map library) { | 199 Map library) { |
| 198 if (library.containsKey(TYPES)) { | 200 if (library.containsKey(TYPES)) { |
| 199 String libraryName = library[NAME]; | 201 String libraryName = library[NAME]; |
| 200 for (Map<String,Dynamic> type in library[TYPES]) { | 202 for (Map<String,dynamic> type in library[TYPES]) { |
| 201 String typeName = type[NAME]; | 203 String typeName = type[NAME]; |
| 202 matchType(results, searchText, libraryName, type); | 204 matchType(results, searchText, libraryName, type); |
| 203 matchTypeMembers(results, searchText, libraryName, type); | 205 matchTypeMembers(results, searchText, libraryName, type); |
| 204 } | 206 } |
| 205 } | 207 } |
| 206 } | 208 } |
| 207 | 209 |
| 208 void matchType(List<Result> results, SearchText searchText, | 210 void matchType(List<Result> results, SearchText searchText, |
| 209 String libraryName, Map type) { | 211 String libraryName, Map type) { |
| 210 String typeName = type[NAME]; | 212 String typeName = type[NAME]; |
| 211 StringMatch typeMatch = obtainMatch(searchText, typeName); | 213 StringMatch typeMatch = obtainMatch(searchText, typeName); |
| 212 if (typeMatch != null) { | 214 if (typeMatch != null) { |
| 213 results.add(new Result(typeMatch, type[KIND], | 215 results.add(new Result(typeMatch, type[KIND], |
| 214 getTypeUrl(libraryName, type), | 216 getTypeUrl(libraryName, type), |
| 215 library: libraryName, args: type[ARGS])); | 217 library: libraryName, args: type[ARGS])); |
| 216 } | 218 } |
| 217 } | 219 } |
| 218 | 220 |
| 219 void matchTypeMembers(List<Result> results, SearchText searchText, | 221 void matchTypeMembers(List<Result> results, SearchText searchText, |
| 220 String libraryName, Map type) { | 222 String libraryName, Map type) { |
| 221 if (type.containsKey(MEMBERS)) { | 223 if (type.containsKey(MEMBERS)) { |
| 222 String typeName = type[NAME]; | 224 String typeName = type[NAME]; |
| 223 for (Map<String,Dynamic> member in type[MEMBERS]) { | 225 for (Map<String,dynamic> member in type[MEMBERS]) { |
| 224 StringMatch memberMatch = obtainMatch(searchText, member[NAME]); | 226 StringMatch memberMatch = obtainMatch(searchText, member[NAME]); |
| 225 if (memberMatch != null) { | 227 if (memberMatch != null) { |
| 226 results.add(new Result(memberMatch, member[KIND], | 228 results.add(new Result(memberMatch, member[KIND], |
| 227 getTypeMemberUrl(libraryName, typeName, member), | 229 getTypeMemberUrl(libraryName, typeName, member), |
| 228 library: libraryName, type: typeName, args: type[ARGS], | 230 library: libraryName, type: typeName, args: type[ARGS], |
| 229 noargs: member[NO_PARAMS])); | 231 noargs: member[NO_PARAMS])); |
| 230 } | 232 } |
| 231 } | 233 } |
| 232 } | 234 } |
| 233 } | 235 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 searchInput = query('#q'); | 349 searchInput = query('#q'); |
| 348 dropdown = query('#drop-down'); | 350 dropdown = query('#drop-down'); |
| 349 | 351 |
| 350 searchInput.on.keyDown.add(handleUpDown); | 352 searchInput.on.keyDown.add(handleUpDown); |
| 351 searchInput.on.keyUp.add(updateDropDown); | 353 searchInput.on.keyUp.add(updateDropDown); |
| 352 searchInput.on.change.add(updateDropDown); | 354 searchInput.on.change.add(updateDropDown); |
| 353 searchInput.on.reset.add(updateDropDown); | 355 searchInput.on.reset.add(updateDropDown); |
| 354 searchInput.on.focus.add((event) => showDropDown()); | 356 searchInput.on.focus.add((event) => showDropDown()); |
| 355 searchInput.on.blur.add((event) => hideDropDown()); | 357 searchInput.on.blur.add((event) => hideDropDown()); |
| 356 } | 358 } |
| OLD | NEW |