Exemplo n.º 1
0
        /// <summary>
        /// Called when the application is about to exist.
        /// </summary>
        /// <returns>
        /// True if the application can exit. False to abbort exit.
        /// </returns>
        public virtual bool CanExit()
        {
            if (this.SelectedModelContextViewModel == null)
            {
                return(true);
            }
            if (this.SelectedModelContextViewModel.ModelContext == null)
            {
                return(true);
            }

            if (this.SelectedModelContextViewModel.ModelContext.RootElement != null)
            {
                if (this.SelectedModelContextViewModel.ModelContext.IsDirty)
                {
                    IMessageBoxService  messageBox = this.GlobalServiceProvider.Resolve <IMessageBoxService>();
                    CustomDialogResults dlgResult  = messageBox.ShowYesNoCancel("Save changes to the current Model?", CustomDialogIcons.Question);
                    if (dlgResult == CustomDialogResults.Cancel)
                    {
                        return(false);
                    }
                    if (dlgResult == CustomDialogResults.Yes)
                    {
                        using (new ToolFramework.Modeling.Visualization.ViewModel.UI.WaitCursor())
                        {
                            this.SelectedModelContextViewModel.ModelContext.Save((this.SelectedModelContextViewModel.ModelContext.RootElement as IParentModelElement).DomainFilePath);
                        }
                    }
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Close model command executed.
        /// </summary>
        /// <returns></returns>
        protected virtual bool CloseModelCommandExecute()
        {
            if (this.SelectedModelContextViewModel == null)
            {
                return(false);
            }
            if (this.SelectedModelContextViewModel.ModelContext == null)
            {
                return(false);
            }

            if (this.SelectedModelContextViewModel.ModelContext.IsDirty)
            {
                IMessageBoxService  messageBox = this.GlobalServiceProvider.Resolve <IMessageBoxService>();
                CustomDialogResults dlgResult  = messageBox.ShowYesNoCancel("Save changes to the current Model?", CustomDialogIcons.Question);
                if (dlgResult == CustomDialogResults.Cancel)
                {
                    return(false);
                }
                else if (dlgResult == CustomDialogResults.Yes)
                {
                    using (new ToolFramework.Modeling.Visualization.ViewModel.UI.WaitCursor())
                    {
                        this.SelectedModelContextViewModel.ModelContext.Save((this.SelectedModelContextViewModel.ModelContext.RootElement as IParentModelElement).DomainFilePath);
                        //this.SelectedModelContextViewModel.ModelContext.Save(this.ViewModelStore.GetDomainModelServices(this.SelectedModelContextViewModel.ModelContext.RootElement).ElementParentProvider.GetDomainModelFilePath(this.SelectedModelContextViewModel.ModelContext.RootElement));
                    }
                }
            }
            using (new ToolFramework.Modeling.Visualization.ViewModel.UI.WaitCursor())
            {
                for (int i = this.UnknownOpenedModels.Count - 1; i >= 0; i--)
                {
                    BaseDiagramSurfaceViewModel vm = this.UnknownOpenedModels[i] as BaseDiagramSurfaceViewModel;
                    if (vm == null)
                    {
                        continue;
                    }

                    //foreach (BaseDiagramSurfaceViewModel vm in this.UnknownOpenedModels)
                    if (!vm.IsDisposed)
                    {
                        this.EventManager.GetEvent <CloseViewModelRequestEvent>().Publish(new CloseViewModelRequestEventArgs(vm, true));
                    }
                }

                this.Reset();
                this.ModelData.Reset();
            }

            this.CloseCommand.RaiseCanExecuteChanged();
            this.SaveAsModelCommand.RaiseCanExecuteChanged();
            this.SaveModelCommand.RaiseCanExecuteChanged();

            this.SelectedModelContextViewModel.OnDocumentClosed();

            return(true);
        }