Exemplo n.º 1
0
        /// <summary>
        /// Closes the document
        /// </summary>
        public virtual void Close()
        {
            if (IsClosed)
            {
                return;
            }

            IsClosed = true;
            _textDocumentFactoryService.TextDocumentDisposed -= OnTextDocumentDisposed;

            DocumentClosing?.Invoke(this, null);

            if (EditorTree != null)
            {
                _editorTree.Dispose(); // this will also remove event handlers
                _editorTree = null;
            }

            if (DocumentClosing != null)
            {
                foreach (EventHandler <EventArgs> eh in DocumentClosing.GetInvocationList())
                {
                    Debug.Fail(String.Format(CultureInfo.CurrentCulture, "There are still listeners in the EditorDocument.OnDocumentClosing event list: {0}", eh.Target));
                    DocumentClosing -= eh;
                }
            }

            ServiceManager.RemoveService <REditorDocument>(TextBuffer);
            TextBuffer = null;
        }
Exemplo n.º 2
0
        async Task OnDocumentClosing(DocumentCloseEventArgs args)
        {
            try {
                if (DocumentClosing != null)
                {
                    foreach (var handler in DocumentClosing.GetInvocationList().Cast <DocumentCloseAsyncEventHandler> ())
                    {
                        await handler(this, args);

                        if (args.Cancel)
                        {
                            break;
                        }
                    }
                }
            } catch (Exception ex) {
                LoggingService.LogError("Exception before closing documents", ex);
            }
        }