Exemple #1
0
        public void CloseHtml()
        {
            this.hostControl.Resize -= new EventHandler(this.HostControl_Resize);

            try
            {
                if (this.propertyNotifySinkCookie != null)
                {
                    this.propertyNotifySinkCookie.Disconnect();
                    this.propertyNotifySinkCookie = null;
                }

                if (this.document != null)
                {
                    this.documentView  = null;
                    this.document      = null;
                    this.commandTarget = null;
                    this.activeObject  = null;

                    if (adviseSinkCookie != 0)
                    {
                        this.oleObject.Unadvise(adviseSinkCookie);
                        this.adviseSinkCookie = 0;
                    }

                    this.oleObject.Close(NativeMethods.OLECLOSE_NOSAVE);
                    this.oleObject.SetClientSite(null);
                    this.oleObject = null;
                }
            }
            catch (Exception exception)
            {
                Debug.Fail(exception.ToString());
            }
        }
Exemple #2
0
        public void CreateHtml()
        {
            Debug.Assert(this.document == null, "Must call CloseHtml before recreating.");

            bool created = false;

            try
            {
                // create the trident instance
                this.document  = (NativeMethods.IHTMLDocument2) new NativeMethods.HTMLDocument();
                this.oleObject = (NativeMethods.IOleObject) this.document;

                // hand it our NativeMethods.IOleClientSite implementation
                this.oleObject.SetClientSite((NativeMethods.IOleClientSite) this);

                created = true;

                this.propertyNotifySinkCookie = new NativeMethods.ConnectionPointCookie(this.document, this, typeof(NativeMethods.IPropertyNotifySink), false);

                this.oleObject.Advise((NativeMethods.IAdviseSink) this, out adviseSinkCookie);
                Debug.Assert(adviseSinkCookie != 0);

                this.commandTarget = (NativeMethods.IOleCommandTarget) this.document;
            }
            finally
            {
                if (created == false)
                {
                    this.document      = null;
                    this.oleObject     = null;
                    this.commandTarget = null;
                }
            }
        }
Exemple #3
0
 private void Disconnect()
 {
     if (this.connection != null)
     {
         this.connection.Dispose();
         this.connection = null;
     }
 }
Exemple #4
0
 /// <include file='doc\ViewFilter.uex' path='docs/doc[@for="ViewFilter.ViewFilter"]/*' />
 public ViewFilter(CodeWindowManager mgr, IVsTextView view)
 {
     this.pvaChar          = IntPtr.Zero;
     this.mgr              = mgr;
     this.service          = mgr.LanguageService;
     this.source           = mgr.Source;
     this.commentSupported = this.service.Preferences.EnableCommenting;
     this.textView         = view;
     NativeMethods.ThrowOnFailure(view.AddCommandFilter(this, out nextTarget));
     this.textViewEvents = new NativeMethods.ConnectionPointCookie(view, this, typeof(IVsTextViewEvents));
 }
Exemple #5
0
 private void Connect()
 {
     if (this.connection == null && this.site != null)
     {
         IVsTextManager2 textMgr2 = this.site.GetService(typeof(SVsTextManager)) as IVsTextManager2;
         if (textMgr2 != null)
         {
             this.connection = new NativeMethods.ConnectionPointCookie(textMgr2, (IVsTextManagerEvents2)this, typeof(IVsTextManagerEvents2));
         }
     }
 }
        /// <include file='doc\ShellTextBuffer.uex' path='docs/doc[@for="ShellTextBuffer.SinkTextBufferEvents"]/*' />
        /// <devdoc>
        ///     Called to hook and unhook our the underlying buffer's text changed
        ///     events.
        /// </devdoc>
        private void SinkTextBufferEvents(bool sink)
        {
            if (sink && textStream != null)
            {
                if (bufferEventCookie == null)
                {
                    this.bufferEventCookie = new NativeMethods.ConnectionPointCookie(textStream, this, typeof(IVsTextBufferDataEvents));
                }

                if (textEventCookie == null)
                {
                    textEventCookie = new NativeMethods.ConnectionPointCookie(textStream, this, typeof(IVsTextStreamEvents));
                }

                if (clusterEventCookie == null)
                {
                    clusterEventCookie = new NativeMethods.ConnectionPointCookie(textStream.GetUndoManager(), this, typeof(IVsChangeClusterEvents));
                }
            }
            else
            {
                if (textEventCookie != null)
                {
                    textEventCookie.Disconnect();
                    textEventCookie = null;
                }

                if (bufferEventCookie != null)
                {
                    bufferEventCookie.Disconnect();
                    bufferEventCookie = null;
                }

                if (clusterEventCookie != null)
                {
                    clusterEventCookie.Disconnect();
                    clusterEventCookie = null;
                }
            }
        }
Exemple #7
0
        /// <include file='doc\ViewFilter.uex' path='docs/doc[@for="ViewFilter.Close"]/*' />
        public virtual void Close()
        {
            Trace.WriteLine("ViewFilter::Close");

            if (textViewEvents != null)
            {
                textViewEvents.Dispose();
                textViewEvents = null;
            }

            if (textView == this.service.LastActiveTextView)
            {
                this.service.OnActiveViewChanged(null);
            }

            textView.RemoveCommandFilter(this); // do not care about HRESULT.
            if (textTipData != null)
            {
                textTipData.Close(textView);
                textTipData = null;
            }

            Dispose();
        }
Exemple #8
0
        // Overriden in source.fs, it calls this base implementation
        public virtual void Dispose()
        {
#if LANGTRACE
            Trace.WriteLine("Source::Cleanup");
#endif
            this.disposed = true;
            try
            {
                if (this.textLinesEvents != null)
                {
                    this.textLinesEvents.Dispose();
                    this.textLinesEvents = null;
                }
            }
            finally
            {
                try
                {
                    if (this.userDataEvents != null)
                    {
                        this.userDataEvents.Dispose();
                        this.userDataEvents = null;
                    }
                }
                finally
                {
                    try
                    {
                        if (this.hiddenTextSession != null)
                        {
                            // We can't throw or exit here because we need to call Dispose on the
                            // other members that need to be disposed.
                            this.hiddenTextSession.UnadviseClient();
                            // This is causing a debug assert in vs\env\msenv\textmgr\vrlist.cpp
                            // at line 1997 in CVisibleRegionList::Terminate
                            //this.hiddenTextSession.Terminate();
                            this.hiddenTextSession = null;
                        }
                    }
                    finally
                    {
                        try
                        {
                            if (this.methodData != null)
                            {
                                this.methodData.Dispose();
                                this.methodData = null;
                            }
                        }
                        finally
                        {
                            try
                            {
                                if (this.completionSet != null)
                                {
                                    this.completionSet.Dispose();
                                    this.completionSet = null;
                                }
                            }
                            finally
                            {
                                try
                                {
                                    // clear out any remaining tasks for this doc in the task list
                                    // tp may not be the same as taskProvider

                                    // REVIEW: This should be: if (null != this.taskReporter)
                                    // Right now, MSBuild 4.0 can clear out build loggers responsibly, so this.taskReporter will always
                                    // be null when we get to this point, so we'll need to create a new taskReporter to clear out the
                                    // background tasks
                                    TaskReporter tr = this.GetTaskReporter();  // may be our own TR or one from ProjectSite of this file
                                    if (null != tr)
                                    {
                                        tr.ClearBackgroundTasksForFile(this.GetFilePath());
                                        // Refresh the task list
                                        tr.OutputTaskList();
                                    }
                                    if (null != this.taskReporter)      // dispose the one we own (do not dispose one shared by project site!)
                                    {
                                        this.taskReporter.Dispose();
                                        this.taskReporter = null;
                                        this.taskProvider = null;
                                    }
                                }
                                finally
                                {
                                    try
                                    {
                                        this.service = null;
                                        if (this.colorizer != null)
                                        {
                                            // The colorizer is owned by the core text editor, so we don't close it, the core text editor
                                            // does that for us when it is ready to do so.
                                            //colorizer.CloseColorizer();
                                            this.colorizer = null;
                                        }
                                    }
                                    finally
                                    {
                                        this.colorState = null;
                                        try
                                        {
                                            if (this.expansionProvider != null)
                                            {
                                                this.expansionProvider.Dispose();
                                                this.expansionProvider = null;
                                            }

                                        }
                                        finally
                                        {
                                            // Sometimes OnCloseSource is called when language service is changed, (for example
                                            // when you save the file with a different file extension) in which case we cannot 
                                            // null out the site because that will cause a crash inside msenv.dll.
                                            //            if (this.textLines != null) {
                                            //                ((IObjectWithSite)this.textLines).SetSite(null);
                                            //            }
                                            if (this.textLines != null)
                                            {
                                                this.textLines = null;
                                                Marshal.Release(pUnkTextLines);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #9
0
        internal SourceImpl(LanguageService service, IVsTextLines textLines, Colorizer colorizer)
        {
#if LANGTRACE
            Tracing.TraceRef(textLines, "Source.textLines");
#endif
            this.service = service;
            this.textLines = textLines;
            // REVIEW: why the next line? RCW in this.textLines holds IUnknown already. (released in Dispose correctly though)
            pUnkTextLines = Marshal.GetIUnknownForObject(this.textLines); //so it can't get disposed on us
            this.colorizer = colorizer;
            this.completionSet = this.CreateCompletionSet();
            this.methodData = new MethodData(this.service.Site);
            this.colorState = (IVsTextColorState)textLines;
            // track source changes
            this.textLinesEvents = new NativeMethods.ConnectionPointCookie(textLines, this, typeof(IVsTextLinesEvents));
            this.userDataEvents = new NativeMethods.ConnectionPointCookie(textLines, this, typeof(IVsUserDataEvents));

            this.doOutlining = this.service.Preferences.AutoOutlining;
            if (this.doOutlining)
            {
                GetHiddenTextSession();
            }
            this.expansionProvider = GetExpansionProvider();

            this.lastOnIdleRequestDuration = 0;

            this.openedTime = System.DateTime.Now;
        }
 internal ViewFilter(CodeWindowManager mgr, IVsTextView view) {
     this.pvaChar = IntPtr.Zero;
     this.mgr = mgr;
     this.service = mgr.LanguageService;
     this.source = mgr.Source;
     this.commentSupported = this.service.Preferences.EnableCommenting;
     this.textView = view;
     NativeMethods.ThrowOnFailure(view.AddCommandFilter(this, out nextTarget));
     this.textViewEvents = new NativeMethods.ConnectionPointCookie(view, this, typeof(IVsTextViewEvents));
     if (this.service != null) {
         IVsExpansionManager emgr = this.service.Site.GetService(typeof(SVsExpansionManager)) as IVsExpansionManager;
         if (emgr != null) {
             int fBound;
             emgr.GetSnippetShortCutKeybindingState(out fBound);
             this.snippetBound = fBound == 0 ? false : true;
             this.expansionEvents = new NativeMethods.ConnectionPointCookie(emgr, this, typeof(IVsExpansionEvents));
         }
     }
 }
        public virtual void Close() {
#if LANGTRACE
            Trace.WriteLine("ViewFilter::Close");
#endif
            if (this.expansionEvents != null) {
                expansionEvents.Dispose();
                expansionEvents = null;
            }
            if (textViewEvents != null) {
                textViewEvents.Dispose();
                textViewEvents = null;
            }

            if (textView == this.service.LastActiveTextView)
                this.service.OnActiveViewChanged(null);

            textView.RemoveCommandFilter(this); // do not care about HRESULT.
            if (textTipData != null) {
                textTipData.Close(textView);
                textTipData = null;
            }

            Dispose();
        }
Exemple #12
0
 private void Disconnect() {
     if (this.connection != null) {
         this.connection.Dispose();
         this.connection = null;
     }
 }
Exemple #13
0
 private void Connect() {
     if (this.connection == null && this.site != null) {
         IVsTextManager2 textMgr2 = this.site.GetService(typeof(SVsTextManager)) as IVsTextManager2;
         if (textMgr2 != null) {
             this.connection = new NativeMethods.ConnectionPointCookie(textMgr2, (IVsTextManagerEvents2)this, typeof(IVsTextManagerEvents2));
         }
     }
 }
Exemple #14
0
 /// <include file='doc\Source.uex' path='docs/doc[@for="Source.RegisterTextBufferEventHandlers"]/*' />
 public virtual void RegisterTextBufferEventHandlers(IVsTextLines textLines)
 {
     // track source changes
     this.textLinesEvents = new NativeMethods.ConnectionPointCookie(textLines, this, typeof(IVsTextLinesEvents));
     this.userDataEvents = new NativeMethods.ConnectionPointCookie(textLines, this, typeof(IVsUserDataEvents));
 }
Exemple #15
0
        /// <include file='doc\LanguageService.uex' path='docs/doc[@for="Source.Dispose"]/*' />
        public virtual void Dispose()
        {
            #if LANGTRACE
            Trace.WriteLine("Source::Cleanup");
            #endif
            try {
                if (this.textLinesEvents != null) {
                    this.textLinesEvents.Dispose();
                    this.textLinesEvents = null;
                }
            } catch (COMException) {
            }
            try {
                if (this.userDataEvents != null) {
                    this.userDataEvents.Dispose();
                    this.userDataEvents = null;
                }
            } catch (COMException) {
            }
            try {
                if (this.hiddenTextSession != null) {
                    // We can't throw or exit here because we need to call Dispose on the
                    // other members that need to be disposed.
                    this.hiddenTextSession.UnadviseClient();
                    this.hiddenTextSession = null;
                }
            } catch (COMException) {
            }
            try {
                if (this.methodData != null) {
                    this.methodData.Dispose();
                    this.methodData = null;
                }
            } catch (COMException) {
            }
            try {
                if (this.completionSet != null) {
                    this.completionSet.Dispose();
                    this.completionSet = null;
                }
            } catch (COMException) {
            }
            try {

                if (this.taskProvider != null) {
                    this.taskProvider.Dispose();
                    this.taskProvider = null;
                }
            } catch (COMException) {
            }
            try {
                this.service = null;
                if (this.colorizer != null) {
                    // The colorizer is owned by the core text editor, so we don't close it, the core text editor
                    // does that for us when it is ready to do so.
                    //colorizer.CloseColorizer();
                    this.colorizer = null;
                }
            } catch (COMException) {
            }
            try {
                if (this.colorState != null) {
                    this.colorState = null;
                }
            } catch (COMException) {
            }
            try {
                if (this.expansionProvider != null) {
                    this.expansionProvider.Dispose();
                    this.expansionProvider = null;
                }

            } catch (COMException) {
            }
            try {

                // Sometimes OnCloseSource is called when language service is changed, (for example
                // when you save the file with a different file extension) in which case we cannot
                // null out the site because that will cause a crash inside msenv.dll.
                //            if (this.textLines != null) {
                //                ((IObjectWithSite)this.textLines).SetSite(null);
                //            }
                if (this.textLines != null) {
                    this.textLines = null; //rely on GC rather control lifetime through ReleaseCOMObject
                    Marshal.Release(pUnkTextLines);
                }
            } catch (COMException) {
            }
        }