如何获取ProjectItem/VsTextbuffer文件名更改事件
我想构建一个多文件编辑器.我使用了示例"MultiFileEditor",来自VS 2008 SDK.而不是创建"FileLinesDocument.cs";我注册了"IVsTextBuffer".如果用户重命名打开的文件,则我没有得到此更改,我的编辑器将保存该文件. 数据保存到旧文件路径.
I want to build a Multifile Editor. I used the Sample "MultiFileEditor" from VS 2008 SDK. Instead of creating "FileLinesDocument.cs" I register a "IVsTextBuffer". If the user renames the opened files I did not get this change and my Editor will save the data to the old file paths.
致谢
托马斯
复制:
1.打开"MultiFileEditor" VS 2008 SDK的示例
1. Open "MultiFileEditor" Sample from VS 2008 SDK
2.创建并打开old.sve文件
2. Create and Open old.sve file
3.在编辑器中添加文字
3. Add Text in Editor
4.将old.sve文件重命名为new.sve并保存
4. Rename old.sve file to new.sve and save
=>编辑器将保存到old.sve
=> The Editor will save to old.sve
软件:
Windows 7 64位,Visual Studio 2010专业版
Windows 7 64 Bit, Visual Studio 2010 Professional
更新:
我想出了一种对我有用的解决方案.我使用"EnvDTE80.DTE2"迭代解决方案/项目/项目.对于每个ProjectItem,我从"CSharpProjectItemsEvents"注册ItemRenamed事件.本来我想不使用
dte对象.有更好的方法吗?
I figured out one solution that works for me. I iterate through the solution/ project/ projectitems using "EnvDTE80.DTE2". For each ProjectItem I register ItemRenamed Event from "CSharpProjectItemsEvents". Originally I wanted to do this without using the
dte object. Is there a better way?
events = projectItem.DTE.Events.GetObject("CSharpProjectItemsEvents") as ProjectItemsEvents;
events.ItemRenamed += new _dispProjectItemsEvents_ItemRenamedEventHandler(events_ItemRenamed);