Changeset 388 for trunk/ICeCoffEE/ICeCoffEE/ICeCoffEE.m
- Timestamp:
- 02/22/08 19:53:07 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ICeCoffEE/ICeCoffEE/ICeCoffEE.m
r381 r388 7 7 #import "ICeCoffEESuper.h" 8 8 #import "ICeCoffEEServices.h" 9 #import "ICeCoffEET rigger.h"9 #import "ICeCoffEETextViewTrigger.h" 10 10 #import "ICeCoffEEParser.h" 11 11 … … 190 190 Boolean ICCF_enabled = true; 191 191 192 BOOL ICCF_HandleException(NSException *e ) {192 BOOL ICCF_HandleException(NSException *e, NSEvent *event) { 193 193 if ([e reason] == nil || [[e reason] length] == 0) 194 194 return NO; … … 196 196 if (ICCF_prefs.errorSoundEnabled) NSBeep(); 197 197 if (!ICCF_prefs.errorDialogEnabled) return YES; 198 199 [[NSApplication sharedApplication] activateIgnoringOtherApps: YES]; 200 [[event window] makeKeyAndOrderFront: nil]; 198 201 199 202 int result = NSRunAlertPanel(ICCF_LocalizedString(@"AlertTitle"), ICCF_LocalizedString(@"AlertMessage%@"), nil, nil, ICCF_LocalizedString(@"AlertDisableButton"), e); … … 208 211 209 212 void ICCF_LaunchURLFromTextView(NSTextView *self, NSEvent *triggeringEvent) { 210 NSRange range = [self selectedRange];211 213 NSColor *insertionPointColor = [self insertionPointColor]; 212 NSString *s = [[self textStorage] string]; // according to the class documentation, sending 'string' is guaranteed to be O(1)213 int i;214 214 215 215 NS_DURING 216 216 217 NSString *s = [[self textStorage] string]; // according to the class documentation, sending 'string' is guaranteed to be O(1) 218 unsigned length = [s length]; 219 NSCAssert(s != nil, ICCF_LocalizedString(@"Sorry, ICeCoffEE is unable to locate the insertion point or selection")); 220 NSCAssert(length != 0, ICCF_LocalizedString(@"No text was found")); 221 222 ICCF_StartIC(); 223 224 NSRange range = [self selectedRange]; 217 225 NSCAssert(range.location != NSNotFound, ICCF_LocalizedString(@"There is no insertion point or selection in the text field where you clicked")); 218 NSCAssert(s != nil, ICCF_LocalizedString(@"Sorry, ICeCoffEE is unable to locate the insertion point or selection")); 219 220 ICCF_StartIC(); 221 222 NSCAssert([s length] != 0, ICCF_LocalizedString(@"No text was found")); 223 224 if (range.location == [s length]) range.location--; // work around bug in selectionRangeForProposedRange (r. 2845418) 225 226 // XXX is this even worth it to get a starting range? Can just grab back and forth ICCF_MAX_URL_LEN (will need to remove some ICCF_CheckRange calls though) 227 range = [self selectionRangeForProposedRange: range granularity: NSSelectByWord]; 228 229 // However, NSSelectByWord does not capture even the approximate boundaries of a URL 230 // (text to a space/line ending character); it'll stop at a period in the middle of a hostname. 231 // So, we expand it as follows: 232 233 range = ICCF_URLEnclosingRange(s, range); 234 235 [self setSelectedRange: range affinity: NSSelectionAffinityDownstream stillSelecting: NO]; 236 [self display]; 226 227 if (range.length == 0) { 228 if (range.location == length) range.location--; 229 range.length = 1; 230 range = ICCF_URLEnclosingRange(s, range); 231 [self setSelectedRange: range affinity: NSSelectionAffinityDownstream stillSelecting: NO]; 232 } 237 233 238 234 if (ICCF_LaunchURL([s substringWithRange: range], ICCF_KeyboardAction(triggeringEvent)) && ICCF_prefs.textBlinkEnabled) { 239 for ( i = 0 ; i < ICCF_prefs.textBlinkCount ; i++) {235 for (unsigned i = 0 ; i < ICCF_prefs.textBlinkCount ; i++) { 240 236 NSRange emptyRange = {range.location, 0}; 241 237 [self setSelectedRange: emptyRange affinity: NSSelectionAffinityDownstream stillSelecting: YES]; … … 250 246 251 247 NS_HANDLER 252 ICCF_HandleException(localException );248 ICCF_HandleException(localException, triggeringEvent); 253 249 NS_ENDHANDLER 254 250 … … 418 414 } 419 415 420 - (void)mouseDown:(NSEvent *) e;416 - (void)mouseDown:(NSEvent *)downEvent; 421 417 { 422 418 #if ICCF_DEBUG … … 427 423 } 428 424 down = YES; 429 ICLog(@"ICeCoffEE down: %@", e);425 ICLog(@"ICeCoffEE down: %@", downEvent); 430 426 #endif 431 if (ICCF_sharedTrigger != nil) { 432 ICLog(@"%@ cancelling", ICCF_sharedTrigger); 433 [ICCF_sharedTrigger cancel]; 434 } 435 if (ICCF_enabled && ICCF_prefs.commandClickEnabled && ICCF_EventIsCommandMouseDown(e)) { 436 BOOL inheritModifierFlags; 437 if ([self respondsToSelector: @selector(selectedRanges)]) { 438 // Command-multiple-click or -drag for discontiguous selection, Mac OS X 10.4 or later 439 inheritModifierFlags = YES; 440 } else { 441 // don't want to trigger selection extension or anything else; pass through as a plain click 442 // (on Mac OS X 10.3, command does not modify behavior) 443 inheritModifierFlags = NO; 444 } 445 [super mouseDown: ICCF_MouseDownEventWithModifierFlags(e, inheritModifierFlags)]; 427 [ICeCoffEETrigger cancel]; 428 429 if (ICCF_enabled && ICCF_prefs.commandClickEnabled && ICCF_EventIsCommandMouseDown(downEvent)) { 430 [super mouseDown: ICCF_MouseDownEventWithModifierFlags(downEvent, YES)]; 446 431 // we don't actually get a mouseUp event, just wait for mouseDown to return 447 432 NSEvent *upEvent = [[self window] currentEvent]; 448 NSPoint downPt = [ elocationInWindow];433 NSPoint downPt = [downEvent locationInWindow]; 449 434 NSPoint upPt = [upEvent locationInWindow]; 450 435 ICLog(@"next: %@", upEvent); 451 436 NSAssert([upEvent type] == NSLeftMouseUp, @"NSTextView mouseDown: did not return with current event as mouse up!"); 452 437 if (abs(downPt.x - upPt.x) <= kICHysteresisPixels && abs(downPt.y - upPt.y) <= kICHysteresisPixels) { 453 if (inheritModifierFlags) { 454 // Mac OS X 10.4 and later: make sure we don't have a command-double-click 455 [ICeCoffEETrigger setTriggerForEvent: e onTarget: self]; // gets stored in ICCF_sharedTrigger; the reason for this weird calling pattern is that we don't want to add methods to NSTextView, and we don't want to add a method call on every mouseDown 456 ICLog(@"%@ set", ICCF_sharedTrigger); 457 } else { 458 // Mac OS X 10.3 459 ICCF_LaunchURLFromTextView(self, e); 460 } 438 // make sure we don't have a Command-double-click 439 [ICeCoffEETextViewTrigger setTriggerForEvent: downEvent onTarget: self]; // gets stored in ICCF_sharedTrigger; the reason for this weird calling pattern is that we don't want to add methods to NSTextView, and we don't want to add a method call on every mouseDown 461 440 } 462 441 } else { 463 [super mouseDown: e];442 [super mouseDown: downEvent]; 464 443 } 465 444 #if ICCF_DEBUG
Note:
See TracChangeset
for help on using the changeset viewer.