How to handle file stacks with an integer as name?

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

How to handle file stacks with an integer as name?

Post by Mag » Thu Nov 24, 2016 3:08 pm

I noticed that If i assign to a new stack a number, for example 2, then I have problems to handle it because LC thinks that I'm talking of the stack 2, not the stack with the short name "2".

Code: Select all

create invisible  stack "2"
If is it a limit of LC, is there a way to avoid this? I can't choice the name because is the user that choice it.

PS
This happens in my code and could be a problem I create with some logical error in some statement.
Last edited by Mag on Thu Nov 24, 2016 8:18 pm, edited 5 times in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: create invisible stack "2"

Post by dunbarx » Thu Nov 24, 2016 4:53 pm

Mag.

It is NEVER a good idea to use an integer to name anything, control, stack, whatever, because you will inevitably create a conflict between LC's native properties, as you discovered, and likely already knew.

Can't you direct the user to use something that is not an integer?

Or perhaps name your stack "XYZ 2", and then write a code snippet that asks something like (pseudo)

Code: Select all

ask "which stack?"
--  user enters "2"
go stack "XYZ" && it
In this way LC is happy, the user is happy, and happy Thanksgiving.

Craig

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: create invisible stack "2"

Post by Mag » Thu Nov 24, 2016 4:59 pm

Thank you Craig.

The name entered by the user is used for naming a file saved on disk, so I haven't the possibility to use a different name from the one assigned to the user. What's more the user can change the name of the stack in the Finder.

Having not control over the name of the stack file, is there a way to use the ID to refer to the stack to save it on disk and set/read its properties?
Last edited by Mag on Thu Nov 24, 2016 6:07 pm, edited 1 time in total.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Using stacks with an integer as name

Post by jmburnod » Thu Nov 24, 2016 6:27 pm

Hi Mag,
What's more the user can change the name of the stack in the Finder
And they can also move the file...
I wonder if you can use one substack for each user.
Jean-Marc
https://alternatic.ch

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Using stacks with an integer as name

Post by dunbarx » Thu Nov 24, 2016 6:43 pm

Jean-Marc's idea of using substacks has the advantage that they cannot be accessed apart from the mainStack, so the re-name thing might go away.

But the mainStack itself can be moved and renamed. There is no way for LC to know about this sort of shenanigans. Either get better users, or force them to reset the pathname if it all of a sudden does not exist in the expected location. This can be easily tested, and if it has been moved, it serves them right to have to find it again. If it has been renamed, you can charge for customer support.

Craig

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Using stacks with an integer as name

Post by Mag » Thu Nov 24, 2016 6:49 pm

Thank you for the info. Anyway I'm using stack files ad app documents (they only store properties and I open them invisible when user double click them on the Finder only for read and write properties), so users have to have them available on the disk as icon to open them, share, delete and so on...

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Using stacks with an integer as name

Post by jmburnod » Thu Nov 24, 2016 7:16 pm

I understand I did the inverse for an app multiusers.
The app open a list of users with edit tools (new, erase, rename, choose a picture etc..).
Each user have a folder in documents folder with .txt and .png files.
When the user choose his name the content of his folder is available for app.
What is the best way ? I don't know :roll:
https://alternatic.ch

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How to handle file stacks with an integer as name?

Post by jacque » Fri Nov 25, 2016 8:09 pm

The script can check the name the user enters and if it is a single integer, put up a second dialog telling them that the name must include at least one alphabetic character.

A second method would be for the script to add its own identifier. So if the user enters 2, the script would name the stack "file 2". If you want, you can also set the stack label to "2" so the user doesn't know about it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: How to handle file stacks with an integer as name?

Post by Mag » Fri Nov 25, 2016 8:20 pm

jacque wrote:The script can check the name the user enters and if it is a single integer, put up a second dialog telling them that the name must include at least one alphabetic character.

A second method would be for the script to add its own identifier. So if the user enters 2, the script would name the stack "file 2". If you want, you can also set the stack label to "2" so the user doesn't know about it.
Thank you Jacque, this solves the problem when the file is saved on disk, but remains a problem: I have not control over what the user does in Finder with its stack files... :cry:

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How to handle file stacks with an integer as name?

Post by jacque » Fri Nov 25, 2016 8:25 pm

You can't control the location of the file. The script should check the existence of the file before trying to open it and if it does not exist, put up an open file dialog asking the user to locate it.

If they see that enough times maybe they will leave it where you originally put it. :-)

Edit : My experience has been that if you store user files in Preferences or Application Support, users will rarely move them.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: How to handle file stacks with an integer as name?

Post by Mag » Fri Nov 25, 2016 8:35 pm

My problem is with documents that the user creates (which can be open it with a double click on the Finder)... :oops:

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: How to handle file stacks with an integer as name?

Post by FourthWorld » Fri Nov 25, 2016 9:20 pm

Mag wrote:My problem is with documents that the user creates (which can be open it with a double click on the Finder)... :oops:
The file name of a stack file need not be the same as the names of the mainstack and any substacks within it.

If you need to ensure unique names for stack objects within a stack file you might consider the UUID function.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: How to handle file stacks with an integer as name?

Post by Mag » Fri Nov 25, 2016 10:16 pm

FourthWorld wrote:
Mag wrote:My problem is with documents that the user creates (which can be open it with a double click on the Finder)... :oops:
The file name of a stack file need not be the same as the names of the mainstack and any substacks within it.

If you need to ensure unique names for stack objects within a stack file you might consider the UUID function.
Thank you. Actually the stack names ar unique (I check and don't open two stacks files with the same name). The problem appears when I use a number as stack name. Can I refer to a stack with its fulmpath on disk to read its propertyes?

Post Reply

Return to “Mac OS”