private void SetActiveView(IView view) { PerformanceUtility.MeasurePerformanceUntilRender(PerformanceEvent.SwitchView); IDocumentView documentView = view as IDocumentView; DocumentService.Item obj = documentView != null ? this.items[documentView.Document] : (DocumentService.Item)null; this.SetActiveDocumentAndView(view, obj); }
private void SetActiveDocumentAndView(IView view, DocumentService.Item item) { PerformanceUtility.StartPerformanceSequence(PerformanceEvent.SetActiveDocumentAndView); ViewChangedEventArgs e1 = view != this.activeView ? new ViewChangedEventArgs(this.activeView, view) : (ViewChangedEventArgs)null; IDocument oldDocument = this.activeItem != null ? this.activeItem.Document : (IDocument)null; IDocument newDocument = item != null ? item.Document : (IDocument)null; DocumentChangedEventArgs e2 = item != this.activeItem ? new DocumentChangedEventArgs(oldDocument, newDocument) : (DocumentChangedEventArgs)null; if (e1 != null || e2 != null) { if (e1 != null) { PerformanceUtility.MarkInterimStep(PerformanceEvent.SetActiveDocumentAndView, "OnActiveViewChanging"); if (e1.OldView != null) { e1.OldView.Deactivating(); } this.OnActiveViewChanging(e1); } if (e2 != null) { PerformanceUtility.MarkInterimStep(PerformanceEvent.SetActiveDocumentAndView, "OnActiveDocumentChanging"); this.OnActiveDocumentChanging(e2); } this.activeItem = item; this.activeView = view; if (this.activeView != null) { PerformanceUtility.MarkInterimStep(PerformanceEvent.SetActiveDocumentAndView, "RecordViewUse"); this.RecordViewUse(this.activeView); this.activeView.ReturnFocus(); } else { try { if (Application.Current != null) { if (Application.Current.MainWindow != null) { FocusManager.SetFocusedElement((DependencyObject)Application.Current.MainWindow, (IInputElement)Application.Current.MainWindow); } } } catch { } } if (e2 != null) { PerformanceUtility.MarkInterimStep(PerformanceEvent.SetActiveDocumentAndView, "OnActiveDocumentChanged"); this.OnActiveDocumentChanged(e2); } if (e1 != null) { PerformanceUtility.MarkInterimStep(PerformanceEvent.SetActiveDocumentAndView, "OnActiveViewChanged"); if (e1.OldView != null) { e1.OldView.Deactivated(); ICommandTarget target = e1.OldView as ICommandTarget; if (target != null) { this.commandService.RemoveTarget(target); } } if (e1.NewView != null) { e1.NewView.Activated(); ICommandTarget target = e1.NewView as ICommandTarget; if (target != null) { this.commandService.AddTarget(target); } } this.OnActiveViewChanged(e1); } if (e2 != null) { PerformanceUtility.MarkInterimStep(PerformanceEvent.SetActiveDocumentAndView, "UpdateTargets"); ICommandTarget target1; if ((target1 = oldDocument as ICommandTarget) != null) { this.commandService.RemoveTarget(target1); } ICommandTarget target2; if ((target2 = newDocument as ICommandTarget) != null) { this.commandService.AddTarget(target2); } } } PerformanceUtility.EndPerformanceSequence(PerformanceEvent.SetActiveDocumentAndView); }
private void SetActiveItem(DocumentService.Item item) { PerformanceUtility.MeasurePerformanceUntilRender(PerformanceEvent.SwitchView); this.SetActiveDocumentAndView(item == null || item.Views.Count <= 0 ? (IView)null : item.Views[0], item); }
public void CloseView(IView view) { if (view == null) { throw new ArgumentNullException("view"); } if (view == this.ActiveView) { IView view1 = (IView)null; if (this.views.Count > 0) { if (view != this.views[0]) { view1 = this.views[0]; } else if (this.views.Count > 1) { view1 = this.views[1]; } } this.SetActiveView(view1); } this.views.Remove(view); IDocument document = (IDocument)null; try { IDocumentView documentView = view as IDocumentView; DocumentService.Item obj1 = (DocumentService.Item)null; if (documentView != null) { DocumentService.Item obj2 = this.items[documentView.Document]; obj2.RemoveView((IView)documentView); if (obj2.Views.Count == 0) { obj1 = obj2; } } bool flag = this.RecycleView(view); this.OnViewClosed(new ViewEventArgs(view)); if (flag) { view = (IView)null; } else { if (obj1 == null) { return; } ((Collection <DocumentService.Item>) this.items).Remove(obj1); document = obj1.Document; this.documents.Remove(document); this.OnDocumentClosed(new DocumentEventArgs(document)); } } finally { if (view != null) { view.Dispose(); } if (document != null) { document.Dispose(); } } }