Skip to main content
March 1, 2010
Answered

Preference Panel

  • March 1, 2010
  • 1 reply
  • 2348 views

I've created a Preference Panel and gotten the items I want on it by editing the .r file for my plugin. I can't figure out how to access the items via ADM though. I'd also like to add the items via ADM instead of relying on the resource file.

The Preference Panel functions supplied don't seem to do what they are supposed to.

I've tried the following:

1. AddPreferencePanel - this is all good (I think). The dialog in my resources is given the ID 16010. This function returns the AIPreferencelItemGroupHandle and the AIMenuItemHandle.

2. ShowPreferencePanel - this is called when the AIMenuItemHandle returned before is selected. Sends the message AIPreferencePanelMessage, which I catch.

Now this is where things break down:

3. GetPreferencePanelItemRef - pass in the AIPreferencelItemGroupHandle from before, get out an ADMItemRef. Supposed to be a ADM group item that contains all the items in the panel we created above. Calling sADMItem->GetChildItem on it doesn't return any valid handles.

4. GetPreferencePanelBaseItemIndex - pass in the AIPreferencelItemGroupHandle from before, get out an integer index. Supposedly all the item IDs in the group above are offset by this int. It returns the 16010 id from the dialog id.

The docs say you're supposed to be able to use these two functions together somehow to access the individual items, but I can't see any way to use them together at all. They both take the same argument and return a different "property" of the AIPreferencelItemGroupHandle?

So... I can't figure out how to access the items in the panel. I can't seem to add new items to the panel programmatically either. Even at the most basic, I need to add notifiers to some of the ADM items in the preference panel, so I can actually do something with it.

This topic has been closed for replies.
Correct answer Wayne_Constable-AEjbzi

Ok sorry to resurrect this one as I'm sure one of you guys has already nailed it by now, but I thought I'd share my experience with this stuff.

I've just had to implement a preferences page in a plugin that I'm working on and of course, when it came to reading the items in the panel, I ended up here. I thought I'd hit a brick wall until a few hours ago when I made a bit of a breakthrough while I was actually writing a post to this thread asking for help!

I originally had the same trouble accessing the items in the panel as btemp did and found the functions GetPreferencePanelItemRef and GetPreferencePanelBaseItemIndex to be equally as useless.  But after a bit of fiddling and a lot of swearing, I've finally managed to get notifications from the controls in my preference panel.

So here's how I did it:

Add your preferences panel in the usual way by adding a resource definition and calling sAIPreference->AddPreferencePanel

Catch the menu item message using the handle returned to you by AddPreferencePanel, more on this later.

Catch kAIPreferenceCaller - this wasn't handled by default in the SDK sample plugins so I added it myself.

Catch the following selectors:

     kAIPreferenceInitSelector

     kAIPreferenceOKSelector

     kAIPreferenceCancelSelector

     kAIPreferenceUpdateSelector

kAIPreferenceInitSelector - Called as your preference panel is first displayed. - It seems you only receive this selector if the user has used the keyboard shortcut to access the preferences pane. If the user has selected the menu item directly from the preferences menu, you will receive the menu item message.

On your kAIPreferenceUpdateSelctor handler you are passed an (AIPreferencePanelMessage*).  Use this parameter to get a handle to the dialog as follows (or something like this):


ASErr MyPlugin::PreferenceUpdate(AIPreferencePanelMessage* message)

{
    ADMItemRef baseItemRef = NULL;
    sAIPreference->GetPreferencePanelItemRef(message->itemGroup, &baseItemRef);

    if (baseItemRef != NULL)

    {
         IADMItem baseItem(baseItemRef);

     // The baseItemRef is actually the dialog item here
         IADMDialog prefsDialog(baseItem.GetDialog());


     // These are just resource IDs from my plugin's .r file, just two radio buttons for now.
         IADMItem firstRadioButton(prefsDialog.GetItem(kMyPluginPrefsPanelDialogID + kMyPluginPrefsFirstRadioButtonResourceID));
         IADMItem secondRadioButton(prefsDialog.GetItem(kMyPluginPrefsPanelDialogID + kMyPluginPrefsSecondRadioButtonResourceID));


     // Set the controls values, read your current preference values and populate the controls here
         firstRadioButtonItem.SetBooleanValue(true);
         secondRadioButtonItem.SetBooleanValue(false);


     // Set your notification procedures and pass any data you may need (I'm passing "this" so I can call a member function later)
         firstRadioButtonItem.SetNotifyProc(MyPlugin::FirstRadioNotifyProc);
         firstRadioButtonItem.SetNotifierData(static_cast<void*>(this));
         secondRadioButtonItem.SetNotifyProc(MyPlugin::SecondRadioNotifyProc);
         secondRadioButtonItem.SetNotifierData(static_cast<void*>(this));
}

You may find that you receive this selector twice so just bear this in mind if you need to allocate memory.


Now you should receive notifications from the controls in your preference panel.

The  kAIPreferenceOKSelector and kAIPreferenceCancelSelector are called when the user clicks Ok or Cancel (surprisingly!) so you have a chance to save or discard any changes the user has made. The AIPreferencePanelMessage* sent with these selectors contains an ADMItemRef which is an ADM group item which as btemp discovered, is pretty darn useless.

This might not be the way Adobe intended it to work but until they sort out the piss-poor documentation out, it works for me.

-W

Edit: Typos

1 reply

A. Patterson
Inspiring
March 1, 2010

I'm afraid I can't help you out here. I tinkered with this years ago and got it only as far "My dialog resource shows up". After that, I decided it wasn't worth the trouble for what I wanted to do (it wasn't, though it was six years before we implemented a different solution).

Presumably it works though, since I assume Adobe uses this API to populate their own preferences.

March 1, 2010

I guess nobody knows how to use the preference suite. There's this post http://forums.adobe.com/message/1263664#1263664 from over two years ago with the same issues I'm having and no one ever responded.

Inspiring
July 19, 2010

Ok sorry to resurrect this one as I'm sure one of you guys has already nailed it by now, but I thought I'd share my experience with this stuff.

I've just had to implement a preferences page in a plugin that I'm working on and of course, when it came to reading the items in the panel, I ended up here. I thought I'd hit a brick wall until a few hours ago when I made a bit of a breakthrough while I was actually writing a post to this thread asking for help!

I originally had the same trouble accessing the items in the panel as btemp did and found the functions GetPreferencePanelItemRef and GetPreferencePanelBaseItemIndex to be equally as useless.  But after a bit of fiddling and a lot of swearing, I've finally managed to get notifications from the controls in my preference panel.

So here's how I did it:

Add your preferences panel in the usual way by adding a resource definition and calling sAIPreference->AddPreferencePanel

Catch the menu item message using the handle returned to you by AddPreferencePanel, more on this later.

Catch kAIPreferenceCaller - this wasn't handled by default in the SDK sample plugins so I added it myself.

Catch the following selectors:

     kAIPreferenceInitSelector

     kAIPreferenceOKSelector

     kAIPreferenceCancelSelector

     kAIPreferenceUpdateSelector

kAIPreferenceInitSelector - Called as your preference panel is first displayed. - It seems you only receive this selector if the user has used the keyboard shortcut to access the preferences pane. If the user has selected the menu item directly from the preferences menu, you will receive the menu item message.

On your kAIPreferenceUpdateSelctor handler you are passed an (AIPreferencePanelMessage*).  Use this parameter to get a handle to the dialog as follows (or something like this):


ASErr MyPlugin::PreferenceUpdate(AIPreferencePanelMessage* message)

{
    ADMItemRef baseItemRef = NULL;
    sAIPreference->GetPreferencePanelItemRef(message->itemGroup, &baseItemRef);

    if (baseItemRef != NULL)

    {
         IADMItem baseItem(baseItemRef);

     // The baseItemRef is actually the dialog item here
         IADMDialog prefsDialog(baseItem.GetDialog());


     // These are just resource IDs from my plugin's .r file, just two radio buttons for now.
         IADMItem firstRadioButton(prefsDialog.GetItem(kMyPluginPrefsPanelDialogID + kMyPluginPrefsFirstRadioButtonResourceID));
         IADMItem secondRadioButton(prefsDialog.GetItem(kMyPluginPrefsPanelDialogID + kMyPluginPrefsSecondRadioButtonResourceID));


     // Set the controls values, read your current preference values and populate the controls here
         firstRadioButtonItem.SetBooleanValue(true);
         secondRadioButtonItem.SetBooleanValue(false);


     // Set your notification procedures and pass any data you may need (I'm passing "this" so I can call a member function later)
         firstRadioButtonItem.SetNotifyProc(MyPlugin::FirstRadioNotifyProc);
         firstRadioButtonItem.SetNotifierData(static_cast<void*>(this));
         secondRadioButtonItem.SetNotifyProc(MyPlugin::SecondRadioNotifyProc);
         secondRadioButtonItem.SetNotifierData(static_cast<void*>(this));
}

You may find that you receive this selector twice so just bear this in mind if you need to allocate memory.


Now you should receive notifications from the controls in your preference panel.

The  kAIPreferenceOKSelector and kAIPreferenceCancelSelector are called when the user clicks Ok or Cancel (surprisingly!) so you have a chance to save or discard any changes the user has made. The AIPreferencePanelMessage* sent with these selectors contains an ADMItemRef which is an ADM group item which as btemp discovered, is pretty darn useless.

This might not be the way Adobe intended it to work but until they sort out the piss-poor documentation out, it works for me.

-W

Edit: Typos