Esempio n. 1
0
        private void EditorForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            //!!!!было в старом
            ////for lost focus in PropertyGrid
            //PropertiesForm.Focus();

            bool?result = ShowDialogAndSaveDocuments(workspaceController.GetDockWindows());

            if (result == null)
            {
                e.Cancel = true;
                return;
            }

            //save docking state
            if (canSaveConfig)
            //if( !forceCloseForm )
            {
                string configFile = VirtualPathUtility.GetRealPathByVirtual(dockingConfigFileName);
                EditorAPI.GetRestartApplication(out _, out var resetWindowsSettings);
                if (resetWindowsSettings)
                {
                    if (File.Exists(configFile))
                    {
                        File.Delete(configFile);
                    }
                }
                else
                {
                    if (!Directory.Exists(Path.GetDirectoryName(configFile)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(configFile));
                    }

                    workspaceController.SaveLayoutToFile(configFile);

                    // temp experimental:
                    //foreach (var wnd in workspaceController.OfType<WorkspaceWindow>())
                    //{
                    //	string configFileName = string.Format(workspaceConfigFileName, wnd.Name);
                    //	string workspaceConfigFile = VirtualPathUtils.GetRealPathByVirtual(configFileName);
                    //	var controller = wnd.WorkspaceController;
                    //	controller.SaveLayoutToFile(workspaceConfigFile);
                    //}
                }
            }

            EditorAPI.ClosingApplication = true;

            EditorLocalization.Shutdown();

            //destroy all documents
            {
                //!!!!может окна документов сначала удалить?
                foreach (var document in Documents.ToArray())
                {
                    document.Destroy();
                }
            }

            //destroy all viewport controls
            foreach (var control in EngineViewportControl.allInstances.ToArray())
            {
                control.Dispose();
            }

            if (!canSaveConfig)
            {
                EngineApp.NeedSaveConfig = false;
            }
            EngineApp.Shutdown();
        }