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)); } } } } }
public IHelpService CreateLocalContext(HelpContextType contextType) { IVsUserContext newContext = null; int cookie = 0; return(CreateLocalContext(contextType, false, out newContext, out cookie)); }
public void Release() { // Called from "OnDelete" // task list makes sure it doesn't show up // and we remove it later when an enumeration is asked. isDeleted = true; if (marker != null) { marker.Invalidate(); marker = null; } if (commands != null) { commands.Dispose(); commands = null; } userContext = null; taskManager = null; if (location != null) { location.Dispose(); location = null; } if (persistLoc != null) { persistLoc.Dispose(); persistLoc = null; } if (initLoc != null) { initLoc.Dispose(); initLoc = null; } }
void IHelpService.AddContextAttribute(string name, string value, HelpKeywordType keywordType) { if (_ServiceProvider != null) { IVsUserContext userContext = GetUserContext(); if (userContext != null) { VSUSERCONTEXTATTRIBUTEUSAGE usage = VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1; switch (keywordType) { case HelpKeywordType.F1Keyword: usage = VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1; break; case HelpKeywordType.GeneralKeyword: usage = VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Lookup; break; case HelpKeywordType.FilterKeyword: usage = VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter; break; } NativeMethods.ThrowOnFailure(userContext.AddAttribute(usage, name, value)); NotifyContextChange(userContext); } } }
/// <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)); } }
IHelpService IHelpService.CreateLocalContext(HelpContextType contextType) { IVsUserContext localContext = null; uint cookie = 0; return(CreateLocalContext(contextType, false, out localContext, out cookie)); }
/// <devdoc> /// </devdoc> private HelpService(HelpService parentService, IVsUserContext subContext, uint cookie, IServiceProvider provider, HelpContextType priority) { this.context = subContext; this.provider = provider; this.cookie = cookie; this.parentService = parentService; this.priority = priority; }
int IVsProvideUserContext.GetUserContext(out IVsUserContext ppctx) { // We don't currently plumb the error code (e.g. 'FS0123') around. Need to explicitly say NOT_IMPL so that VS fallback // logic will kick in and go to 'Error List' help topic when you press F1 on an F# task. ppctx = null; return(NativeMethods.E_NOTIMPL); }
private HelpService(HelpService parentService, IVsUserContext subContext, int cookie, IServiceProvider provider, HelpContextType priority) { this.context = subContext; this.provider = provider; this.cookie = cookie; this.parentService = parentService; this.priority = priority; }
/// <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; }
// -------------------------------------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="HelpService"/> class. /// </summary> /// <param name="parentService">The parent service.</param> /// <param name="subContext">The sub context.</param> /// <param name="cookie">The cookie.</param> /// <param name="provider">The provider.</param> /// <param name="priority">The priority.</param> // -------------------------------------------------------------------------------------------- private HelpService(HelpService parentService, IVsUserContext subContext, uint cookie, IServiceProvider provider, HelpContextType priority) { _Context = subContext; _ServiceProvider = provider; _Cookie = cookie; _ParentService = parentService; _Priority = priority; }
void IHelpService.RemoveContextAttribute(string name, string value) { if (_ServiceProvider != null) { IVsUserContext userContext = GetUserContext(); if (userContext != null) { NativeMethods.ThrowOnFailure(userContext.RemoveAttribute(name, value)); NotifyContextChange(userContext); } } }
public int OnElementValueChanged(uint elementid, object varValueOld, object varValueNew) { ThreadHelper.ThrowIfNotOnUIThread(); switch ((VSConstants.VSSELELEMID)elementid) { case VSConstants.VSSELELEMID.SEID_WindowFrame: _activeFrameObject = _activeFrameControl = null; _activeFrameTextView = null; _determinedActiveFrameTextView = false; _activeFrame = varValueNew as IVsWindowFrame; break; case VSConstants.VSSELELEMID.SEID_DocumentFrame: _activeDocumentFrameObject = _activeDocumentControl = null; _activeDocumentFrameTextView = null; _determinedActiveDocumentFrameTextView = false; _activeDocumentFrame = varValueNew as IVsWindowFrame; break; #if NEVER case VSConstants.VSSELELEMID.SEID_UserContext: IVsUserContext userContext = varValueNew as IVsUserContext; break; case VSConstants.VSSELELEMID.SEID_PropertyBrowserSID: IVsPropertyBrowser pb = varValueNew as IVsPropertyBrowser; break; case VSConstants.VSSELELEMID.SEID_ResultList: IOleCommandTarget ct = varValueNew as IOleCommandTarget; break; case VSConstants.VSSELELEMID.SEID_StartupProject: IVsProject2 pr = varValueNew as IVsProject2; break; case VSConstants.VSSELELEMID.SEID_UndoManager: IOleUndoManager ud = varValueNew as IOleUndoManager; break; #endif } _activeDocumentFileName = null; // Flush on every document state change ClearCache(); return(VSErr.S_OK); }
/// <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); }
/// <include file='doc\HelpService.uex' path='docs/doc[@for="HelpService.NotifyContextChange"]/*' /> /// <devdoc> /// Called to notify the IDE that our user context has changed. /// </devdoc> private void NotifyContextChange(IVsUserContext cxt) { if (provider == null || !notifySelection) { return; } IVsTrackSelectionEx ts = (IVsTrackSelectionEx)provider.GetService(typeof(IVsTrackSelectionEx)); if (ts != null) { Object obj = cxt; ts.OnElementValueChange(5 /* SEID_UserContext */, 0, obj); } }
/// <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); }
/// <include file='doc\HelpService.uex' path='docs/doc[@for="HelpService.RemoveContextAttribute"]/*' /> /// <devdoc> /// Removes a previously added context attribute. /// </devdoc> public virtual void RemoveContextAttribute(string name, string value) { if (provider == null) { return; } // First, get our context and update the attribute. // IVsUserContext cxt = GetUserContext(); if (cxt != null) { cxt.RemoveAttribute(name, value); NotifyContextChange(cxt); } }
/// <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); }
/// <devdoc> /// Removes a previously added context attribute. /// </devdoc> void IHelpService.RemoveContextAttribute(string name, string value) { if (provider == null) { return; } // First, get our context and update the attribute. // IVsUserContext cxt = GetUserContext(); if (cxt != null) { NativeMethods.ThrowOnFailure(cxt.RemoveAttribute(name, value)); NotifyContextChange(cxt); } }
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); }
public HelpContext2(IVsUserContext userContext) { int count; userContext.CountAttributes(null, 1, out count); for (int i = 0; i < count; i++) { string name, value; int priority; userContext.GetAttributePri(i, null, 1, out priority, out name, out value); VSUSERCONTEXTATTRIBUTEUSAGE[] usageArray = new VSUSERCONTEXTATTRIBUTEUSAGE[1]; userContext.GetAttrUsage(i, 1, usageArray); VSUSERCONTEXTATTRIBUTEUSAGE usage = usageArray[0]; HelpAttribute attr = new HelpAttribute(); attr.Name = name; attr.Value = value; attr.Priority = (VSUSERCONTEXTPRIORITY)priority; attr.Usage = usage; // name == "keyword" ? VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Lookup : VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter; this.Add(attr); } }
/// <devdoc> /// Recretes the context /// </devdoc> private void RecreateContext() { if (parentService != null && needsRecreate) { needsRecreate = false; if (this.context == null) { parentService.CreateLocalContext(this.priority, true, out this.context, out this.cookie); } else { VSUSERCONTEXTPRIORITY vsPriority = 0; switch (priority) { case HelpContextType.ToolWindowSelection: vsPriority = VSUSERCONTEXTPRIORITY.VSUC_Priority_ToolWndSel; break; case HelpContextType.Selection: vsPriority = VSUSERCONTEXTPRIORITY.VSUC_Priority_Selection; break; case HelpContextType.Window: vsPriority = VSUSERCONTEXTPRIORITY.VSUC_Priority_Window; break; case HelpContextType.Ambient: vsPriority = VSUSERCONTEXTPRIORITY.VSUC_Priority_Ambient; break; } IVsUserContext cxtParent = parentService.GetUserContext(); IVsUserContext cxt = GetUserContext(); if (cxt != null && cxtParent != null) { NativeMethods.ThrowOnFailure(cxtParent.AddSubcontext(cxt, (int)vsPriority, out this.cookie)); } } } }
private void RecreateContext() { if ((_ParentService != null) && _NeedsRecreate) { _NeedsRecreate = false; if (_Context == null) { _ParentService.CreateLocalContext(_Priority, true, out _Context, out _Cookie); } else { VSUSERCONTEXTPRIORITY vsusercontextpriority = VSUSERCONTEXTPRIORITY.VSUC_Priority_None; switch (_Priority) { 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 = _ParentService.GetUserContext(); IVsUserContext pSubCtx = GetUserContext(); if ((pSubCtx != null) && (userContext != null)) { NativeMethods.ThrowOnFailure(userContext.AddSubcontext(pSubCtx, (int)vsusercontextpriority, out _Cookie)); } } } }
/// <include file='doc\HelpService.uex' path='docs/doc[@for="HelpService.Dispose"]/*' /> /// <devdoc> /// Disposes this object. /// </devdoc> public virtual void Dispose() { if (subContextList != null && subContextList.Count > 0) { foreach (HelpService hs in subContextList) { hs.parentService = null; if (context != null) { context.RemoveSubcontext(hs.cookie); } hs.Dispose(); } subContextList = null; } if (parentService != null) { IHelpService parent = parentService; parentService = null; parent.RemoveLocalContext(this); } if (provider != null) { IDesignerHost host = (IDesignerHost)provider.GetService(typeof(IDesignerHost)); if (host != null) { host.Activated -= new EventHandler(this.OnDesignerActivate); } provider = null; } if (context != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(context); context = null; } this.cookie = 0; }
void IDisposable.Dispose() { if ((_SubContextList != null) && (_SubContextList.Count > 0)) { foreach (HelpService service in _SubContextList) { service._ParentService = null; if (_Context != null) { try { _Context.RemoveSubcontext(service._Cookie); } catch { } } ((IDisposable)service).Dispose(); } _SubContextList = null; } if (_ParentService != null) { IHelpService parentService = _ParentService; _ParentService = null; parentService.RemoveLocalContext(this); } if (_ServiceProvider != null) { _ServiceProvider = null; } if (_Context != null) { Marshal.ReleaseComObject(_Context); _Context = null; } _Cookie = 0; }
/// <devdoc> /// Disposes this object. /// </devdoc> void IDisposable.Dispose() { if (subContextList != null && subContextList.Count > 0) { foreach (HelpService hs in subContextList) { hs.parentService = null; if (context != null) { try { // Here we don't want to check for the return code because we are // disposing the object, so there is nothing we can do in case of error. context.RemoveSubcontext(hs.cookie); } catch (COMException) { /* do nothing */ } } ((IDisposable)hs).Dispose(); } subContextList = null; } if (parentService != null) { IHelpService parent = parentService; parentService = null; parent.RemoveLocalContext(this); } if (provider != null) { provider = null; } if (context != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(context); context = null; } this.cookie = 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); }
/// <include file='doc\HelpService.uex' path='docs/doc[@for="HelpService.AddContextAttribute"]/*' /> /// <devdoc> /// Adds a context attribute to the document. Context attributes are used /// to provide context-sensitive help to users. The designer host will /// automatically add context attributes from available help attributes /// on selected components and properties. This method allows you to /// further customize the context-sensitive help. /// </devdoc> public virtual void AddContextAttribute(string name, string value, HelpKeywordType keywordType) { if (provider == null) { return; } // First, get our context and update the attribute. // IVsUserContext cxt = GetUserContext(); if (cxt != null) { tagVsUserContextAttributeUsage usage = tagVsUserContextAttributeUsage.VSUC_Usage_LookupF1; switch (keywordType) { case HelpKeywordType.F1Keyword: usage = tagVsUserContextAttributeUsage.VSUC_Usage_LookupF1; break; case HelpKeywordType.GeneralKeyword: usage = tagVsUserContextAttributeUsage.VSUC_Usage_Lookup; break; case HelpKeywordType.FilterKeyword: usage = tagVsUserContextAttributeUsage.VSUC_Usage_Filter; break; } cxt.AddAttribute(usage, name, value); // Then notify the shell that it has been updated. // NotifyContextChange(cxt); } }
/// <devdoc> /// Adds a context attribute to the document. Context attributes are used /// to provide context-sensitive help to users. The designer host will /// automatically add context attributes from available help attributes /// on selected components and properties. This method allows you to /// further customize the context-sensitive help. /// </devdoc> void IHelpService.AddContextAttribute(string name, string value, HelpKeywordType keywordType) { if (provider == null) { return; } // First, get our context and update the attribute. // IVsUserContext cxt = GetUserContext(); if (cxt != null) { VSUSERCONTEXTATTRIBUTEUSAGE usage = VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1; switch (keywordType) { case HelpKeywordType.F1Keyword: usage = VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1; break; case HelpKeywordType.GeneralKeyword: usage = VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Lookup; break; case HelpKeywordType.FilterKeyword: usage = VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter; break; } NativeMethods.ThrowOnFailure(cxt.AddAttribute(usage, name, value)); // Then notify the shell that it has been updated. // NotifyContextChange(cxt); } }
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)); } } } } }
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; }
// Help for functions and keywords. Initiated by pressing F1. public override void UpdateLanguageContext(LanguageContextHint hint, IVsTextLines buffer, TextSpan[] ptsSelection, IVsUserContext context) { string searchingKeyword = null; // Search keyword as the function that presented where cursor stays or just before it Source source = (Source)this.GetSource(buffer); Debug.Assert(ptsSelection.Length > 0); int line = ptsSelection[0].iStartLine; int endPosition = ptsSelection[0].iEndIndex; var colorState = new DaxEditor.DaxFormatter.DummyColorState(); TokenInfo[] lineInfos = source.GetColorizer().GetLineInfo(buffer, line, colorState); foreach (var tokenInfo in lineInfos) { if (!(tokenInfo.Type == TokenType.Identifier || tokenInfo.Type == TokenType.Keyword)) { continue; } var span = new TextSpan(); span.iStartLine = line; span.iEndLine = line; span.iStartIndex = tokenInfo.StartIndex; span.iEndIndex = tokenInfo.EndIndex + 1; searchingKeyword = source.GetText(span); if (span.iEndIndex >= endPosition) { break; } } if (!string.IsNullOrEmpty(searchingKeyword)) { ErrorHandler.ThrowOnFailure(context.RemoveAttribute(null, null)); ErrorHandler.ThrowOnFailure(context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Lookup, "keyword", "SQL11.AS.DAXREF." + searchingKeyword + ".F1")); } }
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); }
// IVsProvideUserContext methods public void GetUserContext(out IVsUserContext ppUserContext) { ppUserContext = null; }
internal abstract void GetF1KeywordString(TextSpan span, IVsUserContext context);
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; }
/// <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; }
// IVsProvideUserContext methods public int GetUserContext(out IVsUserContext ppUserContext){ ppUserContext = null; return 0; }
internal virtual int UpdateLanguageContext(LanguageContextHint hint, IVsTextLines buffer, TextSpan[] ptsSelection, IVsUserContext context) { // From the docs: Any failure code: means the implementer is "passing" on this opportunity to provide context and the text editor will fall back to other mechanisms. if (ptsSelection == null || ptsSelection.Length != 1) return NativeMethods.E_FAIL; context.RemoveAttribute(null, null); TextSpan span = ptsSelection[0]; IVsTextLines lastActiveBuffer; IVsTextView lastAciveView = this.LastActiveTextView; if (lastActiveView == null) return NativeMethods.E_FAIL; NativeMethods.ThrowOnFailure(lastActiveView.GetBuffer(out lastActiveBuffer)); if (lastActiveBuffer != buffer) return NativeMethods.E_FAIL; ISource source = GetSource(buffer); if (source == null) return NativeMethods.E_FAIL; var req = source.BeginBackgroundRequest(span.iStartLine, span.iStartIndex, new TokenInfo(), BackgroundRequestReason.FullTypeCheck, lastActiveView, RequireFreshResults.No, new BackgroundRequestResultHandler(this.HandleUpdateLanguageContextResponse)); if (req == null || req.Result == null) return NativeMethods.E_FAIL; if ((req.IsSynchronous || ((req.Result != null) && req.Result.TryWaitForBackgroundRequestCompletion(1000)))) { if (req.IsAborted) return NativeMethods.E_FAIL; if (req.ResultScope != null) { req.ResultScope.GetF1KeywordString(span, context); return NativeMethods.S_OK; } } else // result is asynchronous and have not completed within 1000 ms { context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter, "devlang", "fsharp"); context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1_CaseSensitive, "keyword", "fsharp.typechecking.incomplete"); return NativeMethods.S_OK; } return NativeMethods.E_FAIL; }
/// <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) ); } }
void IDisposable.Dispose() { if ((_SubContextList != null) && (_SubContextList.Count > 0)) { foreach (HelpService service in _SubContextList) { service._ParentService = null; if (_Context != null) { try { _Context.RemoveSubcontext(service._Cookie); } catch { } } ((IDisposable) service).Dispose(); } _SubContextList = null; } if (_ParentService != null) { IHelpService parentService = _ParentService; _ParentService = null; parentService.RemoveLocalContext(this); } if (_ServiceProvider != null) { _ServiceProvider = null; } if (_Context != null) { Marshal.ReleaseComObject(_Context); _Context = null; } _Cookie = 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; }
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; }
// IVsProvideUserContext methods public void GetUserContext(out IVsUserContext ppUserContext){ ppUserContext = null; }
/// <include file='doc\LanguageService.uex' path='docs/doc[@for="LanguageService.UpdateLanguageContext"]/*' /> public virtual void UpdateLanguageContext(LanguageContextHint hint, IVsTextLines buffer, TextSpan[] ptsSelection, IVsUserContext context) { }