文文小星的blog
asp.net技术,C#,atlas

 

HierarchyEvents hierarchyEvent = new HierarchyEvents(pHierarchy);
uint cookie;
pHierarchy.AdviseHierarchyEvents(hierarchyEvent, out cookie);

public class HierarchyEvents : Microsoft.VisualStudio.Shell.Interop.IVsHierarchyEvents
{
public IVsHierarchy IVsHierarchy { get; set; }
public HierarchyEvents()
{

}
public HierarchyEvents(IVsHierarchy hierarchy)
{
this.IVsHierarchy = hierarchy;
}
#region IVsHierarchyEvents Members

public int OnInvalidateIcon(IntPtr hicon)
{
return VSConstants.S_OK;
}

public int OnInvalidateItems(uint itemidParent)
{
return VSConstants.S_OK;
}

public int OnItemAdded(uint itemidParent, uint itemidSiblingPrev, uint itemidAdded)
{
return VSConstants.S_OK;
}

public int OnItemDeleted(uint itemid)
{
return VSConstants.S_OK;
}

public int OnItemsAppended(uint itemidParent)
{
return VSConstants.S_OK;
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "OnPropertyChanged"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "nop"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "ex"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Windows.Forms.MessageBox.Show(System.String)"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1300:SpecifyMessageBoxOptions")]
public int OnPropertyChanged(uint itemid, int propid, uint flags)
{
//MessageBox.Show("changed"+itemid+ " "+propid+" "+flags);

try
{
object ppObject;
if (IVsHierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_ExtObject, out ppObject) == VSConstants.S_OK)
{
if (ppObject is ProjectItem)
{
MessageBox.Show(("Hierarchy->OnPropertyChanged: " + ((ProjectItem)ppObject).Name));
}
}
if (IVsHierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_Name, out ppObject) == VSConstants.S_OK)
{
int nop = 0;
}
}
catch (Exception ex)
{
int nop = 0;
}

return VSConstants.S_OK;
}

#endregion
}

posted on 2013-03-20 16:35  冯文元  阅读(378)  评论(0编辑  收藏  举报