Scrolling List loses selection when switching card

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

tluyben
Posts: 9
Joined: Fri Mar 23, 2018 12:58 am

Scrolling List loses selection when switching card

Post by tluyben » Sat Mar 24, 2018 9:47 am

When I put a List on Card 1 and selection of an item in that list + button click goes to Card 2, clicking back from Card 2 to Card 1 then shows the selected item on the List is now no longer selected. How can I make it hold selection when switching cards?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Scrolling List loses selection when switching card

Post by richmond62 » Sat Mar 24, 2018 11:21 am

selection.png
The listField contains this script:

on mouseUp
put the selectedLine of me into fld "SELECTION"
end mouseUp

The script to make sure the line is reselected when you return to this card is in the cardScript:

Code: Select all

on openCard
   put fld "SELECTION" into XXX
   select XXX
end openCard
Hold The Selection.livecode.zip
Here's the stack.
(1.43 KiB) Downloaded 179 times

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Scrolling List loses selection when switching card

Post by FourthWorld » Sat Mar 24, 2018 4:59 pm

Set the field's sharedText to true, place it in a group, set the group's sharedBehavior and backgroundBehavior to true.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Scrolling List loses selection when switching card

Post by richmond62 » Sat Mar 24, 2018 5:39 pm

Set the field's sharedText to true, place it in a group, set the group's sharedBehavior and backgroundBehavior to true.
While I am quite sure that is a far more elegant solution than my one,
could you possibly rephrase it in a somewhat less opaque fashion so
us "bottom feeders" could understand it. :D

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Scrolling List loses selection when switching card

Post by FourthWorld » Sat Mar 24, 2018 8:23 pm

These are properties available in the Inspector. Throughout LiveCode, as with many dev tools, objects have properties which govern common behavior. That set of property settings addresses the OP's need. For details on each they're described betterin the Dictionary than I could replicate here.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Scrolling List loses selection when switching card

Post by jacque » Sat Mar 24, 2018 8:44 pm

FourthWorld wrote:
Sat Mar 24, 2018 4:59 pm
Set the field's sharedText to true, place it in a group, set the group's sharedBehavior and backgroundBehavior to true.
I did all that but it doesn't work here I'm afraid, though I have vague memories that it used to. I had to do this:

In field script:

Code: Select all

on mouseUp
  set the cLine of me to the hilitedline of me
  go next
end mouseUp
In group script:

Code: Select all

on preOpenControl
  set the hilitedline of fld 1 of me to the cLine of fld 1
end preOpenControl
The preOpenControl handler will only work if the card you're coming from doesn't have that group placed.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Scrolling List loses selection when switching card

Post by richmond62 » Sat Mar 24, 2018 8:51 pm

Does this mean that hilitedLine is a synonym for selectedLine ?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Scrolling List loses selection when switching card

Post by FourthWorld » Sat Mar 24, 2018 8:53 pm

jacque wrote:
Sat Mar 24, 2018 8:44 pm
FourthWorld wrote:
Sat Mar 24, 2018 4:59 pm
Set the field's sharedText to true, place it in a group, set the group's sharedBehavior and backgroundBehavior to true.
I did all that but it doesn't work here I'm afraid, though I have vague memories that it used to. I had to do this:

In field script:

Code: Select all

on mouseUp
  set the cLine of me to the hilitedline of me
  go next
end mouseUp
In group script:

Code: Select all

on preOpenControl
  set the hilitedline of fld 1 of me to the cLine of fld 1
end preOpenControl
The preOpenControl handler will only work if the card you're coming from doesn't have that group placed.
I used to do that, and double-checked before posting to make sure a property-only approach would work. It does here in v9RC1, at least under Ubuntu 14.04. Just to make sure I just ran the recipe again - continues to work.

If the working behavior is limited to a single platform, that would seem a bug. And given how common this need is, it would seem a bug worth addressing.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Scrolling List loses selection when switching card

Post by FourthWorld » Sat Mar 24, 2018 8:54 pm

richmond62 wrote:
Sat Mar 24, 2018 8:51 pm
Does this mean that hilitedLine is a synonym for selectedLine ?
No. They can sometimes be used in similar tasks, but return very different values. When in doubt the Dictionary contains useful details.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Scrolling List loses selection when switching card

Post by jacque » Sat Mar 24, 2018 11:15 pm

Someone else should check the property method. I tested it as written and it didn't work in 9.rc1 on Mac. I may have missed something though.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Scrolling List loses selection when switching card

Post by FourthWorld » Sat Mar 24, 2018 11:30 pm

I just tested on Mac and got the same good result. What are we doing differently? The complete steps I take are:
1. Create a new stack
2. Create a scrolling list field put
3. Use the Inspector to put some text in it.
4. In the Inspector, set the field's sharedText
5. Group it
6. In the Inspector, set the group's backgroundBehavior and the sharedBehavior
7. Choose browse tool
8. Click a line other than the first one to hilite it
9. Choose "Go Next" from the View menu

RESULT: the line I selected remains selected as I switch cards
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Scrolling List loses selection when switching card

Post by jacque » Sat Mar 24, 2018 11:43 pm

I turned off the group's sharedBehavior and it started working.

Odd, that.

Edit: I just noticed I'm in 8.1.9. I have several versions of LC running and got mixed up.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10324
Joined: Wed May 06, 2009 2:28 pm

Re: Scrolling List loses selection when switching card

Post by dunbarx » Sun Mar 25, 2018 12:53 am

I have only just skimmed this thread, but isn't the easiest way to simply set a custom property of the list field to its hilitedLine , and on openCard, hilite that line?

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Scrolling List loses selection when switching card

Post by FourthWorld » Sun Mar 25, 2018 1:52 am

dunbarx wrote:
Sun Mar 25, 2018 12:53 am
I have only just skimmed this thread, but isn't the easiest way to simply set a custom property of the list field to its hilitedLine , and on openCard, hilite that line?
There are many ways to solve many things. We can write custom scripts to mirror most built-in property-driven behaviors if we want to. Personally, I prefer to let the engine do the work where I can, leaving script space free and open for things property settings can't do.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Scrolling List loses selection when switching card

Post by richmond62 » Sun Mar 25, 2018 1:29 pm

There are many ways to solve many things.
Indeed. 8)

set the script of the listField to this:

Code: Select all

on mouseUp
   set the LYNE of me to the selectedLine of me
end mouseUp
where LYNE is a custom property of the listField

then in the cardScript:

Code: Select all

on openCard
   put the LYNE of fld "myList" into LLINE
   select LLINE
end openCard
I am sure someone a bit craftier than me can reduce the last script to something shorter. :D

Post Reply