Пример #1
0
 protected override int ExecCommandOnNode(Guid cmdGroup, uint cmd, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
 {
     if (cmdGroup == VsMenus.guidStandardCommandSet97)
     {
         switch ((VsCommands)cmd)
         {
         case VsCommands.Delete:
         case VsCommands.Remove:
             string message = string.Format(
                 DynamicProjectSR.GetString(DynamicProjectSR.SearchPathRemoveConfirmation),
                 this.Caption);
             string          title         = string.Empty;
             OLEMSGICON      icon          = OLEMSGICON.OLEMSGICON_WARNING;
             OLEMSGBUTTON    buttons       = OLEMSGBUTTON.OLEMSGBUTTON_OK | OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL;
             OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
             int             res           = Microsoft.VisualStudio.Shell.VsShellUtilities.ShowMessageBox(this.ProjectMgr.Site, title, message, icon, buttons, defaultButton);
             if (res == 1)
             {
                 Remove(false);
             }
             return(VSConstants.S_OK);
         }
     }
     return(base.ExecCommandOnNode(cmdGroup, cmd, nCmdexecopt, pvaIn, pvaOut));
 }
Пример #2
0
        /// <summary>
        /// Executes Add Search Path menu command.
        /// </summary>
        internal int AddSearchPath()
        {
            // Get a reference to the UIShell.
            IVsUIShell uiShell = GetService(typeof(SVsUIShell)) as IVsUIShell;

            if (null == uiShell)
            {
                return(VSConstants.S_FALSE);
            }
            //Create a fill in a structure that defines Browse for folder dialog
            VSBROWSEINFOW[] browseInfo = new VSBROWSEINFOW[1];
            //Dialog title
            browseInfo[0].pwzDlgTitle = DynamicProjectSR.GetString(DynamicProjectSR.SelectFolderForSearchPath);
            //Initial directory - project directory
            browseInfo[0].pwzInitialDir = _projectDir;
            //Parent window
            uiShell.GetDialogOwnerHwnd(out browseInfo[0].hwndOwner);
            //Max path length
            browseInfo[0].nMaxDirName = NativeMethods.MAX_PATH;
            //This struct size
            browseInfo[0].lStructSize = (uint)Marshal.SizeOf(typeof(VSBROWSEINFOW));
            //Memory to write selected directory to.
            //Note: this one allocates unmanaged memory, which must be freed later
            IntPtr pDirName = Marshal.AllocCoTaskMem(NativeMethods.MAX_PATH);

            browseInfo[0].pwzDirName = pDirName;
            try {
                //Show the dialog
                int hr = uiShell.GetDirectoryViaBrowseDlg(browseInfo);
                if (hr == VSConstants.OLE_E_PROMPTSAVECANCELLED)
                {
                    //User cancelled the dialog
                    return(VSConstants.S_OK);
                }
                //Check for any failures
                ErrorHandler.ThrowOnFailure(hr);
                //Get selected directory
                string dirName = Marshal.PtrToStringAuto(browseInfo[0].pwzDirName);
                AddSearchPathEntry(dirName);
            } finally {
                //Free allocated unmanaged memory
                if (pDirName != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pDirName);
                }
            }
            return(VSConstants.S_OK);
        }