protected void SaveTextFile(ref string FileName, string title, Entry entry, ManagedArray data)
    {
        TextSaver.Title = title;

        TextSaver.SelectFilename(FileName);

        string directory;

        // Add most recent directory
        if (!string.IsNullOrEmpty(TextSaver.Filename))
        {
            directory = System.IO.Path.GetDirectoryName(TextSaver.Filename);

            if (Directory.Exists(directory))
            {
                TextSaver.SetCurrentFolder(directory);
            }
        }

        if (TextSaver.Run() == (int)ResponseType.Accept)
        {
            if (!string.IsNullOrEmpty(TextSaver.Filename))
            {
                FileName = TextSaver.Filename;

                directory = GetDirectory(FileName);

                var ext = TextSaver.Filter.Name;

                FileName = String.Format("{0}.{1}", GetBaseFileName(FileName), ext);

                if (data != null)
                {
                    var current   = DelimiterBox.Active;
                    var delimiter = current >= 0 && current < Delimiters.Count ? Delimiters[current].Character : '\t';

                    var fullpath = String.Format("{0}/{1}", directory, FileName);

                    try
                    {
                        ManagedFile.Save2D(fullpath, data, delimiter);

                        FileName = fullpath;

                        entry.Text = FileName;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error saving {0}: {1}", FileName, ex.Message);
                    }
                }
            }
        }

        TextSaver.Hide();
    }
Example #2
0
    protected void SaveImageFile()
    {
        ImageSaver.Title = "Save filtered image";

        string directory;

        // Add most recent directory
        if (!string.IsNullOrEmpty(ImageSaver.Filename))
        {
            directory = GetDirectory(ImageSaver.Filename);

            if (Directory.Exists(directory))
            {
                ImageSaver.SetCurrentFolder(directory);
            }
        }

        if (ImageSaver.SelectFilename(FileName) && ImageSaver.Run() == (int)ResponseType.Accept)
        {
            if (!string.IsNullOrEmpty(ImageSaver.Filename))
            {
                FileName = ImageSaver.Filename;

                directory = GetDirectory(FileName);

                var ext = ImageSaver.Filter.Name;

                var fmt = ext;

                switch (ext)
                {
                case "jpg":

                    if (!FileName.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) && !FileName.EndsWith(".jpeg", StringComparison.OrdinalIgnoreCase))
                    {
                        FileName = String.Format("{0}.jpg", GetFileName(FileName));
                    }

                    fmt = "jpeg";

                    break;

                case "tif":

                    if (!FileName.EndsWith(".tif", StringComparison.OrdinalIgnoreCase) && !FileName.EndsWith(".tiff", StringComparison.OrdinalIgnoreCase))
                    {
                        FileName = String.Format("{0}.tif", GetFileName(FileName));
                    }

                    fmt = "tiff";

                    break;

                default:

                    FileName = String.Format("{0}.{1}", GetFileName(FileName), ext);

                    break;
                }

                if (OutputPixbuf != null)
                {
                    FileName = GetName(FileName);

                    var fullpath = String.Format("{0}/{1}", directory, FileName);

                    try
                    {
                        OutputPixbuf.Save(fullpath, fmt);

                        FileName = fullpath;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error saving {0}: {1}", FileName, ex.Message);
                    }
                }
            }
        }

        ImageSaver.Hide();
    }