2012-12-02 1 views
3

내가 패키지 클래스에이 특성을 사용하여 VS에서 도구 창을 노출하고 있습니다 :VSIX :보기 -에 도구 창을 추가> 기타 윈도우

[ProvideToolWindow(typeof(MyToolWindow), 
     Style = VsDockStyle.Tabbed, 
     Orientation = ToolWindowOrientation.Right)] 

이 잘 작동하고 나는 그것을 프로그래밍이 코드를 사용하여 열 수 있습니다 :

private void ShowToolWindow() 
    { 
    //this method will show the window if it's not active or bring it to front if it's collapsed 
    ToolWindowPane window = this.FindToolWindow(typeof(MyToolWindow), 0, true); 
    if ((null == window) || (null == window.Frame)) 
    { 
     throw new NotSupportedException(); 
    } 
    IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; 
    Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show()); 
    } 

그러나 사용자가 우연히 창을 닫으면 복원 할 방법이 없습니다. 다른 확장 프로그램이 NuGet과 같이 Tools-> Other Windows에 어떻게 추가하는지 궁금합니다. NuGet 소스 코드에서 아무 것도 발견 할 수 없었습니다.

+0

안녕하세요. VSIX 기본 사항을 시작하는 데 도움을 줄 수 있습니까? 이전에 VS Add-in을 만들었으니 이제 vsix로 마이그레이션하고 싶습니다. 내 추가 기능은 도구 창으로 구성되어 있습니다 –

답변

3

ShowToolWindow 루틴을 호출하는 명령을 추가해야합니다.

파일이 몇 외부 참조해야합니다 vsct 패키지의 상단 :

<!--This is the file that defines the IDs for all the commands exposed by VisualStudio. --> 
<Extern href="stdidcmd.h"/> 
<!--This header contains the command ids for the menus provided by the shell. --> 
<Extern href="vsshlids.h"/> 

일부 기호 정의해야이 파일을 패키지의 vsct 파일의 Buttons 블록에서

<Symbols> 
    <!-- Use your package guid. --> 
    <GuidSymbol name="guidPackage" value="{00000000-0000-0000-0000-000000000000}" /> 

    <!-- Use a new GUID to uniquely identify your package commands --> 
    <GuidSymbol name="guidCmdSet" value="{11111111-1111-1111-1111-111111111111}"> 
     <IDSymbol name="cmdidViewMyToolWindow" value="0x0500" /> 
    </GuidSymbol> 
</Symbols> 

를 추가를 다음과 같아야합니다.

<Button guid="guidCmdSet" id="cmdidViewMyToolWindow" priority="0x0100" type="Button"> 
    <!--IDG_VS_WNDO_OTRWNDWS0 is the first group in "View|Other Windows". See 
    C:\Program Files (x86)\Microsoft Visual Studio 2010 SDK SP1\VisualStudioIntegration\Common\Inc 
    for other options. --> 
    <Parent guid="guidSHLMainMenu" id="IDG_VS_WNDO_OTRWNDWS0"/> 
    <CommandFlag>DynamicVisibility</CommandFlag> 
    <CommandFlag>DefaultInvisible</CommandFlag> 
    <Strings> 
     <ButtonText>View &amp;My Tool Window</ButtonText> 
    </Strings> 
</Button> 

이 모든 항목은 "내 T ool Window "가 View 메뉴의 상단 섹션에 나타납니다. 이제 누군가가 클릭하면 행동을 취해야합니다.

귀하의 패키지 명령 가시성을 다루는 IOleCommandTarget를 구현 가능하게한다 :

public class MyPackage : Package, IOleCommandTarget 
{ 
    #region IOleCommandTarget implementation 

    /// <summary> 
    /// The VS shell calls this function to know if a menu item should be visible and 
    /// if it should be enabled/disabled. 
    /// This is called only when the package is active. 
    /// </summary> 
    /// <param name="guidCmdGroup">Guid describing which set of commands the current command(s) belong to</param> 
    /// <param name="cCmds">Number of commands for which status are being asked</param> 
    /// <param name="prgCmds">Information for each command</param> 
    /// <param name="pCmdText">Used to dynamically change the command text</param> 
    /// <returns>HRESULT</returns> 
    public int QueryStatus(ref Guid guidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) 
    { 
     // Filter out commands that are not defined by this package 
     if (guidCmdGroup != new Guid("{00000000-0000-0000-0000-000000000000}")) 
      return (int)(Constants.OLECMDERR_E_NOTSUPPORTED); 

     if (cCmds == 0 || prgCmds == null || prgCmds.Length == 0 || cCmds != prgCmds.Length) 
      return VSConstants.E_INVALIDARG; 

     // Show and enable all commands. 
     OLECMDF cmdf = OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED; 
     for (int i = 0; i < cCmds; i++) 
      prgCmds[i].cmdf = (uint)cmdf; 

     return VSConstants.S_OK; 
    } 

    #endregion 
} 

을 그리고 마지막으로, 패키지에서 루틴을 초기화, 당신은 당신의 명령을 클릭 할 때 무엇을해야 하는지를 쉘에게 :

protected override void Initialize() 
{ 
    base.Initialize(); 

    // Add our command handlers (commands must exist in the .vsct file) 
    OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; 
    if (null != mcs) 
    { 
     // "View My Tool Window" command callback 
     CommandID menuCommandID = new CommandID(new Guid("{11111111-1111-1111-1111-111111111111}"), (int)0x500); 
     MenuCommand menuItem = new MenuCommand(ShowToolWindow, menuCommandID); 
     mcs.AddCommand(menuItem); 
    } 
} 

"실제"코드에서는 vsct에 정의 된 기호와 일치하는 C#의 GUID 상수를 일부 정의하고이를 통해 사용할 수 있습니다.

+0

감사합니다. 코드 검토를위한 내 확장 기능의 마지막 비트입니다. - IronBoard –