コード例 #1
0
        public bool SavePalette(bool forceDialog)
        {
            var freshFile = forceDialog || appPal.FileName == null;
            var fileName  = freshFile ? "" : appPal.FileName;

            if (freshFile)
            {
                // if we don't have a name already, give it one based
                // on its palette title name - the save dialog will
                // handle the extension
                if (appPal.FileName == null)
                {
                    savePaletteDialog.FileName = appPal.PaletteName;
                }
                // set the file name later, in case more interruptions
                // will stop us from writing the file (user intervention,
                // exceptions)
                if (savePaletteDialog.ShowDialog(this) == DialogResult.OK)
                {
                    fileName = savePaletteDialog.FileName;
                }
                else
                {
                    return(false);
                }
            }

            // warn if the format doesn't support metadata
            if (!(fileName.EndsWith(".gpl") || fileName.EndsWith(".colors") ||
                  fileName.EndsWith(".acb")))
            {
                MessageBox.Show(this,
                                "This format doesn't support metadata like comments. Metadata will be lost when the file is reloaded.",
                                "Colours", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            try
            {
                appPal.ConvertPalette(fileName);
                File.WriteAllBytes(fileName, appPal.Palette.ToFile());
                appPal.FileName = fileName;
                appPal.Dirty    = false;
                // update the titlebar's dirtiness
                UpdateUI();
                return(true);
            }
            catch (PaletteException e)
            {
                MessageBox.Show(this, e.Message, "Palette Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
コード例 #2
0
    public bool SavePalette(bool forceDialog)
    {
        var freshFile = forceDialog || string.IsNullOrEmpty(appPal.FileName);
        var fileName  = freshFile ? "" : appPal.FileName;

        if (forceDialog || string.IsNullOrEmpty(fileName))
        {
            FileChooserDialog fd = new FileChooserDialog("Save palette as", this,
                                                         FileChooserAction.Save, "Cancel", ResponseType.Cancel, "OK", ResponseType.Ok);
            FileFilter ffGimp = new FileFilter();
            ffGimp.Name = "GIMP Palette";
            ffGimp.AddPattern("*.gpl");
            fd.AddFilter(ffGimp);
            FileFilter ffAco = new FileFilter();
            ffAco.Name = "Photoshop Palette";
            ffAco.AddPattern("*.aco");
            fd.AddFilter(ffAco);
            FileFilter ffAct = new FileFilter();
            ffAct.Name = "Photoshop Colour Table";
            ffAct.AddPattern("*.act");
            fd.AddFilter(ffAct);
            FileFilter ffAse = new FileFilter();
            ffAse.Name = "Adobe Swatch Exchange";
            ffAse.AddPattern("*.ase");
            fd.AddFilter(ffAse);
            FileFilter ffAcb = new FileFilter();
            ffAcb.Name = "Adobe Color Book";
            ffAcb.AddPattern("*.acb");
            fd.AddFilter(ffAcb);
            if (fd.Run() == (int)ResponseType.Ok)
            {
                fileName = fd.Filename;
                fd.Destroy();
            }
            else
            {
                fd.Destroy();
                return(false);
            }
        }

        appPal.ConvertPalette(fileName);
        File.WriteAllBytes(fileName, appPal.Palette.ToFile());

        appPal.Dirty    = false;
        appPal.FileName = fileName;
        UpdateUI();
        return(true);
    }