방법: 현재 선택 항목 액세스 및 제약

도메인 관련 언어에 대 한 제스처 또는 명령 처리기를 작성 하는 경우 요소에서 사용자를 마우스 오른쪽 단추로 클릭을 확인할 수 있습니다.또한 일부 도형 또는 필드 선택에서 방지할 수 있습니다.예를 들어, 사용자 아이콘 데코레이터를 클릭 하면 포함 된 셰이프 대신 선택 됩니다 정렬할 수 있습니다.이 방식으로 선택 영역을 제한 작성 해야 하는 처리기의 수를 줄일 수 있습니다.또한 그는 데코레이터를 방지 하지 않고 도형에서 아무 곳 이나 클릭 수 사용자에 대 한 쉽습니다.

명령 처리기에서 현재 선택 영역에 액세스

도메인 관련 언어에 대 한 명령 집합 클래스에 사용자 지정 명령에 대 한 명령 처리기를 포함 되어 있습니다.CommandSet 파생 되는 도메인-특정 언어에 대 한 명령 집합 클래스, 클래스, 현재 선택 영역에 액세스 하기 위한 몇 가지 멤버를 제공 합니다.

명령에 따라 명령 처리기 모델 디자이너, 모델 탐색기 또는 현재 창에서 선택을 해야 합니다.

선택 정보에 액세스 하려면

  1. CommandSet 클래스는 현재 선택 영역에 액세스 하는 데 사용할 수 있는 다음 멤버를 정의 합니다.

    멤버

    설명

    IsAnyDocumentSelectionCompartment 메서드

    반환 true 모델 디자이너에서 선택한 요소 중 하나에 경우 구획 모양입니다. 그렇지 않으면 false.

    IsDiagramSelected 메서드

    반환 true ; 모델 디자이너에서 다이어그램을 선택한 경우 그렇지 않으면 false.

    IsSingleDocumentSelection 메서드

    반환 true 모델 디자이너에서; 정확 하 게 하나의 요소를 선택한 경우 그렇지 않으면 false.

    IsSingleSelection 메서드

    반환 true ; 현재 창에서 정확히 하나의 요소를 선택한 경우 그렇지 않으면 false.

    CurrentDocumentSelection 속성

    모델 디자이너에서 선택 된 요소의 읽기 전용 컬렉션을 가져옵니다.

    CurrentSelection 속성

    현재 창에서 선택 된 요소의 읽기 전용 컬렉션을 가져옵니다.

    SingleDocumentSelection 속성

    모델 디자이너에서 선택 영역의 기본 요소를 가져옵니다.

    SingleSelection 속성

    현재 창에서 선택 영역의 기본 요소를 가져옵니다.

  2. CurrentDocView 속성에는 CommandSet 클래스에 액세스할 수 있습니다의 DiagramDocView 모델 디자이너 창을 나타내며 모델 디자이너에서 선택한 요소 추가 액세스를 제공 하는 개체.

  3. 또한 탐색기 도구 창의 속성은 생성 된 코드를 정의 하 고 도메인-특정 언어에 대 한 클래스는 탐색기 선택 항목 속성 명령에서 설정 합니다.

    • 탐색기 도구 창의 속성 도메인-특정 언어에 대 한 탐색기 도구 창 클래스의 인스턴스를 반환합니다.탐색기 도구 창 클래스에서 파생 되는 ModelExplorerToolWindow 클래스 및 모델 탐색기의 도메인 관련 언어를 나타냅니다.

    • [ExplorerSelection] 속성 도메인-특정 언어에 대 한 모델 탐색기 창에서 선택한 요소를 반환 합니다.

활성 창을 결정

IMonitorSelectionService 인터페이스 포함 셸의 현재 선택 상태에 액세스 하는 멤버를 정의 합니다.얻을 수 있습니다는 IMonitorSelectionService 패키지 클래스 또는 도메인 관련 언어를 통해 명령 집합 클래스의 개체는 [MonitorSelection] 각 기본 클래스에 정의 된 속성입니다.패키지 클래스에서 파생 되는 ModelingPackage 클래스 및 명령 집합 클래스에서 파생 하는 데는 CommandSet 클래스입니다.

명령 처리기에서 어떤 유형의 창 활성화시킬지 결정 하려면

  1. MonitorSelection 속성에는 CommandSet 반환 클래스는 IMonitorSelectionService 셸의 현재 선택 상태에 액세스 하는 개체.

  2. CurrentSelectionContainer 속성에는 IMonitorSelectionService 인터페이스를 활성 창에서 다를 수 있습니다 활성 선택 컨테이너를 가져옵니다.

  3. 다음 속성은 명령 클래스 활성 창의 유형을 확인 하는 도메인 관련 언어 설정 추가.

    // using Microsoft.VisualStudio.Modeling.Shell;
    
    // Returns true if the model designer is the active selection container;
    // otherwise, false.
    protected bool IsDesignerActive
    {
        get
        {
            return (this.MonitorSelection.CurrentSelectionContainer
                is DiagramDocView);
        }
    }
    
    // Returns true if the model explorer is the active selection container;
    // otherwise, false.
    protected bool IsExplorerActive
    {
        get
        {
            return (this.MonitorSelection.CurrentSelectionContainer
                is ModelExplorerToolWindow);
        }
    }
    

선택 영역 제한

선택 규칙을 추가 하 여 모델에 있는 요소를 선택할 때 어떤 요소를 선택 제어할 수 있습니다.예를 들어, 여러 요소를 하나의 단위로 취급 하는 사용자가 선택 하는 규칙을 사용 합니다.

선택 영역 규칙을 만들려면

  1. DSL 프로젝트에 사용자 지정 코드 파일 만들기

  2. 선택 규칙 클래스에서 파생 된 정의 DiagramSelectionRules 클래스입니다.

  3. 재정의 GetCompliantSelection 선택 기준을 적용 선택 영역 규칙 클래스 메서드를.

  4. Partial 클래스 정의에 추가 [ClassDiagram] 클래스에서 사용자 지정 코드 파일입니다.

    [ClassDiagram] 클래스에서 파생의 Diagram 클래스와 생성 된 코드 파일에서 Diagram.cs, DSL 프로젝트에 정의 됩니다.

  5. 재정의 SelectionRules 속성에는 [ClassDiagram] 클래스에서 사용자 지정 선택 규칙을 반환 합니다.

    기본 구현에서 SelectionRules 속성 선택 영역을 수정 하지 않는 선택 영역 rule 개체를 가져옵니다.

Dd820621.collapse_all(ko-kr,VS.110).gif예제

처음에 선택 된 도메인 셰이프의 모든 인스턴스를 포함 하도록 선택 영역 확장 선택 규칙 다음 코드 파일을 만듭니다.

using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.Modeling;
using Microsoft.VisualStudio.Modeling.Diagrams;

namespace CompanyName.ProductName.GroupingDsl
{
    public class CustomSelectionRules : DiagramSelectionRules
    {
        protected Diagram diagram;
        protected IElementDirectory elementDirectory;

        public CustomSelectionRules(Diagram diagram)
        {
            if (diagram == null) throw new ArgumentNullException();

            this.diagram = diagram;
            this.elementDirectory = diagram.Store.ElementDirectory;
        }

        /// <summary>Called by the design surface to allow selection filtering.
        /// </summary>
        /// <param name="currentSelection">[in] The current selection before any
        /// ShapeElements are added or removed.</param>
        /// <param name="proposedItemsToAdd">[in/out] The proposed DiagramItems to
        /// be added to the selection.</param>
        /// <param name="proposedItemsToRemove">[in/out] The proposed DiagramItems
        /// to be removed from the selection.</param>
        /// <param name="primaryItem">[in/out] The proposed DiagramItem to become
        /// the primary DiagramItem of the selection. A null value signifies that
        /// the last DiagramItem in the resultant selection should be assumed as
        /// the primary DiagramItem.</param>
        /// <returns>true if some or all of the selection was accepted; false if
        /// the entire selection proposal was rejected. If false, appropriate
        /// feedback will be given to the user to indicate that the selection was
        /// rejected.</returns>
        public override bool GetCompliantSelection(
            SelectedShapesCollection currentSelection,
            DiagramItemCollection proposedItemsToAdd,
            DiagramItemCollection proposedItemsToRemove,
            DiagramItem primaryItem)
        {
            if (currentSelection.Count == 0 && proposedItemsToAdd.Count == 0) return true;

            HashSet<DomainClassInfo> itemsToAdd = new HashSet<DomainClassInfo>();

            foreach (DiagramItem item in proposedItemsToAdd)
            {
                if (item.Shape != null)
                    itemsToAdd.Add(item.Shape.GetDomainClass());
            }
            proposedItemsToAdd.Clear();
            foreach (DomainClassInfo classInfo in itemsToAdd)
            {
                foreach (ModelElement element
                    in this.elementDirectory.FindElements(classInfo, false))
                {
                    if (element is ShapeElement)
                    {
                        proposedItemsToAdd.Add(
                            new DiagramItem((ShapeElement)element));
                    }
                }
            }

            return true;
        }
    }

    public partial class ClassDiagram
    {
        protected CustomSelectionRules customSelectionRules = null;

        protected bool multipleSelectionMode = true;

        public override DiagramSelectionRules SelectionRules
        {
            get
            {
                if (multipleSelectionMode)
                {
                    if (customSelectionRules == null)
                    {
                        customSelectionRules = new CustomSelectionRules(this);
                    }
                    return customSelectionRules;
                }
                else
                {
                    return base.SelectionRules;
                }
            }
        }
    }
}

참고 항목

참조

CommandSet

ModelingPackage

DiagramDocView

ModelExplorerToolWindow

IMonitorSelectionService

DiagramSelectionRules

Diagram