Help with drill-down script

Emmett Gray film2 at handheldfilm.com
Mon Jun 21 10:17:41 EDT 2010


Sorry for the long post. I've now got the last of 
my currently-in-use HC stacks running in Rev, so 
I'm finally retiring HC/Sheepshaver. This last 
stack was huge, a labor of love for 20 years. 
It's an address book whose feature set has not 
been matched by a commercial application.

Anyway, there's one feature: the first card is an 
index of all the cards in the stack. In HC, all 
you need to do is start typing and as you add 
letters, the selected line changes to reflect 
what you've typed. When you get to what you want, 
you hit return and that takes you to the 
respective card.

Anyway, it's not working in Rev. What happens is, 
it selects the first line with the first letter 
you type, but stalls there. Then, if you hit 
return, it does nothing, just sits there. And if 
you wait and start over, it doesn't respond. to 
that either, the original selection remains. You 
have to clear that selection to get it to start 
over.

I don' have any idea what to do.

The relevant field properties in Rev are shared 
text, lock text, vertical scroll bar, list 
behavior.

Here's the HC script:

on keyDown theKey -- this is for selecting & 
scrolling the index fields & the notes field & 
the inform field
   global keyBuff, keyTime, indexLine, keywait, 
activeField --there are both white and yellow 
pages
   --White pages is "Index", yellow pages is "Yndex"
   if theKey is in "abcdefghijklmnopqrstuvwxyz" 
then --user typed something to respond to
     if the selectedField is empty then -- no 
cursor in a field, otherwise enter text in a field
       if the visible of fld  activeField is true 
then --make sure we're looking at the proper field
         if the visible of the message is false 
then -- so it's available when needed
           put activeField into theFld
           select line 0 of fld theFld
           put 0 into item 1 of indexLine
           put the ticks into theTime
           if theTime - keyTime < keyWait then put theKey after keyBuff
           --keyWait is how long to wait before 
discarding the buffer and starting over
           else put theKey into keyBuff
           put theTime into keyTime
           get findIndexLetter(keyBuff, theFld)
           if it = 0 then
             put "abcdefghijklmnopqrstuvwxyzz" 
into theAlph -- extra z because looking for next 
char
             put offset(theKey,theAlph) into numTries
             repeat with x =  numTries + 1 to number of chars of theAlph
               get findIndexLetter((char numTries - x of theAlph), theFld)
               if it > 0 then
                 exit repeat
               end if
             end repeat
             if it = 0 then
               repeat with x = -1 to numTries - 1
                 get findIndexLetter((char numTries - x of theAlph), theFld)
                 if it > 0 then
                   exit repeat
                 end if
               end repeat
             end if
           end if
           set scroll of fld theFld to it * (textHeight of fld theFld)
           if number of lines of fld theFld - it < 22 then
             select line it of fld theFld
             put it into item 1 of indexLine
             put theFld into item 2 of indexLine
           end if
           keyDown numToChar(31)
         else
           pass keyDown
         end if
       else
         pass keyDown
       end if
     else
       pass keyDown
     end if
   else -- not an alpha character
     get charToNum(theKey)
     if (space & it & space) is not in " 11 12 30 
31 " then -- pageup & pagedown, up & down arrows
       if it = 1 then go card 1 --home key
       else pass keyDown -- not trapped key so get out
     else --trapped key, proceed
       if the number of this card = 1 then
         if the selectedField is not empty then
           pass keyDown --conditions not met, get out
         else
           if the visible of fld "inform" is false 
then --another field that might be showing instead
             if it = 11 or it = 30 then
               if the optionKey is not down and it = 30 then
                 grabLine -1, activeField
               else
                 selectNot
                 set scroll of fld activeField to 
scroll of fld activeField - 252
               end if
             else if it = 12 or it = 31 then
               if the optionKey is not down and it = 31 then
                 grabLine 1, activeField
               else
                 selectNot
                 set scroll of fld activeField to 
scroll of fld activeField + 252
               end if
             end if
           else --inform field is showing, not the 
index so do something else, not relevant to this 
post
             if it = 11 then drag from 460,52 to 
460,51-- vals for "notes", change to scroll method
             else
               drag from 460,213 to 460,214
             end if
           end if
         end if
       else -- not card 1
         -- the index field is normally hidden 
except on card 1 but   can be show on any card
         if the selectedField is not empty then -- 
13 is lookup;1 (last name),2,3,4,5 (sift),8 
(category)
           if (the visible of fld " Index " is 
false and the visible of fld " Yndex " is false) 
then
              -- scroll notes, see below too
             if it = 11 then set scroll of fld 
"Notes" to scroll of fld "Notes" - 182
             else if it = 12 then  set scroll of 
fld "Notes" to scroll of fld "Notes" + 182
             else pass keyDown -- it's not page up or down
           end if
         else
           if (the visible of fld " Index " is 
true or the visible of fld " Yndex " is true) then
             if the visible of fld " Index " is 
true then put " Index " into theFld
             else put " Yndex " into theFld
             if it = 11 or it = 30 then
               if the optionKey is not down and it = 30 then
                 grabLine -1, theFld
               else
                 selectNot
                 set scroll of fld theFld to scroll of fld theFld - 252
               end if
             else if it = 12 or it = 31 then
               if the optionKey is not down and it = 31 then
                 grabLine 1, theFld
               else
                 selectNot
                 set scroll of fld theFld to scroll of fld theFld + 252
               end if
             else -- get out, index showing and no valid key
               pass keyDown
             end if
           else -- Notes field showing; had to do 
this twice to enable scrolling with cursor in a 
field
             if it = 11 then
               set scroll of fld "Notes" to scroll of fld "Notes" - 182
             else if it = 12 then  set scroll of 
fld "Notes" to scroll of fld "Notes" + 182
             else pass keyDown
           end if
         end if
       end if
     end if
   end if
end keyDown

function findIndexLetter theKey, theFld -- 
returns line of theKey or of first found 
letter(s) of theKey
   get number of lines in char 1 to (offset(return 
& theKey, fld theFld)) of fld theFld
   if (it = 0) then if (number of chars of theKey > 1) then
     repeat with x =  (number of chars of theKey - 1) down to 1
       get number of lines in char 1 to 
(offset(return & (char 1 to x of theKey), fld 
theFld)) of fld theFld
       if it > 0 then exit repeat
     end repeat
   end if
   return it
end findIndexLetter


on grabLine upOrDown, newFld
   global indexLine
   put item 1 of indexLine into theLine
   put item 2 of indexLine into theFld
   if newFld ‚ theFld then
     select line 0 of fld theFld -- deselect other fld
     put 0 into theLine
   end if
   put newFld into theFld
   put scroll of fld theFld into theScroll
   if theScroll mod 12 ‚ 0 then -- take care of last page with bogus scroll
     repeat until theScroll mod 12 = 0
       add -1 to theScroll
     end repeat
     set the scroll of fld theFld to theScroll
   end if
   if theLine < 1 then
     put scroll of fld theFld into theScroll
     put theScroll/12 + 1 into theLine
   else
     if not (theLine = number of lines of fld theFld  and upOrDown = 1) then
       add upOrDown to theLine
     end if
   end if
   if theLine = 1 then add 1 to theLine
   select line (theLine) of fld theFld
   if  (scroll of fld theFld)/12 „ theLine then
     set scroll of fld theFld to round(theLine * 12) - 264 --scroll up one page
   end if
   put theLine into item 1 of indexLine
   put theFld into item 2 of indexLine
end grabLine

on returnKey
   global indexLine
   if the optionKey is not down and the visible of fld "inform" is false then
     get item 1 of indexLine
     selectNot
     if it >1 then
       if item 2 of indexLine  is " Index "
       then
         go card it
       else
         goToHeading (line it of fld " Yndex ") 
--Heading is a yellow page category
       end if
     else
       if the visible of cd btn 1 is true then
         click at the loc of btn "proceed"
       else pass returnKey
     end if
   else pass returnKey
end returnKey

on selectNot
   global indexLine
   select line 0 of fld (item 2 of indexLine)
   put 0 into item 1 of indexLine
end selectNo

Thanks for reading this far. And since you did, I 
can't resist mentioning some of the features of 
this stack:
1) Smart synchronization: if the copy at the 
office gets a new email address and the same 
person at home gets a new cell phone number, both 
are kept and the card is flagged and put in a 
list. You can deal with it later, like when you 
next go to that card which shows the dates of 
both new entries, or go through the list if you 
want
2) Parsing of clipboard data, from v-cards, email 
signatures and the like, when making new entries.
3) A "Business" checkbox which then alphabetizes 
business names phone-book style, ignoring and 
initial "The" etc.
4) Auto-capitalization; you don't have to hit the 
shift key when entering names. It's smart, knows 
about "de" and "von" etc.
5) One-click or keystroke phone dialing, via a 
modem, Skype out, or Skype-to-Skype (if there's a 
Skype name in the Notes field).
6) Envelope printing of 4 different  custom styles (size, return address)
7) Sifting to create subsets (Christmas card 
lists, European contacts, email addresses, etc.) 
for export in CSV or tab-delimited format
8) Smart printing of Filofax-style pages (no 
entry broken over a page; print one side, turn 
the stack over and print again, all comes out in 
proper order)
9) Ability to change the spelling or 
capitalization of a name, then automatically 
moved to where it belongs as needed, and have the 
corresponding Yellow or White pages version 
auto-updated.
10) Hidden "Filed as" field to override the 
default alphabetization, useful for names like 
"van Beethoven" - filed under v or b?
11) URL launching (grabs the first or selected 
email or web address) and file/app launching such 
as Word templates,  with the appropriate info 
(name and address) in the clipboard
12) Unlimited delete and restore of cards (until you quit).
13) Name conflict resolution: If you have a John 
Smith entry, and make a new John Smith card, you 
get an alert that he's there already. You can 
delete the new one, the old one, or keep both
14) A database of national and international area 
codes so if you have an unknown phone number you 
can see where it's probably located
15) And of course it relies on HC/Rev's brilliant 
"Find" so you can for example type a first name 
and a state abbreviation or city name to find 
someone whose last name you don't remember, but 
you know where they live
16) Customizable abbreviations expanded on 
address data entry: ny expands to New York, NY 
and de expands to Germany, but only if followed 
by a space (or nothing) and must be the first 
characters of the last line in the address field.
17) Phone numbers corrected to be in a standard 
form (dots & parentheses replaced by dashes). US 
numbers get 1- in front, other countries get 
their country code - you can use the 
abbreviations used in the Address field such as 
de for Germany to enter the proper country code 
so you don't have to remember it.
There's more but I'll stop now...



More information about the use-livecode mailing list