/// <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; }
/// <summary> /// Closes the document</summary> /// <param name="document">Document to close</param> /// <returns>True iff close was not cancelled by user</returns> public virtual bool Close(IDocument document) { if (document == null) { return(true); } var args = new DocumentClosingEventArgs(document); DocumentClosing.Raise(this, args); bool closeConfirmed = args.Cancel == false && ConfirmClose(document); if (closeConfirmed) { IDocumentClient client = GetClient(document); OnDocumentClosing(document); client.Close(document); DocumentRegistry.Remove(document); m_untitledDocuments.Remove(document); // in case it was untitled m_newDocumentPaths.Remove(document.Uri.LocalPath); // probably not necessary, but seems like a good idea to clean-up OnDocumentClosed(document); DocumentClosed.Raise(this, new DocumentEventArgs(document, DocumentEventType.Closed)); } return(closeConfirmed); }
/// <summary> /// Create a document relative to specified pane, in a new container. /// </summary> public Control CreateDocument(Control pane, WinForm.ServiceInterfaces.DockAlignment dockAlignment, string tabText, string metadata = "", double portion = 0.25) { DockContent dockContent = new GenericDockContent(metadata); dockContent.DockAreas = DockAreas.Float | DockAreas.DockBottom | DockAreas.DockLeft | DockAreas.DockRight | DockAreas.DockTop | DockAreas.Document; dockContent.TabText = tabText; dockContent.Show(((DockContent)pane).Pane, (WeifenLuo.WinFormsUI.Docking.DockAlignment)dockAlignment, portion); dockContent.FormClosing += (sndr, args) => DocumentClosing.Fire(dockContent, EventArgs.Empty); return(dockContent); }
/// <summary> /// Create a document in the active document panel. /// </summary> public Control CreateDocument(WinForm.ServiceInterfaces.DockState dockState, string tabText, string metadata = "") { DockContent dockContent = new GenericDockContent(metadata); dockContent.DockAreas = DockAreas.Float | DockAreas.DockBottom | DockAreas.DockLeft | DockAreas.DockRight | DockAreas.DockTop | DockAreas.Document; dockContent.TabText = tabText; dockContent.Show(dockPanel, (WeifenLuo.WinFormsUI.Docking.DockState)dockState); dockContent.FormClosing += (sndr, args) => DocumentClosing.Fire(dockContent, EventArgs.Empty); return(dockContent); }
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); } }
protected void LoadApplicationContent() { // ToList(), in case contents are modified while iterating. foreach (DockContent document in dockPanel.Contents.ToList()) { // For content loaded from a layout, we need to rewire FormClosing, since we didn't actually create the DockContent instance. document.FormClosing += (sndr, args) => DocumentClosing.Fire(document, EventArgs.Empty); ContentLoaded.Fire(this, new ContentLoadedEventArgs() { DockContent = document, Metadata = ((GenericDockContent)document).Metadata }); } //foreach (var window in dockPanel.FloatWindows.ToList()) //{ // window.Dispose(); //} //foreach (DockContent doc in dockPanel.Contents.ToList()) //{ // doc.DockHandler.DockPanel = null; // doc.Close(); //} }
protected void RaiseDocumentClosingEvent(EnvDTE.Document document) => DocumentClosing?.Invoke(document);
private void OnDocumentClosing(DocumentContent documentContent) { DocumentClosing?.Invoke(documentContent); }