Libraryless. Click here for Pure Java version (13160L/97K).
!7 srecord Result(S text, S moduleID, S moduleDesc, O[] params, double value) { O coreObject() { ret optPar(params, 'additionalInfo, text); } } module QuickSearchManager > DynQuickSearch { transient S resultsQuery; transient Map<S, L<Result>> resultsByModule = synchroMap(); transient L<Result> shownResults; transient Map<S, Number> moduleRankings; start { //set doSearchVerbose; thread { moduleRankings = mapValues(f parseDouble, mechMap("Search Module Rankings")); } } afterVisualize { onDoubleClickOrEnter(list, r { Result r = _get(shownResults, getSelectedIndex(list)); if (r == null) ret; dm_hideQuickSearchModules(); O defaultAction = getOpt(r.coreObject(), 'defaultAction); if (defaultAction == null) defaultAction = optPar(r.params, 'defaultAction); callFInNewThread(defaultAction, r.coreObject()); }); listPopupMenu(list, voidfunc(JPopupMenu menu, S item) { final Result r = _get(shownResults, getSelectedIndex(list)); if (r == null) ret; O[] params = optPar(r.params, 'popupItems); for (int i = 0; i+1 < l(params); i += 2) { if (isMenuSeparatorIndicator(params[i])) continue with --i; fO action = params[i+1]; addMenuItem(menu, str(params[i]), r { callFInNewThread(action, r.coreObject()) }); } }); } LS calc_impl() { L<Result> results = concatLists(cloneValues(getResultsByModule(dm_topInput()))); sortByFieldDesc_inPlace(results, 'value); ret map(func(Result r) -> S { resultToText(r) }, shownResults = takeFirst(50, results)); } S resultToText(Result r) { ret "[" + r.moduleDesc + "] " + r.text; } // clear if query changed Map<S, L<Result>> getResultsByModule(S input) { synchronized(resultsByModule) { if (neq(resultsQuery, input)) { resultsQuery = input; resultsByModule.clear(); } ret resultsByModule; } } // API void setResultsForModule(S moduleID, S query, L results) { setResultsForModule(moduleID, null, query, results); } // results: LS or LPair<S, O> (string to print, additional info) void setResultsForModule(fS moduleID, S _moduleDesc, S query, L results, fO... _) { fS moduleDesc = _moduleDesc != null ? _moduleDesc : dm_moduleName(moduleID); if (neq(query, dm_topInput())) ret with print("Results for wrong query: " + query); final double moduleValue = toDouble(mapGet(moduleRankings, dm_programID(moduleID))); synchronized(resultsByModule) { getResultsByModule(query).put(moduleID, map(results, func(O o) -> Result { o instanceof S ? Result((S) o, moduleID, moduleDesc, _, 0) : Result(getString(o, 'a), moduleID, moduleDesc, paramsPlus(_, additionalInfo := _get(o, 'b)), moduleValue) })); } // show/update list //if (nempty(results)) doSearch(resultsQuery); } }
download show line numbers debug dex old transpilations
Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, hpgrupgrauku, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1020446 |
Snippet name: | Quick Search [unifies other search modules] |
Eternal ID of this version: | #1020446/39 |
Text MD5: | c97879fbd15d2fbc158a9a9836d04869 |
Transpilation MD5: | 724dc76451f4c34cc4ec242457635a45 |
Author: | stefan |
Category: | javax / stefan's os |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-01-21 13:34:28 |
Source code size: | 3031 bytes / 88 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 482 / 8098 |
Version history: | 38 change(s) |
Referenced in: | #1020448 - dm_quickSearchManager #1020463 - dm_requireQuickSearchManager |