Example #1
0
 /// <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;
 }
Example #2
0
 /// <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;
 }
Example #3
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;
        }
Example #4
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;
        }
Example #5
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;
        }
Example #6
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);
        }