/// <summary>
        /// Saves the layout prompting using for a filename if needed.
        /// </summary>
        public bool SaveLayout(LayoutControl layoutControl, bool saveAs, IWin32Window parent, bool silent = false)
        {
            string filename = layoutControl.Filename;

            if (saveAs || string.IsNullOrWhiteSpace(filename))
            {
                filename = GetSaveFilename(parent);
            }

            if (string.IsNullOrWhiteSpace(filename))
            {
                return(false);
            }

            var serializer = new LayoutSerializer();

            if (serializer.SaveLayout(layoutControl, layoutControl.PrinterSettings, filename))
            {
                if (!silent)
                {
                    MessageService.Current.Info("Layout was saved successfully.");
                }

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Loads layout, prompting to save changes to the exiting one if needed.
        /// </summary>
        public void LoadNewLayout(
            LayoutControl layoutControl,
            IAppContext context,
            IEnvelope extents,
            IWin32Window parent)
        {
            if (!PromptToSaveChanges(layoutControl, parent))
            {
                return;
            }

            string filename = GetLoadFilename(parent);

            if (string.IsNullOrWhiteSpace(filename))
            {
                return;
            }

            var serializer = new LayoutSerializer();

            var settings = layoutControl.PrinterSettings;

            if (serializer.LoadLayout(context, layoutControl, filename, extents, settings))
            {
                MessageService.Current.Info("Layout was loaded successfully.");
            }
        }
        /// <summary>
        /// Promps user to save changes to the existing layout and does the saving if selected.
        /// </summary>
        public bool PromptToSaveChanges(LayoutControl layoutControl, IWin32Window parent)
        {
            var ls = new LayoutSerializer();

            if (ls.LayoutChanged(layoutControl, layoutControl.PrinterSettings, layoutControl.Filename))
            {
                var result = MessageService.Current.AskWithCancel("Do you want to save changes to the current layout?");

                switch (result)
                {
                case DialogResult.Cancel:
                    return(false);

                case DialogResult.Yes:
                    ls.SaveLayout(layoutControl, false, parent, true);
                    break;

                case DialogResult.No:
                    // do nothing
                    break;
                }
            }

            return(true);
        }