示例#1
0
        private bool SaveFile(Document document, string file, FormatDescriptor format)
        {
            if (string.IsNullOrEmpty(file))
            {
                file = document.PathAndFileName;
            }

            if (format == null)
            {
                format = PintaCore.System.ImageFormats.GetFormatByFile(file);
            }

            if (format == null || format.IsReadOnly())
            {
                MessageDialog md = new MessageDialog(PintaCore.Chrome.MainWindow, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, Catalog.GetString("Pinta does not support saving images in this file format."), file);
                md.Title = Catalog.GetString("Error");

                md.Run();
                md.Destroy();
                return(false);
            }

            // If the user tries to save over a read only file, give a more informative error message than "Unhandled Exception"
            FileInfo file_info = new FileInfo(file);

            if (file_info.Exists && file_info.IsReadOnly)
            {
                MessageDialog md = new MessageDialog(PintaCore.Chrome.MainWindow, DialogFlags.Modal, MessageType.Error,
                                                     ButtonsType.Ok, Catalog.GetString("Cannot save read only file."));
                md.Title = Catalog.GetString("Error");

                md.Run();
                md.Destroy();
                return(false);
            }

            // Commit any pending changes
            PintaCore.Tools.Commit();

            format.Exporter.Export(document, file);

            document.Filename = Path.GetFileName(file);
            document.IsDirty  = false;

            return(true);
        }
        private bool SaveFile(Document document, string file, FormatDescriptor format, Window parent)
        {
            if (string.IsNullOrEmpty(file))
            {
                file = document.PathAndFileName;
            }

            if (format == null)
            {
                format = PintaCore.System.ImageFormats.GetFormatByFile(file);
            }

            if (format == null || format.IsReadOnly())
            {
                MessageDialog md = new MessageDialog(parent, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, Catalog.GetString("Pinta does not support saving images in this file format."), file);
                md.Title = Catalog.GetString("Error");

                md.Run();
                md.Destroy();
                return(false);
            }

            // If the user tries to save over a read only file, give a more informative error message than "Unhandled Exception"
            FileInfo file_info = new FileInfo(file);

            if (file_info.Exists && file_info.IsReadOnly)
            {
                MessageDialog md = new MessageDialog(parent, DialogFlags.Modal, MessageType.Error,
                                                     ButtonsType.Ok, Catalog.GetString("Cannot save read only file."));
                md.Title = Catalog.GetString("Error");

                md.Run();
                md.Destroy();
                return(false);
            }

            // Commit any pending changes
            PintaCore.Tools.Commit();

            try {
                format.Exporter.Export(document, file, parent);
            } catch (GLib.GException e) {             // Errors from GDK
                if (e.Message == "Image too large to be saved as ICO")
                {
                    string primary   = Catalog.GetString("Image too large");
                    string secondary = Catalog.GetString("ICO files can not be larger than 255 x 255 pixels.");
                    string message   = string.Format(markup, primary, secondary);

                    MessageDialog md = new MessageDialog(parent, DialogFlags.Modal, MessageType.Error,
                                                         ButtonsType.Ok, message);

                    md.Run();
                    md.Destroy();
                    return(false);
                }
                else
                {
                    throw e;                     // Only catch exceptions we know the reason for
                }
            } catch (OperationCanceledException) {
                return(false);
            }

            // Set Pathname and Filename properties which triggers the document.Renamed event
            document.PathAndFileName = file;

            PintaCore.Tools.CurrentTool.DoAfterSave();

            // Mark the document as clean following the tool's after-save handler, which might
            // adjust history (e.g. undo changes that were committed before saving).
            document.Workspace.History.SetClean();

            //Now the Document has been saved to the file it's associated with in this session.
            document.HasBeenSavedInSession = true;

            return(true);
        }
        private bool SaveFile(Document document, string file, FormatDescriptor format)
        {
            if (string.IsNullOrEmpty(file))
            {
                file = document.PathAndFileName;
            }

            if (format == null)
            {
                format = PintaCore.System.ImageFormats.GetFormatByFile(file);
            }

            if (format == null || format.IsReadOnly())
            {
                MessageDialog md = new MessageDialog(PintaCore.Chrome.MainWindow, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, Catalog.GetString("Pinta does not support saving images in this file format."), file);
                md.Title = Catalog.GetString("Error");

                md.Run();
                md.Destroy();
                return(false);
            }

            // If the user tries to save over a read only file, give a more informative error message than "Unhandled Exception"
            FileInfo file_info = new FileInfo(file);

            if (file_info.Exists && file_info.IsReadOnly)
            {
                MessageDialog md = new MessageDialog(PintaCore.Chrome.MainWindow, DialogFlags.Modal, MessageType.Error,
                                                     ButtonsType.Ok, Catalog.GetString("Cannot save read only file."));
                md.Title = Catalog.GetString("Error");

                md.Run();
                md.Destroy();
                return(false);
            }

            // Commit any pending changes
            PintaCore.Tools.Commit();

            try {
                format.Exporter.Export(document, file);
            } catch (GLib.GException e) {             // Errors from GDK
                if (e.Message == "Image too large to be saved as ICO")
                {
                    string primary   = Catalog.GetString("Image too large");
                    string secondary = Catalog.GetString("ICO files can not be larger than 255 x 255 pixels.");
                    string message   = string.Format(markup, primary, secondary);

                    MessageDialog md = new MessageDialog(PintaCore.Chrome.MainWindow, DialogFlags.Modal, MessageType.Error,
                                                         ButtonsType.Ok, message);

                    md.Run();
                    md.Destroy();
                    return(false);
                }
                else
                {
                    throw e;                     // Only catch exceptions we know the reason for
                }
            }

            document.Filename = Path.GetFileName(file);
            document.IsDirty  = false;

            return(true);
        }