Example #1
0
        public static bool ConfirmClose(IDocument document, IFileDialogService fileDialogService)
        {
            var game = document.As <Game.GameExtensions>();

            if (game == null)
            {
                return(true);
            }
            var terrain      = game.Terrain;
            var sceneManager = game.SceneManager;

            if (terrain == null || sceneManager == null)
            {
                return(true);
            }

            var  layerIds       = terrain.GetAllLayerIds();
            bool hasActiveLocks = false;

            foreach (var l in layerIds)
            {
                hasActiveLocks |= sceneManager.HasTerrainLock(l);
            }

            if (hasActiveLocks)
            {
                string message = "You still have active terrain locks. These are unsaved areas of terrain."
                                 + System.Environment.NewLine + "Do you want to save all active terrain locks?";
                FileDialogResult result = fileDialogService.ConfirmFileClose(message);
                if (result == FileDialogResult.Yes)
                {
                    foreach (var l in layerIds)
                    {
                        try
                        {
                            using (var progress = new ControlsLibrary.ProgressDialog.ProgressInterface())
                            {
                                sceneManager.SaveTerrainLock(l, progress);
                            }
                        }
                        catch (Exception ex)
                        {
                            ControlsLibrary.BasicControls.ExceptionReport.Show(ex, "Saving terrain lock");
                        }
                    }
                }
                else if (result == FileDialogResult.Cancel)
                {
                    return(false);
                }
            }

            return(true);
        }