public void AddDocument(IDocumentTabViewModel document) { DocumentTabs.Documents.Add(document); DocumentTabs.SelectedDocument = document; DocumentTabs.InvalidateSeperatorVisibility(); }
public void RemoveDocument(IDocumentTabViewModel document) { if (document == null) { return; } IDocumentTabViewModel newSelectedTab = DocumentTabs.SelectedDocument; if (DocumentTabs.SelectedDocument == document) { var index = DocumentTabs.Documents.IndexOf(document); var current = index; bool foundTab = false; while (!foundTab) { index++; if (index < DocumentTabs.Documents.Count) { if (DocumentTabs.Documents[index].IsVisible) { foundTab = true; newSelectedTab = DocumentTabs.Documents[index]; break; } } else { break; } } index = current; while (!foundTab) { index--; if (index >= 0) { if (DocumentTabs.Documents[index].IsVisible) { foundTab = true; newSelectedTab = DocumentTabs.Documents[index]; break; } } else { break; } } } DocumentTabs.SelectedDocument = newSelectedTab; document.IsVisible = false; if (document is EditorViewModel doc) { doc.Save(); } if (DocumentTabs.TemporaryDocument == document) { DocumentTabs.TemporaryDocument = null; } if (DocumentTabs.Documents.OfType <EditorViewModel>().Where(d => !d.IsVisible).Count() == 5) { var toRemove = DocumentTabs.Documents.OfType <EditorViewModel>().Where(d => !d.IsVisible).First(); DocumentTabs.Documents.Remove(toRemove); toRemove.OnClose(); Dispatcher.UIThread.InvokeAsync(async() => { await Task.Delay(25); GC.Collect(); }); } DocumentTabs.InvalidateSeperatorVisibility(); }