Skip to content

PreferencePage Addin

DamianSuess edited this page Dec 18, 2018 · 1 revision

Introduction

ToolsHub add-ins allow you to create your own Preference pages - Options - extend the PreferencePage. Each entry of the extension node creates a new node in the Preference window's TreeView.

Name Type
ExtensionPoint Path /ToolsHub/PreferencePage
ExtensionNode PreferencePageAddin

Interface Parts

IPreferencePageExtension

  • Id - Add-in ID.
  • IsModified - Used to notify the OnSave method that changes have been made.
  • Page - Preference page view (Windows.Form).
  • Title - Display name in Preference window's TreeView
  • InitializePage() - Initializes our Preference page. Accessed via the Page property.
  • OnSave() - Save method called when, OK button is clicked on Preference window.

IPreferencePageForm (optional)

When creating a PreferencePage form it's recommended for you to use the IPreferencePageForm. This helps us adhere to keeping a commonality between our add-ins and naming conventions.

  • IsModified - Tells our extension node that we have modified data that needs saved.
  • OnSave() - Triggered when save is called from our extension node.

Extension Model

Registering a Preference Page

The PreferencePageAddin extension node can be used to register any PreferencePageExtension abstract class. We have 2 methods for attaching to the preferences window, XML and Assembly code.

XML Manifest:

  <Extension path="/ToolsHub/PreferencePage">
    <PreferencePageAddin
      type="Xeno.ToolsHub.SampleXmlAddin.PreferenceHandler" />
  </Extension>

The following attribute(s) must be supplied when registering a preference page:

  • type: class that implements the page (must be IPreferencePageExtension).

Assembly Code:

using Xeno.ToolsHub.ExtensionModel;
using Xeno.ToolsHub.ExtensionModel.Preferences;

namespace Xeno.Test
{
  [Mono.Addins.Extension(
    NodeName = ExtensionName.PreferencePageAddin,
    Path = ExtensionPath.PreferencePage)]
  public class PreferenceHandler : PreferencePageExtension
  {
    // ...
  }
}

Saving Settings

The PreferencePageExtension required you to

In most cases, you'll probably maintain your saving inside of your view (Windows Form). Below is an example of that.

  // PerferenceHandler.cs
    public override void OnSave()
    {
      _page.OnSave();
    }

  // PreferencePage.cs
    public bool OnSave()
    {
      Log.Debug("Mock save, perform actions here.");
      return true;
    }