midora Posted February 13, 2013 Posted February 13, 2013 (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 February 13, 2013 by midora 1 Quote
Ego Eram Reputo Posted February 13, 2013 Posted February 13, 2013 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. Quote ebook: Mastering Paint.NET | resources: Plugin Index | Stereogram Tut | proud supporter of Codelab plugins: EER's Plugin Pack | Planetoid | StickMan | WhichSymbol+ | Dr Scott's Markup Renderer | CSV Filetype | dwarf horde plugins: Plugin Browser | ShapeMaker
Rick Brewster Posted February 16, 2013 Posted February 16, 2013 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. Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.