O$: Typeahead / automagic droplists
Kelly Burgess
kellyb at montana.com
Thu Jul 24 21:16:10 EDT 2014
Hi Caroline,
Not a droplist, but in TheRecipeManager we've got a quick search box and a menu for choosing which attribute to search on. This rests on the fact that we've got a task var list (tMasterRecList) that always contains all the open recipes, and an object var (ivRecMgr) containing a list for display purposes (ivRecList). Behind the search box kEntry field we read keys --
On evKey
If (pSystemKey<>0)&(pSystemKey<>30)
If pSystemKey=27 ;; Tab
; Quit event handler (Discard event) ;; stay in the search field
End If
Quit event handler (Pass to next handler)
End If
If #COMMAND ;; e.g. command-M modify comes through here sometimes...
Quit event handler (Pass to next handler) ;; without this bailout, unexpected searches took place
End If
Process event and continue ;; update $contents
Do ivRecMgr.$recipeSearch(iSearchKind,$cfield.$contents)
--------------------------------
$recipeSearch (pSearchKind,pSearchText) :
Calculate newlyEmptied as (pSearchText='')&(ivLastSearchText<>'')
Calculate lvSameSearch as (pSearchText=ivLastSearchText)&(pSearchKind=ivLastSearchKind)
Calculate ivLastSearchText as pSearchText
Calculate ivLastSearchKind as pSearchKind
If newlyEmptied
Do $cinst.$restoreAllRecipes() ;; empty search text restores full list
Quit method
Else If lvSameSearch
Quit method
End If
;
Calculate uprSearchText as upp(pSearchText)
; v1.0.1 - formerly copied tMasterRecList, searched that and removed unselected. Now search tMasterRecList and merge selected, much faster!
Do tMasterRecList.$search(kFalse) ;; nothing selected
Switch pSearchKind
Case 'Name'
Do tMasterRecList.$search(pos(uprSearchText,upp($ref.REC_TITLE))>0,kTrue,kFalse,kTrue,kTrue)
Case 'Source'
Do tMasterRecList.$search(pos(uprSearchText,upp($ref.REC_FROM))>0,kTrue,kFalse,kTrue,kTrue)
Case 'Category'
Do tMasterRecList.$search(pos(uprSearchText,upp($ref.REC_CATEGORY))>0,kTrue,kFalse,kTrue,kTrue)
< . . etc. . >
End Switch
Do ivRecList.$clear()
Do ivRecList.$merge(tMasterRecList,kFalse,kTrue) ;; by col#,not name, selected only
That's followed by a bit of logic to reselect the line that was current, if it's still in the list, or to pick a new selection, and redraw. Note the comment about how searching the main list and merging selected into the display list was a lot faster. This keeps up pretty well as you type, filtering the display list down to matching lines.
We've got other code that's more complicated for type-ahead in measure and ingredient fields, where the searched list isn't displayed, but the entry field shows what you've typed so far, and shows the rest of the first potential match as a highlighted suggestion ahead of the cursor -- e.g. type 't' and the measure field shows 'tablespoon' with all but the 't' selected, then type 'e' and it changes to 'teaspoon' with all but the 'te' selected. Let me know if you want to see some of that.
Hope it's useful.
Kelly
More information about the omnisdev-en
mailing list