Title: How to register IVsEditorFactoryNotify in VS.NET extension package?
Tags: visual-studio
Question: I am trying to monitor the item added event.
I have created a custom editor factory such as
public class ProjectEditorFactory : IVsEditorFactoryNotify, IVsEditorFactory
public int NotifyDependentItemSaved(IVsHierarchy pHier, uint itemidParent, string pszMkDocumentParent, uint itemidDpendent, string pszMkDocumentDependent)
return VSConstants.S_OK;
public int NotifyItemAdded(uint grfEFN, IVsHierarchy pHier, uint itemid, string pszMkDocument)
return VSConstants.S_OK;
public int NotifyItemRenamed(IVsHierarchy pHier, uint itemid, string pszMkDocumentOld, string pszMkDocumentNew)
return VSConstants.S_OK;
............
And then in my Initialize method of the package
RegisterEditorFactory( new ProjectEditorFactory());
but after I run, the event handler is not hit after I add a new item to the project.
Does anyone know how to catch the event?
What I actually really want is to grammatically add a few files, and then create the Dependency to one specific file. Does anyone know another way other than listening to the ItemAdded event?
thanks

Here is the accepted answer: You don't want an Editor factory here, that's when you want to provide a custom editor (like the text editor inside Visual Studio). You should look into integrating with the project system. I don't remember the ways to do it via the newer project system, but you can probably get away with http://msdn.microsoft.com/en-US/library/microsoft.visualstudio.shell.interop.ivshierarchyevents(v=vs.110).aspx
Comment for this answer: No you need to grab the IVsHierarchy, and then call the AdviseHierarchyEvents method on it and pass an implementation of IVsHierarchyEvents. Take a look at http://blogs.clariusconsulting.net/pga/how-do-i-get-a-project-from-a-ivshierarchy-and-viceversa/ this shows you how to grab a hold of a project. Once you have that, call http://msdn.microsoft.com/en-US/library/microsoft.visualstudio.shell.interop.ivshierarchy.advisehierarchyevents(v=vs.80).aspx to receive events of interest.
Comment for this answer: sorry, I am too dumb for this. So are you saying if I want my VS.NET extension (Package) to be notified when an item (file) is added, my Package should implement the IVsHierarchyEvents interface? I just tried it, the event is still not hit.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:08/01/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<visual-studio>', 'Title': 'How to register IVsEditorFactoryNotify in VS.NET extension package?', 'ViewCount': 134, 'id': 18004486, 'user_AboutMe': '<p>Curious in applying technology to impact people. </p>\n\n<p>Tech: Master in HCI, Microsoft Stack, User Study, User Experience Research, and Web Development</p>\n', 'user_AccountId': 294586.0, 'user_DisplayName': 'sowen', 'user_Reputation': 1021.0, 'user_Views': 138.0, 'user_id': 598562.0}}