Exemplo n.º 1
0
        /// <summary>
        /// Brings up the browse folder dialog.
        /// </summary>
        /// <param name="sender">The browse button.</param>
        /// <param name="e">The <see cref="EventArgs"/> object that contains the event data.</param>
        private void OnBrowseButtonClick(object sender, EventArgs e)
        {
            // initialize the dialog to the current directory (if it exists)
            bool   overridePersistedInitialDirectory = false;
            string initialDirectory = null;

            if (Directory.Exists(FullPath))
            {
                initialDirectory = FullPath;
                overridePersistedInitialDirectory = true;
            }

            IntPtr      parentWindow    = Handle;
            Guid        persistenceSlot = typeof(FileBrowserTextBox).GUID;
            IVsUIShell2 shell           = (IVsUIShell2)Package.GetGlobalService(typeof(SVsUIShell));
            // show the dialog
            string path = shell.GetDirectoryViaBrowseDialog(parentWindow, persistenceSlot, "Select folder", initialDirectory, overridePersistedInitialDirectory);

            if (path != null)
            {
                if (MakeRelative && !string.IsNullOrEmpty(RootFolder))
                {
                    string rootFolder = Path.GetFullPath(RootFolder);
                    if (Directory.Exists(rootFolder))
                    {
                        if (!rootFolder.EndsWith(Path.DirectorySeparatorChar.ToString()) && !rootFolder.EndsWith(Path.AltDirectorySeparatorChar.ToString()))
                        {
                            rootFolder = rootFolder + Path.DirectorySeparatorChar;
                        }

                        path = new Url(rootFolder).MakeRelative(new Url(path));
                    }
                }

                this.folderTextBox.Text = path;
            }
        }