SnTT: Programmatically Modify Designer Tools Menu
Back in March, Andre posted code for importing design elements from DXL, because the Designer Tools menu includes options for viewing, exporting, and transforming DXL... but not importing. Adding this code to an agent allows you to import design elements into the database containing that agent. Today's tip shows you how to add a custom entry to the Tools menu that does the same thing, but imports the elements into whichever database you currently have open in Designer - without having to first add an import agent to that database. The sample database contains two elements:
- a hidden agent that is very nearly identical to the code Andre posted.
- an Actions menu agent that "installs" the import option in your Tools menu.
Set dbCurrent = sesCurrent.CurrentDatabase
Set dbBookmarks = sesCurrent.GetDatabase("","bookmark.nsf")
Set outDesignTools = dbBookmarks.GetOutline("DesignTools")
Set oentAlways = outDesignTools.GetFirst()
Set oentImporter = outDesignTools.CreateEntryFrom(oentAlways,oentAlways,True,True)
Let oentImporter.Label = "Import DXL"
Call oentImporter.SetAction(|@Environment("DesignDXLImportTarget";@Subset(@DbName;1) + "!!" + @Subset(@DbName;-1));
@Command( [FileOpenDatabase]; "| & dbCurrent.Server & |":"| & Replace(dbCurrent.FilePath,"\","\\") & |");
@UpdateFormulaContext;
@Command([ToolsRunMacro];"(ImportDXL)");
@PostedCommand([FileCloseWindow])|)
Call outDesignTools.Save()
Msgbox "The Tools menu has been updated. Happy importing."
The formula in the new menu item does five things:
- sets an INI variable to the location of the database you're in when you invoke the tool
- opens the importer database
- updates the formula context to gain access to the importer database's agents
- runs the import agent (which gets a handle on the target database by reading the same INI variable - this is the only change from Andre's original code)
- closes the importer database, returning you to wherever you were
Comments
Posted by Tim Tripcony At 02:14:18 AM On 11/01/2007 | - Website - |
Wouldn't it be even nicer to copy the import-agent into the bookmark file as well? That way both the added menu and the agent would work on another pc through replication of bookmark.nsf
Posted by Klaus Terman At 06:21:52 AM On 10/30/2007 | - Website - |