Change folder/file display

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

Post Reply
ChrisM
Posts: 24
Joined: Sat Mar 29, 2014 3:11 pm

Change folder/file display

Post by ChrisM » Mon Sep 14, 2015 6:47 pm

Hi,

Anyone know how to change the display of folders and files to give a sort of Windows 8/10 look and feel, Ideally I'm looking for something along the lines of the following:-

Lookup Folderlocation and put into field
If Type is "Folder" then display a custom button with the folder name in the centre
it type if "File" then display a custom button with the file name in the centre

Preferably with mouseover so I can change the colour/tint of the button when hovered over

Any help appreciated

Steve Denney
Posts: 101
Joined: Wed Dec 22, 2010 8:17 pm

Re: Change folder/file display

Post by Steve Denney » Tue Sep 15, 2015 8:19 am

Not quite sure what you’re hoping for, but no replies so I’ll give it a go…
Livecode uses your operating system’s dialog boxes for queries like answer file or answer folder. For example, if you make a button with the script:

Code: Select all

on mouseUp
   answer file "Browse to your file’s location"
end mouseUp
Then you should pop up the same dialog box you’d normally see when browsing.
The folder that is shown will be the defaultFolder, which you can change with the script:

Code: Select all

set the defaultFolder to whatever -- where whatever is a filepath like “C:/Windows/system32”
You can use specialFolderPath to open windows user libraries, like so:

Code: Select all

put specialfolderpath(0x0027) into whatever --0x0027 - The "My Pictures" folder 
(look up specialFolderPath in the dictionary for codes).
Then you’d set the defaultFolder and answer file as described above.
However, I’m guessing you want something more like the windows 8 desktop to appear when you click your custom browse button.
If so you have to create your own interface.
You could…
Create a group, give it a name like showFoldersGrp, give it H and V scrollbars.
You’d get the list of folders and files in the defaultFolder with:

Code: Select all

put the folders into folderList -- folderList is a local variable I just made up, could be a field or any container. 
If you got the detailed folders you’d have a lot more information like creation date and size which you can parse by item.
Same goes for files:

Code: Select all

put the files into fileList
Now you have lists of files and folders. You could write a procedure to loop through those lists to create a bunch of controls i.e. buttons, fields, images. You could use a folder or file image, line them up in rows and columns in your group (which would scroll if there were a lot of them). Give them layered overlapping fields with their names. Assign code to the fields and images so they’d do what you wanted when the user clicked them.
I find it easiest to use hidden template button/fields/images to do this. So you’re not creating controls, the code is more like:

Code: Select all

Copy img templateImage to  grp showFoldersGrp
Show img templateImage of grp showFoldersGrp
Set the name of img templateImage of grp showFoldersGrp to (whatever name you want)
Etc…
You’d store the list information in the object’s name or toolTip or create a custom property. I do this because sometimes ‘set the script’ hasn’t worked for me.
The object’s script can then access the correct file or folder path.
To get the mouseOver tint change you mention you could use two images and show-hide them on mouseEnter and mouseLeave (scripts would be in the templateImages).
You’d have to clean up each time you browsed (i.e. delete all controls in the group).
Sound like too much work when liveCode already uses your system’s default file browser? Does to me. It would however give you the effect I think you’re after.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”