Method to rename stack
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Method to rename stack
Hi
Is there a method to rename a stack and still preserve 'behaviour's?
Problem
If I rename a stack just by giving it a new name in the properties of the stack, all my behaviours no longer work as they reference the name of the stack. I cannot see how to do a global replace.
Reason
My stack has a sucky name! I did not realise it would be 'sticky'
Thanks
Is there a method to rename a stack and still preserve 'behaviour's?
Problem
If I rename a stack just by giving it a new name in the properties of the stack, all my behaviours no longer work as they reference the name of the stack. I cannot see how to do a global replace.
Reason
My stack has a sucky name! I did not realise it would be 'sticky'
Thanks
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Method to rename stack
Hi.
When you define a button script as behavior this is the long id of the button and its change if you change the name of your stack.
I've taken the habit to reset behavior links at open stack/card.
Best regards
Jean-Marc
Yes,Is there a method to rename a stack and still preserve 'behaviour's?
When you define a button script as behavior this is the long id of the button and its change if you change the name of your stack.
I've taken the habit to reset behavior links at open stack/card.
Best regards
Jean-Marc
https://alternatic.ch
Re: Method to rename stack
Hi Jean-Marc
Ok. You have my interest.
Do you script the updating of behaviours? If so, it means you will need to keep a list of all objects that have behaviours associated so the script can perform the re-association. Is that what you meant?
Ok. You have my interest.
Do you script the updating of behaviours? If so, it means you will need to keep a list of all objects that have behaviours associated so the script can perform the re-association. Is that what you meant?
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Method to rename stack
You have my interest as well.
Firstly, I only just found out that behaviors may now (since v.8?) reference a stack as well as a button. Good. I always thought a stack was far more appropriate than a button anyway.
The "long ID" as relates to behaviors neglects the full pathname, rather stopping at the stack name. The dictionary states that this is to allow a stack to be moved and not break the behavior reference. Well and good.
That sort of thing?
Craig Newman
Firstly, I only just found out that behaviors may now (since v.8?) reference a stack as well as a button. Good. I always thought a stack was far more appropriate than a button anyway.
The "long ID" as relates to behaviors neglects the full pathname, rather stopping at the stack name. The dictionary states that this is to allow a stack to be moved and not break the behavior reference. Well and good.
But doesn't this mean that one can manipulate a stack-referenced behavior:The value of the behavior property is a reference to a button or stack containing the script to use. The format stored in the object it's assigned to is similar to a long ID. The main difference is that where a long ID includes the full path to the stack file, the form stored in the behavior includes only the stack name, allowing the reference to continue to work after the stack file has been moved to another computer. If you set the behavior to a long ID, LiveCode converts it to a rugged form without the stack file path.
Code: Select all
set the behavior of button "yourButton" to the long id of stack the name of this stack
or
set the behavior of button "yourButton" to the long id of stack the mainStack of this stack
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 9867
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Method to rename stack
"There are only two hard things in Computer Science: cache invalidation and naming things."
- Martin Fowler
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 7266
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Method to rename stack
That happened to me once and I had to go through the whole stack and reset the behaviors. I complained and people agreed that relative references would be better, but then LC introduced stacks as behavior containers and that was the end of it.
If you're pretty sure you won't be changing the name again you can edit everything manually. For automated updating, you'll need to scan every control in the stack and if it has a behavior, replace the old stack name with the new one and set the behavior to the edited reference.
If you're pretty sure you won't be changing the name again you can edit everything manually. For automated updating, you'll need to scan every control in the stack and if it has a behavior, replace the old stack name with the new one and set the behavior to the edited reference.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Method to rename stack
Hi mvillion,
As Jacqueline explaned
When i use a behavior I reset behavior of controls which have a behavior
Behavior are scripts of btns named "behaviorName_BEH" of a card "cMyBEH"
I use this script at the first opening of one card:
I only tested this method with a single stack app
You will save a lot of time by applying the motto recalled by Richard
Best regards
Jean-Marc
Yes,Do you script the updating of behaviours?
As Jacqueline explaned
When i use a behavior I reset behavior of controls which have a behavior
Behavior are scripts of btns named "behaviorName_BEH" of a card "cMyBEH"
I use this script at the first opening of one card:
Code: Select all
on firstOpenCD
set the behavior of group "grPictosMes" to the long id of btn "bPictoMes_BEH" of cd "cMyBEH"
end firstOpenCD
You will save a lot of time by applying the motto recalled by Richard
Best regards
Jean-Marc
https://alternatic.ch
Re: Method to rename stack
Ok. This is interesting
Currently, I have a card with different buttons with my behaviours in them and I reference the behaviours via that mechanism.
My current references look like this
button id 6379414 of stack "Sucky Stack name"
You mention set the behaviour 'to the edited reference.' What do you mean by this?
I understand I could place a script on every card to recode each behaviour and I think I will do that going forwards as it is a good coding model.
I am not sure what this means.but then LC introduced stacks as behavior containers and that was the end of it.
Currently, I have a card with different buttons with my behaviours in them and I reference the behaviours via that mechanism.
Hmm. The name is sucky but not that sucky. 8-DIf you're pretty sure you won't be changing the name again you can edit everything manually.
Okay. Not sure what is meant by scan. Manually or is there an automated way to find them?For automated updating, you'll need to scan every control in the stack and if it has a behavior, replace the old stack name with the new one and set the behavior to the edited reference.
My current references look like this
button id 6379414 of stack "Sucky Stack name"
You mention set the behaviour 'to the edited reference.' What do you mean by this?
I understand I could place a script on every card to recode each behaviour and I think I will do that going forwards as it is a good coding model.
-
- VIP Livecode Opensource Backer
- Posts: 7266
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Method to rename stack
When behaviors were only stored in buttons, it would be possible to make the behavior reference relative to the stack by omitting the stack name. But later, whole stack scripts were introduced as containers for behaviors, and in that case you really do need the stack name. So relative references weren't persued.
Basically you use a repeat loop to look at every object on each card and see if it has a behavior assigned. If so, you edit the behavior to include the new stack name. You ony need to do that once after changing the name. Or if you only have a few objects with behaviors, you can just write a script that lists them and changes each one in the list.Okay. Not sure what is meant by scan. Manually or is there an automated way to find them?For automated updating, you'll need to scan every control in the stack and if it has a behavior, replace the old stack name with the new one and set the behavior to the edited reference.
Something like this:You mention set the behaviour 'to the edited reference.' What do you mean by this?
Code: Select all
get the behavior of btn "xyz"
replace "suckyName" with "goodName" in it
set the behavior of btn "xyz" to it
It's really only necessary once, unless the stack name is going to change a lot. Jean-Marc's method is insurance but I don't do it that way. Usually I just run a temporary handler to reassign the behavior buttons.I understand I could place a script on every card to recode each behaviour and I think I will do that going forwards as it is a good coding model.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Method to rename stack
I just want to say thanks to everyone who has contributed on this and all my other threads. I would be lost without you.
One script per card that checks for behaviours is a neat way to do it
[Surely it can't be that easy]!
One script per card that checks for behaviours is a neat way to do it
So now, one last question on this thread. How would you (by script) find all of the objects on a card (without having to define the list)? I can't think of a way. [Now I am sure someone has figured this out too and when I see it I will go doh! I was thinking, if there is a way to enumerate child objects then the script could be constructed to enumerate the cards in a stack then the objects in the cards and thus a single script to rename all behaviours!get the behavior of btn "xyz"
replace "suckyName" with "goodName" in it
set the behavior of btn "xyz" to it
[Surely it can't be that easy]!
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Method to rename stack
Hi.
"All the objects on a card" can be translated to "All the controls on a card"
Then you can (pseudo):
Craig Newman
"All the objects on a card" can be translated to "All the controls on a card"
Then you can (pseudo):
Code: Select all
repeat with y = 1 to the number of controls
doSomeThingToEachControlIfRequired
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Method to rename stack
Hi mvillion
Best regards
Jean-Marc
Yes, something like that:...if there is a way to enumerate child objects...
Code: Select all
on setAllBeh pOldName,pNewName
set the lockmessages to true
repeat with u = 1 to the num of cds
open cd u
put the num of controls into tNbC
repeat with i = 1 to tNbC
get the behavior of control i
if it <> empty then
replace pOldName with pNewName in it
set the behavior of control i to it
end if
end repeat
end repeat
end setAllBeh
Jean-Marc
https://alternatic.ch
Re: Method to rename stack
Sweet.
I did not know that LC had 'number of controls'. I should have known. 8-D
'Copy -> paste' into my code snippet bin.
Many thanks
I did not know that LC had 'number of controls'. I should have known. 8-D
'Copy -> paste' into my code snippet bin.
Many thanks