public static Result <List <IVsWindowFrame> > GetDocumentWindowFrames(this IVsUIShell4 vsShell, __WindowFrameTypeFlags flags)
        {
            IEnumWindowFrames enumFrames;
            var hr = vsShell.GetWindowEnum((uint)flags, out enumFrames);

            return(ErrorHandler.Failed(hr) ? Result.CreateError(hr) : enumFrames.GetContents());
        }
        /// <summary>
        /// This function is called when the user clicks the menu item that shows the
        /// tool window. See the Initialize method to see how the menu item is associated to
        /// this function using the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void ShowMergeToolWindow(object sender, EventArgs e)
        {
            IVsUIShell4 uiShell = GetService(typeof(SVsUIShell)) as IVsUIShell4;

            // Get the instance number 0 of this tool window. This window is single instance so this instance
            // is actually the only one.
            // The last flag is set to true so that if the tool window does not exists it will be created.
            ToolWindowPane window = this.FindToolWindow(typeof(vMergeMergeToolWindow), 0, true);

            if ((null == window) || (null == window.Frame))
            {
                throw new NotSupportedException(Resources.CanNotCreateWindow);
            }
            IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
            SetMergeToolWindowIsVisible();

            var windowEvents = new ToolWindowEvents(windowFrame);

            windowEvents.OnClose = (options) =>
            {
                MergeToolWindowIsVisible = false;
                if (_mergeToolWindowVisibilityChanged != null)
                {
                    _mergeToolWindowVisibilityChanged(this, new EventArgs());
                }
                windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_ViewHelper, null);
                windowEvents.Dispose();
                return(VSConstants.S_OK);
            };
            windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_ViewHelper, windowEvents);

            vMergeMergeToolWindow mergeToolWindow = (vMergeMergeToolWindow)window;
        }
Beispiel #3
0
        public static IEnumerable <IVsWindowFrame> EnumerateWindows(this IVsUIShell4 shell, __WindowFrameTypeFlags flags, Guid?windowGuid = null)
        {
            IEnumWindowFrames enumerator;

            ErrorHandler.ThrowOnFailure(shell.GetWindowEnum((uint)flags, out enumerator));

            var  frames  = new IVsWindowFrame[1];
            uint fetched = 0;

            while (VSConstants.S_OK == enumerator.Next(1, frames, out fetched) && fetched > 0)
            {
                var frame = frames[0];

                bool include = true;
                if (windowGuid.HasValue)
                {
                    Guid persist;
                    ErrorHandler.ThrowOnFailure(frame.GetGuidProperty((int)__VSFPROPID.VSFPROPID_GuidPersistenceSlot, out persist));
                    include = persist == windowGuid;
                }

                if (include)
                {
                    yield return(frame);
                }
            }
        }
        private void CreateToolBar()
        {
            // Retrieve the shell UI object
            IVsUIShell4 shell4 = GetService(typeof(SVsUIShell)) as IVsUIShell4;

            if (shell4 != null)
            {
                // Create the toolbar tray
                IVsToolbarTrayHost host = null;
                if (ErrorHandler.Succeeded(shell4.CreateToolbarTray(this, out host)))
                {
                    // Add the toolbar as defined in vsct
                    host.AddToolbar(GuidList.guidCommandTargetRGBCmdSet, PkgCmdIDList.RGBToolbar);

                    IVsUIElement uiElement;
                    host.GetToolbarTray(out uiElement);

                    // Get the WPF element
                    object uiObject;
                    uiElement.GetUIObject(out uiObject);
                    IVsUIWpfElement wpfe = uiObject as IVsUIWpfElement;

                    // Retrieve and set the toolbar tray
                    object frameworkElement;
                    wpfe.GetFrameworkElement(out frameworkElement);
                    control.SetTray(frameworkElement as ToolBarTray);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Enumerate the window frames looking for the owner of the context
        /// </summary>
        /// <param name="selCtx"></param>
        /// <returns></returns>
        object GetContextOwner(IVsTrackSelectionEx selCtx)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (selCtx == null)
            {
                return(null);
            }

            // No frame owns the empty selection context, just return it as its own owner.
            if (IsEmptySelectionContext(selCtx))
            {
                return(selCtx);
            }

            IVsUIShell4 shell4 = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell4;

            Guid trackSelectionExServiceGuid = typeof(SVsTrackSelectionEx).GUID;
            Guid trackSelecitonExGuid        = typeof(IVsTrackSelectionEx).GUID;

            shell4.GetWindowEnum((uint)__WindowFrameTypeFlags.WINDOWFRAMETYPE_All, out var frameEnum);

            foreach (IVsWindowFrame frame in ComUtilities.EnumerableFrom(frameEnum))
            {
                if (ErrorHandler.Succeeded(frame.GetProperty((int)__VSFPROPID.VSFPROPID_SPFrame, out var frameServiceProvider)) && frameServiceProvider != null)
                {
                    IntPtr pTrackSelection = IntPtr.Zero;
                    try
                    {
                        if (ErrorHandler.Succeeded(((IOleServiceProvider)frameServiceProvider).QueryService(ref trackSelectionExServiceGuid, ref trackSelecitonExGuid, out pTrackSelection)))
                        {
                            IVsTrackSelectionEx frameCtx = Marshal.GetObjectForIUnknown(pTrackSelection) as IVsTrackSelectionEx;
                            if (ComUtilities.IsSameComObject(selCtx, frameCtx))
                            {
                                return(frame);
                            }
                        }
                    }
                    finally
                    {
                        if (pTrackSelection != IntPtr.Zero)
                        {
                            Marshal.Release(pTrackSelection);
                        }
                    }
                }
            }

            return(null);
        }
Beispiel #6
0
        public void Init()
        {
            {
                var A = new EditorHostFactory();
                var B = A.CreateCompositionContainer();
                IEditorFormatMapService efms = B.GetExportedValue <IEditorFormatMapService>();
                if (!VsSettings.IsInitialized)
                {
                    VsSettings.Initialize(this.pkg, efms);
                }
            }

            CreateMenu();
            cmdExec = new CommandExecutorService()
            {
            };
            disableVsVimCmdAvailable = cmdExec.IsCommandAvailable(VsVimSetDisabled);
            enableVsVimCmdAvailable  = cmdExec.IsCommandAvailable(VsVimSetEnabled);
            viEmuPluginPresent       = cmdExec.IsCommandAvailable(ViEmuEnableDisableCommand);
            iVsUiShell  = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell;
            iVsUiShell4 = iVsUiShell as IVsUIShell4;
            JumpLabelUserControl.WarmupCache();
            // warmup options
            GeneralOptions.Instance.caretPositionSensivity = GeneralOptions.Instance.caretPositionSensivity;
            // warmp up:
#if MEASUREEXECTIME
            var watch2_0 = System.Diagnostics.Stopwatch.StartNew();
#endif
            var wfs = iVsUiShell.GetDocumentWindowFrames().GetValueOrDefault();
            if (wfs.Count > 0)
            {
                Trace.WriteLine("GetDocumentWindowFrames warmed up");
                foreach (var wf in wfs)
                {
                    wf.GetProperty((int)VsFramePropID.Caption, out var oce);
                    wf.SetProperty((int)VsFramePropID.Caption, (string)oce);
                }
            }
#if MEASUREEXECTIME
            watch2_0.Stop();
            Trace.WriteLine($"PeasyMotion Adornment warmup document tabs: {watch2_0.ElapsedMilliseconds} ms");
#endif
        }
        private IVsInfoBarHost GetInfoBarHost(string fileType)
        {
            IVsUIShell4       uiShell = _serviceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell4;
            IEnumWindowFrames windowEnumerator;

            uint flags = unchecked (((uint)(__WindowFrameTypeFlags.WINDOWFRAMETYPE_Document)));

            ErrorHandler.ThrowOnFailure(uiShell.GetWindowEnum(flags, out windowEnumerator));

            IVsWindowFrame[] frame   = new IVsWindowFrame[1];
            uint             fetched = 0;
            int hr = VSConstants.S_OK;

            // Note that we get S_FALSE when there is no more item, so only loop while we are getting S_OK
            while (hr == VSConstants.S_OK)
            {
                // For each tool window, add it to the list
                hr = windowEnumerator.Next(1, frame, out fetched);
                ErrorHandler.ThrowOnFailure(hr);
                if (fetched == 1)
                {
                    if (frame[0].IsVisible() == VSConstants.S_OK)
                    {
                        // We successfully retrieved a window frame, update our lists
                        object obj;
                        object caption;
                        frame[0].GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out obj);
                        frame[0].GetProperty((int)__VSFPROPID.VSFPROPID_Caption, out caption);

                        if (obj != null && caption != null && caption.ToString().Contains(fileType))
                        {
                            return((IVsInfoBarHost)obj);
                        }
                    }
                }
            }

            return(null);
        }
        /// <summary>
        /// Update the content of the list by asking VS
        /// </summary>
        /// <returns></returns>
        public void RefreshList()
        {
            framesList      = new List <IVsWindowFrame>();
            toolWindowNames = new List <string>();

            // Get the UI Shell service
            IVsUIShell4 uiShell = (IVsUIShell4)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsUIShell));
            // Get the tool windows enumerator
            IEnumWindowFrames windowEnumerator;

            uint flags = unchecked (((uint)__WindowFrameTypeFlags.WINDOWFRAMETYPE_Tool | (uint)__WindowFrameTypeFlags.WINDOWFRAMETYPE_Uninitialized));

            ErrorHandler.ThrowOnFailure(uiShell.GetWindowEnum(flags, out windowEnumerator));

            IVsWindowFrame[] frame   = new IVsWindowFrame[1];
            uint             fetched = 0;
            int hr = VsConstants.S_OK;

            // Note that we get S_FALSE when there is no more item, so only loop while we are getting S_OK
            while (hr == VsConstants.S_OK)
            {
                // For each tool window, add it to the list
                hr = windowEnumerator.Next(1, frame, out fetched);
                ErrorHandler.ThrowOnFailure(hr);
                if (fetched == 1)
                {
                    if (frame[0].IsVisible() == VsConstants.S_OK)
                    {
                        // We successfully retrieved a window frame, update our lists
                        string caption = (string)GetProperty(frame[0], (int)__VSFPROPID.VSFPROPID_Caption);
                        toolWindowNames.Add(caption);
                        framesList.Add(frame[0]);
                    }
                }
            }
        }
Beispiel #9
0
 public ShowPlotWindowCommand(IApplicationShell appShell, IRInteractiveWorkflow workflow)
 {
     _plotManager = workflow.Plots;
     _shell       = appShell.GlobalServices.GetService <IVsUIShell4>(typeof(SVsUIShell));
 }
Beispiel #10
0
 public HideAllPlotWindowsCommand(IApplicationShell appShell) :
     base(RGuidList.RCmdSetGuid, RPackageCommandId.icmdPlotWindowsHideAll)
 {
     _appShell = appShell;
     _shell    = appShell.GlobalServices.GetService <IVsUIShell4>(typeof(SVsUIShell));
 }
Beispiel #11
0
 public HideAllPlotWindowsCommand(IApplicationShell appShell) :
     base(RGuidList.RCmdSetGuid, RPackageCommandId.icmdPlotWindowsHideAll) {
     _appShell = appShell;
     _shell = appShell.GetGlobalService<IVsUIShell4>(typeof(SVsUIShell));
 }
Beispiel #12
0
 public void SetUp()
 {
     this.iVsUIShell     = Substitute.For <IVsUIShell4>();
     this.templateLoader = new TemplateLoader();
 }
Beispiel #13
0
 public ShowPlotWindowCommand(ICoreShell shell, IRInteractiveWorkflow workflow)
 {
     _plotManager = workflow.Plots as IRPlotManagerVisual;
     _shell       = shell.GetService <IVsUIShell4>(typeof(SVsUIShell));
 }
Beispiel #14
0
 public ShowPlotWindowCommand(IApplicationShell appShell, IRInteractiveWorkflow workflow) {
     _plotManager = workflow.Plots;
     _shell = appShell.GetGlobalService<IVsUIShell4>(typeof(SVsUIShell));
 }
Beispiel #15
0
 public HideAllPlotWindowsCommand(ICoreShell shell) :
     base(RGuidList.RCmdSetGuid, RPackageCommandId.icmdPlotWindowsHideAll)
 {
     _ui      = shell.UI();
     _vsshell = shell.GetService <IVsUIShell4>(typeof(SVsUIShell));
 }