tab into table and use up/down arrow keys to navigate

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
billworld
Posts: 188
Joined: Sat Oct 25, 2008 12:32 am

tab into table and use up/down arrow keys to navigate

Post by billworld » Fri Nov 07, 2008 1:12 pm

I'm not figuring out how to tab into a field and allow one to immediately use the up/down arrows to navigate, preferably starting from the location of the last hilited line.

I've been searching and experimenting with various options. For example, the following doesn't work.

Code: Select all

on focusin
    click at the hilitedLine
end focusin
We know what the hilitedLine is. How do we recognize that location as the starting point for keyboard navigation once entering the field?

I'm sure this is brain-dead easy.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Fri Nov 07, 2008 1:25 pm

Hi Bill,

It seems that you have to click in the field to make the arrowKeys work, which is a silly situation of course.

Try this in your list field:

Code: Select all

on arrowKey theKey
   put the hilitedLine of me into myLine
   if theKey is up then
      put max(1,myLine-1) into myLine
   else if theKey is down then
      put min(number of lines of me,myLine+1) into myLine
   else
      pass arrowKey
   end if
   set the hilitedLine of me to myLine
end arrowKey
Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

billworld
Posts: 188
Joined: Sat Oct 25, 2008 12:32 am

Post by billworld » Fri Nov 07, 2008 1:30 pm

That works. Thanks!
Mark wrote:Hi Bill,

It seems that you have to click in the field to make the arrowKeys work, which is a silly situation of course.

Try this in your list field:

Code: Select all

on arrowKey theKey
   put the hilitedLine of me into myLine
   if theKey is up then
      put max(1,myLine-1) into myLine
   else if theKey is down then
      put min(number of lines of me,myLine+1) into myLine
   else
      pass arrowKey
   end if
   set the hilitedLine of me to myLine
end arrowKey
Best,

Mark

billworld
Posts: 188
Joined: Sat Oct 25, 2008 12:32 am

Post by billworld » Fri Nov 07, 2008 2:08 pm

Now I'm stuck on the issue of being able to press the return key (after using the keyboard to navigate into the table) to grab data from the current line. I've set a local var on myLine to pick up the up/down key line setting, and I'm getting that data into the returnInField handler. However, I'm not seeing how to get values out of that line. The "set the selectedLine to myLine" code is incorrect, but, conceptually that's what needs to occur. How do I transfer the concept of what's set in myLine to becoming the current selectedLine from which I can then grab values?

Code: Select all

on returnInField
   set the itemDelimiter to tab
   set the selectedLine to myLine
   answer item 1 of the value of selectedLine
end returnInField
Thanks

Bill
billworld wrote:That works. Thanks!
Mark wrote:Hi Bill,

It seems that you have to click in the field to make the arrowKeys work, which is a silly situation of course.

Try this in your list field:

Code: Select all

on arrowKey theKey
   put the hilitedLine of me into myLine
   if theKey is up then
      put max(1,myLine-1) into myLine
   else if theKey is down then
      put min(number of lines of me,myLine+1) into myLine
   else
      pass arrowKey
   end if
   set the hilitedLine of me to myLine
end arrowKey
Best,

Mark

billworld
Posts: 188
Joined: Sat Oct 25, 2008 12:32 am

Post by billworld » Fri Nov 07, 2008 2:14 pm

Actually, to further clarify, there needs to be a way for myLine to be recognized as the currently selectedLine. For example, I could click on a line and then hit the return key or navig. up/down with arrow keys and then hit the return key and what gets returned would be the same. This is where I'm stumbling, transferring the concept of what is visually selected via either the mouse or keyboard to the concept of what is actually known to be selected. Hopefully that's clear.
billworld wrote:Now I'm stuck on the issue of being able to press the return key (after using the keyboard to navigate into the table) to grab data from the current line. I've set a local var on myLine to pick up the up/down key line setting, and I'm getting that data into the returnInField handler. However, I'm not seeing how to get values out of that line. The "set the selectedLine to myLine" code is incorrect, but, conceptually that's what needs to occur. How do I transfer the concept of what's set in myLine to becoming the current selectedLine from which I can then grab values?

Code: Select all

on returnInField
   set the itemDelimiter to tab
   set the selectedLine to myLine
   answer item 1 of the value of selectedLine
end returnInField
Thanks

Bill
billworld wrote:That works. Thanks!
Mark wrote:Hi Bill,

It seems that you have to click in the field to make the arrowKeys work, which is a silly situation of course.

Try this in your list field:

Code: Select all

on arrowKey theKey
   put the hilitedLine of me into myLine
   if theKey is up then
      put max(1,myLine-1) into myLine
   else if theKey is down then
      put min(number of lines of me,myLine+1) into myLine
   else
      pass arrowKey
   end if
   set the hilitedLine of me to myLine
end arrowKey
Best,

Mark

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Fri Nov 07, 2008 3:25 pm

Hi Bill,

You need to have a look in the documentation to see the distinction between the "selectedLine" and the "hilitedLine"

selectedLine is a function and returns a chunk expression containing information about the currently selected line(s)
Rev dictionary wrote:The selectedLine function returns a chunk expression of the form
line lineNumber of field fieldNumber
if the text selection is on one line, or
line startLine to endLine of field fieldNumber
if the text selection crosses multiple lines.
hilitedLine is a property that can be interrogated, or set
Rev dictionary wrote:The hilitedLine of a field is a list of one or more integers, separated by commas.
So your code

Code: Select all

on returnInField 
   set the itemDelimiter to tab 
   set the selectedLine to myLine 
   answer item 1 of the value of selectedLine 
end returnInField 
should probably be along the lines of

Code: Select all

on returnInField 
   set the itemDelimiter to tab 
   set the hilitedLine of me to myLine 
   answer item 1 of line the hilitedLine of me
-- or answer item 1 of (the selectedLine)
-- or answer item 1 of line myLine of field "targetField"
-- etc
end returnInField 

billworld
Posts: 188
Joined: Sat Oct 25, 2008 12:32 am

Post by billworld » Fri Nov 07, 2008 3:42 pm

Yeah, I was going down the wrong path. As I had the right row with hilitedLine, all I then needed to do is:

Code: Select all

answer item 1 of line myLine of me
rather than trying to figure out what the selectedLine was/is and try to pull a value out of that.

Anyway, got it.

Thanks, and sorry for the trouble!
SparkOut wrote:Hi Bill,

You need to have a look in the documentation to see the distinction between the "selectedLine" and the "hilitedLine"
Rev dictionary wrote:The selectedLine function returns a chunk expression of the form
line lineNumber of field fieldNumber
if the text selection is on one line, or
line startLine to endLine of field fieldNumber
if the text selection crosses multiple lines.
Rev dictionary wrote:The hilitedLine of a field is a list of one or more integers, separated by commas.

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Fri Nov 07, 2008 3:44 pm

OK!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Fri Nov 07, 2008 7:23 pm

Bill,
to activate the arrowkeys you can put

Code: Select all

 -- activates the arrowkeys
    if (the hilitedline of me) <> "" then -- in case there is no selection
        select line (item 1 of the hilitedline of me) of me -- in case there is multiple selections
    else  select line 1 of me 
into the focusIn handler and you dont have to trap for the arrowkeys.
regards
bernd

billworld
Posts: 188
Joined: Sat Oct 25, 2008 12:32 am

Post by billworld » Fri Nov 07, 2008 7:55 pm

That approach is closer to the direction I was initially thinking and it does work at first, HOWEVER, it doesn't handle situations where you open a dialog based on the current row and then after returning to the row you need to arrow up/down with the keyboard. That doesn't work. So, unless there's a way to account for that scenario with this more streamlined approach, I'm going with trapping for the arrowkeys.
bn wrote:Bill,
to activate the arrowkeys you can put

Code: Select all

 -- activates the arrowkeys
    if (the hilitedline of me) <> "" then -- in case there is no selection
        select line (item 1 of the hilitedline of me) of me -- in case there is multiple selections
    else  select line 1 of me 
into the focusIn handler and you dont have to trap for the arrowkeys.
regards
bernd

billworld
Posts: 188
Joined: Sat Oct 25, 2008 12:32 am

Post by billworld » Fri Nov 07, 2008 9:00 pm

Actually, for this portion of the code (for those who might be interested) I'm finding I need to account in this handler for situations where multiple lines are selected. (A different handler requires the ability to handle multiple lines, so, I need to trap for both scenarios.)

So, I need to do the following for the handler which fails if more than a single row is selected:

Code: Select all

on returnInField 
   set the itemDelimiter to tab
   put the hilitedLine of me into myLine
   if myLine contains comma
   then answer "Please select just one record."
   else answer item 1 of line myLine of me
end returnInField


billworld wrote:Yeah, I was going down the wrong path. As I had the right row with hilitedLine, all I then needed to do is:

Code: Select all

answer item 1 of line myLine of me
rather than trying to figure out what the selectedLine was/is and try to pull a value out of that.

Anyway, got it.

Thanks, and sorry for the trouble!
SparkOut wrote:Hi Bill,

You need to have a look in the documentation to see the distinction between the "selectedLine" and the "hilitedLine"
Rev dictionary wrote:The selectedLine function returns a chunk expression of the form
line lineNumber of field fieldNumber
if the text selection is on one line, or
line startLine to endLine of field fieldNumber
if the text selection crosses multiple lines.
Rev dictionary wrote:The hilitedLine of a field is a list of one or more integers, separated by commas.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Fri Nov 07, 2008 10:07 pm

Bill,
I don't quite get what you want.
This code passes the selected line/lines to the answer dialog. It is this you're looking for?

Code: Select all

on returnInField
    put the hilitedline of me into tHilited
    put the number of items of tHilited into tCountLines
    if tCountLines < 2 and tCountLines >0 then -- -> 1 line selected
        put line (item 1 of the hilitedline of me) of me into tAnswer
    else -- -> more than 1 line selected
        repeat for each item aSelectedLineNumber in tHilited
            put line aSelectedLineNumber of me & return after tAnswer
        end repeat
        delete char -1 of tAnswer -- return
    end if
    answer tAnswer
end returnInField
this doesnt take care of case no line selected
regards
bernd

billworld
Posts: 188
Joined: Sat Oct 25, 2008 12:32 am

Post by billworld » Fri Nov 07, 2008 11:29 pm

Thanks, but, I got that part of the code working fine now (as I posted above). The desired effect was NOT to pass all selected lines to an answer handler, but, to require the user to select a single line for that particular handler (e.g. to navigate to a detailed record which for now is just going to a dialog). That was auxiliary functionality to the initial post for this thread.

There are other sections of the code I'm still working on (not this section). Namely, I'm trying to merge the two arrowkey approaches Mark recently posted (one in this thread and the other in a different thread). In short, those are:

1. get in the field and immediately navigate using the keyboard arrows (but still need to account for continuous keyboard navigation even after a dialog is called up) <--- This solved the initial question posed in this thread

2. shift-select multiple lines using just the keyboard). <--- Mark provided a routine for this in a diff. thread

I don't have it worked out yet. The two arrowkey approaches are not living harmoniously with one another. Will probably have to take a break from it as I'm head-banging right now.
bn wrote:Bill,
I don't quite get what you want.
This code passes the selected line/lines to the answer dialog. It is this you're looking for?

Code: Select all

on returnInField
    put the hilitedline of me into tHilited
    put the number of items of tHilited into tCountLines
    if tCountLines < 2 and tCountLines >0 then -- -> 1 line selected
        put line (item 1 of the hilitedline of me) of me into tAnswer
    else -- -> more than 1 line selected
        repeat for each item aSelectedLineNumber in tHilited
            put line aSelectedLineNumber of me & return after tAnswer
        end repeat
        delete char -1 of tAnswer -- return
    end if
    answer tAnswer
end returnInField
this doesnt take care of case no line selected
regards
bernd

Post Reply