For Dynamic Programming Model (DPM) style integrations, when a host item is renamed the corresponding code file in the DPM add-in project maintains its original file name and displays the updated host item name in parentheses next to the file name (see screen shot below). This is accomplished by setting the DisplayName property of the IVstaProjectHostItem (projectHostItem.ProgrammingModelHostItem.DisplayName) for the renamed host item. This is demonstrated in the SDK sample ShapeAppDynamicProgrammingModelCSharp where drawings represent host items.
In order to see this simply save a document, add a VB or C# DPM add-in project through the customization menu, then change a drawing name. In the VSTA IDE the code file for the renamed drawing will appear as described above, with the original drawing name as the file name and the updated name in parentheses next to the file name in the Project Explorer pane.
There is a small glitch with the SDK sample. Once a document with a renamed host item (drawing) is customized (by adding a DPM add-in project), saved, and re-opened, a new file is added to the DPM add-in project with a file name matching the updated host item name. This is caused by using the drawing.Name instead of drawing.Cookie in the AddDrawingProjectHostItem method. Below is updated code which solves this problem.
private void AddDrawingProjectHostItem(ShapeApp.Drawing drawing)
{
//To avoid problems with renamed host items,
//use the cookie here instead of name
//IVstaProjectHostItem projectHostItem =
// AddProjectHostItemInternal( drawing.Name , "drawing",
// "DrawingEntryPoint");
IVstaProjectHostItem projectHostItem =
AddProjectHostItemInternal( drawing.Cookie , "drawing",
"DrawingEntryPoint");
//UNCHANGED CODE REMOVED
}
In order to reproduce this problem and see the fix in action follow these steps:
1) Run the setup file for the SDK DPM sample ShapeAppDynamicProgrammingModelCSharp.
2) Save a document.
3) Add a C# or VB add-in project through the customization menu.
4) Rename a drawing.
5) Save and close the project.
6) Re-open the project and launch the VSTA IDE by reselecting the language used for the DPM add-in customization above.
7) In the VSTA IDE note that there is now a file matching the renamed drawing as well as the original drawing name.
Now implement the above fix and re-run the repro steps. Notice that no new code file is added with the renamed host item's name.
For more information on the Dynamic Programming Model please see the MSDN documentation . For more information on changing the display name of a host item in a DPM add-in see the How to: Change the Display Name of a Host Item section.
Posted
Sep 28 2010, 10:34 AM
by
Melody