Beispiel #1
0
        public virtual int SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider site)
        {
            this.site = new ServiceProvider(site);

            // register our independent view with the IVsTextManager so that it knows
            // the user is working with a view over the text buffer. this will trigger
            // the text buffer to prompt the user whether to reload the file if it is
            // edited outside of the development Environment.
            IVsTextManager textManager = (IVsTextManager)this.site.QueryService(VsConstants.SID_SVsTextManager, typeof(IVsTextManager));

            if (textManager != null)
            {
                IVsWindowPane windowPane = (IVsWindowPane)this;
                textManager.RegisterIndependentView(this, (VsTextBuffer)this.buffer);
            }

            //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 this.componentID);
            }
            return(0);
        }
        /// <summary>
        /// Registers an independent view with the IVsTextManager so that it knows
        /// the user is working with a view over the text buffer. This will trigger
        /// the text buffer to prompt the user whether to reload the file if it is
        /// edited outside of the environment.
        /// </summary>
        /// <param name="subscribe">True to subscribe, false to unsubscribe</param>
        void RegisterIndependentView(bool subscribe)
        {
            IVsTextManager textManager = (IVsTextManager)GetService(typeof(SVsTextManager));

            if (textManager != null)
            {
                if (subscribe)
                {
                    textManager.RegisterIndependentView((IVsWindowPane)this, this._textBuffer);
                }
                else
                {
                    textManager.UnregisterIndependentView((IVsWindowPane)this, this._textBuffer);
                }
            }
        }
        /// <summary>
        /// Registers an independent view with the IVsTextManager so that it knows
        /// the user is working with a view over the text buffer. This will trigger
        /// the text buffer to prompt the user whether to reload the file if it is
        /// edited outside of the environment.
        /// </summary>
        /// <param name="subscribe">True to subscribe, false to unsubscribe</param>
        void RegisterIndependentView(bool subscribe)
        {
            IVsTextManager textManager = (IVsTextManager)GetService(typeof(SVsTextManager));

            if (textManager != null)
            {
                if (subscribe)
                {
                    AdviseFileChanges(_fileName);
                    textManager.RegisterIndependentView(this, _textBuffer);
                }
                else
                {
                    UnadviseFileChanges();
                    textManager.UnregisterIndependentView(this, _textBuffer);
                }
            }
        }
Beispiel #4
0
        /// <include file='doc\EditorView.uex' path='docs/doc[@for="SimpleEditorView.SetSite"]/*' />
        public virtual int SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider site)
        {
            this.site = new ServiceProvider(site);

            if (this.buffer != null)
            {
                // register our independent view with the IVsTextManager so that it knows
                // the user is working with a view over the text buffer. this will trigger
                // the text buffer to prompt the user whether to reload the file if it is
                // edited outside of the development Environment.
                IVsTextManager textManager = (IVsTextManager)this.site.GetService(typeof(SVsTextManager));
                // NOTE: NativeMethods.ThrowOnFailure is removed from this method because you are not allowed
                // to fail a SetSite call, see debug assert at f:\dd\env\msenv\core\docwp.cpp line 87.
                int hr = 0;
                if (textManager != null)
                {
                    IVsWindowPane windowPane = (IVsWindowPane)this;
                    hr = textManager.RegisterIndependentView(this, (VsTextBuffer)this.buffer);
                    if (!NativeMethods.Succeeded(hr))
                    {
                        Debug.Assert(false, "RegisterIndependentView failed");
                    }
                    Marshal.ReleaseComObject(textManager);
                }
            }

            //register with ComponentManager for Idle processing
            this.componentManager = (IOleComponentManager)this.site.GetService(typeof(SOleComponentManager));
            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 | (uint)_OLECRF.olecrfNeedAllActiveNotifs | (uint)_OLECRF.olecrfNeedSpecActiveNotifs;
                crinfo[0].grfcadvf          = (uint)_OLECADVF.olecadvfModal | (uint)_OLECADVF.olecadvfRedrawOff | (uint)_OLECADVF.olecadvfWarningsOff;
                crinfo[0].uIdleTimeInterval = 1000;
                int hr = this.componentManager.FRegisterComponent(this, crinfo, out this.componentID);
                if (!NativeMethods.Succeeded(hr))
                {
                    Debug.Assert(false, "FRegisterComponent failed");
                }
            }
            return(NativeMethods.S_OK);
        }