다음을 통해 공유


메뉴 및 도구 모음 개요

메뉴 및 도구 모음은 사용자가 확장의 명령에 액세스하는 방법입니다. 이것은 사용자에게 명령을 제공하는 편리한 그래픽 방법입니다. 일반적으로 관련 명령은 동일한 메뉴 또는 도구 모음에 함께 클러스터됩니다.

메뉴 및 도구 모음 작업

이 개요에서는 메뉴 및 도구 모음을 사용하기 위한 다음과 같은 주요 시나리오를 다룹니다.

메뉴 만들기

새 확장성 모델을 사용하여 메뉴를 만들려면 정적 MenuConfiguration 속성을 추가하여 클래스를 특성으로 VisualStudioContribution 표시합니다. 이 정적 속성은 확장 프로젝트의 모든 클래스에 배치할 수 있습니다. 새 확장성 모델 샘플에서는 단순성을 위해 클래스에 Extension 존재합니다. 표시되는 자식이 없는 메뉴는 UI에 표시되지 않습니다.

[VisualStudioContribution]
public class ExtensionEntrypoint : Extension
{
  [VisualStudioContribution]
  public static MenuConfiguration MyMenu => new("%MyMenu.DisplayName%");
}

MenuConfiguration 클래스에는 익숙해져야 하는 몇 가지 매개 변수가 있습니다.

매개 변수 Type 필수 Description
DisplayName 문자열 메뉴의 기본 표시 이름입니다. 이 문자열을 '%' 문자로 묶어 이 문자열을 지역화할 수 있도록 합니다. 메타데이터 지역화를 참조하세요.
TooltipText 문자열 아니요 메뉴가 가리키거나 포커스가 있을 때 도구 설명으로 표시할 텍스트입니다. 이 문자열을 '%' 문자로 묶어 이 문자열을 지역화할 수 있도록 합니다. 메타데이터 지역화를 참조하세요.
배치 명령 배치[] 아니요 메뉴를 부모로 지정할 Visual Studio 내의 기존 그룹을 지정합니다. IDE에서 메뉴 배치를 참조하세요.
Children MenuChild[] 아니요 이 메뉴에 부모가 되어야 하는 명령, 메뉴 및 그룹 집합에 대해 설명합니다. 이러한 항목이 배열에 정의된 순서는 IDE에 시각적으로 표시되는 순서를 나타냅니다. 메뉴의 항목 배치에서 보기

IDE에 메뉴 배치

메뉴는 명령과 동일한 방식으로 IDE에 배치됩니다. IDE에 명령 배치를 참조하세요.

public override MenuConfiguration MyMenu => new("%MyMenu.DisplayName%")
{
    Placements = new CommandPlacement[]
    {
        CommandPlacement.KnownPlacements.ToolsMenu
    },
};

메뉴에 항목 배치

메뉴의 항목에 배치는 의 배열에 항목을 Children 추가하여 수행됩니다 MenuConfiguration. 이 배열에 항목이 추가되는 순서에 따라 이러한 항목이 IDE에 시각적으로 표시되는 방식이 결정됩니다.

메뉴에 명령 배치

메뉴에 명령을 배치하는 작업은 메서드를 MenuChild.Command<T> 사용하여 수행되며 템플릿 인수를 클래스 이름으로 Command바꿔야 합니다.

[VisualStudioContribution]
public static MenuConfiguration MyMenu => new("%MyMenu.DisplayName%")
{
    Children = new[]
    {
        MenuChild.Command<MyCommand>(),
    },
};

메뉴에 메뉴 배치

메뉴에 메뉴를 배치하는 작업은 메서드를 MenuChild.Menu 사용하여 수행되며 다른 MenuConfiguration 메뉴를 매개 변수로 전달합니다.

[VisualStudioContribution]
public static MenuConfiguration MyChildMenu => new("My Child Menu!");

[VisualStudioContribution]
public static MenuConfiguration MyParentMenu => new("My Parent Menu!")
{
    Children = new[]
    {
        MenuChild.Menu(MyChildMenu),
    },
};

메뉴 항목을 그룹으로 구분

메뉴 내의 항목은 항목 간을 MenuChild.Separator 사용하여 함께 그룹화할 수 있습니다. 시각적으로 두 항목 사이에 배치된 얇은 선처럼 보입니다.

[VisualStudioContribution]
public static MenuConfiguration MyMenu1 => new("%MyMenu.DisplayName%")
{
    Children = new[]
    {
        MenuChild.Command<MyCommand1>(), // Assuming there is a `Command` defined in the extension called `MyCommand1`
        MenuChild.Menu(MyMenu2), // Assuming there is a `MenuConfiguration` defined in the extension called `MyMenu2`
        MenuChild.Separator,
        MenuChild.Command<MyCommand2>(), // Assuming there is a `Command` defined in the extension called `MyCommand2`
        MenuChild.Menu(MyMenu3), // Assuming there is a `MenuConfiguration` defined in the extension called `MyMenu3`
    },
};

이 작업은 메서드를 사용하여 MenuChild.Group 그룹 인라인을 정의하여 수행할 수도 있습니다. 그런 다음 클래스를 GroupChild 사용하여 그룹에 대한 부모 항목을 사용합니다.

[VisualStudioContribution]
public static MenuConfiguration MyMenu1 => new("%MyMenu.DisplayName%")
{
    Children = new[]
    {
        MenuChild.Group(
            GroupChild.Command<MyCommand1>(), // Assuming there is a `Command` defined in the extension called `MyCommand1`
            GroupChild.Menu(MyMenu2)), // Assuming there is a `MenuConfiguration` defined in the extension called `MyMenu2`
        MenuChild.Group(
            GroupChild.Command<MyCommand2>(), // Assuming there is a `Command` defined in the extension called `MyCommand2`
            GroupChild.Menu(MyMenu3)), // Assuming there is a `MenuConfiguration` defined in the extension called `MyMenu3`
    },
};

이전의 두 예제에서 결과 메뉴는 IDE에서 동일합니다. 메뉴 MyMenu1 는 다음 스크린샷의 메뉴와 같습니다.

Screenshot of menu with separator.

도구 모음 만들기

새 확장성 모델을 사용하여 도구모음을 만들려면 정적 ToolbarConfiguration 속성을 추가하여 클래스를 특성으로 VisualStudioContribution 표시합니다. 이 정적 속성은 확장 프로젝트의 모든 클래스에 배치할 수 있습니다. 새 확장성 모델 샘플에서는, 단순성을 위해 클래스에 Extension 존재합니다.

[VisualStudioContribution]
public class ExtensionEntrypoint : Extension
{
  [VisualStudioContribution]
  public static ToolbarConfiguration MyToolbar => new("%MyToolbar.DisplayName%");
}

ToolbarConfigurationPlacement 속성을 null 으로 두면 표준 도구 모음에 도구 모음이 배치되고 View -> Toolbars 메뉴에서 도구 모음을 선택하여 볼 수 있습니다.

ToolbarConfiguration 클래스

ToolbarConfiguration 클래스에는 익숙해져야 하는 몇 가지 속성이 있습니다.

속성 형식 필수 Description
DisplayName 문자열 도구 모음의 기본 표시 이름입니다. 이 문자열을 '%' 문자로 묶어 이 문자열을 지역화할 수 있도록 합니다. 메타데이터 지역화를 참조하세요.
TooltipText 문자열 아니요 도구 모음이 가리키거나 포커스가 있을 때 도구 설명으로 표시할 텍스트입니다. 이 문자열을 '%' 문자로 묶어 이 문자열을 지역화할 수 있도록 합니다. 메타데이터 지역화를 참조하세요.
배치 명령 배치[] 아니요 도구 모음을 부모로 지정할 Visual Studio 내의 기존 그룹을 지정합니다. IDE에서 명령 배치를 참조하세요. 이 속성을 null 로 두면 표준 도구 모음에 도구 모음이 배치되며 View -> Toolbars 메뉴에서 도구 모음을 선택하여 볼 수 있습니다
Children ToolbarChild[] 아니요 이 도구 모음에 부모가 되어야 하는 명령, 메뉴 및 그룹 집합에 대해 설명합니다. 이러한 항목이 배열에 정의된 순서는 IDE에 시각적으로 표시되는 순서를 나타냅니다. 도구 모음의 항목 배치 참조

도구 모음에 항목 배치

도구 모음에 명령을 배치하는 작업은 메서드를 ToolbarChild.Command<T> 사용하여 수행되며 템플릿 인수를 클래스 이름으로 Command바꿔야 합니다.

[VisualStudioContribution]
public static ToolbarConfiguration MyToolbar => new("%MyToolbar.DisplayName%")
{
    Children = new[]
    {
        ToolbarChild.Command<MyCommand>(),
    },
};

도구 모음 항목을 그룹으로 구분

도구 모음 내의 항목은 항목 간을 ToolbarChild.Separator 사용하여 함께 그룹화할 수 있습니다. 시각적으로 두 항목 사이에 배치된 얇은 선처럼 보입니다.

[VisualStudioContribution]
public static ToolbarConfiguration MyToolbar => new("%MyToolbar.DisplayName%")
{
    Children = new[]
    {
        ToolbarChild.Command<MyCommand1>(), // Assuming there is a `Command` defined in the extension called `MyCommand1`
        ToolbarChild.Separator,
        ToolbarChild.Command<MyCommand2>(), // Assuming there is a `Command` defined in the extension called `MyCommand2`
    },
};

이 작업은 메서드를 사용하여 ToolbarChild.Group 그룹 인라인을 정의하여 수행할 수도 있습니다. 그런 다음 클래스를 ToolbarChild 사용하여 그룹에 대한 부모 항목을 사용합니다.

[VisualStudioContribution]
public static ToolbarConfiguration MyToolbar => new("%MyToolbar.DisplayName%")
{
    Children = new[]
    {
        ToolbarChild.Group(
            GroupChild.Command<MyCommand1>(), // Assuming there is a `Command` defined in the extension called `MyCommand1`
        ToolbarChild.Group(
            GroupChild.Command<MyCommand2>(), // Assuming there is a `Command` defined in the extension called `MyCommand2`
    },
};

여기에 있는 두 예제에서 결과 도구 모음은 IDE에서 동일합니다. 도구 모음 MyToolbar 은 아래 스크린샷의 도구 모음과 같습니다.

Screenshot of a toolbar with separator.

그룹 만들기

그룹은 인접 그룹의 마지막 항목과 첫 번째 항목 사이에 구분 기호가 배치되는 항목의 시각적 그룹입니다. 위의 섹션에서는 MenuConfiguration 또는 ToolbarConfigurationChildren 속성 컨텍스트 내부에 그룹을 만드는 방법을 설명합니다. 자체 CommandGroupConfiguration그룹 내부에 그룹을 정의할 수도 있습니다. 이는 고유한 메뉴 또는 도구 모음을 정의하지 않고 Visual Studio의 기존 메뉴 또는 도구 모음에 그룹을 부모로 지정하려는 경우에 유용합니다. 그룹 정의를 메뉴 및 도구 모음 정의와 구분하는 방식으로 코드의 서식을 지정하려는 경우에도 유용할 수 있습니다.

새 확장성 모델을 사용하여 그룹을 만들려면 정적 CommandGroupConfiguration 속성을 추가합니다. 이 정적 속성은 확장 프로젝트의 모든 클래스에 배치할 수 있습니다. 새 확장성 모델 샘플에서는, 단순성을 위해 클래스에 Extension 존재합니다. 지정된 CommandGroupConfigurationPlacement경우 특성으로 VisualStudioContribution 표시되어야 합니다.

public static CommandGroupConfiguration MyGroup => new();

[VisualStudioContribution]
private static CommandGroupConfiguration MyGroupWithPlacement => new(GroupPlacement.KnownPlacements.ToolsMenu);

CommandGroupConfiguration 클래스

CommandGroupConfiguration 클래스에는 익숙해져야 하는 몇 가지 매개 변수가 있습니다.

매개 변수 Type 필수 설명
배치 GroupPlacement 아니요 그룹을 보호할 Visual Studio 내의 기존 메뉴 또는 도구 모음을 지정합니다. IDE에서 그룹 배치를 참조하세요.
Children GroupChild[] 아니요 이 그룹에 연결해야 하는 명령 및 메뉴 집합을 설명합니다. 이러한 항목이 배열에 정의된 순서는 IDE에 시각적으로 표시되는 순서를 나타냅니다. 그룹의 항목 배치에서 보기

IDE에 그룹 배치

Visual Studio에는 명령을 배치할 수 있는 잘 정의된 위치 집합이 있습니다. 이러한 배치는 클래스 Commands.GroupPlacement의 속성 CommandPlacement.KnownPlacements 에 의해 정의됩니다. KnownPlacements 의 현재 세트는 다음과 같습니다:

  • ToolsMenu - 명령은 Visual Studio의 최상위 "도구" 메뉴 아래에 있는 그룹에 배치됩니다.
  • ViewOtherWindowsMenu - Visual Studio의 최상위 "보기" -> "기타 창" 메뉴 아래의 그룹에 명령이 배치됩니다.
  • ExtensionsMenu - 명령은 Visual Studio의 최상위 "확장" 메뉴 아래에 있는 그룹에 배치됩니다.
[VisualStudioContribution]
public static CommandGroupConfiguration MyGroup1 => new(GroupPlacement.KnownPlacements.ToolsMenu);

[VisualStudioContribution]
public static CommandGroupConfiguration MyGroup2 => new(GroupPlacement.KnownPlacements.ExtensionsMenu.WithPriority(0x100));

그룹에 항목 배치

명령 및 메뉴는 CommandGroupConfigurationChildren 배열 속성을 사용하여 그룹에 배치할 수 있습니다.

그룹에 명령 배치

그룹에 명령을 배치하는 작업은 템플릿 인수를 Command 클래스 이름으로 대체하여 GroupChild.Command<T> 메서드를 사용하여 수행됩니다.

[VisualStudioContribution]
public static CommandGroupConfiguration MyGroup => new(GroupPlacement.KnownPlacements.ToolsMenu)
{
    Children = new[]
    {
        GroupChild.Command<MyCommand>(),
    },
};

그룹에 메뉴 배치

그룹에 메뉴를 배치하는 작업은 GroupChild.Menu 메서드를 사용하여 MenuConfiguration 를 매개 변수로 전달합니다.

[VisualStudioContribution]
public static MenuConfiguration MyMenu => new("%MyMenu.DisplayName%");

[VisualStudioContribution]
public static CommandGroupConfiguration MyGroup => new(GroupPlacement.KnownPlacements.ToolsMenu)
{
    Children = new[]
    {
        GroupChild.Menu(MyMenu),
    },
};

메뉴 또는 도구 모음에 그룹 배치

메뉴에 그룹을 배치하는 작업은 MenuChild.Group 방법을 사용하여 CommandGroupConfiguration 를 매개변수로 전달합니다. 도구 모음에 그룹을 배치하는 작업은 ToolbarChild.Group 방법을 사용하여 CommandGroupConfiguration 를 매개변수로 전달합니다. 이러한 방식으로 메뉴나 도구 모음에 부모화된 그룹은 null 이외의 값으로 설정된 CommandGroupConfigurationPlacement 속성을 가질 수 없으며, VisualStudioContribution 속성으로 꾸며져서는 안 됩니다.

private static CommandGroupConfiguration MyGroup => new()
{
    Children = new[]
    {
        GroupChild.Command<MyCommand1>(), // Assuming there is a `Command` defined in the extension called `MyCommand1`
        GroupChild.Command<MyCommand2>(), // Assuming there is a `Command` defined in the extension called `MyCommand2`
    },
};

[VisualStudioContribution]
public static MenuConfiguration MyMenu => new("%MyMenu.DisplayName%")
{
    Children = new[]
    {
        MenuChild.Group(MyGroup),
    },
};
private static CommandGroupConfiguration MyGroup => new()
{
    Children = new[]
    {
        GroupChild.Command<MyCommand1>(), // Assuming there is a `Command` defined in the extension called `MyCommand1`
        GroupChild.Command<MyCommand2>(), // Assuming there is a `Command` defined in the extension called `MyCommand2`
    },
}

[VisualStudioContribution]
public static ToolbarConfiguration MyToolbar => new("%MyToolbar.DisplayName%")
{
    Children = new[]
    {
        ToolbarChild.Group(MyGroup),
    },
};

배치 순서 지정(우선 순위)

배치는 동일한 그룹, 메뉴 또는 도구 모음에 부모로 설정된 다른 항목을 기준으로 VSCT에 정의된 컨트롤에 부모로 설정된 경우 해당 속성의 값 Priority 에 따라 정렬됩니다. Priority 속성은 unsigned short입니다. CommandPlacementGroupPlacement 의 기본 Priority 값은 0 이며, 원하는 Priority 값을 입력하고 CommandPlacement.WithPriority 또는 GroupPlacement.WithPriority 메서드를 호출하여 수정할 수 있습니다. PriorityCommandPlacement.VsctParentGroupPlacement.VsctParent 방법을 사용하고 원하는 Priority 를 직접 입력하여 설정할 수도 있습니다.

Priority 속성은 VisualStudio.확장성 모델을 사용하여 구성 개체를 통해 정의된 제어에 대한 항목을 양육할 때 관련되지 않습니다. 즉, 부모가 되는 그룹, 메뉴 또는 도구 모음은 CommandGroupConfiguration, MenuConfiguration 또는 ToolbarConfiguration를 사용하여 정의되었습니다.

GroupPlacement

GroupPlacement.KnownPlacements.ToolsMenu.WithPriority(0x0500);
// Parenting a group to the "Help" top level menu
GroupPlacement.VsctParent(new Guid("{d309f791-903f-11d0-9efc-00a0c911004f}"), id: 0x0088, priority: 0x0500);

CommandPlacement

CommandPlacement.KnownPlacements.ToolsMenu.WithPriority(0x0500);
// Parenting a command to the "Help -> About" group
CommandPlacement.VsctParent(new Guid("{d309f791-903f-11d0-9efc-00a0c911004f}"), id: 0x016B, priority: 0x0801);