Changeset 435 for trunk


Ignore:
Timestamp:
03/04/08 17:29:41 (17 years ago)
Author:
Nicholas Riley
Message:

Operate on the link target, rather than the text, of NSTextView hyperlinks

Location:
trunk/ICeCoffEE/ICeCoffEE
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ICeCoffEE/ICeCoffEE/APEMain.m

    r393 r435  
    129129        if (ICCF_CFBundleIDMatches(bundleID, CFSTR("com.apple.xcode"))) {
    130130            if (ICCF_PatchMethod("XCTextView", "ICeCoffEE", "ICeCoffEESuper", "mouseDown:")) {
     131                ICCF_PatchMethod("XCTextView", "ICeCoffEE", "ICeCoffEESuper", "clickedOnLink:atIndex:");
    131132                ICCF_PatchMethod("XCSourceCodeTextView", "ICeCoffEEMenuOnly", "ICeCoffEEMenuSuper", "menuForEvent:");
    132133                ICCF_PatchMethod("XCDiffTextView", "ICeCoffEE", "ICeCoffEESuper", "mouseDown:");
     134                ICCF_PatchMethod("XCDiffTextView", "ICeCoffEE", "ICeCoffEESuper", "clickedOnLink:atIndex:");
    133135                ICCF_PatchMethod("XCDiffTextView", "ICeCoffEE", "ICeCoffEESuper", "menuForEvent:"); // subclass of PBXTextView; patching both is bad
    134136            } else {
     
    166168    if (shouldLoadInNSTextView) {
    167169        ICCF_PatchMethod("NSTextView", "ICeCoffEE", "ICeCoffEESuper", "mouseDown:") &&
     170        ICCF_PatchMethod("NSTextView", "ICeCoffEE", "ICeCoffEESuper", "clickedOnLink:atIndex:") &&
    168171        ICCF_PatchMethod("NSTextView", "ICeCoffEE", "ICeCoffEESuper", "menuForEvent:");
    169172        ICapeprintf("ICeCoffEE APE: loaded generic NSTextView support\n");
  • trunk/ICeCoffEE/ICeCoffEE/ICeCoffEE.m

    r388 r435  
    224224        NSRange range = [self selectedRange];
    225225        NSCAssert(range.location != NSNotFound, ICCF_LocalizedString(@"There is no insertion point or selection in the text field where you clicked"));
    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         }
    233 
    234         if (ICCF_LaunchURL([s substringWithRange: range], ICCF_KeyboardAction(triggeringEvent)) && ICCF_prefs.textBlinkEnabled) {
     226        NSString *url = nil;
     227   
     228        if ([[self textStorage] attribute: NSLinkAttributeName atIndex: range.location
     229                           effectiveRange: NULL] != nil) {
     230            NSRange linkRange;
     231            id link = [[self textStorage] attribute: NSLinkAttributeName atIndex: range.location longestEffectiveRange: &linkRange inRange: NSMakeRange(0, length)];
     232            if (NSMaxRange(range) <= NSMaxRange(linkRange)) {
     233                // selection is entirely within link range
     234                url = [link isKindOfClass: [NSURL class]] ? [link absoluteString] : link;
     235                range = linkRange;
     236                [self setSelectedRange: range affinity: NSSelectionAffinityDownstream stillSelecting: NO];
     237            }
     238        }
     239        if (url == nil) {
     240            if (range.length == 0) {
     241                if (range.location == length) range.location--;
     242                range.length = 1;
     243                range = ICCF_URLEnclosingRange(s, range);
     244                [self setSelectedRange: range affinity: NSSelectionAffinityDownstream stillSelecting: NO];
     245            }
     246       
     247            url = [s substringWithRange: range];
     248        }
     249
     250        if (ICCF_LaunchURL(url, ICCF_KeyboardAction(triggeringEvent)) && ICCF_prefs.textBlinkEnabled) {
    235251            for (unsigned i = 0 ; i < ICCF_prefs.textBlinkCount ; i++) {
    236252                NSRange emptyRange = {range.location, 0};
     
    384400}
    385401
    386 
    387402@implementation ICeCoffEE
    388403
     
    412427    NSMenu *myMenu = [super menuForEvent: e];
    413428    return ICCF_MenuForEvent(self, myMenu, e);
     429}
     430
     431static BOOL ICCF_inMouseDown;
     432
     433- (void)clickedOnLink:(id)link atIndex:(unsigned)charIndex;
     434{
     435    if (!ICCF_inMouseDown)
     436        [super clickedOnLink: link atIndex: charIndex];
    414437}
    415438
     
    428451
    429452    if (ICCF_enabled && ICCF_prefs.commandClickEnabled && ICCF_EventIsCommandMouseDown(downEvent)) {
    430         [super mouseDown: ICCF_MouseDownEventWithModifierFlags(downEvent, YES)];
     453        ICCF_inMouseDown = YES;
     454        @try {
     455            [super mouseDown: ICCF_MouseDownEventWithModifierFlags(downEvent, YES)];
     456        } @finally {
     457            ICCF_inMouseDown = NO;
     458        }
    431459        // we don't actually get a mouseUp event, just wait for mouseDown to return
    432460        NSEvent *upEvent = [[self window] currentEvent];
  • trunk/ICeCoffEE/ICeCoffEE/ICeCoffEESuper.m

    r66 r435  
    1717}
    1818
     19- (void)clickedOnLink:(id)link atIndex:(unsigned)charIndex;
     20{
     21    [super clickedOnLink: link atIndex: charIndex];
     22}
     23
    1924- (void)mouseDown:(NSEvent *)e;
    2025{
Note: See TracChangeset for help on using the changeset viewer.