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