Even More Misha Cat: Why are the number of Actions in VSTO's Smart Tag feature fixed?
Misha also worked on the VSTO Smart Tags feature. I recently asked him this question:
Eric: One aspect of the smart tag design seems pretty strange to me:
Why do you have to do this:
SmartTag mySmartTag = new SmartTag("https://smarttags.me.com#fish", "Fish Tag");
mySmartTag.Terms.Add("Halibut");
Action myAction = new Action("Show fishey picture...");
mySmartTag.Actions = new Action[] { myAction };
myAction.Click += new ActionClickEventHandler(myAction_Click);
Globals.ThisWorkbook.VstoSmartTags.Add(myAction);
Instead of this:
SmartTag mySmartTag = new SmartTag("https://smarttags.me.com#fish", "Fish Tag");
mySmartTag.Terms.Add("Halibut");
Action myAction = new Action("Show fishey picture...");
mySmartTag.Actions.Add(myAction);
myAction.Click += new ActionClickEventHandler(myAction_Click);
Globals.ThisWorkbook.VstoSmartTags.Add(myAction);
Misha: We wanted the programming model to express the fact that the size of the Actions collection has to be set in stone before the smart tag is added to VSTOSmartTags. This is a limitation of Office's Smart Tag feature. Many people ask this question. So, yes, this feels a bit strange. On the other hand if one wants to add more actions lately one can initialized the actions array with empty pointers e.g.:
SmartTag mySmartTag = new SmartTag("https://smarttags.me.com#fish", "Fish Tag");
mySmartTag.Terms.Add("Halibut");
Action myAction = new Action("Show fishey picture...");
mySmartTag.Actions = new Action[] { myAction, null, null };
myAction.Click += new ActionClickEventHandler(myAction_Click);
Globals.ThisWorkbook.VstoSmartTags.Add(myAction);
and some time later do
mySmartTag.Actions[1] = new Action("show pretty picture");
mySmartTag.Actions[2] = new Action("go to a web site with silly pictures");
This is a way to dynamically add and remove actions at runtime--albeit with a fixed upper limit on available actions.