Ocean Menu

R

Roger Light

Guest
Hi there,

I wrote this skill procedure and thought others might find it useful.It
has certainly proved reasonably popular here.

All it does is create an "Ocean" menu in the CIW. The menu contains
items that correspond to all of the .ocn files in a given directory.
Clicking an item will load that Ocean file. Simple! There is also a menu
item for updating the menu when new Ocean files are created during a
session.

Comments/improvements/criticisms gratefully received.

Cheers,

Roger


/* autoOceanMenu.il

Author: Roger Light
Date: 2005/08/15

Creates a pulldown menu "Ocean" in the CIW which contains
a list of menu items corresponding to all of the Ocean files
in the given directory. Selecting a menu item loads the Ocean
file.

Also creates an "Update Menu" item which is used to rebuild the
"Ocean" pulldown menu in the event of new Ocean files being
created.

Usage:

autoOceanMenu(path_to_ocean_files)

Example:

load("autoOceanMenu.il")
autoOceanMenu( strcat( getWorkingDir() "/ocean" ) )

*/

procedure(autoOceanMenu( ocnpath )
ocnfiles = getDirFiles( ocnpath )
ciw = hiGetCIWindow( )

if( length(hiGetBannerMenus( ciw )) <= 1 then
ciwMenuInit()
)

/* Delete the banner menu if it already exists. */
if( boundp( 'autoocn_pulldown ) then
ciwmenus = hiGetBannerMenus( ciw )
for( i 0 length( ciwmenus )-1
if( nth( i ciwmenus ) == 'autoocn_pulldown
hiDeleteBannerMenu( ciw i )
)
)
)

/* Start our menu list with an item to allow updating the list */
ocnitems = tconc( nil hiCreateMenuItem( ?name 'autoocn_update
?itemText "Update Menu"
?callback strcat( "autoOceanMenu( \"" ocnpath "\" )" )
))

tconc( ocnitems hiCreateSeparatorMenuItem( ?name 'autoocn_sep ))

/* Start the loop at "2" to ignore "." and "..". */
for( i 2 length(ocnfiles)-1
filename = nth( i ocnfiles )
ending = substring( filename strlen(filename)-2 3)
if( strcmp( ending "ocn" ) == 0 then
ocnfile = strcat( ocnpath "/" filename )
callback = strcat( "load \"" ocnfile "\"" )

tconc( ocnitems hiCreateMenuItem(?name stringToSymbol( filename )
?itemText filename
?callback callback
)
)
)
)

ocnitems = car( ocnitems )

hiCreateMenu( 'autoocn_pulldown "Ocean" ocnitems )
hiInsertBannerMenu( ciw 'autoocn_pulldown length( hiGetBannerMenus( ciw )))
)
 
Thanks Roger for the tip. I should try this out.

Roger Light wrote:
Hi there,

I wrote this skill procedure and thought others might find it useful.It
has certainly proved reasonably popular here.

All it does is create an "Ocean" menu in the CIW. The menu contains
items that correspond to all of the .ocn files in a given directory.
Clicking an item will load that Ocean file. Simple! There is also a menu
item for updating the menu when new Ocean files are created during a
session.

Comments/improvements/criticisms gratefully received.

Cheers,

Roger


/* autoOceanMenu.il

Author: Roger Light
Date: 2005/08/15

Creates a pulldown menu "Ocean" in the CIW which contains
a list of menu items corresponding to all of the Ocean files
in the given directory. Selecting a menu item loads the Ocean
file.

Also creates an "Update Menu" item which is used to rebuild the
"Ocean" pulldown menu in the event of new Ocean files being
created.

Usage:

autoOceanMenu(path_to_ocean_files)

Example:

load("autoOceanMenu.il")
autoOceanMenu( strcat( getWorkingDir() "/ocean" ) )

*/

procedure(autoOceanMenu( ocnpath )
ocnfiles = getDirFiles( ocnpath )
ciw = hiGetCIWindow( )

if( length(hiGetBannerMenus( ciw )) <= 1 then
ciwMenuInit()
)

/* Delete the banner menu if it already exists. */
if( boundp( 'autoocn_pulldown ) then
ciwmenus = hiGetBannerMenus( ciw )
for( i 0 length( ciwmenus )-1
if( nth( i ciwmenus ) == 'autoocn_pulldown
hiDeleteBannerMenu( ciw i )
)
)
)

/* Start our menu list with an item to allow updating the list */
ocnitems = tconc( nil hiCreateMenuItem( ?name 'autoocn_update
?itemText "Update Menu"
?callback strcat( "autoOceanMenu( \"" ocnpath "\" )" )
))

tconc( ocnitems hiCreateSeparatorMenuItem( ?name 'autoocn_sep ))

/* Start the loop at "2" to ignore "." and "..". */
for( i 2 length(ocnfiles)-1
filename = nth( i ocnfiles )
ending = substring( filename strlen(filename)-2 3)
if( strcmp( ending "ocn" ) == 0 then
ocnfile = strcat( ocnpath "/" filename )
callback = strcat( "load \"" ocnfile "\"" )

tconc( ocnitems hiCreateMenuItem(?name stringToSymbol( filename )
?itemText filename
?callback callback
)
)
)
)

ocnitems = car( ocnitems )

hiCreateMenu( 'autoocn_pulldown "Ocean" ocnitems )
hiInsertBannerMenu( ciw 'autoocn_pulldown length( hiGetBannerMenus( ciw )))
)
 

Welcome to EDABoard.com

Sponsor

Back
Top