Providing help book for plugin (Cocoa)

Providing help book for plugin (Cocoa)

Post by mytvc1 » Wed, 18 Feb 2004 15:00:43


I have a program that uses plugins to provide extended functionality,
and would like each plugin to have its own help book (provided with
the plugin bundle). If I wire up a help button on the plugin menu to
call "showHelp" I just get the Help Book for the main app. Is there
any way to contextually redirect these requests so that such a help
button would launch the help book contained in the plugin bundle?
Seems like this should be possible, but the Help documentation does
not seem to contain the required info.

Thanks for any advice,

ER
 
 
 

Providing help book for plugin (Cocoa)

Post by mytvc1 » Thu, 26 Feb 2004 22:32:56

In a later post I got this to work and posted the following solution:

// Carbon included for help API
#include <Carbon/Carbon.h>

...

-(IBAction)showPluginHelp:(id)sender {

// This method allows subclasses to launch their own Help menu
// The usual requirements for bundled help apply (Info.plist
entries)
// The root help file MUST be called index.html - not sure how to
get around this

// Get bundle info dictionary
NSDictionary *bundleInfo = [[NSBundle bundleForClass:[self class]]
infoDictionary ];

{ // Register help book
NSString *bundleIdent = [bundleInfo
objectForKey:@"CFBundleIdentifier"];
CFBundleRef mainBundle =
CFBundleGetBundleWithIdentifier((CFStringRef)bundleIdent);
if (mainBundle)
{
CFURLRef bundleURL = NULL;
CFRetain(mainBundle);
bundleURL = CFBundleCopyBundleURL(mainBundle);
if (bundleURL)
{
FSRef bundleFSRef;
if (CFURLGetFSRef(bundleURL, &bundleFSRef))
AHRegisterHelpBook(&bundleFSRef);
CFRelease(bundleURL);
}
CFRelease(mainBundle);
}
}

NSString *page = @"index.html";

NSString *helpBookName = [bundleInfo
objectForKey:@"CFBundleHelpBookName"];

AHGotoPage( (CFStringRef)helpBookName, (CFStringRef)page, nil );

}