//
//  ICeCoffEESetServicesMenu.m
//  ICeCoffEE APE
//
//  Created by Nicholas Riley on 5/10/05.
//  Copyright 2005 Nicholas Riley. All rights reserved.
//

#import "ICeCoffEESetServicesMenu.h"


void ICCF_SetServicesMenu(NSMenu *servicesMenu) {
    // in 10.3, this populates the menu; in 10.4, it attaches a delegate (NSServiceMaster)
    [[NSApplication sharedApplication] setServicesMenu: servicesMenu];
    id delegate;
    if ( (delegate = [servicesMenu delegate]) != nil) {
	// populate menu so we have something to filter
	if ([delegate respondsToSelector: @selector(menuNeedsUpdate:)]) {
	    [delegate menuNeedsUpdate: servicesMenu];
	}
	if ([delegate respondsToSelector: @selector(menu:updateItem:atIndex:shouldCancel:)]) {
	    int itemCount = [delegate numberOfItemsInMenu: servicesMenu];
	    for (int i = 0 ; i < itemCount ; i++) {
		[servicesMenu addItemWithTitle: @"" action: NULL keyEquivalent: @""];
	    }
	    for (int i = 0 ; i < itemCount ; i++) {
		if (![delegate menu: servicesMenu updateItem: (NSMenuItem *)[servicesMenu itemAtIndex: i] atIndex: i shouldCancel: NO])
		    break;
	    }
	}
    }
}
