如何在 Visual Studio 2008 中按文件类型对选项卡进行排序?
我一直在尝试(没有太多运气)为 Visual Studio 2008 编写一个宏,它将打开的 .cpp 和 .h 文件排序到两个选项卡组中,将标题放在左侧选项卡组上,将 .cpp 文件放在右侧。我很想拥有这个功能,因为我花了大量的时间来移动我的选项卡,这样我就可以看到我正在处理的课程的两个部分。我知道 Visual Studio 有一个非免费的附加组件,允许选项卡管理,但它与我需要用于工作的附加组件冲突,使宏成为迄今为止我的最佳选择。
我确信如果我能让它工作的话,这也可以应用于其他布局和排序需求。我的想法是让每次打开文档窗口时自动进行排序,因此我在 Visual Studio Macro IDE 的环境事件部分创建了一个 Visual Basic 宏。下面是我到目前为止的代码:
Public Sub keepHeaderAndCxxInDifferentTabs() Handles WindowEvents.WindowCreated
Dim openedFile As String
openedFile = ActiveWindow.Document.FullName
If openedFile.Contains(".h") Then
' if the file being opened is a header file make sure it appears on the left
If DTE.ActiveDocument.ActiveWindow.Left > 600 Then
DTE.ExecuteCommand("Window.MovetoNextTabGroup")
End If
ElseIf openedFile.Contains(".cpp") Then
' if the file being opened is a cpp file make sure it appears on the right
If DTE.ActiveDocument.ActiveWindow.Left < 250 Then
DTE.ExecuteCommand("Window.MovetoNextTabGroup")
End If
Else
' if the file being opened is anything else make sure it appears on the right
If DTE.ActiveDocument.ActiveWindow.Left < 250 Then
DTE.ExecuteCommand("Window.MovetoNextTabGroup")
End If
End If
End Sub
遗憾的是这个宏目前没有做任何事情。我最好的猜测是,我可以使用活动窗口的“Left”属性来确定新窗口出现在哪个选项卡组中,然后将窗口移动到下一个选项卡组(如果它不是我想要的位置)。我已经为“Left”属性尝试了一系列不同的值,但到目前为止,我的选项卡都没有移动。
有谁知道我做错了什么或有什么建议?预先感谢您抽出时间。
I have been trying (without much luck) to write a macro for Visual Studio 2008 that will sort opened .cpp and .h files into two tab groups, placing headers on the left tab group and .cpp files on the right. I would love to have this feature because of the amount of time I spend moving my tabs around so that I can see both parts of the class that I am working on. I know that there is a non-free add-on for visual studio that allows tab managing, but it conflicts with an add-on that I need to use for work, making a macro my best option so far.
I am sure that this could be applied to other layouts and sorting needs as well if I can get it working. My thinking was to make the sorting happen automatically for me each time I open a document window, so I created a visual basic macro in the environment events section of the Visual Studio Macro IDE. Below is the code that I have so far:
Public Sub keepHeaderAndCxxInDifferentTabs() Handles WindowEvents.WindowCreated
Dim openedFile As String
openedFile = ActiveWindow.Document.FullName
If openedFile.Contains(".h") Then
' if the file being opened is a header file make sure it appears on the left
If DTE.ActiveDocument.ActiveWindow.Left > 600 Then
DTE.ExecuteCommand("Window.MovetoNextTabGroup")
End If
ElseIf openedFile.Contains(".cpp") Then
' if the file being opened is a cpp file make sure it appears on the right
If DTE.ActiveDocument.ActiveWindow.Left < 250 Then
DTE.ExecuteCommand("Window.MovetoNextTabGroup")
End If
Else
' if the file being opened is anything else make sure it appears on the right
If DTE.ActiveDocument.ActiveWindow.Left < 250 Then
DTE.ExecuteCommand("Window.MovetoNextTabGroup")
End If
End If
End Sub
Sadly this macro currently does not do anything. My best guess was that I could use the 'Left' property of the active window to figure out which tab group the new window appeared in and then move the window to the next tab group if it is not where I want it to be. I have tried a range of different values for the 'Left' property but so far none of my tabs move.
Does anyone know what I did wrong or have any suggestions? Thank you in advance for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一种使用下面的函数来做我想做的事情的方法。只要我在运行宏时设置了两个垂直选项卡,它就会将所有标题放入左侧选项卡组中,将所有其他文件放入右侧选项卡组中。这可以进一步扩展,以便当我使用任何其他宏打开任何文件时,我编写的它也会通过在宏运行后调用它来对它们进行排序。遗憾的是,这不会自动工作,每当触发特定事件(使用环境事件部分)时,我都无法让它实际执行排序。
如果有人可以进一步改进这一点
I found a way to do what I wanted using the function below. As long as I have my two vertical tabs setup when I run the macro it puts all headers in the left tab group and all other files in the right tab group. This can be further extended so that when I open any files using any other macros I write it sorts them as well by making a call to it after the macro has run. Sadly this does not work automatically, I am having problems getting it to actually perform the sorting whenever a specific event is triggered (using the environment events section).
If anyone can improve this further pl