Discussion:
UIPUTFILE functionality
(too old to reply)
JWagberg
2007-05-02 23:20:30 UTC
Permalink
I suspect I already know the very sad answer to to this question, but
I must ask anyhow.

I want to let the user pick a file for saving his/her data, so I use
UIPUTFILE to get a filename. If the file doesn't exist, UIPUTFILE
returns the new filename as I want to. But, if the file already
exists, a second dialog pops up, pointing out the fact and asks if the
user want to replace it.

However, I want to let the user _append_ to an existing file, making
the dialog's question very confusing. Can this second dialog somehow
be disabled or tweaked, so that I can do the check myself?

I tried to use UIGETFILE instead, but that dialog checks that the file
indeed exist beforehand and puts up a dialog if it doesn't.

Does anyone have a solution to this or am I forced to build my own
dialog?

jewa & wagberg . net (replace the obvious)

PS:Don't use my registered email. It's flooded with spam and not
active.
Dan Hensley
2007-05-03 13:42:48 UTC
Permalink
Sadly, you're out of luck. I first asked for this feature in 1999, and
recently asked again. The response was "it will be available in a future
release". No timetable. So the best thing to do is contact Mathworks
and add your name to the list of people who want this feature.

Dan
I suspect I already know the very sad answer to to this question, but I
must ask anyhow.
I want to let the user pick a file for saving his/her data, so I use
UIPUTFILE to get a filename. If the file doesn't exist, UIPUTFILE
returns the new filename as I want to. But, if the file already exists,
a second dialog pops up, pointing out the fact and asks if the user want
to replace it.
However, I want to let the user _append_ to an existing file, making the
dialog's question very confusing. Can this second dialog somehow be
disabled or tweaked, so that I can do the check myself?
I tried to use UIGETFILE instead, but that dialog checks that the file
indeed exist beforehand and puts up a dialog if it doesn't.
Does anyone have a solution to this or am I forced to build my own
dialog?
jewa & wagberg . net (replace the obvious)
PS:Don't use my registered email. It's flooded with spam and not active.
JWagberg
2007-05-04 07:27:50 UTC
Permalink
Post by Dan Hensley
Sadly, you're out of luck. I first asked for this feature in 1999, and
recently asked again. The response was "it will be available in a future
release". No timetable. So the best thing to do is contact Mathworks
and add your name to the list of people who want this feature.
Dan
I suspect I already know the very sad answer to to this question, but I
must ask anyhow.
I want to let the user pick a file for saving his/her data, so I use
UIPUTFILE to get a filename. If the file doesn't exist, UIPUTFILE
returns the new filename as I want to. But, if the file already exists,
a second dialog pops up, pointing out the fact and asks if the user want
to replace it.
However, I want to let the user _append_ to an existing file, making the
dialog's question very confusing. Can this second dialog somehow be
disabled or tweaked, so that I can do the check myself?
I tried to use UIGETFILE instead, but that dialog checks that the file
indeed exist beforehand and puts up a dialog if it doesn't.
Does anyone have a solution to this or am I forced to build my own
dialog?
jewa & wagberg . net (replace the obvious)
PS:Don't use my registered email. It's flooded with spam and not active.
Thank you for the confirmation, although I would have been happier if
you had found something I had missed...

However, I did find a solution that worked for me. Microsofts
CommonDialog ActiveX control solved my immediate problem, since my
application will only be used on PC's. It would be nice to have a more
general solution though, so I'll take your advice and request for it
at Mathworks too.

jewa & wagberg . net (replace the obvious)
Doug Schwarz
2007-05-15 12:42:35 UTC
Permalink
[snip]
Post by JWagberg
Post by JWagberg
I want to let the user pick a file for saving his/her data, so I use
UIPUTFILE to get a filename. If the file doesn't exist, UIPUTFILE
returns the new filename as I want to. But, if the file already exists,
a second dialog pops up, pointing out the fact and asks if the user want
to replace it.
However, I want to let the user _append_ to an existing file, making the
dialog's question very confusing. Can this second dialog somehow be
disabled or tweaked, so that I can do the check myself?
I tried to use UIGETFILE instead, but that dialog checks that the file
indeed exist beforehand and puts up a dialog if it doesn't.
Does anyone have a solution to this or am I forced to build my own
dialog?
[snip]
Post by JWagberg
However, I did find a solution that worked for me. Microsofts
CommonDialog ActiveX control solved my immediate problem, since my
application will only be used on PC's. It would be nice to have a more
general solution though, so I'll take your advice and request for it
at Mathworks too.
The correct solution is to have two separate menu items (or buttons or
whatever), one labeled "Save As..." (from which you call uiputfile) and
the other labeled "Append To..." (from which you call uigetfile). I
don't think you will find any (many) professionally written programs
that do what you originally described. They all have a separate
"append" menu item. That way the user knows exactly what to expect.
--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.
Dan Hensley
2007-05-15 13:56:54 UTC
Permalink
Post by Doug Schwarz
The correct solution is to have two separate menu items (or buttons or
whatever), one labeled "Save As..." (from which you call uiputfile) and
the other labeled "Append To..." (from which you call uigetfile). I
don't think you will find any (many) professionally written programs
that do what you originally described. They all have a separate
"append" menu item. That way the user knows exactly what to expect.
I have a command-line function. There is an optional input argument
'append' to specify that the user wants to append rather than overwrite.
But there's still no guarantee that the file exists yet (append if it
does, create it if it doesn't). So in my situation your suggestion will
not work.

Besides, it seems rather stupid to have to check for a file's existence
to decide which dialog to present. fopen doesn't require this with the
'a' open parameter.

Dan
Doug Schwarz
2007-05-15 14:36:05 UTC
Permalink
Post by Dan Hensley
Post by Doug Schwarz
The correct solution is to have two separate menu items (or buttons or
whatever), one labeled "Save As..." (from which you call uiputfile) and
the other labeled "Append To..." (from which you call uigetfile). I
don't think you will find any (many) professionally written programs
that do what you originally described. They all have a separate
"append" menu item. That way the user knows exactly what to expect.
I have a command-line function. There is an optional input argument
'append' to specify that the user wants to append rather than overwrite.
But there's still no guarantee that the file exists yet (append if it
does, create it if it doesn't). So in my situation your suggestion will
not work.
Besides, it seems rather stupid to have to check for a file's existence
to decide which dialog to present. fopen doesn't require this with the
'a' open parameter.
Dan
Hi Dan,

Well, you can't check for a file's existence before you have specified
the name of the file so I'm not sure what you mean by that.

It sounds like you have a command line function (i.e., not a GUI
program) from which you need to save data to a file, specified by name,
and you don't care when you specify the file name whether the file
exists already or you have to create it. Is that right? In that case,
you don't need uiputfile at all. One of the advantages of uiputfile is
that you can see what files already exist when you pick a name for your
new file, but since this is not an issue for you why not just specify a
directory and file name some other way? (You could pass them into your
function or just pass in the file name and use uigetdir to get the
directory, for example.) My point is that your user interface is not
really the standard way to use uiputfile, but you want to use it anyway
because it's convenient (understandable). IMO, a better solution is to
create your own small GUI program that does exactly what you want and
then call that from your command line function.
--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.
Dan Hensley
2007-05-15 17:55:29 UTC
Permalink
Post by Doug Schwarz
Hi Dan,
Well, you can't check for a file's existence before you have specified
the name of the file so I'm not sure what you mean by that.
I'm thinking of the general use case. More below.
Post by Doug Schwarz
It sounds like you have a command line function (i.e., not a GUI
program) from which you need to save data to a file, specified by name,
and you don't care when you specify the file name whether the file
exists already or you have to create it. Is that right? In that case,
you don't need uiputfile at all. One of the advantages of uiputfile is
that you can see what files already exist when you pick a name for your
new file, but since this is not an issue for you why not just specify a
directory and file name some other way? (You could pass them into your
function or just pass in the file name and use uigetdir to get the
directory, for example.) My point is that your user interface is not
really the standard way to use uiputfile, but you want to use it anyway
because it's convenient (understandable). IMO, a better solution is to
create your own small GUI program that does exactly what you want and
then call that from your command line function.
I have a command line function (actually several) that are part of one of
our commercial Matlab toolboxes. You're correct on the usage. The user
may or may not specify a filename when they call it. If they don't, or
it has wildcards, a file dialog pops up to allow the user to select an
existing file or enter a new one.

Creating a small GUI program to work around this is not a good solution
in my case. At any rate it seems like an awful lot of work to get around
something that could be solved with one simple command-line addition to
uiputfile:

uiputfile('*.txt','appendok')

or something like that. If you pass in this optional string you don't
warn if the user selects an existing file. Otherwise you do as it does
now. uiputfile is the wrong place to check for overwrite anyway. It's
so Microsoftian--it has decided that the user is going to overwrite the
file, whether or not it is actually true. There are many, many cases
when this is not true. Why not let the developer decide this and act
accordingly, instead of forcing a behavior? A file dialog should NOT
care what happens to the file. Its only purpose should be to return a
filename (or a way of determining that the user has canceled), either by
picking or by typing.

I disagree with your assessment that the current uiputfile is the
standard way to use it. Whose standard? I didn't ask it to put up that
overwrite warning. And multiple people have asked to be able to turn
that off. Of course it's the only way to use it right now, and the way
Mathworks has decided it must be used, but it's not the way I and others
want to use it.

Dan
Doug Schwarz
2007-05-17 17:44:21 UTC
Permalink
Post by Dan Hensley
I have a command line function (actually several) that are part of one of
our commercial Matlab toolboxes. You're correct on the usage. The user
may or may not specify a filename when they call it. If they don't, or
it has wildcards, a file dialog pops up to allow the user to select an
existing file or enter a new one.
Okay, it's pretty common to present a file dialog when the file name is
not passed in. What is unusual in your case (I'm not saying it's bad or
incorrect, just unusual) is that you want to have the option of
appending to an existing file. Most of the time when people are saving
data to a file they want to create a new file and they would want to be
warned *while still in the file dialog* that the name they chose is
already taken. That's what I mean by standard usage.
Post by Dan Hensley
Creating a small GUI program to work around this is not a good solution
in my case.
Why not?
Post by Dan Hensley
At any rate it seems like an awful lot of work to get around
something that could be solved with one simple command-line addition to
uiputfile('*.txt','appendok')
or something like that. If you pass in this optional string you don't
warn if the user selects an existing file. Otherwise you do as it does
now. uiputfile is the wrong place to check for overwrite anyway. It's
so Microsoftian--it has decided that the user is going to overwrite the
file, whether or not it is actually true. There are many, many cases
when this is not true. Why not let the developer decide this and act
accordingly, instead of forcing a behavior? A file dialog should NOT
care what happens to the file. Its only purpose should be to return a
filename (or a way of determining that the user has canceled), either by
picking or by typing.
I disagree with your assessment that the current uiputfile is the
standard way to use it. Whose standard? I didn't ask it to put up that
overwrite warning. And multiple people have asked to be able to turn
that off. Of course it's the only way to use it right now, and the way
Mathworks has decided it must be used, but it's not the way I and others
want to use it.
Dan
I'm not sure how to answer you. You seem to have made up your mind
about this so I'm not sure anything I say will convince you. It remains
my opinion that you are using the wrong tool to do what you want. Yes,
it's true that the exact tool you need doesn't already exist and yes,
it's true that uiputfile is close to what you want. Since you don't
care if the file you specify already exists there is no reason to
display the names of the files the way uiputfile does. That is what
makes it the wrong tool -- it presents unnecessary information to the
user. This has nothing to do with the "file exists" error dialog --
uiputfile would be the wrong tool even if you could turn that off.
--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.
Dan Hensley
2007-05-17 23:36:15 UTC
Permalink
Post by Doug Schwarz
Post by Dan Hensley
I have a command line function (actually several) that are part of one
of our commercial Matlab toolboxes. You're correct on the usage. The
user may or may not specify a filename when they call it. If they
don't, or it has wildcards, a file dialog pops up to allow the user to
select an existing file or enter a new one.
Okay, it's pretty common to present a file dialog when the file name is
not passed in. What is unusual in your case (I'm not saying it's bad or
incorrect, just unusual) is that you want to have the option of
appending to an existing file. Most of the time when people are saving
data to a file they want to create a new file and they would want to be
warned *while still in the file dialog* that the name they chose is
already taken. That's what I mean by standard usage.
I'm not sure I agree with you about "most of the time" and "appending is
unusual". Maybe in your experience, but not in mine. It depends on the
application. Think about data aquisition. Sometimes you want to start
over, other times you want to append your data to some existing data in a
file. Is that unusual?

So in some instances people want to be warned while still in the file
dialog, *some do not*. All I'm asking for is the option to have it
either way.
Post by Doug Schwarz
Post by Dan Hensley
Creating a small GUI program to work around this is not a good solution
in my case.
Why not?
Because the file may or may not exist. Envision this:

Dialog has two buttons, Save and Append. The user has to decide which he/
she wants. One button uses uigetfile, one uses uiputfile. So the user
has to know ahead of time whether the file exists to decide which button
to push. They think it exists, so they hit Append. Oops, it doesn't.
Have to Cancel, hit Save, then type in the filename.
Post by Doug Schwarz
Post by Dan Hensley
I disagree with your assessment that the current uiputfile is the
standard way to use it. Whose standard? I didn't ask it to put up
that overwrite warning. And multiple people have asked to be able to
turn that off. Of course it's the only way to use it right now, and
the way Mathworks has decided it must be used, but it's not the way I
and others want to use it.
Dan
I'm not sure how to answer you. You seem to have made up your mind
about this so I'm not sure anything I say will convince you. It remains
my opinion that you are using the wrong tool to do what you want. Yes,
I want a file dialog that allows me to either enter a new file or select
an existing one. And I don't know ahead of time if the user wants to
create a new file or select an existing one.

Could you perhaps point me to the right tool if uiputfile is the wrong
one?

Your arguments don't convince me because they don't make any sense to
me. I guess we're probably just crossing paths and talking past each
other. And I don't see how my request for uiputfile is unreasonable.
Post by Doug Schwarz
it's true that the exact tool you need doesn't already exist and yes,
it's true that uiputfile is close to what you want. Since you don't
care if the file you specify already exists there is no reason to
display the names of the files the way uiputfile does. That is what
makes it the wrong tool -- it presents unnecessary information to the
user. This has nothing to do with the "file exists" error dialog --
uiputfile would be the wrong tool even if you could turn that off.
I don't follow you at all. What unnecessary information does uiputfile
present to the user? uiputfile presents a standard file dialog that
people are used to. The only difference is that you are allowed to type
in a filename, where uigetfile requires you to select an existing one.

Dan
Walter Roberson
2007-05-18 18:47:22 UTC
Permalink
Post by Doug Schwarz
Yes,
it's true that the exact tool you need doesn't already exist and yes,
it's true that uiputfile is close to what you want. Since you don't
care if the file you specify already exists there is no reason to
display the names of the files the way uiputfile does. That is what
makes it the wrong tool -- it presents unnecessary information to the
user. This has nothing to do with the "file exists" error dialog --
uiputfile would be the wrong tool even if you could turn that off.
My users use the display of existing files in the directory as a guide
to forming the new filename. The filenames can be fairly
complex, and the difference between this one and the last one might
be 50 characters followed by 'Seed7' changed to those 50 characters
followed by 'Seed8'. Presenting the information about what files
are already there doesn't hurt (except in-so-far as it slows
down the file dialog), and it may substantially help the user get the
filename right.
--
All is vanity. -- Ecclesiastes
JWagberg
2007-05-21 20:58:48 UTC
Permalink
Post by Doug Schwarz
[snip]
Post by JWagberg
Post by JWagberg
I want to let the user pick a file for saving his/her data, so I use
UIPUTFILE to get a filename. If the file doesn't exist, UIPUTFILE
returns the new filename as I want to. But, if the file already exists,
a second dialog pops up, pointing out the fact and asks if the user want
to replace it.
However, I want to let the user _append_ to an existing file, making the
dialog's question very confusing. Can this second dialog somehow be
disabled or tweaked, so that I can do the check myself?
I tried to use UIGETFILE instead, but that dialog checks that the file
indeed exist beforehand and puts up a dialog if it doesn't.
Does anyone have a solution to this or am I forced to build my own
dialog?
[snip]
Post by JWagberg
However, I did find a solution that worked for me. Microsofts
CommonDialog ActiveX control solved my immediate problem, since my
application will only be used on PC's. It would be nice to have a more
general solution though, so I'll take your advice and request for it
at Mathworks too.
The correct solution is to have two separate menu items (or buttons or
whatever), one labeled "Save As..." (from which you call uiputfile) and
the other labeled "Append To..." (from which you call uigetfile). I
don't think you will find any (many) professionally written programs
that do what you originally described. They all have a separate
"append" menu item. That way the user knows exactly what to expect.
--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.
If the file exists, my current implementation displays a dialog asking
if the user wants to overwrite or append to it. This way, also, the
user will know exactly what to expect.

I think this logic is comparable to how uiputfile works now for
overwriting files. You enter a filename, if it doesn't exist, the
filename is returned. If it exists, you have the option to overwrite
or cancel.

My uiappendfile works nearly the same. You enter a filename, it if
doesn't exist, the filename is returned. If it does exist, you have
the option to overwrite, append or cancel.

jewa & wagberg , net (replace the obvious)
Christopher
2013-01-17 21:51:08 UTC
Permalink
Post by JWagberg
I suspect I already know the very sad answer to to this question, but
I must ask anyhow.
I want to let the user pick a file for saving his/her data, so I use
UIPUTFILE to get a filename. If the file doesn't exist, UIPUTFILE
returns the new filename as I want to. But, if the file already
exists, a second dialog pops up, pointing out the fact and asks if the
user want to replace it.
However, I want to let the user _append_ to an existing file, making
the dialog's question very confusing. Can this second dialog somehow
be disabled or tweaked, so that I can do the check myself?
I tried to use UIGETFILE instead, but that dialog checks that the file
indeed exist beforehand and puts up a dialog if it doesn't.
Does anyone have a solution to this or am I forced to build my own
dialog?
jewa & wagberg . net (replace the obvious)
PS:Don't use my registered email. It's flooded with spam and not
active.
Being in a position similar to JWagberg, I worked out a java hack to solve the problem, appended below. The issue for me was that my application opens an existing file for reading and/or writing (as chosen by the user from within the application), and otherwise creates a new one. In my case, the warning from uiputfile is either inaccurate or superfluous, depending on the intentions of the user.

%%%%%%%%%%

function filename = uigetfilename

parframe = com.mathworks.hg.peer.utils.DialogUtilities.createParentWindow;
obj = javahandle_withcallbacks.com.mathworks.mwswing.MJFileChooser;
obj.showOpenDialog(parframe);
filename = char(obj.getSelectedFile);
delete(obj)
Christopher
2013-01-17 21:52:05 UTC
Permalink
Post by JWagberg
I suspect I already know the very sad answer to to this question, but
I must ask anyhow.
I want to let the user pick a file for saving his/her data, so I use
UIPUTFILE to get a filename. If the file doesn't exist, UIPUTFILE
returns the new filename as I want to. But, if the file already
exists, a second dialog pops up, pointing out the fact and asks if the
user want to replace it.
However, I want to let the user _append_ to an existing file, making
the dialog's question very confusing. Can this second dialog somehow
be disabled or tweaked, so that I can do the check myself?
I tried to use UIGETFILE instead, but that dialog checks that the file
indeed exist beforehand and puts up a dialog if it doesn't.
Does anyone have a solution to this or am I forced to build my own
dialog?
jewa & wagberg . net (replace the obvious)
PS:Don't use my registered email. It's flooded with spam and not
active.
Being in a position similar to JWagberg, I worked out a java hack to solve the problem, appended below. The issue for me was that my application opens an existing file for reading and/or writing (as chosen by the user from within the application), and otherwise creates a new one. In my case, the warning from uiputfile is either inaccurate or superfluous, depending on the intentions of the user.

%%%%%%%%%%

function filename = uigetfilename

parframe = com.mathworks.hg.peer.utils.DialogUtilities.createParentWindow;
obj = javahandle_withcallbacks.com.mathworks.mwswing.MJFileChooser;
obj.showOpenDialog(parframe);
filename = char(obj.getSelectedFile);
delete(obj)

Loading...