목차

Macro : Header Source Toggle

  1. Alt+F11 로 매크로 편집기 오픈
  2. 아래 매크로를 추가
  3. 키보드 설정에서, “매크로.” 또는 “Macro.” 를 타이핑 해서 내가 작성한 매크로 찾기
  4. 키 할당
  5. 사용하기

++++ 코드 보기 |

    Public Sub toggleHeaderSource()
        Dim currentDocumentPath As String = DTE.ActiveDocument.FullName
        currentDocumentPath = currentDocumentPath.ToLower()
 
        Dim currentDocumentPathWithoutExtension As String = currentDocumentPath.Remove(currentDocumentPath.LastIndexOf("."))
 
        Dim correspondingDocumentPath As String
        Dim correspondingDocumentPath2 As String
 
        If (currentDocumentPath.EndsWith(".c") Or currentDocumentPath.EndsWith(".cpp")) Then
            correspondingDocumentPath = currentDocumentPathWithoutExtension + ".hpp"
            correspondingDocumentPath2 = currentDocumentPathWithoutExtension + ".h"
        ElseIf (currentDocumentPath.EndsWith(".h") Or currentDocumentPath.EndsWith(".hpp")) Then
            correspondingDocumentPath = currentDocumentPathWithoutExtension + ".cpp"
            correspondingDocumentPath2 = currentDocumentPathWithoutExtension + ".c"
        End If
 
        If (System.IO.File.Exists(correspondingDocumentPath) = True) Then
            DTE.ExecuteCommand("File.OpenFile", correspondingDocumentPath)
        ElseIf (System.IO.File.Exists(correspondingDocumentPath2) = True) Then
            DTE.ExecuteCommand("File.OpenFile", correspondingDocumentPath2)
        End If
    End Sub

++++

Visual Studio 매크로

VS2010에는 플러그인 개발이 오픈소스화 되어 좋은 것들을 쉽게 구할 수 있게 되었다.

뭔가 불편하면, 플러그인을 찾으면 된다.

이 스크립트는 낡았다. 그냥 추억으로 나둠.

++++ Old Script |

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
 
Public Module MyMacroModule
 
    Public Sub toggleHeaderSource()
        Dim currentDocumentPath As String = DTE.ActiveDocument.FullName
        currentDocumentPath = currentDocumentPath.ToLower()
 
        Dim currentDocumentPathWithoutExtension As String = currentDocumentPath.Remove(currentDocumentPath.LastIndexOf("."))
 
        Dim correspondingDocumentPath As String
        Dim correspondingDocumentPath2 As String
 
        If (currentDocumentPath.EndsWith(".c") Or currentDocumentPath.EndsWith(".cpp")) Then
            correspondingDocumentPath = currentDocumentPathWithoutExtension + ".hpp"
            correspondingDocumentPath2 = currentDocumentPathWithoutExtension + ".h"
        ElseIf (currentDocumentPath.EndsWith(".h") Or currentDocumentPath.EndsWith(".hpp")) Then
            correspondingDocumentPath = currentDocumentPathWithoutExtension + ".cpp"
            correspondingDocumentPath2 = currentDocumentPathWithoutExtension + ".c"
        End If
 
        If (System.IO.File.Exists(correspondingDocumentPath) = True) Then
            DTE.ExecuteCommand("File.OpenFile", correspondingDocumentPath)
        ElseIf (System.IO.File.Exists(correspondingDocumentPath2) = True) Then
            DTE.ExecuteCommand("File.OpenFile", correspondingDocumentPath2)
        End If
    End Sub
 
    Sub InsertTMacro()
        Dim selection As EnvDTE.TextSelection
        Dim startPoint As EnvDTE.EditPoint
        Dim endPoint As TextPoint
        Dim commentStart As String
 
        selection = DTE.ActiveDocument.Selection()
        startPoint = selection.TopPoint.CreateEditPoint()
        endPoint = selection.BottomPoint.CreateEditPoint()
 
        DTE.UndoContext.Open("InsertTMacro")
        Try
            startPoint.Insert("_T(")
            endPoint.Insert(")")
        Finally
            DTE.UndoContext.Close()
        End Try
    End Sub
 
End Module

++++