2011-09-23 70 views
1

我一直在努力(没有太多的运气)为Visual Studio 2008编写一个宏,它将打开的.cpp和.h文件分类到两个标签组中,将标题放在左边的标签组和右边的.cpp文件中。我很想拥有这个功能,因为我花了很多时间移动我的标签,这样我就可以看到我正在使用的两个部分。我知道Visual Studio有一个非自由插件允许选项卡管理,但它与我需要用于工作的插件冲突,使得宏成为迄今为止最好的选择。如何按文件类型对Visual Studio 2008中的选项卡进行排序?

我相信这可以应用于其他布局和排序需求,以及如果我能得到它的工作。我的想法是每次打开文档窗口时都会自动进行排序,因此我在Visual Studio Macro IDE的环境事件部分创建了一个可视化基本宏。下面是我到目前为止的代码:

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'属性来确定新窗口出现在哪个标签组中,然后将窗口移到下一个标签组,如果它不在我想要的位置。我已经为“左”属性尝试了一系列不同的值,但到目前为止我的选项卡都没有移动。

有谁知道我做错了什么或有什么建议吗?预先感谢您的时间。

+0

我发现了一个方法,使分拣作业,但只能通过手动点击一个按钮。只要在运行宏时我在Visual Studio中设置了两个垂直选项卡组,我写的方法就会完成我想要的操作。它把所有的头文件放在左边,其他的放在右边。代码如下: – user960341

回答

1

我找到了一种方法来使用下面的函数来做我想要的。只要我运行宏时设置了两个垂直制表符,它会将所有标题放在左侧制表符组中,而将所有其他文件放在正确制表符组中。这可以进一步扩展,以便当我使用任何其他宏打开任何文件时,我写它通过在宏运行之后调用它来排序它们。可悲的是,这不会自动工作,每当触发特定事件时(使用环境事件部分),我都会遇到问题以便实际执行排序。

'===================================================================== 
' Sorts all opened documents putting headers into the left tab group 
' and everything else into the right tab group 
'===================================================================== 
Public Sub SortFilesInTabs() 
    For i = 1 To DTE.Windows.Count Step 1 
     If DTE.Windows.Item(i).Document IsNot Nothing Then 
      If DTE.Windows.Item(i).Document.FullName.Contains(".h") Then 
       ' if the file is a header file make sure it appears on the left 
       If DTE.Windows.Item(i).Document.ActiveWindow.Left > 600 Then 
        WriteOutput("moved file " & DTE.Windows.Item(i).Document.FullName & " to left") 
        DTE.Windows.Item(i).Document.Activate() 
        DTE.ExecuteCommand("Window.MovetoPreviousTabGroup") 
       End If 
      ElseIf DTE.Windows.Item(i).Document.FullName.Contains(".cpp") Then 
       ' if the file is a cpp file make sure it appears on the right 
       If DTE.Windows.Item(i).Document.ActiveWindow.Left < 250 Then 
        WriteOutput("moved file " & DTE.Windows.Item(i).Document.FullName & " to right") 
        DTE.Windows.Item(i).Document.Activate() 
        DTE.ExecuteCommand("Window.MovetoNextTabGroup") 
       End If 
      ElseIf DTE.Windows.Item(i).Document.FullName.Length > 0 Then 
       ' if the file is any other valid document then make sure it appears on the right 
       If DTE.Windows.Item(i).Document.ActiveWindow.Left < 250 Then 
        WriteOutput("moved file " & DTE.Windows.Item(i).Document.FullName & " to right") 
        DTE.Windows.Item(i).Document.Activate() 
        DTE.ExecuteCommand("Window.MovetoNextTabGroup") 
       End If 
      End If 
     End If 
    Next i 
End Sub 

如果任何人都可以改善这种进一步PL

相关问题