Jump to content
Paint.NET 5.1 is now available! ×

Recommended Posts

Posted (edited)

A simple template showing how to add properties (IndirectUi controls) to the save dialog.

 

Microsoft Visual C# 2010 project: ExamplePropertyBasedFileType.zip

 

using System;
using System.IO;
using System.Collections.Generic;
using PaintDotNet;
using PaintDotNet.IndirectUI;
using PaintDotNet.PropertySystem;

namespace ExamplePropertyBased
{

    /*======================================================================*\
    PBF filetype
    \*======================================================================*/

    public sealed class ExamplePropertyBasedFileTypeFactory : IFileTypeFactory
    {
        public FileType[] GetFileTypeInstances()
        {
            return new[] { new ExamplePropertyBasedFileType() };
        }
    }

    internal class ExamplePropertyBasedFileType : PropertyBasedFileType
    {

        // Names of the properties
        private enum PropertyNames
        {
            Creator
        }

        // Defaults
        const String defaultCreator = "";

        // ----------------------------------------------------------------------
        /// <summary>
        /// Constructs a ExamplePropertyBasedFileType instance
        /// </summary>
        internal ExamplePropertyBasedFileType()
            : base(
                "PBF - PropertyBasedFileType Example",
                0
                | FileTypeFlags.SupportsLayers
                //| FileTypeFlags.SupportsCustomHeaders
                | FileTypeFlags.SupportsSaving
                | FileTypeFlags.SupportsLoading
                //| FileTypeFlags.SavesWithProgress
                ,
               new[] { ".pbf" })
        {
        }

        // ----------------------------------------------------------------------
        /// <summary>
        /// Destroys the ExamplePropertyBasedFileType instance
        /// </summary>
        ~ExamplePropertyBasedFileType()
        {
        }



        // ----------------------------------------------------------------------
        /// <summary>
        /// Add properties to the dialog
        /// </summary>
        public override PropertyCollection OnCreateSavePropertyCollection()
        {
            List<Property> props = new List<Property>();
            props.Add(new StringProperty(PropertyNames.Creator, defaultCreator, 256));

            List<PropertyCollectionRule> propRules = new List<PropertyCollectionRule>();

            return new PropertyCollection(props, propRules);
        }


        // ----------------------------------------------------------------------
        /// <summary>
        /// Adapt properties in the dialog (DisplayName, ...)
        /// </summary>
        public override ControlInfo OnCreateSaveConfigUI(PropertyCollection props)
        {
            ControlInfo configUI = CreateDefaultSaveConfigUI(props);
            configUI.SetPropertyControlValue(PropertyNames.Creator, ControlInfoPropertyNames.DisplayName, "Name of creator");

            return configUI;
        }



        // ----------------------------------------------------------------------
        /// <summary>
        /// Saves a document to a stream respecting the properties
        /// </summary>
        protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
        {
            // add some code here ...
        }

        
        // ----------------------------------------------------------------------
        /// <summary>
        /// Creates a document from a stream
        /// </summary>
        protected override Document OnLoad(Stream input)
        {
            // add some code here ...

            return null;
        }


    }
}

 

Edited by midora
  • Upvote 1

midoras signature.gif

Posted

Very nice!  I've just today posted elsewhere on the forum for the need to  have more effect templates.

 

Thank you for making this available.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...