# To subscribers of the xforms list from Steve Lamont <spl@ncmir.ucsd.edu> :
> 1/ Simple question using the File selector (fselector) 'goodie'
>
> The demo and manual show how one can select a file (read)
> and indeed this works very well.
>
> However, I have an application where I want to save a file,
> with the name given in the text window.
>
> The only way I have managed to get anything like this is to create a
> special 'save' button, but I have to specify a fixed file-name, as
> there seems no way to 'hook-out' the text from the fselector filename
> box from the fselector data structure.
I don't understand what you mean by "hook-out."
You can specify a default file name but the user doesn't have to
choose that.
Here's a piece of code that I use to give a user the option of either
taking the default or typing in their own file name:
#include <sys/types.h>
#include <sys/stat.h>
typedef enum {
False,
True
} Logical;
const char *file_name( const char *label,
const char *default_directory,
const char *suffix,
const char *default_filename )
{
const char *return_file = NULL;
while ( !return_file ) {
const char *output_file =
fl_show_fselector( label,
default_directory,
suffix,
default_filename );
if ( file_exists( output_file, S_IFREG ) ) {
const char buffer[MAXPATHLEN];
int response;
sprintf( ( char *) buffer,
"File `%s' exists\n"
"in directory `%s'",
basename( ( char *) output_file ),
dirname( ( char *) output_file ) );
response = fl_show_choices( buffer,
3,
"Overwrite", "New name",
"Forget it",
2 );
if ( response == 1 ) {
return_file = output_file;
break;
} else if ( response == 3 )
break;
} else {
return_file = output_file;
break;
}
}
return return_file;
}
Logical file_exists( const char *file, int allowable )
{
Logical return_status;
struct stat stat_buf;
if ( ( stat( file, &stat_buf ) != -1 ) &&
( stat_buf.st_mode & allowable ) ) {
uid_t my_uid = geteuid();
gid_t my_gid = getgid();
return_status = ( ( ( stat_buf.st_uid == my_uid ) &&
( stat_buf.st_mode & S_IRUSR ) ) ||
( ( stat_buf.st_gid == my_gid ) &&
( stat_buf.st_mode & S_IRGRP ) ) ||
( stat_buf.st_mode & S_IROTH ) );
} else
return_status = False;
return return_status;
}
and it would be called with something like
sprintf( buffer, "%s.sph", get_object_name( object_ptr ) );
output_file = file_name( "Output File", NULL, "*.sph", buffer );
Is there something else you want to do?
spl
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuhs.mil or see
http://bob.usuhs.mil/mailserv/xforms.html
XForms Home Page: http://world.std.com/~xforms
List Archive: http://bob.usuhs.mil/mailserv/list-archives/
This archive was generated by hypermail 2b29 : Thu Jun 29 2000 - 14:05:07 EDT