using PixiEditor.Extensions.Sdk;
namespace Preferences;
public class PreferencesSampleExtension : PixiEditorExtension
{
///
/// This method is called when extension is loaded.
/// All extensions are first loaded and then initialized. This method is called before .
///
public override void OnLoaded()
{
}
///
/// This method is called when extension is initialized. After this method is called, you can use Api property to access PixiEditor API.
///
public override void OnInitialized()
{
Api.Preferences.AddCallback("HelloCount", (name, value) => Api.Logger.Log($"Hello count changed to {value}!"));
Api.Preferences.AddCallback("TestDouble", (name, value) => Api.Logger.Log($"Test double changed to {value}!"));
Api.Preferences.AddCallback("TestString", (name, value) => Api.Logger.Log($"Test string changed to {value}!"));
Api.Preferences.AddCallback("TestBool", (name, value) => Api.Logger.Log($"Test bool changed to {value}!"));
// Internally this preference will have name "yourCompany.Samples.Preferences:HelloCount".
int helloCount = Api.Preferences.GetPreference("HelloCount");
Api.Preferences.UpdatePreference("HelloCount", helloCount + 1);
Api.Preferences.UpdatePreference("TestDouble", 3.14);
Api.Preferences.UpdatePreference("TestString", "Hello, World!");
Api.Preferences.UpdatePreference("TestBool", true);
// This will overwrite built-in PixiEditor preference. Extension must have WriteNonOwnedPreferences permission.
// Prepending "PixiEditor:" to preference name will access built-in PixiEditor preferences. If you set it to other extension unique name,
// it will access extension preferences.
// You can do analogous thing with UpdatePreference.
Api.Preferences.UpdateLocalPreference(
"PixiEditor:OverwrittenPixiEditorPreference",
"This is overwritten value of preference that is built-in in PixiEditor.");
// You don't need any special permission for reading any kind of preference.
Api.Logger.Log(Api.Preferences.GetLocalPreference("PixiEditor:OverwrittenPixiEditorPreference"));
}
}