Exemplo n.º 1
0
 public static void FocusAssociatedDiffWindow(this SolutionSelectionContainer <ISolutionSelection> selectedItem, IVsUIShell vsUIShell)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     foreach (IVsWindowFrame vsWindowFrame in GetAllWindowFramesFromShell(vsUIShell))
     {
         // check if the frame is (A) The same as the selected item name AND (B) is a DifferenceCodeWindowType
         var frameImpl = vsWindowFrame as WindowFrame;
         if (frameImpl != null &&
             frameImpl.IsDocument &&
             frameImpl.DocumentMoniker.Equals(selectedItem.FullName, StringComparison.OrdinalIgnoreCase) &&
             IsDiffWindowFrame(frameImpl))
         {
             frameImpl.Show();
             break;
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Here we iterate over all open window frames in UI Shell, and check if a frame has the same name as this projectItem, and
        /// if that frame is of type DifferenceCodeWindow.
        /// </summary>
        /// <remarks>
        /// Note that if this method proves to be too slow for large number of document frames opened in UI shell:
        /// We can just checks for Window captions of the windows in given projectItem: projectItem.Document.Windows.
        /// Any window with caption that contains the string: "Vs. {projectItem.Document.Name}" has got to be a diff window associated with this item.
        /// </remarks>
        public static bool HasNoAssociatedDiffWindow(this SolutionSelectionContainer <ISolutionSelection> selectedItem, IVsUIShell vsUIShell)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // Specific checks for EnvDTE.ProjectItem so it becomes easy to return early
            if (selectedItem.Item is SelectedProjectItem)
            {
                if (selectedItem.Item.Document == null)
                {
                    return(true);
                }

                if (selectedItem.Item.Document.Windows.Count == 0)
                {
                    // No windows at all...
                    return(true);
                }
            }

            bool diffWindowExistsForDocument = false;

            foreach (IVsWindowFrame vsWindowFrame in GetAllWindowFramesFromShell(vsUIShell))
            {
                // check if the frame is (A) The same as the selected item name AND (B) is a DifferenceCodeWindowType
                var frameImpl = vsWindowFrame as WindowFrame;
                if (frameImpl != null &&
                    frameImpl.IsDocument &&
                    frameImpl.DocumentMoniker.Equals(selectedItem.FullName, StringComparison.OrdinalIgnoreCase) &&
                    IsDiffWindowFrame(frameImpl))
                {
                    diffWindowExistsForDocument = true;
                    break;
                }
            }

            return(!diffWindowExistsForDocument);
        }