Changeset 182 for trunk/ICeCoffEE/ICeCoffEE/ICeCoffEE.m
- Timestamp:
- 05/14/05 02:47:12 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ICeCoffEE/ICeCoffEE/ICeCoffEE.m
r181 r182 1 // ICeCoffEE - Internet Config C ocoa Editor Extension1 // ICeCoffEE - Internet Config Carbon/Cocoa Editor Extension 2 2 // Nicholas Riley <mailto:icecoffee@sabi.net> 3 3 4 4 /* To do/think about: 5 5 6 - TXNClick - MLTE has its own support in Jaguar and later, but it's lousy 7 8 Done: 9 10 - TEClick - TextEdit 11 - flash on success (like BBEdit) 12 - display dialog on failure (decode OSStatus) 13 - adjust URL blinking 14 - app exclusion list - make a pref pane (see AquaShade config) 15 - _LSCopyApplicationURLsForItemURL - list apps 16 - Menu on command-option-click: add bookmark, open with other helper, pass to configurable service, ...? 6 - TXNClick - MLTE has its own (lousy) support in Jaguar, seems improved in Panther, good enough to leave? 17 7 18 8 */ … … 22 12 #include <unistd.h> 23 13 #import "ICeCoffEESuper.h" 14 #import "ICeCoffEESetServicesMenu.h" 24 15 25 16 iccfPrefRec ICCF_prefs; … … 91 82 92 83 [set autorelease]; 93 [set formUnionWithCharacterSet: [[NSCharacterSet characterSetWithRange: NSMakeRange(0 , 128)] invertedSet]]; // removenon-ASCII characters84 [set formUnionWithCharacterSet: [[NSCharacterSet characterSetWithRange: NSMakeRange(0x21, 0x5e)] invertedSet]]; // nonprintable and non-ASCII characters 94 85 [set formUnionWithCharacterSet: [NSCharacterSet punctuationCharacterSet]]; 95 [set removeCharactersInString: @";/?:@&=+$,-_.!~*'()%#"]; // RFC 2396 ¤2.2, 2.3, 2.4, plus #86 [set removeCharactersInString: @";/?:@&=+$,-_.!~*'()%#"]; // RFC 2396 ¤2.2, 2.3, 2.4, plus % and # from "delims" set 96 87 97 88 tmpSet = [[set mutableCopy] autorelease]; … … 198 189 } 199 190 191 // input/output 'range' is the range of source document which contains 'string' 200 192 void ICCF_ParseURL(NSString *string, NSRange *range) { 201 193 OSStatus err; 202 194 Handle h; 203 long selStart , selEnd;195 long selStart = 0, selEnd = range->length; // local offsets within 'string' 204 196 char *urlData = NULL; 205 197 206 NSCAssert( range->length== [string length], @"Internal error: URL string is wrong length");198 NSCAssert(selEnd == [string length], @"Internal error: URL string is wrong length"); 207 199 208 200 NS_DURING 209 201 if ([[NSCharacterSet characterSetWithCharactersInString: @";,."] characterIsMember: 210 [string characterAtIndex: range->length - 1]]) { 211 range->length--; 212 } 213 214 string = [string substringToIndex: range->length]; 202 [string characterAtIndex: selEnd - 1]]) { 203 selEnd--; 204 } 205 NSCharacterSet *alphanumericCharacterSet = [NSCharacterSet alphanumericCharacterSet]; 206 while (![alphanumericCharacterSet characterIsMember: [string characterAtIndex: selStart]]) { 207 selStart++; 208 NSCAssert(selStart < selEnd, @"No URL is selected"); 209 } 210 211 string = [string substringWithRange: NSMakeRange(selStart, selEnd - selStart)]; 215 212 216 213 ICLog(@"Parsing URL |%@|", string); … … 221 218 NSCAssert(urlData != NULL, @"Internal error: can't allocate memory for URL string"); 222 219 223 selStart = 0; selEnd = range->length; 224 220 // XXX getCString: is deprecated in 10.4, but this is safe and shouldn't assert because we've already verified the string can be converted to ASCII, which should be a subset of any possible system encoding. The replacement (getCString:maxLength:encoding:) is not available until 10.4, so we leave this until we dump Internet Config and gain IDN friendliness. 225 221 [string getCString: urlData]; 226 222 … … 402 398 NSMenuItem *ICCF_ServicesMenuItem() { 403 399 NSMenuItem *servicesItem; 404 NSMenu *servicesMenu; 405 // don't want to use [[NSApp servicesMenu] title] because the Services menu may not have been created yet 406 NSString *servicesTitle = [[NSBundle bundleWithIdentifier: @"com.apple.AppKit"] localizedStringForKey: @"Services" value: nil table: @"ServicesMenu"]; 407 if (servicesTitle == nil) { 408 ICLog(@"Can't get localized text for 'Services' in AppKit.framework"); 409 servicesTitle = @"Services"; 400 NSString *servicesTitle = nil; 401 NSMenu *servicesMenu = [NSApp servicesMenu]; 402 403 if (servicesMenu != nil) { 404 servicesTitle = [servicesMenu title]; 405 if (servicesTitle == nil) { 406 ICLog(@"Can't get service menu title"); 407 servicesTitle = @"Services"; 408 } 409 } else { 410 servicesTitle = [[NSBundle bundleWithIdentifier: @"com.apple.AppKit"] localizedStringForKey: @"Services" value: nil table: @"ServicesMenu"]; 411 if (servicesTitle == nil) { 412 ICLog(@"Can't get localized text for 'Services' in AppKit.framework"); 413 servicesTitle = @"Services"; 414 } 410 415 } 411 416 servicesMenu = [[NSMenu alloc] initWithTitle: servicesTitle]; 412 417 servicesItem = [[NSMenuItem alloc] initWithTitle: servicesTitle action:nil keyEquivalent:@""]; 413 [[NSApplication sharedApplication] setServicesMenu: servicesMenu];418 ICCF_SetServicesMenu(servicesMenu); 414 419 [servicesItem setSubmenu: servicesMenu]; 415 420 [servicesItem setRepresentedObject: ICCF_SERVICES_ITEM]; … … 448 453 } 449 454 } else { 455 [menuItem setKeyEquivalent: @""]; 450 456 shouldKeepItem = [menuItem isEnabled]; 451 457 } … … 494 500 } 495 501 502 503 @interface NSTextView (IC_NSSharing) 504 // only in Mac OS X 10.4 and later 505 - (NSArray *)selectedRanges; 506 @end 507 496 508 @implementation ICeCoffEE 497 509 … … 536 548 #endif 537 549 if (ICCF_enabled && ICCF_prefs.commandClickEnabled && ICCF_EventIsCommandMouseDown(e)) { 538 // don't want to trigger selection extension or anything else; pass through as a plain click 550 if ([self respondsToSelector: @selector(selectedRanges)]) { 551 // discontiguous selection support, Mac OS X 10.4 or later 552 NSArray *ranges = [self selectedRanges]; 553 ICLog(@"ICeCoffEE selected ranges: %@", ranges); 554 if ([ranges count] > 1 || [[ranges objectAtIndex: 0] rangeValue].length != 0) 555 goto bypass; 556 } else { 557 // don't want to trigger selection extension or anything else; pass through as a plain click 558 // (on Panther and earlier, command does not modify behavior) 559 } 539 560 [super mouseDown: [NSEvent mouseEventWithType: NSLeftMouseDown location: [e locationInWindow] modifierFlags: 0 timestamp: [e timestamp] windowNumber: [e windowNumber] context: [e context] eventNumber: [e eventNumber] clickCount: 1 pressure: 0]]; 540 561 // we don't actually get a mouseUp event, just wait for mouseDown to return … … 548 569 } 549 570 } else { 571 bypass: 550 572 [super mouseDown: e]; 551 573 }
Note:
See TracChangeset
for help on using the changeset viewer.