/// <summary> /// Switch model contexts. /// </summary> /// <param name="newContextVM">New model context vm.</param> /// <param name="oldContextVM">Old model context vm.</param> /// <returns>True if a switch did occur. False otherwise.</returns> protected virtual bool SwitchContexts(ModelContextViewModel newContextVM, ModelContextViewModel oldContextVM) { if (this.ModelData.CurrentModelContext.RootElement != null) { // notify that the current document will be closed IMessageBoxService messageBox = this.GlobalServiceProvider.Resolve <IMessageBoxService>(); if (messageBox.ShowYesNoCancel("The currently opened document will be closed in the process of a context switch! Do you want to proceed?", CustomDialogIcons.Question) != CustomDialogResults.Yes) { return(false); } } PleaseWaitHelper.Show(); BeforeSwitchContexts(newContextVM, oldContextVM); if (this.ModelData.CurrentModelContext.RootElement != null) { this.ModelData.CurrentModelContext.Reset(); } this.Reset(); // update model data this.ModelData.CurrentModelContext = newContextVM.ModelContext; AfterSwitchContexts(newContextVM, oldContextVM); PleaseWaitHelper.Hide(); return(true); }
/// <summary> /// This method is called from the SwitchContexts method after a switch occurs. /// </summary> /// <param name="newContextVM">New model context vm.</param> /// <param name="oldContextVM">Old model context vm.</param> protected virtual void AfterSwitchContexts(ModelContextViewModel newContextVM, ModelContextViewModel oldContextVM) { if (newContextVM != null) { //if (newContextVM.DiagramSurfaceModel != null) // this.EventManager.GetEvent<ShowViewModelRequestEvent>().Publish(new ShowViewModelRequestEventArgs(newContextVM.DiagramSurfaceModel)); newContextVM.OnActivated(); } }
/// <summary> /// This method is called from the SwitchContexts method before a switch occurs. /// </summary> /// <param name="newContextVM">New model context vm.</param> /// <param name="oldContextVM">Old model context vm.</param> protected override void BeforeSwitchContexts(ModelContextViewModel newContextVM, ModelContextViewModel oldContextVM) { if (oldContextVM != null) { if (this.LayoutManager != null) { this.LayoutManager.SaveCurrentConfiguration(oldContextVM.ModelContext.Name); } } base.BeforeSwitchContexts(newContextVM, oldContextVM); }
/// <summary> /// This method is called from the SwitchContexts method after a switch occurs. /// </summary> /// <param name="newContextVM">New model context vm.</param> /// <param name="oldContextVM">Old model context vm.</param> protected override void AfterSwitchContexts(ModelContextViewModel newContextVM, ModelContextViewModel oldContextVM) { base.AfterSwitchContexts(newContextVM, oldContextVM); if (newContextVM != null) { if (this.LayoutManager != null) { this.LayoutManager.RestoreConfiguration(newContextVM.ModelContext.Name, this.AllViewModels); } } this.CloseCommand.RaiseCanExecuteChanged(); this.SaveAsModelCommand.RaiseCanExecuteChanged(); this.SaveModelCommand.RaiseCanExecuteChanged(); }
/// <summary> /// This method is called from the SwitchContexts method before a switch occurs. /// </summary> /// <param name="newContextVM">New model context vm.</param> /// <param name="oldContextVM">Old model context vm.</param> protected virtual void BeforeSwitchContexts(ModelContextViewModel newContextVM, ModelContextViewModel oldContextVM) { if (oldContextVM != null) { foreach (BaseDiagramSurfaceViewModel vm in oldContextVM.AdditionalDiagramSurfaceModels) { if (vm.IsDockingPaneVisible) { this.EventManager.GetEvent <CloseViewModelRequestEvent>().Publish(new CloseViewModelRequestEventArgs(vm)); } } foreach (BaseDiagramSurfaceViewModel vm in oldContextVM.PluginDiagramSurfaceModels) { if (vm.IsDockingPaneVisible) { this.EventManager.GetEvent <CloseViewModelRequestEvent>().Publish(new CloseViewModelRequestEventArgs(vm)); } } for (int i = unknownOpenedModels.Count - 1; i >= 0; i--) { BaseDockingViewModel vm = unknownOpenedModels[i]; if (!vm.IsDisposed) { this.EventManager.GetEvent <CloseViewModelRequestEvent>().Publish(new CloseViewModelRequestEventArgs(vm, true)); } } } // close all view models that do not belong to the new context foreach (BaseDockingViewModel vm in this.AllViewModels) { if (vm is BaseDiagramSurfaceViewModel) { if ((vm as BaseDiagramSurfaceViewModel).ModelContextName != newContextVM.ModelContext.Name && !String.IsNullOrEmpty((vm as BaseDiagramSurfaceViewModel).ModelContextName)) { this.EventManager.GetEvent <CloseViewModelRequestEvent>().Publish(new CloseViewModelRequestEventArgs(vm)); } } } }
/// <summary> /// This method is called from the SwitchContexts method after a switch occurs. /// </summary> /// <param name="newContextVM">New model context vm.</param> /// <param name="oldContextVM">Old model context vm.</param> protected override void AfterSwitchContexts(ModelContextViewModel newContextVM, ModelContextViewModel oldContextVM) { base.AfterSwitchContexts(newContextVM, oldContextVM); if (newContextVM != null) { if (this.LayoutManager != null) this.LayoutManager.RestoreConfiguration(newContextVM.ModelContext.Name, this.AllViewModels); } this.CloseCommand.RaiseCanExecuteChanged(); this.SaveAsModelCommand.RaiseCanExecuteChanged(); this.SaveModelCommand.RaiseCanExecuteChanged(); }
/// <summary> /// This method is called from the SwitchContexts method before a switch occurs. /// </summary> /// <param name="newContextVM">New model context vm.</param> /// <param name="oldContextVM">Old model context vm.</param> protected override void BeforeSwitchContexts(ModelContextViewModel newContextVM, ModelContextViewModel oldContextVM) { if (oldContextVM != null) { if (this.LayoutManager != null) this.LayoutManager.SaveCurrentConfiguration(oldContextVM.ModelContext.Name); } base.BeforeSwitchContexts(newContextVM, oldContextVM); }