1. Save As options and parameters

posted by: a.admin at myway.it

In several demo programs I find the 'Save As' instruction. Let's take the

.\Win32lib-59-1\Demo\GENERIC editor.EXW

-- 07/Sep/2000 Wolfgang Fritz
--------------------------------------------------------------------
-- This demo shows off a lot of the features of Win32Lib, including:
--
-- Menus
-- File Open/Save/SaveAs dialogs


constant FileTypes = {
    "dialog flags", {OFN_ALLOWMULTISELECT},
    "Text File", "*.TXT",
    "Euphoria Program", "*.EX;*.EXW;*.E;*.EW",
    "All Files", "*.*" }

and then    
 
    fName = getSaveFileName( Generic, openFileName, FileTypes )
    
    if length(fName) = 0 then
        return
    end if    
    
    -- save the file
    saveFile( fName )
    
    
The question is to what do they serve all these defined FileTypes, since 'fName'
will not include any of them, even if choosed?

I mean, if I select "Euphoria Program", I expect one of the
"*.EX;*.EXW;*.E;*.EW" be appended to the typed name, exactly as every Windows
program naturally does.

As is, this option is a booby-trap, 'cause it creates for more the illusion...
Is there a way to get the selected file_type, in order to add it before saving ?

Thanks to everyone.
    
Antonio Alessi

new topic     » topic index » view message » categorize

2. Re: Save As options and parameters

Hi Antonio,
    The filetypes must append by your program, a common save dialog 
can't do this. (Windows API don't know about which file are u editing)
    The only reason for those file types being there is that because its 
likely that you'll want to save a file with that extention and if it 
exists it's easier to see it and just click on it to get it's name.

Best Regards,
    Guillermo Bonvehi

Guest wrote:

>
>
>posted by: a.admin at myway.it
>
>In several demo programs I find the 'Save As' instruction. Let's take the
>
>.\Win32lib-59-1\Demo\GENERIC editor.EXW
>
>-- 07/Sep/2000 Wolfgang Fritz
>--------------------------------------------------------------------
>-- This demo shows off a lot of the features of Win32Lib, including:
>--
>-- Menus
>-- File Open/Save/SaveAs dialogs
>
>
>constant FileTypes = {
>    "dialog flags", {OFN_ALLOWMULTISELECT},
>    "Text File", "*.TXT",
>    "Euphoria Program", "*.EX;*.EXW;*.E;*.EW",
>    "All Files", "*.*" }
>
>and then    
> 
>    fName = getSaveFileName( Generic, openFileName, FileTypes )
>    
>    if length(fName) = 0 then
>        return
>    end if    
>    
>    -- save the file
>    saveFile( fName )
>    
>    
>The question is to what do they serve all these defined FileTypes, since
>'fName' will not include any of them, even if choosed?
>
>I mean, if I select "Euphoria Program", I expect one of the
>"*.EX;*.EXW;*.E;*.EW" be appended to the typed name, exactly as every Windows
>program naturally does.
>
>As is, this option is a booby-trap, 'cause it creates for more the illusion...
>Is there a way to get the selected file_type, in order to add it before saving
>?
>
>Thanks to everyone.
>    
>Antonio Alessi
>  
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: Save As options and parameters

Voila! I love hacking Win32Lib. Here's a version of getSaveFileName() that
returns the index of the selected file type. Its simply a matter of fetching
and returning another value from the 'ofn' structure. Of course, it's up to
you to determine how to use the index from the filter list. It's basically a
matter of storing your filters properly so you can look them up with the
returned index.

-- begin code --
global function getSaveFileName2( integer id, sequence fName, sequence
filters )
-- getSaveFileName2()
-- returns { File name, Filter Index ) on success
-- returns {} on user cancel

    atom ofn, flags
    atom fIndex -- filter index

    -- build the structure
    if find("DIALOG FLAGS", upper(filters)) = 0 then
        -- Default setting
        flags = or_bits(OFN_OVERWRITEPROMPT, OFN_HIDEREADONLY)
    else
        flags = 0
    end if
    ofn = buildDefaultOfn( id, fName, filters, flags) -- warn if exists

    -- call the routine
    if w32Func(xGetSaveFileName, {ofn}) then
        -- get the name
        fName = fetch( ofn, ofnFile )
        fIndex = fetch( ofn, ofnFilterIndex )
    else
    -- cancelled
        fName = ""
    end if

    -- release the structure and strings
    release_mem( ofn )

    -- return result
    return {fName, fIndex}

end function
-- end code --

~Greg


----- Original Message -----
From: "Guest" <guest at RapidEuphoria.com>
To: <EUforum at topica.com>
Sent: Wednesday, February 11, 2004 10:56 AM
Subject: Save As options and parameters


>
>
> posted by: a.admin at myway.it
>
> In several demo programs I find the 'Save As' instruction. Let's take the
>
> .\Win32lib-59-1\Demo\GENERIC editor.EXW
>
> -- 07/Sep/2000 Wolfgang Fritz
> --------------------------------------------------------------------
> -- This demo shows off a lot of the features of Win32Lib, including:
> --
> -- Menus
> -- File Open/Save/SaveAs dialogs
>
>
> constant FileTypes = {
>     "dialog flags", {OFN_ALLOWMULTISELECT},
>     "Text File", "*.TXT",
>     "Euphoria Program", "*.EX;*.EXW;*.E;*.EW",
>     "All Files", "*.*" }
>
> and then
>
>     fName = getSaveFileName( Generic, openFileName, FileTypes )
>
>     if length(fName) = 0 then
>         return
>     end if
>
>     -- save the file
>     saveFile( fName )
>
>
> The question is to what do they serve all these defined FileTypes, since
'fName' will not include any of them, even if choosed?
>
> I mean, if I select "Euphoria Program", I expect one of the
"*.EX;*.EXW;*.E;*.EW" be appended to the typed name, exactly as every
Windows program naturally does.
>
> As is, this option is a booby-trap, 'cause it creates for more the
illusion...
> Is there a way to get the selected file_type, in order to add it before
saving ?
>
> Thanks to everyone.
>
> Antonio Alessi
>
>
>
> TOPICA - Start your own email discussion group. FREE!
>
>

new topic     » goto parent     » topic index » view message » categorize

4. Re: Save As options and parameters

Figures! I release code and I find a bug! Grrr... Apparently if you clicked
'Cancel', fIndex would have no value and produce an error. Here's the fixed
code:

-- begin code --
global function getSaveFileName2( integer id, sequence fName, sequence
filters )
-- getSaveFileName2()
-- returns { File name, Filter Index ) on success
-- returns {} on user cancel

    atom ofn, flags
    atom fIndex -- filter index

    -- build the structure
    if find("DIALOG FLAGS", upper(filters)) = 0 then
        -- Default setting
        flags = or_bits(OFN_OVERWRITEPROMPT, OFN_HIDEREADONLY)
    else
        flags = 0
    end if
    ofn = buildDefaultOfn( id, fName, filters, flags) -- warn if exists

    -- call the routine
    if w32Func(xGetSaveFileName, {ofn}) then
        -- get the name
        fName = fetch( ofn, ofnFile )
    end if

    if length(fName) then
        fIndex = fetch( ofn, ofnFilterIndex )
        fName = {fName, fIndex}
    end if

    -- release the structure and strings
    release_mem( ofn )

    -- return result
    return fName

end function
-- end code --


----- Original Message -----
From: "Greg Haberek" <g.haberek at comcast.net>
To: <EUforum at topica.com>
Sent: Wednesday, February 11, 2004 1:10 PM
Subject: Re: Save As options and parameters


>
>
> Voila! I love hacking Win32Lib. Here's a version of getSaveFileName() that
> returns the index of the selected file type. Its simply a matter of
fetching
> and returning another value from the 'ofn' structure. Of course, it's up
to
> you to determine how to use the index from the filter list. It's basically
a
> matter of storing your filters properly so you can look them up with the
> returned index.
>
> -- begin code --
> global function getSaveFileName2( integer id, sequence fName, sequence
> filters )
> -- getSaveFileName2()
> -- returns { File name, Filter Index ) on success
> -- returns {} on user cancel
>
>     atom ofn, flags
>     atom fIndex -- filter index
>
>     -- build the structure
>     if find("DIALOG FLAGS", upper(filters)) = 0 then
>         -- Default setting
>         flags = or_bits(OFN_OVERWRITEPROMPT, OFN_HIDEREADONLY)
>     else
>         flags = 0
>     end if
>     ofn = buildDefaultOfn( id, fName, filters, flags) -- warn if exists
>
>     -- call the routine
>     if w32Func(xGetSaveFileName, {ofn}) then
>         -- get the name
>         fName = fetch( ofn, ofnFile )
>         fIndex = fetch( ofn, ofnFilterIndex )
>     else
>     -- cancelled
>         fName = ""
>     end if
>
>     -- release the structure and strings
>     release_mem( ofn )
>
>     -- return result
>     return {fName, fIndex}
>
> end function
> -- end code --
>
> ~Greg
>
>
> ----- Original Message -----
> From: "Guest" <guest at RapidEuphoria.com>
> To: <EUforum at topica.com>
> Sent: Wednesday, February 11, 2004 10:56 AM
> Subject: Save As options and parameters
>
>
> > posted by: a.admin at myway.it
> >
> > In several demo programs I find the 'Save As' instruction. Let's take
the
> >
> > .\Win32lib-59-1\Demo\GENERIC editor.EXW
> >
> > -- 07/Sep/2000 Wolfgang Fritz
> > --------------------------------------------------------------------
> > -- This demo shows off a lot of the features of Win32Lib, including:
> > --
> > -- Menus
> > -- File Open/Save/SaveAs dialogs
> >
> >
> > constant FileTypes = {
> >     "dialog flags", {OFN_ALLOWMULTISELECT},
> >     "Text File", "*.TXT",
> >     "Euphoria Program", "*.EX;*.EXW;*.E;*.EW",
> >     "All Files", "*.*" }
> >
> > and then
> >
> >     fName = getSaveFileName( Generic, openFileName, FileTypes )
> >
> >     if length(fName) = 0 then
> >         return
> >     end if
> >
> >     -- save the file
> >     saveFile( fName )
> >
> >
> > The question is to what do they serve all these defined FileTypes, since
> 'fName' will not include any of them, even if choosed?
> >
> > I mean, if I select "Euphoria Program", I expect one of the
> "*.EX;*.EXW;*.E;*.EW" be appended to the typed name, exactly as every
> Windows program naturally does.
> >
> > As is, this option is a booby-trap, 'cause it creates for more the
> illusion...
> > Is there a way to get the selected file_type, in order to add it before
> saving ?
> >
> > Thanks to everyone.
> >
> > Antonio Alessi
> >
> >
> > TOPICA - Start your own email discussion group. FREE!
> >
> >
>
>
> TOPICA - Start your own email discussion group. FREE!
>
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu