Changeset 79 for trunk/ICeCoffEE/ICeCoffEE/ICeCoffEE.m
- Timestamp:
- 02/02/03 14:06:10 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ICeCoffEE/ICeCoffEE/ICeCoffEE.m
r75 r79 7 7 for both files and text 8 8 - if it's not a URL, try using TextExtras' open list 9 - John Hayes' suggestions10 - Menu on command-option-click: add bookmark, open with other helper, pass to configurable service, ...?11 9 - TXNClick - MLTE has its own support in Jaguar and later, but it's lousy 12 10 … … 19 17 - app exclusion list - make a pref pane (see AquaShade config) 20 18 - _LSCopyApplicationURLsForItemURL - list apps 19 - Menu on command-option-click: add bookmark, open with other helper, pass to configurable service, ...? 21 20 22 21 */ … … 130 129 } 131 130 132 ConstStringPtr ICCF_GetHint(ICInstance inst, const char *urlData, long startIndex, long endIndex) {131 ConstStringPtr ICCF_GetHint(ICInstance inst, const char *urlData, Size length, long *selStart, long *selEnd, Boolean *needsSlashes) { 133 132 Handle h = NewHandle(0); 134 133 OSStatus err; 135 long tmpStartIndex = startIndex, tmpEndIndex = endIndex; 136 134 137 135 if (h == NULL) return NULL; 138 136 139 137 // parse the URL providing a bogus protocol, to get rid of escaped forms 140 err = ICParseURL(inst, "\p*", urlData + startIndex, endIndex - startIndex + 1, 141 &tmpStartIndex, &tmpEndIndex, h); 138 err = ICParseURL(inst, "\p*", urlData, length, selStart, selEnd, h); 142 139 if (err != noErr) return NULL; 143 140 … … 149 146 long i = 0; 150 147 Boolean sawAt = false; 151 if ( urlParsed[0] == '*' && urlParsed[1] == ':') {148 if (hSize >= 2 && urlParsed[0] == '*' && urlParsed[1] == ':') { 152 149 // this is an IC-inserted protocol; skip over it 153 150 i = 2; 154 } 151 *needsSlashes = (hSize < i + 2 || urlParsed[i] != '/' || urlParsed[i + 1] != '/'); 152 } else *needsSlashes = false; 155 153 for ( ; i < hSize ; i++) { 156 154 char c = urlParsed[i]; … … 164 162 } 165 163 DisposeHandle(h); 166 return (sawAt ? "\pmailto" : "\phttp"); 164 if (sawAt) { 165 *needsSlashes = false; 166 return "\pmailto"; 167 } 168 return "\phttp"; 169 } 170 171 static const char *kICSlashes = "//"; 172 173 void ICCF_AddSlashes(Handle h, ConstStringPtr hint) { 174 Size sizeBefore = GetHandleSize(h); 175 unsigned char hintLength = StrLength(hint); 176 char *copy = (char *)malloc(sizeBefore); 177 memcpy(copy, *h, sizeBefore); 178 ICLog(@"ICCF_AddSlashes before: |%s|\n", *h); 179 ReallocateHandle(h, sizeBefore + 2); 180 181 // if *h begins with '<hint>:', then copy the slashes after it 182 if (sizeBefore > hintLength + 1 && strncmp(&hint[1], copy, hintLength) == 0 && copy[hintLength] == ':') { 183 memcpy(*h, copy, hintLength + 1); 184 memcpy(*h + hintLength + 1, kICSlashes, 2); 185 memcpy(*h + hintLength + 3, ©[hintLength + 1], sizeBefore - hintLength - 1); 186 } else { 187 memcpy(*h, kICSlashes, 2); 188 memcpy(*h + 2, copy, sizeBefore); 189 } 190 191 free(copy); 192 ICLog(@"ICCF_AddSlashes after: |%s|\n", *h); 167 193 } 168 194 … … 215 241 unsigned len = [string length]; 216 242 217 char *urlData= NULL;243 Handle h = NULL; 218 244 219 245 NS_DURING 220 urlData = (char *)malloc( (len + 1) * sizeof(char)); 221 NSCAssert(urlData != NULL, @"Internal error: canÕt allocate memory for URL string"); 222 223 [string getCString: urlData]; 246 h = NewHandle(len); 247 if (h == NULL) 248 ICCF_OSErrCAssert(MemError(), @"NewHandle"); 249 250 if (CFStringGetBytes((CFStringRef)string, CFRangeMake(0, len), kCFStringEncodingASCII, '\0', false, *h, len, NULL) != len) 251 ICCF_OSErrCAssert(kTECNoConversionPathErr, @"CFStringGetBytes"); 224 252 225 253 selStart = 0; selEnd = len; 226 254 227 ConstStringPtr hint = ICCF_GetHint(ICCF_GetInst(), urlData, selStart, selEnd); 255 Boolean needsSlashes; 256 ConstStringPtr hint = ICCF_GetHint(ICCF_GetInst(), *h, len, &selStart, &selEnd, &needsSlashes); 228 257 NSCAssert(hint != NULL, @"Internal error: canÕt get protocol hint for URL"); 229 258 259 if (needsSlashes) { 260 ICCF_AddSlashes(h, hint); 261 len = selEnd = GetHandleSize(h); 262 } 263 230 264 if (chooseApp) { 231 err = ICCF_DoURLActionMenu(ICCF_GetInst(), hint, urlData, selStart, selEnd);265 err = ICCF_DoURLActionMenu(ICCF_GetInst(), hint, *h, selStart, selEnd); 232 266 ICCF_OSErrCAssert(err, @"ICCF_DoURLActionMenu"); 233 267 } else { 234 err = ICLaunchURL(ICCF_GetInst(), hint, urlData, len, &selStart, &selEnd);268 err = ICLaunchURL(ICCF_GetInst(), hint, *h, len, &selStart, &selEnd); 235 269 ICCF_OSErrCAssert(err, @"ICLaunchURL"); 236 270 } 237 271 238 272 NS_HANDLER 239 free(urlData);273 DisposeHandle(h); 240 274 [localException raise]; 241 275 NS_ENDHANDLER 242 276 243 free(urlData);277 DisposeHandle(h); 244 278 } 245 279 … … 404 438 @implementation ICeCoffEE 405 439 406 + (NSString *)IC_version;407 {408 // XXX get from bundle if possible: centralize409 return [NSString stringWithCString: ICCF_VERSION];410 }411 412 440 + (void)IC_addRemoveServicesMenu; 413 441 {
Note:
See TracChangeset
for help on using the changeset viewer.