1. Question...

Hi again!

How do I make GENERIC.EXW to come up automatically with a file w/o
having to push File|Open? I've tried taking routine_id out of it and
everything, and now i'm just lost.

Thanx!

"LEVIATHAN"

new topic     » topic index » view message » categorize

2. Re: Question...

"LEVIATHAN" wrote:

>How do I make GENERIC.EXW to come up automatically with a file w/o
>having to push File|Open? I've tried taking routine_id out of it and
>everything, and now i'm just lost.

This is hardly bulletproof, but it gets the job done.

-- WHAT TO DO --

1. Replace the existing 'onMenu_MenuOpen' routine with 'openFile' and =
the new 'onMenu_OpenMenu'.
2. Replace the existing 'onLoad_Generic' with the new 'onLoad_Generic'.

-- EXPLANATION --

The first problem is that the file loading code is embedded into the =
menu code. So I pulled it out into a seperate routine (openFile), and =
rewrote the menu code (onMenu_MenuOpen) to use that routine.

Next, I added some code into the routine that is run when the window is =
first opened (onLoad_Generic) to checks for the a file name in the =
command line. If there is an argument, it calls 'openFile' to load that =
file. Note that the code doesn't bother to test to ensure that the file =
actually exists.=20

I haven't really had a chance to bulletproof the code - it needs to be =
made more robust, but you should get the general idea.

-- THE CODE --

-------------------------------------------
procedure openFile( sequence fName )

    -- read a file into the MLE
   =20
    integer handle
    sequence buffer
    object data
   =20
    -- entered a file name?
    if length( fName ) =3D 0 then
        return
    end if

    -- open the file
    handle =3D open( fName, "r" )
   =20
    -- read the file
    buffer =3D {}
    while 1 do
        -- get data
        data =3D gets(handle)
       =20
        -- end of file?
        if atom(data) then
            exit
        end if

        -- replace { ... 10 } with { ... 13, 10 }
        data =3D data[1..length(data)-1] & 13 & 10
       =20
        -- append
        buffer =3D buffer & data

    end while

    -- close the file
    close( handle )

    -- place the data in the mle
    setText( GText, buffer )

    -- set file name
    setOpenFileName( fName )   =20
   =20
end procedure

-------------------------------------------
procedure onMenu_MenuOpen()

    -- read a file into the MLE
   =20
    -- get the file name   =20
    openFile( getOpenFileName( Generic, "", FileTypes ) )
   =20
end procedure



-------------------------------------------
procedure onLoad_Generic()                    =20
   =20
    sequence parms
   =20
    -- dim the edit menu
    -- this doesn't work yet.
    enableMenuItem( MenuUndo,   0 )
    enableMenuItem( MenuCut,    0 )
    enableMenuItem( MenuCopy,   0 )
    enableMenuItem( MenuPaste,  0 )
    enableMenuItem( MenuDelete, 0 )
   =20
    -- check for file name in command line
    parms =3D command_line()
    if length( parms ) > 2 then
        openFile( parms[3] )
    end if

end procedure     =20


--=20

Hope this helps!

-- David Cuny

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

Search



Quick Links

User menu

Not signed in.

Misc Menu