public IImageImporter GetImporterByExtension(string extension)
        {
            FormatDescriptor format = GetFormatByExtension(extension);

            if (format == null)
            {
                return(null);
            }

            return(format.Importer);
        }
Exemple #2
0
        /// <summary>
        /// Finds the correct exporter to use for the given file extension, or null
        /// if no exporter exists for that extension.
        /// </summary>
        private IImageExporter GetExporterByExtension(string extension)
        {
            FormatDescriptor format = GetFormatByExtension(extension);

            if (format == null)
            {
                return(null);
            }

            return(format.Exporter);
        }
 /// <summary>
 /// Registers a new file format.
 /// </summary>
 public void RegisterFormat(FormatDescriptor fd)
 {
     formats.Add(fd);
 }
		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;
			}

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

			PintaCore.Tools.CurrentTool.DoAfterSave();

			//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 ();

            format.Exporter.Export (document, file);

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

            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;
            }

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

            format.Exporter.Export (document, file);

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

            return true;
        }
Exemple #7
0
        private void SaveFile(string file, FormatDescriptor format)
        {
            if (format == null) {
                string ext = System.IO.Path.GetExtension (file);
                // Is the fallback to PNG even necessary?
                format = formatsByExt[string.IsNullOrEmpty (ext) ? ".png" : ext];
            }

            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;
            }

            format.Exporter.Export (PintaCore.Layers, file);

            PintaCore.Workspace.Filename = Path.GetFileName (file);
            PintaCore.Workspace.IsDirty = false;
        }
 /// <summary>
 /// Registers a new file format.
 /// </summary>
 public void RegisterFormat(FormatDescriptor fd)
 {
     formats.Add (fd);
 }