Ejemplo n.º 1
0
        public static bool Save(Window window, DesktopDocument document)
        {
            if (document != null)
            {
                if (document.IsDirty)
                {
                    if (String.IsNullOrEmpty(document.Path))
                    {
                        return(SaveAs(window, document));
                    }

                    return(document.Save());
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        public static bool Close(Window window, DesktopDocument document)
        {
            if (document != null)
            {
                if (document.IsDirty)
                {
                    MessageBoxResult result = MessageBox.Show(window, "Save '" + document.Title + "'?",
                                                              "Save before closing", MessageBoxButton.YesNoCancel, MessageBoxImage.Exclamation);
                    if (result == MessageBoxResult.Yes)
                    {
                        return(Save(window, document));
                    }
                    else if (result == MessageBoxResult.Cancel)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        public static bool SaveAs(Window window, DesktopDocument document)
        {
            string         filename = FileSupport.MakeValidFileName(document.Title);
            SaveFileDialog fd       = new SaveFileDialog
            {
                InitialDirectory = DesktopApp.Instance.Settings.DocumentFolder,
                FileName         = filename,
                Filter           = BaseDocument.GetFilterString(true, document.DocType),
                FilterIndex      = 0,
            };

            if (fd.ShowDialog(window) == true)
            {
                string path = fd.FileName;
                if (File.Exists(path) && path != document.Path)
                {
                    if (MessageBox.Show(window, "File '" + path + "' exists.  Overwrite?", "Save Document",
                                        MessageBoxButton.OKCancel, MessageBoxImage.Exclamation) == MessageBoxResult.OK)
                    {
                        return(document.Save(path, true));
                    }

                    return(false);
                }
                else if (path == document.Path)
                {
                    return(document.Save());
                }
                else
                {
                    return(document.Save(path, false));
                }
            }

            return(false);
        }