예제 #1
0
        public virtual void Close()
        {
            if (this.site != null)
            {
                if (this.editorFactory != null)
                {
                    Guid editorGuid        = this.editorFactory.GetType().GUID;
                    IVsRegisterEditors vre = (IVsRegisterEditors)site.QueryService(VsConstants.SID_SVsRegisterEditors, typeof(IVsRegisterEditors));
                    vre.UnregisterEditor(this.editorFactoryCookie);
                    this.editorFactory.Close();
                    this.editorFactory = null;
                }
                if (this.projectFactory != null)
                {
                    IVsRegisterProjectTypes rpt = (IVsRegisterProjectTypes)this.site.QueryService(VsConstants.SID_IVsRegisterProjectTypes, typeof(IVsRegisterProjectTypes));
                    if (rpt != null)
                    {
                        rpt.UnregisterProjectType(this.projectFactoryCookie);
                    }
                    this.projectFactoryCookie = 0;
                    this.projectFactory.Close();
                    this.projectFactory = null;
                }
            }
            foreach (LanguageService svc in this.languageServices.Values)
            {
                svc.Done();
            }
            this.languageServices.Clear();

            if (this.componentID != 0)
            {
                this.componentManager.FRevokeComponent(this.componentID);
                this.componentID = 0;
            }
            this.componentManager = null;

            if (site != null)
            {
                site.Dispose();
            }
            this.site = null;
            GC.Collect();
        }
예제 #2
0
    public virtual void SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider site){

      this.site = new ServiceProvider(site);
      this.editorFactory = CreateEditorFactory();
      if (this.editorFactory != null) {
        this.editorFactory.SetSite(site);
        Guid editorGuid = this.editorFactory.GetType().GUID;
        IVsRegisterEditors vre = (IVsRegisterEditors)this.site.QueryService( VsConstants.SID_SVsRegisterEditors, typeof(IVsRegisterEditors));
        vre.RegisterEditor(ref editorGuid, editorFactory, out this.editorFactoryCookie);
      }

      this.projectFactory = CreateProjectFactory();
      if (this.projectFactory != null) {
        this.projectFactory.SetSite(site);
        IVsRegisterProjectTypes rpt = (IVsRegisterProjectTypes)this.site.QueryService(VsConstants.SID_IVsRegisterProjectTypes, typeof(IVsRegisterProjectTypes));
        if (rpt != null) {
          Guid projectType = this.projectFactory.GetType().GUID;
          rpt.RegisterProjectType(ref projectType, this.projectFactory, out this.projectFactoryCookie);          
        }
      }

      uint lcid = VsShell.GetProviderLocale(this.site);

      languageServices = new Hashtable();
      string thisPackage = "{"+this.GetType().GUID.ToString() + "}";
      ServiceProvider thisSite = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)this);

      ILocalRegistry3 localRegistry = (ILocalRegistry3)this.site.QueryService( VsConstants.SID_SLocalRegistry, typeof(ILocalRegistry3));
      string root = null;        
      if (localRegistry != null) {
        localRegistry.GetLocalRegistryRoot(out root);
      }
      using (RegistryKey rootKey = Registry.LocalMachine.OpenSubKey(root)) {
        if (rootKey != null) {
          using (RegistryKey languages = rootKey.OpenSubKey("Languages\\Language Services")) {
            if (languages != null) {
              foreach (string languageName in languages.GetSubKeyNames()) {
                using (RegistryKey langKey = languages.OpenSubKey(languageName)) {
                  object pkg = langKey.GetValue("Package");
                  if (pkg is string && (string)pkg == thisPackage) {
                    object guid = langKey.GetValue(null);
                    if (guid is string) {
                      Guid langGuid = new Guid((string)guid);
                      if (!this.languageServices.Contains(langGuid.ToString())){
                        LanguageService svc = CreateLanguageService(ref langGuid);
                        if (svc != null) {
                          svc.Init(thisSite, ref langGuid, lcid, GetFileExtensions(rootKey, (string)guid));
                          this.languageServices.Add(langGuid.ToString(), svc);
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }

      //register with ComponentManager for Idle processing
      this.componentManager = (IOleComponentManager)this.site.QueryService(VsConstants.SID_SOleComponentManager, typeof(IOleComponentManager));
      if (componentID == 0)
      {
          OLECRINFO[]   crinfo = new OLECRINFO[1];
          crinfo[0].cbSize   = (uint)Marshal.SizeOf(typeof(OLECRINFO));
          crinfo[0].grfcrf   = (uint)OLECRF.olecrfNeedIdleTime |
                               (uint)OLECRF.olecrfNeedPeriodicIdleTime; 
          crinfo[0].grfcadvf = (uint)OLECADVF.olecadvfModal |
                               (uint)OLECADVF.olecadvfRedrawOff |
                               (uint)OLECADVF.olecadvfWarningsOff;
          crinfo[0].uIdleTimeInterval = 1000;
          this.componentManager.FRegisterComponent(this, crinfo, out componentID);
      }

    }
예제 #3
0
    public virtual void Close()	{
      if (this.site != null) {
        if (this.editorFactory != null) {
          Guid editorGuid = this.editorFactory.GetType().GUID;
          IVsRegisterEditors vre = (IVsRegisterEditors)site.QueryService( VsConstants.SID_SVsRegisterEditors, typeof(IVsRegisterEditors));
          vre.UnregisterEditor(this.editorFactoryCookie);
          this.editorFactory.Close();
          this.editorFactory = null;
        }
        if (this.projectFactory != null) {
          IVsRegisterProjectTypes rpt = (IVsRegisterProjectTypes)this.site.QueryService(VsConstants.SID_IVsRegisterProjectTypes, typeof(IVsRegisterProjectTypes));
          if (rpt != null) {
            rpt.UnregisterProjectType(this.projectFactoryCookie);          
          }
          this.projectFactoryCookie = 0;
          this.projectFactory.Close();
          this.projectFactory = null;
        }

      }
      foreach (LanguageService svc in this.languageServices.Values) {
        svc.Done();
      }
      this.languageServices.Clear();

      if (this.componentID != 0) {
        this.componentManager.FRevokeComponent(this.componentID);
        this.componentID = 0;
      }
      this.componentManager = null;

      if (site != null) site.Dispose();
      this.site = null;
      GC.Collect();
    }
예제 #4
0
        public virtual void SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider site)
        {
            this.site          = new ServiceProvider(site);
            this.editorFactory = CreateEditorFactory();
            if (this.editorFactory != null)
            {
                this.editorFactory.SetSite(site);
                Guid editorGuid        = this.editorFactory.GetType().GUID;
                IVsRegisterEditors vre = (IVsRegisterEditors)this.site.QueryService(VsConstants.SID_SVsRegisterEditors, typeof(IVsRegisterEditors));
                vre.RegisterEditor(ref editorGuid, editorFactory, out this.editorFactoryCookie);
            }

            this.projectFactory = CreateProjectFactory();
            if (this.projectFactory != null)
            {
                this.projectFactory.SetSite(site);
                IVsRegisterProjectTypes rpt = (IVsRegisterProjectTypes)this.site.QueryService(VsConstants.SID_IVsRegisterProjectTypes, typeof(IVsRegisterProjectTypes));
                if (rpt != null)
                {
                    Guid projectType = this.projectFactory.GetType().GUID;
                    rpt.RegisterProjectType(ref projectType, this.projectFactory, out this.projectFactoryCookie);
                }
            }

            uint lcid = VsShell.GetProviderLocale(this.site);

            languageServices = new Hashtable();
            string          thisPackage = "{" + this.GetType().GUID.ToString() + "}";
            ServiceProvider thisSite    = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider) this);

            ILocalRegistry3 localRegistry = (ILocalRegistry3)this.site.QueryService(VsConstants.SID_SLocalRegistry, typeof(ILocalRegistry3));
            string          root          = null;

            if (localRegistry != null)
            {
                localRegistry.GetLocalRegistryRoot(out root);
            }
            using (RegistryKey rootKey = Registry.LocalMachine.OpenSubKey(root)) {
                if (rootKey != null)
                {
                    using (RegistryKey languages = rootKey.OpenSubKey("Languages\\Language Services")) {
                        if (languages != null)
                        {
                            foreach (string languageName in languages.GetSubKeyNames())
                            {
                                using (RegistryKey langKey = languages.OpenSubKey(languageName)) {
                                    object pkg = langKey.GetValue("Package");
                                    if (pkg is string && (string)pkg == thisPackage)
                                    {
                                        object guid = langKey.GetValue(null);
                                        if (guid is string)
                                        {
                                            Guid langGuid = new Guid((string)guid);
                                            if (!this.languageServices.Contains(langGuid.ToString()))
                                            {
                                                LanguageService svc = CreateLanguageService(ref langGuid);
                                                if (svc != null)
                                                {
                                                    svc.Init(thisSite, ref langGuid, lcid, GetFileExtensions(rootKey, (string)guid));
                                                    this.languageServices.Add(langGuid.ToString(), svc);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //register with ComponentManager for Idle processing
            this.componentManager = (IOleComponentManager)this.site.QueryService(VsConstants.SID_SOleComponentManager, typeof(IOleComponentManager));
            if (componentID == 0)
            {
                OLECRINFO[] crinfo = new OLECRINFO[1];
                crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO));
                crinfo[0].grfcrf = (uint)OLECRF.olecrfNeedIdleTime |
                                   (uint)OLECRF.olecrfNeedPeriodicIdleTime;
                crinfo[0].grfcadvf = (uint)OLECADVF.olecadvfModal |
                                     (uint)OLECADVF.olecadvfRedrawOff |
                                     (uint)OLECADVF.olecadvfWarningsOff;
                crinfo[0].uIdleTimeInterval = 1000;
                this.componentManager.FRegisterComponent(this, crinfo, out componentID);
            }
        }