Posted on: Sunday 6/10, 2007;  6:29 PM

Although this is not strictly an item that has to do directly with A WorkLife FrameWork it is perhaps useful anyway.  It is a bit of code that generalizes—using a few techniques from Mathematica 6—a small bit of code for locating the standard packages in Mathematica 6 that was posted on the comp.soft-sys.math.mathematica newsgroup.

Here is the code (use the Notebook link at the bottom of this post to download the notebook version of this post):

StandardPackagesPalette

ClearAll[StandardPackagesPalette];

StandardPackagesPalette::usage="StandardPackagesPalette[], generates 
a palette of pull-down menus that allow you to load the standard 
packages. StandardPackagesPalette[\"LegacyPackages\"] does the same 
for those legacy packages that are included in the Mathematica 
distribution. Similarly for StandardPackagesPalette[\"ExtraPackages\"]. ";


StandardPackagesPalette[root:"Packages"|"LegacyPackages"|"ExtraPackages"]:=
Module[{directories,context,packageFiles,packageData,toMenuData,menuData,menus},

context[dir_]:=
StringReplace[dir,{DirectoryName[dir]->"",$PathnameSeparator->""}];

packageFiles[dir_]:=
DeleteCases[StringDrop[
StringReplace[#,DirectoryName[#]->""]&/@FileNames[{"*.m"},{dir}],
-2],
"PacletInfo"|"Usage",∞];

directories=FileNames[{"*"},
{ToFileName[{$InstallationDirectory,"AddOns",root}]}];

directories=Select[directories,FileType[#]===Directory&];

packageData={context[#],packageFiles[#]}&/@directories;

packageData=DeleteCases[packageData,{_,{}}];

toMenuData[{cont_,files_}]:=
With[{topContext=cont<>"`"},

{cont,#:>Quiet[Needs[topContext<>#<>"`"]]&/@files}
];

menuData=toMenuData/@packageData;

menus=ActionMenu[Sequence@@#,
BaseStyle->{FontSize->10,FontFamily->"Helvetica"},
FieldSize->12]&/@menuData;


CreatePalette[
Column[Flatten[{
Button["Close",NotebookClose[ButtonNotebook[]],
BaseStyle->{FontSize->10,FontFamily->"Helvetica",
FontColor->RGBColor[.4,0,0]},Appearance->"Palette"],
menus}]],
WindowSize->{All,350},
WindowElements->{"VerticalScrollBar","StatusArea"},
WindowTitle->"Load "<>root,
WindowMargins->{{Automatic,10},{Automatic,5}}]

];

StandardPackagesPalette[]:=StandardPackagesPalette["Packages"];

When this code is executed the function StandardPackagesPalette[] creates a palette that looks like this: