Esempio n. 1
0
        //
        // Open the Visual Studio native dialog for selecting a directory
        //
        public static String BrowserFolderDialog(IntPtr owner, String title, String initialDirectory)
        {
            IVsUIShell shell = Package.Instance.UIShell;

            VSBROWSEINFOW[] browseInfo = new VSBROWSEINFOW[1];
            browseInfo[0].lStructSize = (uint)Marshal.SizeOf(typeof(VSBROWSEINFOW));
            browseInfo[0].pwzInitialDir = initialDirectory;
            browseInfo[0].pwzDlgTitle = title;
            browseInfo[0].hwndOwner = owner;
            browseInfo[0].nMaxDirName = 260;
            IntPtr pDirName = Marshal.AllocCoTaskMem(520);
            browseInfo[0].pwzDirName = pDirName;

            try
            {
                int hr = shell.GetDirectoryViaBrowseDlg(browseInfo);
                if (hr == VSConstants.OLE_E_PROMPTSAVECANCELLED)
                {
                    return String.Empty;
                }
                ErrorHandler.ThrowOnFailure(hr);
                return Marshal.PtrToStringAuto(browseInfo[0].pwzDirName);
            }
            finally
            {
                if (pDirName != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pDirName);
                }
            }
        }
        //
        // Open the Visual Studio native dialog for selecting a directory
        //
        public static String BrowserFolderDialog(IntPtr owner, String title, String initialDirectory)
        {
            IVsUIShell shell = Package.Instance.UIShell;

            VSBROWSEINFOW[] browseInfo = new VSBROWSEINFOW[1];
            browseInfo[0].lStructSize   = (uint)Marshal.SizeOf(typeof(VSBROWSEINFOW));
            browseInfo[0].pwzInitialDir = initialDirectory;
            browseInfo[0].pwzDlgTitle   = title;
            browseInfo[0].hwndOwner     = owner;
            browseInfo[0].nMaxDirName   = 260;
            IntPtr pDirName = Marshal.AllocCoTaskMem(520);

            browseInfo[0].pwzDirName = pDirName;

            try
            {
                int hr = shell.GetDirectoryViaBrowseDlg(browseInfo);
                if (hr == VSConstants.OLE_E_PROMPTSAVECANCELLED)
                {
                    return(String.Empty);
                }
                ErrorHandler.ThrowOnFailure(hr);
                return(Marshal.PtrToStringAuto(browseInfo[0].pwzDirName));
            }
            finally
            {
                if (pDirName != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pDirName);
                }
            }
        }
Esempio n. 3
0
        private void OnBrowseButtonClick(object sender, RoutedEventArgs e)
        {
            var block = System.IntPtr.Zero;

            try {
                var dte             = VsServiceProvider.GetService <DTE>();
                var serviceProvider = new ServiceProvider(dte as IServiceProvider);
                var iVsUIShell      = VsServiceProvider.GetService <SVsUIShell, IVsUIShell>();

                System.IntPtr owner;
                iVsUIShell.GetDialogOwnerHwnd(out owner);

                var browseInfo = new VSBROWSEINFOW[1];
                browseInfo[0].lStructSize   = (uint)Marshal.SizeOf(typeof(VSBROWSEINFOW));
                browseInfo[0].pwzInitialDir = Location;
                browseInfo[0].pwzDlgTitle   = @"Location";
                browseInfo[0].hwndOwner     = owner;
                browseInfo[0].nMaxDirName   = 260;
                block = Marshal.AllocCoTaskMem(520);
                browseInfo[0].pwzDirName = block;

                var result = iVsUIShell.GetDirectoryViaBrowseDlg(browseInfo);
                if (result == Microsoft.VisualStudio.VSConstants.S_OK)
                {
                    Location = Marshal.PtrToStringAuto(browseInfo[0].pwzDirName);
                    LocationComboBox.Text = Marshal.PtrToStringAuto(browseInfo[0].pwzDirName);
                }
            } finally {
                if (block != System.IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(block);
                }
            }
        }
Esempio n. 4
0
        public static string GetDirectoryViaBrowseDialog(this IVsUIShell2 shell, IntPtr parentWindow, Guid persistenceSlot, string title, string initialDirectory, bool overridePersistedInitialDirectory)
        {
            if (shell == null)
            {
                throw new ArgumentNullException("shell");
            }
            if (title == null)
            {
                throw new ArgumentNullException("title");
            }

            const int MaxDirName    = 10000;
            IntPtr    dirNameBuffer = Marshal.AllocCoTaskMem((MaxDirName + 1) * sizeof(char));

            try
            {
                VSBROWSEINFOW[] browse = new VSBROWSEINFOW[]
                {
                    new VSBROWSEINFOW
                    {
                        pwzDlgTitle   = title,
                        dwFlags       = (uint)BrowseInfoFlags.ReturnOnlyFileSystemDirectories,
                        hwndOwner     = parentWindow,
                        pwzInitialDir = GetInitialDirectoryToUse(initialDirectory, overridePersistedInitialDirectory, persistenceSlot),
                        nMaxDirName   = MaxDirName,
                        lStructSize   = (uint)Marshal.SizeOf(typeof(VSBROWSEINFOW)),
                        pwzDirName    = dirNameBuffer,
                        dwHelpTopic   = 0
                    }
                };

                string             helpTopic       = string.Empty;
                string             openButtonLabel = null;
                string             ceilingDir      = null;
                VSNSEBROWSEINFOW[] nseBrowseInfo   = null;

                ErrorHandler.ThrowOnFailure(shell.GetDirectoryViaBrowseDlgEx(browse, helpTopic, openButtonLabel, ceilingDir, nseBrowseInfo));
                string folder = Marshal.PtrToStringUni(browse[0].pwzDirName);
                if (!string.IsNullOrEmpty(folder))
                {
                    PersistLastUseDirectory(persistenceSlot, folder);
                }

                return(folder);
            }
            catch (COMException ex) when(ex.ErrorCode == VSConstants.OLE_E_PROMPTSAVECANCELLED)
            {
            }
            finally
            {
                if (dirNameBuffer != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(dirNameBuffer);
                    dirNameBuffer = IntPtr.Zero;
                }
            }

            return(null);
        }
Esempio n. 5
0
        public static String BrowseForDirectory(IntPtr owner, string initialDirectory = null, string title = null)
        {
            IVsUIShell uiShell = (IVsUIShell)Package.GetGlobalService(typeof(SVsUIShell));

            if (null == uiShell)
            {
                using (var ofd = new FolderBrowserDialog()) {
                    ofd.RootFolder          = Environment.SpecialFolder.Desktop;
                    ofd.SelectedPath        = initialDirectory;
                    ofd.ShowNewFolderButton = false;
                    DialogResult result;
                    if (owner == IntPtr.Zero)
                    {
                        result = ofd.ShowDialog();
                    }
                    else
                    {
                        result = ofd.ShowDialog(NativeWindow.FromHandle(owner));
                    }
                    if (result == DialogResult.OK)
                    {
                        return(ofd.SelectedPath);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            if (owner == IntPtr.Zero)
            {
                ErrorHandler.ThrowOnFailure(uiShell.GetDialogOwnerHwnd(out owner));
            }
            VSBROWSEINFOW[] browseInfo = new VSBROWSEINFOW[1];
            browseInfo[0].lStructSize   = (uint)Marshal.SizeOf(typeof(VSBROWSEINFOW));
            browseInfo[0].pwzInitialDir = initialDirectory;
            browseInfo[0].pwzDlgTitle   = title;
            browseInfo[0].hwndOwner     = owner;
            browseInfo[0].nMaxDirName   = 260;
            IntPtr pDirName = IntPtr.Zero;

            try {
                browseInfo[0].pwzDirName = pDirName = Marshal.AllocCoTaskMem(520);
                int hr = uiShell.GetDirectoryViaBrowseDlg(browseInfo);
                if (hr == VSConstants.OLE_E_PROMPTSAVECANCELLED)
                {
                    return(null);
                }
                ErrorHandler.ThrowOnFailure(hr);
                return(Marshal.PtrToStringAuto(browseInfo[0].pwzDirName));
            }
            finally {
                if (pDirName != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pDirName);
                }
            }
        }
        public static string GetDirectoryViaBrowseDialog(this IVsUIShell2 shell, IntPtr parentWindow, Guid persistenceSlot, string title, string initialDirectory, bool overridePersistedInitialDirectory)
        {
            if (shell == null)
                throw new ArgumentNullException("shell");
            if (title == null)
                throw new ArgumentNullException("title");

            const int MaxDirName = 10000;
            IntPtr dirNameBuffer = Marshal.AllocCoTaskMem((MaxDirName + 1) * sizeof(char));
            try
            {
                VSBROWSEINFOW[] browse = new VSBROWSEINFOW[]
                    {
                        new VSBROWSEINFOW
                        {
                            pwzDlgTitle = title,
                            dwFlags = (uint)BrowseInfoFlags.ReturnOnlyFileSystemDirectories,
                            hwndOwner = parentWindow,
                            pwzInitialDir = GetInitialDirectoryToUse(initialDirectory, overridePersistedInitialDirectory, persistenceSlot),
                            nMaxDirName = MaxDirName,
                            lStructSize = (uint)Marshal.SizeOf(typeof(VSBROWSEINFOW)),
                            pwzDirName = dirNameBuffer,
                            dwHelpTopic = 0
                        }
                    };

                string helpTopic = string.Empty;
                string openButtonLabel = null;
                string ceilingDir = null;
                VSNSEBROWSEINFOW[] nseBrowseInfo = null;

                ErrorHandler.ThrowOnFailure(shell.GetDirectoryViaBrowseDlgEx(browse, helpTopic, openButtonLabel, ceilingDir, nseBrowseInfo));
                string folder = Marshal.PtrToStringUni(browse[0].pwzDirName);
                if (!string.IsNullOrEmpty(folder))
                    PersistLastUseDirectory(persistenceSlot, folder);

                return folder;
            }
            catch (COMException ex)
            {
                if (ex.ErrorCode != VSConstants.OLE_E_PROMPTSAVECANCELLED)
                    throw;
            }
            finally
            {
                if (dirNameBuffer != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(dirNameBuffer);
                    dirNameBuffer = IntPtr.Zero;
                }
            }

            return null;
        }
        private async Task OnBrowseButtonClickedAsync()
        {
            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            const int MaxDirectoryLength = 1000;

            //const int BIF_RETURNONLYFSDIRS = 0x00000001;   // For finding a folder to start document searching.
            const int BIF_BROWSEINCLUDEURLS = 0x00000080; // Allow URLs to be displayed or entered.

            var uiShell = await _asyncServiceProvider.GetServiceAsync <SVsUIShell, IVsUIShell2>();

            Assumes.Present(uiShell);
            var rgch = new char[MaxDirectoryLength + 1];

            // allocate a buffer in unmanaged memory for file name (string)
            var bufferPtr = Marshal.AllocCoTaskMem((rgch.Length + 1) * 2);

            // copy initial path to bufferPtr
            Marshal.Copy(rgch, 0, bufferPtr, rgch.Length);

            var pBrowse = new VSBROWSEINFOW[1];

            pBrowse[0] = new VSBROWSEINFOW
            {
                lStructSize   = (uint)Marshal.SizeOf(pBrowse[0]),
                dwFlags       = BIF_BROWSEINCLUDEURLS,
                pwzDlgTitle   = Resources.BrowseFolderDialogDescription,
                nMaxDirName   = MaxDirectoryLength,
                hwndOwner     = Handle,
                pwzDirName    = bufferPtr,
                pwzInitialDir = DetermineInitialDirectory()
            };

            var browseInfo = new VSNSEBROWSEINFOW[1] {
                new VSNSEBROWSEINFOW()
            };

            var ret = uiShell.GetDirectoryViaBrowseDlgEx(pBrowse, "", Resources.BrowseFolderDialogSelectButton, "", browseInfo);

            if (ret == VSConstants.S_OK)
            {
                var pathPtr = pBrowse[0].pwzDirName;
                var path    = Marshal.PtrToStringAuto(pathPtr);
                NewPackageSource.Text = path;

                // if the package name text box is empty, we fill it with the selected folder's name
                if (string.IsNullOrEmpty(NewPackageName.Text))
                {
                    NewPackageName.Text = Path.GetFileName(path);
                }
            }
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        private void OnBrowseButtonClicked(object sender, EventArgs e)
        {
            const int MaxDirectoryLength = 1000;

            //const int BIF_RETURNONLYFSDIRS = 0x00000001;   // For finding a folder to start document searching.
            const int BIF_BROWSEINCLUDEURLS = 0x00000080;   // Allow URLs to be displayed or entered.

            var uiShell = (IVsUIShell2)_serviceProvider.GetService(typeof(SVsUIShell));

            char[] rgch = new char[MaxDirectoryLength + 1];

            // allocate a buffer in unmanaged memory for file name (string)
            IntPtr bufferPtr = Marshal.AllocCoTaskMem((rgch.Length + 1) * 2);

            // copy initial path to bufferPtr
            Marshal.Copy(rgch, 0, bufferPtr, rgch.Length);

            VSBROWSEINFOW[] pBrowse = new VSBROWSEINFOW[1];
            pBrowse[0] = new VSBROWSEINFOW()
            {
                lStructSize   = (uint)Marshal.SizeOf(pBrowse[0]),
                dwFlags       = (uint)(BIF_BROWSEINCLUDEURLS),
                pwzDlgTitle   = Resources.BrowseFolderDialogDescription,
                nMaxDirName   = (uint)MaxDirectoryLength,
                hwndOwner     = this.Handle,
                pwzDirName    = bufferPtr,
                pwzInitialDir = DetermineInitialDirectory()
            };

            var browseInfo = new VSNSEBROWSEINFOW[1] {
                new VSNSEBROWSEINFOW()
            };

            int ret = uiShell.GetDirectoryViaBrowseDlgEx(pBrowse, "", Resources.BrowseFolderDialogSelectButton, "", browseInfo);

            if (ret == VSConstants.S_OK)
            {
                var pathPtr = pBrowse[0].pwzDirName;
                var path    = Marshal.PtrToStringAuto(pathPtr);
                NewPackageSource.Text = path;

                // if the package name text box is empty, we fill it with the selected folder's name
                if (String.IsNullOrEmpty(NewPackageName.Text))
                {
                    NewPackageName.Text = Path.GetFileName(path);
                }
            }
        }
Esempio n. 10
0
        public static string SelectDirectoryUsingDialog(IntPtr handle, string title, string startFolder, string helpTopic,
                                                        string openButtonLabel)
        {
            var vsUiShell2 = GetService(typeof(SVsUIShell)) as IVsUIShell2;

            if (vsUiShell2 == null)
            {
                return(null);
            }
            var vsbrowseinfow = new VSBROWSEINFOW();
            var ptr           = Marshal.AllocCoTaskMem(2048);

            vsbrowseinfow.lStructSize   = (uint)Marshal.SizeOf(typeof(VSBROWSEINFOW));
            vsbrowseinfow.hwndOwner     = handle;
            vsbrowseinfow.pwzDirName    = ptr;
            vsbrowseinfow.nMaxDirName   = 1024U;
            vsbrowseinfow.pwzDlgTitle   = title;
            vsbrowseinfow.pwzInitialDir = startFolder;
            vsbrowseinfow.dwFlags       = 1U;
            string str = null;

            try
            {
                if (vsUiShell2.GetDirectoryViaBrowseDlgEx(new[]
                {
                    vsbrowseinfow
                }, helpTopic, openButtonLabel, null, null) == 0)
                {
                    str = Marshal.PtrToStringAuto(ptr);
                }
            }
            finally
            {
                if (ptr != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(ptr);
                }
            }
            return(str);
        }
Esempio n. 11
0
        private string GetFolder(string title, string starting)
        {
            var shell = CompareDirectoriesPackage.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell;

            if (shell != null)
            {
                const int       MaxBuffer  = 2048;
                VSBROWSEINFOW[] browseInfo = new VSBROWSEINFOW[1];
                IntPtr          ownerHwnd;

                shell.GetDialogOwnerHwnd(out ownerHwnd);

                browseInfo[0].lStructSize = (uint)Marshal.SizeOf(typeof(VSBROWSEINFOW));
                browseInfo[0].pwzDlgTitle = title;
                browseInfo[0].dwFlags     = 1; // RestrictToFilesystem;
                browseInfo[0].nMaxDirName = 1024;

                browseInfo[0].pwzInitialDir = string.IsNullOrWhiteSpace(starting) ? Environment.CurrentDirectory : starting;
                browseInfo[0].hwndOwner     = ownerHwnd;

                try
                {
                    browseInfo[0].pwzDirName = Marshal.AllocCoTaskMem(MaxBuffer);

                    if (shell.GetDirectoryViaBrowseDlg(browseInfo) == VSConstants.S_OK)
                    {
                        starting = Marshal.PtrToStringAuto(browseInfo[0].pwzDirName);
                    }
                }
                finally
                {
                    Marshal.FreeCoTaskMem(browseInfo[0].pwzDirName);
                }
            }

            return(starting);
        }
Esempio n. 12
0
        private string BrowseForDirectory(string initialDirectory)
        {
            IVsUIShell uiShell = _provider.GetService(typeof(SVsUIShell)) as IVsUIShell;
            if (null == uiShell) {
                using (var ofd = new FolderBrowserDialog()) {
                    ofd.RootFolder = Environment.SpecialFolder.Desktop;
                    ofd.ShowNewFolderButton = false;
                    var result = ofd.ShowDialog(this);
                    if (result == DialogResult.OK) {
                        return ofd.SelectedPath;
                    } else {
                        return null;
                    }
                }
            }

            VSBROWSEINFOW[] browseInfo = new VSBROWSEINFOW[1];
            browseInfo[0].lStructSize = (uint)Marshal.SizeOf(typeof(VSBROWSEINFOW));
            browseInfo[0].pwzInitialDir = initialDirectory;
            browseInfo[0].hwndOwner = Handle;
            browseInfo[0].nMaxDirName = 260;
            IntPtr pDirName = Marshal.AllocCoTaskMem(520);
            browseInfo[0].pwzDirName = pDirName;
            try {
                int hr = uiShell.GetDirectoryViaBrowseDlg(browseInfo);
                if (hr == VSConstants.OLE_E_PROMPTSAVECANCELLED) {
                    return null;
                }
                ErrorHandler.ThrowOnFailure(hr);
                return Marshal.PtrToStringAuto(browseInfo[0].pwzDirName);
            } finally {
                if (pDirName != IntPtr.Zero) {
                    Marshal.FreeCoTaskMem(pDirName);
                }
            }
        }
 int IVsUIShell.GetDirectoryViaBrowseDlg(VSBROWSEINFOW[] browse)
 {
     throw new NotImplementedException();
 }
        private void OnBrowseButtonClicked(object sender, EventArgs e)
        {
            const int MaxDirectoryLength = 1000;

            //const int BIF_RETURNONLYFSDIRS = 0x00000001;   // For finding a folder to start document searching.
            const int BIF_BROWSEINCLUDEURLS = 0x00000080;   // Allow URLs to be displayed or entered.

            var uiShell = (IVsUIShell2)_serviceProvider.GetService(typeof(SVsUIShell));

            char[] rgch = new char[MaxDirectoryLength + 1];

            // allocate a buffer in unmanaged memory for file name (string)
            IntPtr bufferPtr = Marshal.AllocCoTaskMem((rgch.Length + 1) * 2);
            // copy initial path to bufferPtr
            Marshal.Copy(rgch, 0, bufferPtr, rgch.Length);

            VSBROWSEINFOW[] pBrowse = new VSBROWSEINFOW[1];
            pBrowse[0] = new VSBROWSEINFOW()
            {
                lStructSize = (uint)Marshal.SizeOf(pBrowse[0]),
                dwFlags = (uint)(BIF_BROWSEINCLUDEURLS),
                pwzDlgTitle = Resources.BrowseFolderDialogDescription,
                nMaxDirName = (uint)MaxDirectoryLength,
                hwndOwner = this.Handle,
                pwzDirName = bufferPtr,
                pwzInitialDir = DetermineInitialDirectory()
            };

            var browseInfo = new VSNSEBROWSEINFOW[1] { new VSNSEBROWSEINFOW() };

            int ret = uiShell.GetDirectoryViaBrowseDlgEx(pBrowse, "", Resources.BrowseFolderDialogSelectButton, "", browseInfo);
            if (ret == VSConstants.S_OK)
            {
                var pathPtr = pBrowse[0].pwzDirName;
                var path = Marshal.PtrToStringAuto(pathPtr);
                NewPackageSource.Text = path;

                // if the package name text box is empty, we fill it with the selected folder's name
                if (String.IsNullOrEmpty(NewPackageName.Text))
                {
                    NewPackageName.Text = Path.GetFileName(path);
                }
            }
        }
        public static string BrowseForDirectory(
            IntPtr owner,
            string initialDirectory = null,
            string title = null
        ) {
            IVsUIShell uiShell = GetService(typeof(SVsUIShell)) as IVsUIShell;
            if (null == uiShell) {
                using (var ofd = new FolderBrowserDialog()) {
                    ofd.RootFolder = Environment.SpecialFolder.Desktop;
                    ofd.SelectedPath = initialDirectory;
                    ofd.ShowNewFolderButton = false;
                    DialogResult result;
                    if (owner == IntPtr.Zero) {
                        result = ofd.ShowDialog();
                    } else {
                        result = ofd.ShowDialog(NativeWindow.FromHandle(owner));
                    }
                    if (result == DialogResult.OK) {
                        return ofd.SelectedPath;
                    } else {
                        return null;
                    }
                }
            }

            if (owner == IntPtr.Zero) {
                ErrorHandler.ThrowOnFailure(uiShell.GetDialogOwnerHwnd(out owner));
            }

            VSBROWSEINFOW[] browseInfo = new VSBROWSEINFOW[1];
            browseInfo[0].lStructSize = (uint)Marshal.SizeOf(typeof(VSBROWSEINFOW));
            browseInfo[0].pwzInitialDir = initialDirectory;
            browseInfo[0].pwzDlgTitle = title;
            browseInfo[0].hwndOwner = owner;
            browseInfo[0].nMaxDirName = 260;
            IntPtr pDirName = IntPtr.Zero;
            try {
                browseInfo[0].pwzDirName = pDirName = Marshal.AllocCoTaskMem(520);
                int hr = uiShell.GetDirectoryViaBrowseDlg(browseInfo);
                if (hr == VSConstants.OLE_E_PROMPTSAVECANCELLED) {
                    return null;
                }
                ErrorHandler.ThrowOnFailure(hr);
                return Marshal.PtrToStringAuto(browseInfo[0].pwzDirName);
            } finally {
                if (pDirName != IntPtr.Zero) {
                    Marshal.FreeCoTaskMem(pDirName);
                }
            }
        }
Esempio n. 16
0
 public int GetDirectoryViaBrowseDlg(VSBROWSEINFOW[] pBrowse) {
     throw new NotImplementedException();
 }
Esempio n. 17
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 = ProjectHome;
     //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;
 }
Esempio n. 18
0
        internal string BrowseForFolder(string title, string initialDir) {
            // Get a reference to the UIShell.
            IVsUIShell uiShell = GetService(typeof(SVsUIShell)) as IVsUIShell;
            if (null == uiShell) {
                return null;
            }

            //Create a fill in a structure that defines Browse for folder dialog
            VSBROWSEINFOW[] browseInfo = new VSBROWSEINFOW[1];
            //Dialog title
            browseInfo[0].pwzDlgTitle = title;
            //Initial directory - project directory
            browseInfo[0].pwzInitialDir = initialDir;
            //Parent window
            uiShell.GetDialogOwnerHwnd(out browseInfo[0].hwndOwner);
            //Max path length
            //This is WCHARS not bytes
            browseInfo[0].nMaxDirName = (uint)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
            //  Add 1 for the null terminator and double since we are WCHARs not bytes
            IntPtr pDirName = Marshal.AllocCoTaskMem((NativeMethods.MAX_PATH + 1)*2);
            browseInfo[0].pwzDirName = pDirName;
            try {
                //Show the dialog
                int hr = uiShell.GetDirectoryViaBrowseDlg(browseInfo);
                if (hr == VSConstants.OLE_E_PROMPTSAVECANCELLED) {
                    //User cancelled the dialog
                    return null;
                }
                //Check for any failures
                ErrorHandler.ThrowOnFailure(hr);
                //Get selected directory
                return Marshal.PtrToStringAuto(browseInfo[0].pwzDirName);
            } finally {
                //Free allocated unmanaged memory
                if (pDirName != IntPtr.Zero) {
                    Marshal.FreeCoTaskMem(pDirName);
                }
            }
        }