Setting file types in the savepanel
-
Hi again everyone,
I've got a simple one this time
I want to set the "save as type" value in the savepanel. To, let's say, *.csv. It's true that I can make the file be whatever I want it to be, but I'm thinking usability here.
So - does anyone have a clue?
Thanks,- Tali
p.s. Thanks to you guys I'm drawing near to wrapping up this project I'm working on.
-
You can't specify a file-type but you can give the default file-name + .file-type-suffic
filepath=UI.savepanel("DialogTitle","DirectoryPath","DefaultFileName.csv")
that way at least the user starts off with a proper file name that they can mangle later...
You can trap erroneous filepath names later. Let's say that the user inputs "MyFile" without the .csv suffix: use the variable 'filepath' to test it.filepath=filepath.tr("\\","/")#in case any PC ruby weirdness... filebase=File.basename(filepath,".csv")#name with suffix stripped filename=File.basename(filepath)#name with suffx attached if filebase != filename #it's NOT a .csv file UI.messagebox("Filename must end with '.csv' - it will be added...")# option error report filename=filebase+".csv" filepath=File.dirname(filepath)+filename end#if
Now you can use 'filepath' to save the file etc...
Alternatively you could pop up the error message and then immediately re-open the 'savepanel' - perhaps using the 'corrected name' as the new file's default-name - in case the user is likely to totally mistype...
. -
Thanks TIG,
I know I can set the default file name.
But I find it puzzling that the list of file types exists but it's empty and can't be filled. This isn't the case when you're trying to save a model - so it must be possible somehow, and if not - I guess it's the most trivial wishlist item...
I'll wait to see if someone knows how to do this. -
Just getting this thread out of retirement...
Is there any new solution to this?
I would love to see this one fixed. (Meaning a possible mask application or anything for the filetype selector in the savepanel.)Regards
-
Jim, Thanks. I knew about the .ext bug making _.ext, but didn't know about using it with
""|nil
. So, there is no way to force the savepanel to open with .ext in a predetermined folder? -
Why
(""|nil)
instead if justnil
? -
Apologies - that was just meant as a notation for either "" or nil.
-
Ah, gotcha!
-
@honoluludesktop said:
So, there is no way to force the savepanel to open with *.ext in a predetermined folder?
Not that I know.
-
Still can't add filetypes to the "Save as type" dropdown, as far as I know.
But you can provide a extension mask as follows:
UI.savepanel "Title", nil, "*.rb"
(can use empty String or nil for middle param)Note, if you try to provide a directory name (the 2nd parameter,) the file mask gets messed up - it's a bug (IMO.) The file mask asterisk will get translated into an underscore: "
_.rb
"And this might only work on Windows, I don't know.
Also, to work around the bug it may be possible to use
Dir.chdir()
to set the default directory before calling savepanel. (Update: Looks like this doesn't work. Windows must store the MRU location somewhere.) -
It's been reported before - but it doesn't hurt reminding them...
http://forums.sketchucation.com/viewtopic.php?f=11&t=29023 -
Thanks for the effort, guys.
Sadly this doesn't really help.Seems to me as more inconvenient to have to move to the desired folder every time.
What bugs me the most is, that one can't click save and then immediately start typing the filename, in the way that the whole line (including ".xxx")is highlighted.
Since there might be some not really intelligent people handling this, I would love a way for them to immediately start typing, but still have the right extension visible as well.
Do I have to file a bug-report to get this in or is there nothing one can do to try and get functionality of the filetype selector!? -
If the users are so stupid why even give them the chance of saving the file in a weird folder or giving it a stupid name ?
Why not always locate and name the file 'with the model'.
First use a trap(puts "Save SKP!";return nil if model.path==""
in case your SKP is not saved.
You get the folder fromfolder=File.dirname(model.path)
You could then 'set' the file-name based on the model, sofile=model.title+".xxx"
or whatever file type suffix you want.
You could use the Scene name in the name too...
scene=model.pages.selected_page.name.gsub(/[^A-Za-z0-9_-]/,"_")
[Thegsub
is to avoid making a file name with 'illegal' characters like /:"etc]
Thenfile=model.title+"_"+scene+".xxx"
OR you could use a file name based on the 'date/time' which will always be different...
time=sprintf("%.1d\n",(Time.now.to_f*100))
Thenfile=model.title+"_"+time+".xxx"
Set thepath=File.join(folder,file).tr("\\","/")
[Thetr
is only to tidy up if you are to display it later - e.g. in a confirming dialog - as you might get a mix of / and \ on a PC]
Now use thepath
to export, or save as a data file etc...
Alternatively you could let the user set the file name with a simple inputbox
results=inputbox(["File Name: "],[model.title],"Type in XXX File Name [WITHOUT a '.xxx' suffix]") return nil if not results file=(File.basename(results[0]).gsub(/[^A-Za-z0-9_-]/,"_"))+".xxx"
which traps 'stupid' input or file suffix... -
Thanks for those tips! I really appreciate this.
I see your point. Since there are pro and dumb users, the features I would love to include are:
- selecting your own name for the file
- selecting your wished folder to store into
- keep "uneducated" users from messing up the filetype
- keep a clean interface for ease of use and esthetic reasons
And somehow I'm also on the point that talig mentioned
@talig said:
...I find it puzzling that the list of file types exists but it's empty and can't be filled.
Mainly because I think this is just a basic functionality and I don't see the point in this option not being provided.
-
P.S.: I did send in a report, so maybe there might be a fix in the future...
-
@worcoder said:
- keep "uneducated" users from messing up the filetype
Can't you just correct the filename you are returned? If there is not file extension, automatically append it before saving? Since Windows since XP hide the file extension on known files many users are completely unaware of file extensions anyway.
-
@thomthom said:
many users are completely unaware of file extensions anyway.
Sorry for the late reply, was on holiday...
Sure I can correct the file extension, but I'd still love to have the nice looking "clean" solution with a working file type selector.We'll see what the future brings.
-
@thomthom said:
Since Windows since XP hide the file extension on known files many users are completely unaware of file extensions anyway.
Not a given.
On all our machines (or any machine I work on,) I turn file extension display back ON.
-
-
@thomthom said:
Yes - but by default XP hides it.
Which is one of the dumbest things Microsoft does.
Advertisement