Beispiel #1
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);
        }
Beispiel #2
0
        private void Differences_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var clickedItem = GetClickedItem(e);

            if (clickedItem != null)
            {
                var node = (clickedItem as TreeViewItem)?.Tag as TreeNode;
                if (node != null)
                {
                    if (!(string.IsNullOrEmpty(node.LeftPath) || string.IsNullOrEmpty(node.RightPath)))
                    {
                        e.Handled = true;

                        var diff = CompareDirectoriesPackage.GetGlobalService(typeof(SVsDifferenceService)) as IVsDifferenceService;
                        if (diff != null)
                        {
                            var componentModel = (IComponentModel)CompareDirectoriesPackage.GetGlobalService(typeof(SComponentModel));
                            var factory        = componentModel.GetService <IEditorOptionsFactoryService>();
                            factory.GlobalOptions.SetOptionValue(DifferenceViewerOptions.HighlightModeId, (DifferenceHighlightMode)(DifferenceHighlightMode2.BlockOutline));

                            using (new NewDocumentStateScope(__VSNEWDOCUMENTSTATE.NDS_Provisional, CompareDirectoriesPackage.PackageGuid))
                            {
                                diff.OpenComparisonWindow(node.LeftPath, node.RightPath);
                            }
                        }
                    }
                    else
                    {
                        var path = string.IsNullOrEmpty(node.LeftPath) ? (string.IsNullOrEmpty(node.RightPath) ? null : node.RightPath) : node.LeftPath;
                        if (path != null)
                        {
                            e.Handled = true;

                            var shell = CompareDirectoriesPackage.GetGlobalService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
                            if (shell != null)
                            {
                                Guid textViewLogicalView = VSConstants.LOGVIEWID_TextView;
                                Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProviderOfFrame = null;

                                IVsUIHierarchy hierarchy;
                                uint           itemID;
                                IVsWindowFrame windowFrame = null;
                                using (new NewDocumentStateScope(__VSNEWDOCUMENTSTATE.NDS_Provisional, CompareDirectoriesPackage.PackageGuid))
                                {
                                    shell.OpenDocumentViaProject(path,
                                                                 ref textViewLogicalView,
                                                                 out serviceProviderOfFrame,
                                                                 out hierarchy,
                                                                 out itemID,
                                                                 out windowFrame);
                                }

                                if (windowFrame != null)
                                {
                                    windowFrame.Show();
                                }
                            }
                        }
                    }
                }
            }
        }