Changeset 139 for trunk/ICeCoffEE/ICeCoffEE/ICeCoffEE.m
- Timestamp:
- 05/31/03 05:04:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ICeCoffEE/ICeCoffEE/ICeCoffEE.m
r106 r139 56 56 } 57 57 58 CFStringRef ICCF_CopyAppName() { 59 ProcessSerialNumber psn = {0, kCurrentProcess}; 60 CFStringRef appName = NULL; 61 CopyProcessName(&psn, &appName); 62 if (appName == NULL) return CFSTR("(unknown)"); 63 return appName; 64 } 65 58 66 BOOL ICCF_EventIsCommandMouseDown(NSEvent *e) { 59 67 return ([e type] == NSLeftMouseDown && ([e modifierFlags] & NSCommandKeyMask) != 0 && [e clickCount] == 1); … … 83 91 84 92 [set autorelease]; 93 [set formUnionWithCharacterSet: [[NSCharacterSet characterSetWithRange: NSMakeRange(0, 128)] invertedSet]]; // remove non-ASCII characters 85 94 [set formUnionWithCharacterSet: [NSCharacterSet punctuationCharacterSet]]; 86 95 [set removeCharactersInString: @";/?:@&=+$,-_.!~*'()%#"]; // RFC 2396 ¤2.2, 2.3, 2.4, plus # … … 207 216 ICLog(@"Parsing URL |%@|", string); 208 217 218 NSCAssert([string canBeConvertedToEncoding: NSASCIIStringEncoding], @"No URL is selected"); 219 209 220 urlData = (char *)malloc( (range->length + 1) * sizeof(char)); 210 221 NSCAssert(urlData != NULL, @"Internal error: canÕt allocate memory for URL string"); … … 288 299 int result = NSRunAlertPanel(ICCF_LocalizedString(@"AlertTitle"), ICCF_LocalizedString(@"AlertMessage%@"), nil, nil, ICCF_LocalizedString(@"AlertDisableButton"), e); 289 300 if (result != NSAlertDefaultReturn) { 290 result = NSRunAlertPanel(ICCF_LocalizedString(@"DisableAlertTitle"), ICCF_LocalizedString(@"DisableAlertMessage"), ICCF_LocalizedString(@"DisableAlertDisableButton"), ICCF_LocalizedString(@"DisableAlertDontDisableButton"), nil); 301 result = NSRunAlertPanel(ICCF_LocalizedString(@"DisableAlertTitle"), ICCF_LocalizedString(@"DisableAlertMessage%@"), ICCF_LocalizedString(@"DisableAlertDisableButton"), ICCF_LocalizedString(@"DisableAlertDontDisableButton"), nil, 302 [(NSString *)ICCF_CopyAppName() autorelease]); 291 303 if (result == NSAlertDefaultReturn) 292 304 ICCF_enabled = NO; … … 391 403 NSMenuItem *servicesItem; 392 404 NSMenu *servicesMenu; 393 // XXX better to just use [[NSApp servicesMenu] title]? That grabs the title from the existing Services submenu.405 // don't want to use [[NSApp servicesMenu] title] because the Services menu may not have been created yet 394 406 NSString *servicesTitle = [[NSBundle bundleWithIdentifier: @"com.apple.AppKit"] localizedStringForKey: @"Services" value: nil table: @"ServicesMenu"]; 395 407 if (servicesTitle == nil) { 396 ICLog(@"CanÕt get localized text for ÒServicesÓin AppKit.framework");408 ICLog(@"CanÕt get localized text for 'Services' in AppKit.framework"); 397 409 servicesTitle = @"Services"; 398 410 } … … 403 415 [servicesItem setRepresentedObject: ICCF_SERVICES_ITEM]; 404 416 [servicesMenu release]; 405 return servicesItem; 417 return [servicesItem autorelease]; 418 } 419 420 static const unichar UNICHAR_BLACK_RIGHT_POINTING_SMALL_TRIANGLE = 0x25b8; 421 422 // returns YES if menu contains useful items, NO otherwise 423 BOOL ICCF_ConsolidateServicesMenu(NSMenu *menu) { 424 [menu update]; // doesn't propagate to submenus, so we need to do this first 425 NSEnumerator *enumerator = [[menu itemArray] objectEnumerator]; 426 NSMenuItem *menuItem; 427 NSMenu *submenu; 428 BOOL shouldKeepItem = NO, shouldKeepMenu = NO; 429 430 while ( (menuItem = [enumerator nextObject]) != nil) { 431 if ( (submenu = [menuItem submenu]) != nil) { 432 shouldKeepItem = ICCF_ConsolidateServicesMenu(submenu); 433 if (shouldKeepItem && [submenu numberOfItems] == 1) { // consolidate 434 NSMenuItem *serviceItem = [[submenu itemAtIndex: 0] retain]; 435 [serviceItem setTitle: 436 [NSString stringWithFormat: @"%@ %@ %@", [menuItem title], [NSString stringWithCharacters: &UNICHAR_BLACK_RIGHT_POINTING_SMALL_TRIANGLE length: 1], [serviceItem title]]]; 437 438 int serviceIndex = [menu indexOfItem: menuItem]; 439 [submenu removeItemAtIndex: 0]; // can't have item in two menus 440 [menu removeItemAtIndex: serviceIndex]; 441 [menu insertItem: serviceItem atIndex: serviceIndex]; 442 [serviceItem release]; 443 } 444 } else { 445 shouldKeepItem = [menuItem isEnabled]; 446 } 447 if (shouldKeepItem) { 448 shouldKeepMenu = YES; 449 } else { 450 [menu removeItem: menuItem]; 451 } 452 } 453 454 return shouldKeepMenu; 455 } 456 457 NSMenuItem *ICCF_ContextualServicesMenuItem() { 458 NSMenuItem *servicesItem = ICCF_ServicesMenuItem(); 459 if (ICCF_ConsolidateServicesMenu([servicesItem submenu])) 460 return servicesItem; 461 else 462 return nil; 406 463 } 407 464 … … 413 470 } 414 471 415 NSMenu *ICCF_MenuForEvent(NSTextView *self, NSMenu *contextMenu, NSEvent *e) { 472 NSMenu *ICCF_MenuForEvent(NSTextView *self, NSMenu *contextMenu, NSEvent *e) { 416 473 if (contextMenu != nil && [e type] == NSRightMouseDown || ([e type] == NSLeftMouseDown && [e modifierFlags] & NSControlKeyMask)) { 417 474 int servicesItemIndex = [contextMenu indexOfItemWithRepresentedObject: ICCF_SERVICES_ITEM]; 418 if (servicesItemIndex == -1 && ICCF_prefs.servicesInContextualMenu) { 419 [contextMenu addItem: [NSMenuItem separatorItem]]; 420 [contextMenu addItem: ICCF_ServicesMenuItem()]; 421 } else if (servicesItemIndex != -1 && !ICCF_prefs.servicesInContextualMenu) { 475 // always regenerate: make sure menu reflects context 476 if (servicesItemIndex != -1) { 422 477 [contextMenu removeItemAtIndex: servicesItemIndex]; 423 478 [contextMenu removeItemAtIndex: servicesItemIndex - 1]; 479 } 480 if (ICCF_prefs.servicesInContextualMenu) { 481 NSMenuItem *contextualServicesItem = ICCF_ContextualServicesMenuItem(); 482 if (contextualServicesItem != nil) { 483 [contextMenu addItem: [NSMenuItem separatorItem]]; 484 [contextMenu addItem: contextualServicesItem]; 485 } 424 486 } 425 487 } … … 447 509 servicesItem = nil; 448 510 } 511 [[NSApp servicesMenu] update]; // enable keyboard equivalents 449 512 } 450 513
Note:
See TracChangeset
for help on using the changeset viewer.