Ignore:
Timestamp:
05/14/05 02:47:12 (16 years ago)
Author:
Nicholas Riley
Message:

English.lproj/APEInfo.rtfd: Partial documentation update for 1.4.2;
fixed many instances of outdated and incorrect information.

ICeCoffEE.m: Removed completed "to do" comments - that's what
OmniOutliner? and Trac are for. Fixed delimiters to make more sense.
Redid ICCF_ParseURL() to make more sense and strip invalid characters
from beginning of URL. Added note about deprecated getCString:.
Fixed ICCF_ServicesMenuItem() to work on Tiger; moved menu population
logic (where services menu delegate used) to new
ICCF_SetServicesMenu() in ICeCoffEESetServicesMenu.[hm]. Remove key
equivalents from services in ICCF_ConsolidateServicesMenu(). First
pass at a workaround for discontiguous selection: only trigger if
there is no selection. This will be fixed to use a timer.

ICeCoffEEServicePrefController: Fixed service population to work on
Tiger, though keyboard equivalents are not provided; will need to
switch to parsing output of CFServiceControllerCopyServicesEntries()
for that one.

ICeCoffEEWebKit.m: Removed Safari 1.0-1.2 support. Fixed incorrect
comment about -selectionRect? only being in Safari
1.1-1.2.

ICeCoffEESetServicesMenu.[hm]: Handle getting a usable services menu
for Panther and Tiger.

File:
1 edited

Legend:

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

    r181 r182  
    1 // ICeCoffEE - Internet Config Cocoa Editor Extension
     1// ICeCoffEE - Internet Config Carbon/Cocoa Editor Extension
    22// Nicholas Riley <mailto:icecoffee@sabi.net>
    33
    44/* To do/think about:
    55
    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?
    177
    188*/
     
    2212#include <unistd.h>
    2313#import "ICeCoffEESuper.h"
     14#import "ICeCoffEESetServicesMenu.h"
    2415
    2516iccfPrefRec ICCF_prefs;
     
    9182
    9283        [set autorelease];
    93         [set formUnionWithCharacterSet: [[NSCharacterSet characterSetWithRange: NSMakeRange(0, 128)] invertedSet]]; // remove non-ASCII characters
     84        [set formUnionWithCharacterSet: [[NSCharacterSet characterSetWithRange: NSMakeRange(0x21, 0x5e)] invertedSet]]; // nonprintable and non-ASCII characters
    9485        [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
    9687
    9788        tmpSet = [[set mutableCopy] autorelease];
     
    198189}
    199190
     191// input/output 'range' is the range of source document which contains 'string'
    200192void ICCF_ParseURL(NSString *string, NSRange *range) {
    201193    OSStatus err;
    202194    Handle h;
    203     long selStart, selEnd;
     195    long selStart = 0, selEnd = range->length; // local offsets within 'string'
    204196    char *urlData = NULL;
    205197
    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");
    207199   
    208200    NS_DURING
    209201        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)];
    215212
    216213        ICLog(@"Parsing URL |%@|", string);
     
    221218        NSCAssert(urlData != NULL, @"Internal error: can't allocate memory for URL string");
    222219
    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.
    225221        [string getCString: urlData];
    226222
     
    402398NSMenuItem *ICCF_ServicesMenuItem() {
    403399    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        }
    410415    }
    411416    servicesMenu = [[NSMenu alloc] initWithTitle: servicesTitle];
    412417    servicesItem = [[NSMenuItem alloc] initWithTitle: servicesTitle action:nil keyEquivalent:@""];
    413     [[NSApplication sharedApplication] setServicesMenu: servicesMenu];
     418    ICCF_SetServicesMenu(servicesMenu);
    414419    [servicesItem setSubmenu: servicesMenu];
    415420    [servicesItem setRepresentedObject: ICCF_SERVICES_ITEM];
     
    448453            }
    449454        } else {
     455            [menuItem setKeyEquivalent: @""];
    450456            shouldKeepItem = [menuItem isEnabled];
    451457        }
     
    494500}
    495501
     502
     503@interface NSTextView (IC_NSSharing)
     504// only in Mac OS X 10.4 and later
     505- (NSArray *)selectedRanges;
     506@end
     507
    496508@implementation ICeCoffEE
    497509
     
    536548#endif
    537549    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        }
    539560        [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]];
    540561        // we don't actually get a mouseUp event, just wait for mouseDown to return
     
    548569        }
    549570    } else {
     571bypass:
    550572        [super mouseDown: e];
    551573    }
Note: See TracChangeset for help on using the changeset viewer.