Sign in to follow this  
midora

PropertyBasedFileType template using IndirectUI

Recommended Posts

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

Share this post


Link to post
Share on other sites

I recommend removing the "destructor" since it doesn't do anything. It's also something that you should never need to use in the FileType-derived class itself.

Share this post


Link to post
Share on other sites

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.

Sign in to follow this