Member Controls

Developers > Hook into Extra->Preferences
quaxiLink to postposted: Fri Mar 31, 2006 8:44 pm
Avator for quaxi

Member since:
 2006-04-28
Posts:
 3154
Since SimPE 0.57o, SimPE allows you to create preferences Screens for yor Plugins, that are displayed under "Extra->Preferences...".

Currently only the new "Content Plugin" is using this Interface, but it might be usefull to others as well.

Here is the Sourcecode thatw as used to create the basic Prefernce Screen for that Plugin:

/// <summary>
/// The Preferences for the Content Plugin
/// </summary>
public class DownloadsSettings : SimPe.GlobalizedObject, SimPe.Interfaces.ISettings
{

    static ResourceManager  rm = new ResourceManager(typeof(DownloadsSettings));
    const string BASENAME = "DownloadsPlugin";
    XmlRegistryKey xrk;
    public DownloadsSettings() : base(rm)
    {
        xrk = Helper.WindowsRegistry.PluginRegistryKey;
    }
   
    //...


[System.ComponentModel.Category("Recolors")]
    public  bool BuildPreviewForRecolors
    {
        get 
        {
             XmlRegistryKey rkf = xrk.CreateSubKey(BASENAME);
             object o = rkf.GetValue("BuildPreviewForRecolors", true);
             return Convert.ToBoolean(o);
         }
        set
        {
             XmlRegistryKey rkf = xrk.CreateSubKey(BASENAME);
             rkf.SetValue("BuildPreviewForRecolors", value);
        }
    }

    //...


[System.ComponentModel.Category("Recolors")]
    public bool LoadBasedataForRecolors
    {
        get 
        {
            XmlRegistryKey rkf = xrk.CreateSubKey(BASENAME);
            object o = rkf.GetValue("LoadBasedataForRecolors", true);
            return Convert.ToBoolean(o);
        }
        set
        {
            XmlRegistryKey rkf = xrk.CreateSubKey(BASENAME);
            rkf.SetValue("LoadBasedataForRecolors", value);
        }
    }

    //...


    #region ISettings Member

    public object GetSettingsObject()
    {
        return this;
    }

    public override string ToString()
    {
        return rm.GetString("Content Plugin Preferences");
    }

    [System.ComponentModel.Browsable(false)]
    public System.Drawing.Image Icon
    {
        get
        {
            // TODO:  No Image available
            return null;
        }
    }
    #endregion
}


You basically just have to implement the SimPe.Interfaces.ISettings Interface. Any you have to Implement SimPe.Interfaces.Plugin.ISettingsFactory In your WrapperFactory, to make SimPE aware of the new Preferences.

SimPe will simply Display all public Properties (that are Browsable), in a PropertyGrid.
The above example uses a ResourceManager, to allow translation of the Properteis, Descriptions and Categories.
Here is a brief excerp of the resx File I use for the english Version:

<data name="[Category:Recolors]">
    <value>Recolors</value>
</data>

<data name="[Property:BuildPreviewForRecolors]">
    <value>Build Preview</value>
</data>

<data name="[Description:BuildPreviewForRecolors]">
    <value>When true, the Plugin will try to load the base Object for a Recolor, and use it to generate a Preview.

This will slow down the loading Process, but it will also provide you with additional Informations about the Recolor and the base Object. </value>
</data>

<data name="[Property:LoadBasedataForRecolors]">
    <value>Load Informations from Baseobject</value>
</data>

<data name="[Description:LoadBasedataForRecolors]">
    <value>When true, the Plugin will try to load the base Object for a Recolor, and read additional Informations from it.</value>
</data>

<data name="Content Plugin Preferences">
    <value>Content Plugin</value>
</data>


I am using a XmlRegistryKey Object, to store the Settings directly into the apropriate location. (Subkey called "DownloadsPlugin" in the simpe.xreg, which is the appropriate location for custom Settings)

Let me know if anyone needs help with this.
quaxiLink to postposted: Sat Apr 01, 2006 1:27 am
Avator for quaxi

Member since:
 2006-04-28
Posts:
 3154
Btw, you can use

SimPe.RemoteControl.ShowCustomSettings(SimPe.Interfaces.ISettings settings)

to display the Setting Page directly from your Plugins.
quaxiLink to postposted: Thu Apr 20, 2006 2:17 am
Avator for quaxi

Member since:
 2006-04-28
Posts:
 3154
If you want to see a Code Example, check out
  • SimPe Downloads/DownloadsSettings.cs
  • SimPe Downloads/DownloadsSettings.de.resx
  • SimPe Downloads/DownloadsSettings.resx
  • SimPe Downloads/DownloadsFactory.cs
in the SimPE CVS-Repository.
pljonesLink to postposted: Sun May 21, 2006 12:41 pm
Avator for pljones

Member since:
 2005-04-02
From:
 London, UK
Posts:
 610
I got this working in PJSE (for the FileTable load at start up option)... eventually.  I missed one key bit:

public DownloadsSettings() : base(rm)

The "base(rm)" is rather essential to get the descriptive string working.  I missed it when setting up my Settings class initially and it took ages to work out why the descriptions weren't there!


viewthread, 0, 0, Hook-into-Extra-Preferences