예제 #1
0
        /// <devdoc>
        ///     Called to notify the IDE that our user context has changed.
        /// </devdoc>
        private void NotifyContextChange(IVsUserContext cxt)
        {
            if (provider == null)
            {
                return;
            }

            IVsUserContext        currentContext = null;
            IVsMonitorUserContext muc            = (IVsMonitorUserContext)provider.GetService(typeof(IVsMonitorUserContext));

            if (muc != null)
            {
                NativeMethods.ThrowOnFailure(muc.get_ApplicationContext(out currentContext));
            }

            if (currentContext == cxt)
            {
                return;
            }


            IVsTrackSelectionEx ts = (IVsTrackSelectionEx)provider.GetService(typeof(IVsTrackSelectionEx));

            if (ts != null)
            {
                Object obj = cxt;

                NativeMethods.ThrowOnFailure(ts.OnElementValueChange(5 /* SEID_UserContext */, 0, obj));
            }
        }
예제 #2
0
        public List <string> GetF1Keywords()
        {
            return(InvokeOnUIThread(() =>
            {
                var results = new List <string>();
                GetActiveVsTextView().GetBuffer(out var textLines);
                Marshal.ThrowExceptionForHR(textLines.GetLanguageServiceID(out var languageServiceGuid));
                Marshal.ThrowExceptionForHR(Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider.QueryService(languageServiceGuid, out var languageService));
                var languageContextProvider = languageService as IVsLanguageContextProvider;

                IVsMonitorUserContext monitorUserContext = GetGlobalService <SVsMonitorUserContext, IVsMonitorUserContext>();
                Marshal.ThrowExceptionForHR(monitorUserContext.CreateEmptyContext(out var emptyUserContext));
                Marshal.ThrowExceptionForHR(GetActiveVsTextView().GetCaretPos(out var line, out var column));
                var span = new TextManager.Interop.TextSpan()
                {
                    iStartLine = line,
                    iStartIndex = column,
                    iEndLine = line,
                    iEndIndex = column
                };

                Marshal.ThrowExceptionForHR(languageContextProvider.UpdateLanguageContext(0, textLines, new[] { span }, emptyUserContext));
                Marshal.ThrowExceptionForHR(emptyUserContext.CountAttributes("keyword", VSConstants.S_FALSE, out var count));
                for (int i = 0; i < count; i++)
                {
                    emptyUserContext.GetAttribute(i, "keyword", VSConstants.S_FALSE, out var key, out var value);
                    results.Add(value);
                }

                return results;
            }));
        }
예제 #3
0
 private void NotifyContextChange(IVsUserContext cxt)
 {
     if ((_ServiceProvider != null) && (_ParentService == null))
     {
         IVsUserContext        ppContext = null;
         IVsMonitorUserContext service   =
             (IVsMonitorUserContext)_ServiceProvider.GetService(typeof(IVsMonitorUserContext));
         if (service != null)
         {
             NativeMethods.ThrowOnFailure(service.get_ApplicationContext(out ppContext));
         }
         if (ppContext != cxt)
         {
             IVsWindowFrame frame = (IVsWindowFrame)_ServiceProvider.GetService(typeof(IVsWindowFrame));
             if ((frame != null) && !IsToolWindow(frame))
             {
                 IVsTrackSelectionEx ex = (IVsTrackSelectionEx)_ServiceProvider.GetService(typeof(IVsTrackSelectionEx));
                 if (ex != null)
                 {
                     object varValue = cxt;
                     NativeMethods.ThrowOnFailure(ex.OnElementValueChange(5, 0, varValue));
                 }
             }
         }
     }
 }
예제 #4
0
        private IHelpService CreateLocalContext(HelpContextType contextType, bool recreate, out IVsUserContext localContext, out int cookie)
        {
            cookie       = 0;
            localContext = null;
            if (provider == null)
            {
                return(null);
            }

            localContext = null;
            IVsMonitorUserContext muc = (IVsMonitorUserContext)provider.GetService(typeof(IVsMonitorUserContext));

            if (muc != null)
            {
                localContext = muc.CreateEmptyContext();
            }

            if (localContext != null)
            {
                int priority = 0;
                switch (contextType)
                {
                case HelpContextType.ToolWindowSelection:
                    priority = tagVsUserContextPriority.VSUC_Priority_ToolWndSel;
                    break;

                case HelpContextType.Selection:
                    priority = tagVsUserContextPriority.VSUC_Priority_Selection;
                    break;

                case HelpContextType.Window:
                    priority = tagVsUserContextPriority.VSUC_Priority_Window;
                    break;

                case HelpContextType.Ambient:
                    priority = tagVsUserContextPriority.VSUC_Priority_Ambient;
                    break;
                }

                cookie = GetUserContext().AddSubcontext(localContext, priority);

                if (cookie != 0)
                {
                    if (!recreate)
                    {
                        HelpService newHs = new HelpService(this, localContext, cookie, provider, contextType);
                        if (subContextList == null)
                        {
                            subContextList = new ArrayList();
                        }
                        subContextList.Add(newHs);
                        return(newHs);
                    }
                }
            }
            return(null);
        }
예제 #5
0
    public static HelpContext2 GetHelpContext(DTE2 dte)
    {
        // Get a reference to the current active window (presumably a code editor).
        Window activeWindow = dte.ActiveWindow;

        // make a few gnarly COM-interop calls in order to get Help Context
        Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)activeWindow.DTE;
        Microsoft.VisualStudio.Shell.ServiceProvider        serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(sp);
        IVsMonitorUserContext contextMonitor = (IVsMonitorUserContext)serviceProvider.GetService(typeof(IVsMonitorUserContext));
        IVsUserContext        userContext;
        int          hresult = contextMonitor.get_ApplicationContext(out userContext);
        HelpContext2 attrs   = new HelpContext2(userContext);

        return(attrs);
    }
예제 #6
0
        /// <devdoc>
        ///     Retrieves a user context for us to add and remove attributes.  This
        ///     will demand create the context if it doesn't exist.
        /// </devdoc>
        private IVsUserContext GetUserContext()
        {
            // try to rebuild from a parent if possible.
            RecreateContext();

            // Create a new context if we don't have one.
            //
            if (context == null)
            {
                if (provider == null)
                {
                    return(null);
                }


                IVsWindowFrame windowFrame = (IVsWindowFrame)provider.GetService(typeof(IVsWindowFrame));

                if (windowFrame != null)
                {
                    object prop;
                    NativeMethods.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_UserContext, out prop));
                    context = (IVsUserContext)prop;
                }

                if (context == null)
                {
                    IVsMonitorUserContext muc = (IVsMonitorUserContext)provider.GetService(typeof(IVsMonitorUserContext));
                    if (muc != null)
                    {
                        NativeMethods.ThrowOnFailure(muc.CreateEmptyContext(out context));
                        Debug.Assert(context != null, "muc didn't create context");
                    }
                }

                if (subContextList != null && context != null)
                {
                    foreach (object helpObj in subContextList)
                    {
                        if (helpObj is HelpService)
                        {
                            ((HelpService)helpObj).RecreateContext();
                        }
                    }
                }
            }

            return(context);
        }
예제 #7
0
        /// <include file='doc\HelpService.uex' path='docs/doc[@for="HelpService.GetUserContext"]/*' />
        /// <devdoc>
        ///     Retrieves a user context for us to add and remove attributes.  This
        ///     will demand create the context if it doesn't exist.
        /// </devdoc>
        private IVsUserContext GetUserContext()
        {
            // try to rebuild from a parent if possible.
            RecreateContext();

            // Create a new context if we don't have one.
            //
            if (context == null)
            {
                if (provider == null)
                {
                    return(null);
                }


                IVsWindowFrame windowFrame = (IVsWindowFrame)provider.GetService(typeof(IVsWindowFrame));

                if (windowFrame != null)
                {
                    context = (IVsUserContext)windowFrame.GetProperty(__VSFPROPID.VSFPROPID_UserContext);
                }

                if (context == null)
                {
                    IVsMonitorUserContext muc = (IVsMonitorUserContext)provider.GetService(typeof(IVsMonitorUserContext));
                    if (muc != null)
                    {
                        context         = muc.CreateEmptyContext();
                        notifySelection = true;
                        Debug.Assert(context != null, "muc didn't create context");
                    }
                }

                if (subContextList != null && context != null)
                {
                    foreach (object helpObj in subContextList)
                    {
                        if (helpObj is HelpService)
                        {
                            ((HelpService)helpObj).RecreateContext();
                        }
                    }
                }
            }

            return(context);
        }
예제 #8
0
파일: Task.cs 프로젝트: wgwjifeng/windows
        /// <include file='doc\Task.uex' path='docs/doc[@for="Task.GetUserContext"]/*' />
        public int GetUserContext(out IVsUserContext ppctx)
        {
            int hr = NativeMethods.S_OK;

            if (context == null)
            {
                // Create an empty context
                IVsMonitorUserContext monitorContext = owner.GetService(typeof(SVsMonitorUserContext)) as IVsMonitorUserContext;
                NativeMethods.ThrowOnFailure(monitorContext.CreateEmptyContext(out context));

                // Add the required information to the context
                hr = context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1, contextNameKeyword, this.HelpKeyword);
            }
            ppctx = context;

            return(hr);
        }
예제 #9
0
 private IVsUserContext GetUserContext()
 {
     RecreateContext();
     if (_Context == null)
     {
         if (_ServiceProvider == null)
         {
             return(null);
         }
         IVsWindowFrame frame = (IVsWindowFrame)_ServiceProvider.GetService(typeof(IVsWindowFrame));
         if (frame != null)
         {
             object obj2;
             NativeMethods.ThrowOnFailure(frame.GetProperty(-3010, out obj2));
             _Context = (IVsUserContext)obj2;
         }
         if (_Context == null)
         {
             IVsMonitorUserContext context =
                 (IVsMonitorUserContext)_ServiceProvider.GetService(typeof(IVsMonitorUserContext));
             if (context != null)
             {
                 NativeMethods.ThrowOnFailure(context.CreateEmptyContext(out _Context));
                 if (((_Context != null) && (frame != null)) && IsToolWindow(frame))
                 {
                     NativeMethods.ThrowOnFailure(frame.SetProperty(-3010, _Context));
                 }
             }
         }
         if ((_SubContextList != null) && (_Context != null))
         {
             foreach (object obj3 in _SubContextList)
             {
                 HelpService service = obj3 as HelpService;
                 if (service != null)
                 {
                     service.RecreateContext();
                 }
             }
         }
     }
     return(_Context);
 }
예제 #10
0
 public int GetUserContext(out IVsUserContext ppctx)
 {
     // Common.Trace("Task.GetUserContext");
     // set the user context
     if (userContext == null && helpKeyword != null && helpKeyword.Length > 0)
     {
         IVsMonitorUserContext monitor = Common.GetService(typeof(SVsMonitorUserContext)) as IVsMonitorUserContext;
         if (monitor != null)
         {
             int hr = monitor.CreateEmptyContext(out userContext);
             if (hr == 0 && userContext != null)
             {
                 hr = userContext.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1, "keyword", helpKeyword);
             }
             if (hr != 0)
             {
                 userContext = null;
             }
         }
     }
     ppctx = userContext;
     return(0);
 }
예제 #11
0
        private IHelpService CreateLocalContext(HelpContextType contextType, bool recreate, out IVsUserContext localContext,
                                                out uint cookie)
        {
            cookie       = 0;
            localContext = null;
            if (_ServiceProvider != null)
            {
                localContext = null;
                int hr = 0;
                IVsMonitorUserContext context =
                    (IVsMonitorUserContext)_ServiceProvider.GetService(typeof(IVsMonitorUserContext));
                if (context != null)
                {
                    try
                    {
                        hr = context.CreateEmptyContext(out localContext);
                    }
                    catch (COMException exception)
                    {
                        hr = exception.ErrorCode;
                    }
                }
                if (NativeMethods.Succeeded(hr) && (localContext != null))
                {
                    VSUSERCONTEXTPRIORITY vsusercontextpriority = VSUSERCONTEXTPRIORITY.VSUC_Priority_None;
                    switch (contextType)
                    {
                    case HelpContextType.Ambient:
                        vsusercontextpriority = VSUSERCONTEXTPRIORITY.VSUC_Priority_Ambient;
                        break;

                    case HelpContextType.Window:
                        vsusercontextpriority = VSUSERCONTEXTPRIORITY.VSUC_Priority_Window;
                        break;

                    case HelpContextType.Selection:
                        vsusercontextpriority = VSUSERCONTEXTPRIORITY.VSUC_Priority_Selection;
                        break;

                    case HelpContextType.ToolWindowSelection:
                        vsusercontextpriority = VSUSERCONTEXTPRIORITY.VSUC_Priority_ToolWndSel;
                        break;
                    }
                    IVsUserContext userContext = GetUserContext();
                    if (userContext != null)
                    {
                        try
                        {
                            hr = userContext.AddSubcontext(localContext, (int)vsusercontextpriority, out cookie);
                        }
                        catch (COMException exception2)
                        {
                            hr = exception2.ErrorCode;
                        }
                    }
                    if ((NativeMethods.Succeeded(hr) && (cookie != 0)) && !recreate)
                    {
                        HelpService service = new HelpService(this, localContext, cookie, _ServiceProvider, contextType);
                        if (_SubContextList == null)
                        {
                            _SubContextList = new ArrayList();
                        }
                        _SubContextList.Add(service);
                        return(service);
                    }
                }
            }
            return(null);
        }
예제 #12
0
        /// <devdoc>
        /// </devdoc>
        private IHelpService CreateLocalContext(HelpContextType contextType, bool recreate, out IVsUserContext localContext, out uint cookie)
        {
            cookie       = 0;
            localContext = null;
            if (provider == null)
            {
                return(null);
            }

            localContext = null;
            int hr = NativeMethods.S_OK;
            IVsMonitorUserContext muc = (IVsMonitorUserContext)provider.GetService(typeof(IVsMonitorUserContext));

            if (muc != null)
            {
                try {
                    hr = muc.CreateEmptyContext(out localContext);
                } catch (COMException e) {
                    hr = e.ErrorCode;
                }
            }

            if (NativeMethods.Succeeded(hr) && (localContext != null))
            {
                VSUSERCONTEXTPRIORITY priority = 0;
                switch (contextType)
                {
                case HelpContextType.ToolWindowSelection:
                    priority = VSUSERCONTEXTPRIORITY.VSUC_Priority_ToolWndSel;
                    break;

                case HelpContextType.Selection:
                    priority = VSUSERCONTEXTPRIORITY.VSUC_Priority_Selection;
                    break;

                case HelpContextType.Window:
                    priority = VSUSERCONTEXTPRIORITY.VSUC_Priority_Window;
                    break;

                case HelpContextType.Ambient:
                    priority = VSUSERCONTEXTPRIORITY.VSUC_Priority_Ambient;
                    break;
                }

                IVsUserContext cxt = GetUserContext();
                if (cxt != null)
                {
                    try {
                        hr = cxt.AddSubcontext(localContext, (int)priority, out cookie);
                    } catch (COMException e) {
                        hr = e.ErrorCode;
                    }
                }

                if (NativeMethods.Succeeded(hr) && (cookie != 0))
                {
                    if (!recreate)
                    {
                        HelpService newHs = new HelpService(this, localContext, cookie, provider, contextType);
                        if (subContextList == null)
                        {
                            subContextList = new ArrayList();
                        }
                        subContextList.Add(newHs);
                        return(newHs);
                    }
                }
            }
            return(null);
        }