Using Spotlight to query external source
Hi, reading through the spotlight docu I am not sure where to start or if the following is possible. I am trying to find out if a spotlight importer can be used to query external data sources. I know the advantage of spotlight is meant to pre-catalog files in order to quickly return results. But in other cases where there is data not permanently available I am looking for a way to only hook into the user entering something into spotlight to additionally forward the query to another process or even other server or machine. Is this possible? Thank you Alex ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: responding to NSStepper clicks
On Dec 16, 2011, at 11:48 PM, Quincey Morris wrote: > There are various solutions you might choose, depending on how you expect to > handle validation errors for your text field. You can add a number formatter > to the field, or you can change the property to type long long (though you > then need to check for negative numbers yourself), or you can use KVC > validation to substitute a NSNumber object for the NSString object. Changing the value from NSInteger to NSNumber in my model did the trick, I don't get the crash anymore, and everything updates accordingly. I don't have to use a formatter either, although I probably need to add anyway to prevent the user from typing anything else but numbers. The only that does't work yet is that I need to hit enter or tab to have my model respond to a change in the NSTextField. As suggested earlier, I set the binding "Continuously Update Value", but that doesn't work. I also see a small exclamation mark (white on a red circle), in the Model Key Path bindings field, where I bind to my model. Xcode autocompletes the correct property, so I'm not sure what to do with this, since everything works. I don't see that exclamation mark in the NSStepper bindings field. - Koen. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Sheet created by NSObjectContoller??
Hi Everyone, Perhaps someone can help point me in the right direction on this: I have an NSObjectController that maintains a UI for me. I have an NSTextField which contains numerical value. You could type in a number, which populates an NSNumber object deep inside my code.. Magically, my NSObjectController does its thing and maintains the UI. Very cool stuff! I just recently updated my bindings for this NSTextField, so that a a Min and Max Value is respected. As a test, I typed a value which is outside the Min/Max value, to see what I need to implement. To my surprise, a sheet is created saying "The Value 500 is too large." It prompts the user to Discard or Keep Change. Where did this come from? And how do I override this? I can't find info in the docs. I do see a vague reference to a "sheet" in the NSObjectController Docs, with add/remove selectors, etc. But nothing concrete. Ideas? Thanks! bob. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: responding to NSStepper clicks
Here is a simple tutorial by a list member of ours: http://juliuspaintings.co.uk/cgi-bin/paint_css/animatedPaint/059-NSStepper-NSTextField.pl This example uses an object controller but can be reconfigured to bypass it and bind to an ivar easily. Even though it uses a number formatter besides the controller it exposes the problem you are facing, too: (1) Validation happens only when you leave the field. (2) The user is not prevented from entering crap values right on the spot. I took it as a base for some experiments of my own: By setting validates immediately in IB for the text field and putting a handler like - (BOOL)validateFloatValue:(id *)ioValue error:(NSError **)outError { NSLog(@"validating"); return YES; } into the model class, you can prove that whenever you type a number digit into the text field you see a validating message in the console, but at the same time the user may happily type any other crap without the validation even bothering to kick in. Validation furthermore stops if the value exceeds the max value defined in the number formatter. I could not find anything about this in the KVC docs, so go figure. I hope it's just me doing something terribly wrong or Apple's implementation is rather usless for this purpose. I guess you might have to implement this method as a supllement if your value is set programmatically from various other sources. All in all it seems way to complicated to achieve the desired effect without use of the delegate method. I'd be happy to see an example which does not have to rely on it, if this is possible at all. Maybe you have to use a custom value converter in the bindings or something. Dunno. Therefore, my own implementation of a text field + stepper combination goes like this: Specs: - Only integers are allowed. Single 0 inputs, which eventually would lead to leading zeros, are forbidden, since the... - minimum value is hardcoded at 2 anyway. - The maximum value is calculated in code (by the window controller's delegate). So I have a window controller sub-subclass for a modal window implemented like this (only relevant parts are shown here): MyWC.h @interface MyWC : ContextMenuWC { IBOutlet NSTextField *unitNumberField; IBOutlet NSStepper *unitNumberStepper; NSInteger unitSize; IBOutlet id delegate; } @property (nonatomic, assign) NSInteger unitSize; @property (nonatomic, assign) id delegate; - (IBAction) okAction:(id)sender; - (id)initWithDelegate:(id )theDelegate; @end The stepper's value is bound directly to unitSize. IB binding setting is validates immediately. The NSTextField is equally bound to unitSize. IB binding settings are all off. MyWC.m #import "RegexKitLite.h" - (void)controlTextDidChange:(NSNotification *)aNotification { NSText *theFieldEditor = [aNotification.userInfo objectForKey:@"NSFieldEditor"]; NSString *theString = [theFieldEditor string]; //0-9 only, but no single 0 (i.e. 0 only allowed in double or more digit numbers) BOOL isAcceptableIntegersOnly = ([theString isMatchedByRegex:@"^[0-9]{1,2}$"] && ![theString isMatchedByRegex:@"^0{1,2}$"]); if (!isAcceptableIntegersOnly) { //fall back to max value if input is bad [theFieldEditor setString:[NSString stringWithFormat:@"%ld", (NSInteger)[unitNumberStepper maxValue]]]; [theFieldEditor setSelectedRange:NSMakeRange(0, [[theFieldEditor string] length])]; self.unitSize = [[theFieldEditor string] integerValue]; [self.okButton setEnabled:YES]; return; } //regex matches, so the following is safe, otherwise integerValue just extracts digits from any kind of string value NSInteger theInteger = [theString integerValue]; NSInteger theMinValue = (NSInteger)[unitNumberStepper minValue]; //if 10 shall be allowed as input, the user has to be able to type 1 if (theInteger < theMinValue) { [self.okButton setEnabled:NO]; return; } if (theInteger > (NSInteger)[unitNumberStepper maxValue]) { //fall back to max value if input is too high [theFieldEditor setString:[NSString stringWithFormat:@"%ld", (NSInteger)[unitNumberStepper maxValue]]]; [theFieldEditor setSelectedRange:NSMakeRange(0, [[theFieldEditor string] length])]; } [self.okButton setEnabled:YES]; self.unitSize = [[theFieldEditor string] integerValue]; } Note that I initialize the bound variable to some predefined value (the maximum value possible in this case). Moreover, even though both GUI elements are bound to self.unitSize, I set this value "manually" at the end of the delegate method to make things work. Took me quite a bit of experimentation to get it as I wanted it. I also experimented with KVC validation methods for unitSize but these also didn't help. (Furthermore, I experimented with a @property (copy) previousUnitSizeString as a backup to restore a previously accepted value if the code rejects the user input, but the user experience didn't
Re: Sheet created by NSObjectContoller??
Am 17.12.2011 um 19:59 schrieb Robert Monaghan: > Hi Everyone, > > Perhaps someone can help point me in the right direction on this: > > I have an NSObjectController that maintains a UI for me. > I have an NSTextField which contains numerical value. You could type in a > number, which populates an NSNumber object deep inside my code.. > Magically, my NSObjectController does its thing and maintains the UI. Very > cool stuff! > > I just recently updated my bindings for this NSTextField, so that a a Min and > Max Value is respected. Interesting! How did you do that via bindings? > As a test, I typed a value which is outside the Min/Max value, to see what I > need to implement. To my surprise, a sheet is created saying "The Value 500 > is too large." It prompts the user to Discard or Keep Change. > Where did this come from? And how do I override this? Implement a KVC validation method for your property. I guess. See file:///Library/Developer/Shared/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/Validation.html#//apple_ref/doc/uid/20002173 > I can't find info in the docs. I do see a vague reference to a "sheet" in the > NSObjectController Docs, with add/remove selectors, etc. But nothing concrete. > Ideas? > > Thanks! > > bob. > > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > http://lists.apple.com/mailman/options/cocoa-dev/magnard%40web.de > > This email sent to magn...@web.de > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Sheet created by NSObjectContoller??
The binding is straight forward.. You create an NSObjectController, and set the "Mode" to "Class" and the Class Name to your object with a bunch of NSNumbers. (prepared with @property/@synthesize, naturally) In my NSTextField, I bind my "value", "Min Value" and "Max Value" to the NSObjectController, specifying which NSNumbers are to be used for each. So I have have inside my object a set of NSNumbers called "maxVal" "minVal" and "currentVal", my NSTextField would reflect those values. If minVal is 10, maxValue is 20, and currentValue is 15. Everything is great. Now type in 500 in the NSTextField, and out pops a sheet! I am going to see about validation. Perhaps that is how this is happening. bob.. On Dec 17, 2011, at 11:10 AM, Peter wrote: > > Am 17.12.2011 um 19:59 schrieb Robert Monaghan: > >> Hi Everyone, >> >> Perhaps someone can help point me in the right direction on this: >> >> I have an NSObjectController that maintains a UI for me. >> I have an NSTextField which contains numerical value. You could type in a >> number, which populates an NSNumber object deep inside my code.. >> Magically, my NSObjectController does its thing and maintains the UI. Very >> cool stuff! >> >> I just recently updated my bindings for this NSTextField, so that a a Min >> and Max Value is respected. > > Interesting! How did you do that via bindings? > >> As a test, I typed a value which is outside the Min/Max value, to see what I >> need to implement. To my surprise, a sheet is created saying "The Value 500 >> is too large." It prompts the user to Discard or Keep Change. >> Where did this come from? And how do I override this? > > Implement a KVC validation method for your property. I guess. > See > file:///Library/Developer/Shared/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/Validation.html#//apple_ref/doc/uid/20002173 > >> I can't find info in the docs. I do see a vague reference to a "sheet" in >> the NSObjectController Docs, with add/remove selectors, etc. But nothing >> concrete. >> Ideas? >> >> Thanks! >> >> bob. >> >> >> ___ >> >> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) >> >> Please do not post admin requests or moderator comments to the list. >> Contact the moderators at cocoa-dev-admins(at)lists.apple.com >> >> Help/Unsubscribe/Update your Subscription: >> http://lists.apple.com/mailman/options/cocoa-dev/magnard%40web.de >> >> This email sent to magn...@web.de >> > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Using Spotlight to query external source
On Dec 17, 2011, at 3:13 AM, Alexander Reichstadt wrote: > reading through the spotlight docu I am not sure where to start or if the > following is possible. I am trying to find out if a spotlight importer can be > used to query external data sources. I know the advantage of spotlight is > meant to pre-catalog files in order to quickly return results. But in other > cases where there is data not permanently available I am looking for a way to > only hook into the user entering something into spotlight to additionally > forward the query to another process or even other server or machine. Is this > possible? Not unless they’ve done something major to Spotlight in 10.6 or 10.7. As originally designed it is tightly tied to the filesystem, so the objects it indexes are individual files. Your importer will get called on a specific file, and only when that file changes. —Jens___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Sheet created by NSObjectContoller??
Thanks for the info! I never realized that this is possible with object controllers. But wait a minute: While playing around with this mechanism, it turns out that you have a number formatter installed on the text field for this to work. I realized this when my app crashed after I had removed the number formatter with the max value binding still in place! Removing the number formatter made the min and max bindings as well as the discard?-dialogs disappear obviously. Just tested this with the example project I referred to in my posting "Re: responding to NSStepper clicks" of tonight: Implementing the validateXXX method for your property XXX does not help at all. Sorry for pointing into the wrong direction. I had hoped you might need to overwrite something in your object controller subclass but there seems to be nothing. Here is a very old thread initiated by Matt Neuburg on cocoabuilder on the issue: http://www.cocoabuilder.com/archive/cocoa/73532-who-is-putting-up-this-dialog.html And another posting on the issue: http://www.cocoabuilder.com/archive/cocoa/101845-using-validatevalue-forkey-error-to-limit-slider-range-with-cocoa-bindings.html I couldn't make any of these work though. And that's about all I could find - no answers really. Am 17.12.2011 um 20:17 schrieb Robert Monaghan: > The binding is straight forward.. > > You create an NSObjectController, and set the "Mode" to "Class" and the Class > Name to your object with a bunch of NSNumbers. (prepared with > @property/@synthesize, naturally) > > In my NSTextField, I bind my "value", "Min Value" and "Max Value" to the > NSObjectController, specifying which NSNumbers are to be used for each. > So I have have inside my object a set of NSNumbers called "maxVal" "minVal" > and "currentVal", my NSTextField would reflect those values. > > If minVal is 10, maxValue is 20, and currentValue is 15. Everything is great. > Now type in 500 in the NSTextField, and out pops a sheet! > > I am going to see about validation. Perhaps that is how this is happening. > > bob.. > > > > On Dec 17, 2011, at 11:10 AM, Peter wrote: > >> >> Am 17.12.2011 um 19:59 schrieb Robert Monaghan: >> >>> Hi Everyone, >>> >>> Perhaps someone can help point me in the right direction on this: >>> >>> I have an NSObjectController that maintains a UI for me. >>> I have an NSTextField which contains numerical value. You could type in a >>> number, which populates an NSNumber object deep inside my code.. >>> Magically, my NSObjectController does its thing and maintains the UI. Very >>> cool stuff! >>> >>> I just recently updated my bindings for this NSTextField, so that a a Min >>> and Max Value is respected. >> >> Interesting! How did you do that via bindings? >> >>> As a test, I typed a value which is outside the Min/Max value, to see what >>> I need to implement. To my surprise, a sheet is created saying "The Value >>> 500 is too large." It prompts the user to Discard or Keep Change. >>> Where did this come from? And how do I override this? >> >> Implement a KVC validation method for your property. I guess. >> See >> file:///Library/Developer/Shared/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/Validation.html#//apple_ref/doc/uid/20002173 >> >>> I can't find info in the docs. I do see a vague reference to a "sheet" in >>> the NSObjectController Docs, with add/remove selectors, etc. But nothing >>> concrete. >>> Ideas? >>> >>> Thanks! >>> >>> bob. >>> >>> >>> ___ >>> >>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) >>> >>> Please do not post admin requests or moderator comments to the list. >>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com >>> >>> Help/Unsubscribe/Update your Subscription: >>> http://lists.apple.com/mailman/options/cocoa-dev/magnard%40web.de >>> >>> This email sent to magn...@web.de >>> >> > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > http://lists.apple.com/mailman/options/cocoa-dev/magnard%40web.de > > This email sent to magn...@web.de > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Sheet created by NSObjectContoller??
Oops, missed the number formatter.. You are right.. number formatter is needed for the min/max values to show up. Which makes me thing that this is a mechanism that is a part of the number formatter. Will dig around there. Will post a note if I find anything. bob. On Dec 17, 2011, at 2:43 PM, Peter wrote: > Thanks for the info! > I never realized that this is possible with object controllers. > > But wait a minute: While playing around with this mechanism, it turns out > that you have a number formatter installed on the text field for this to > work. I realized this when my app crashed after I had removed the number > formatter with the max value binding still in place! Removing the number > formatter made the min and max bindings as well as the discard?-dialogs > disappear obviously. > > Just tested this with the example project I referred to in my posting "Re: > responding to NSStepper clicks" of tonight: > Implementing the validateXXX method for your property XXX does not help at > all. > Sorry for pointing into the wrong direction. > I had hoped you might need to overwrite something in your object controller > subclass but there seems to be nothing. > > Here is a very old thread initiated by Matt Neuburg on cocoabuilder on the > issue: > > http://www.cocoabuilder.com/archive/cocoa/73532-who-is-putting-up-this-dialog.html > > And another posting on the issue: > > http://www.cocoabuilder.com/archive/cocoa/101845-using-validatevalue-forkey-error-to-limit-slider-range-with-cocoa-bindings.html > > I couldn't make any of these work though. > > And that's about all I could find - no answers really. > > Am 17.12.2011 um 20:17 schrieb Robert Monaghan: > >> The binding is straight forward.. >> >> You create an NSObjectController, and set the "Mode" to "Class" and the >> Class Name to your object with a bunch of NSNumbers. (prepared with >> @property/@synthesize, naturally) >> >> In my NSTextField, I bind my "value", "Min Value" and "Max Value" to the >> NSObjectController, specifying which NSNumbers are to be used for each. >> So I have have inside my object a set of NSNumbers called "maxVal" "minVal" >> and "currentVal", my NSTextField would reflect those values. >> >> If minVal is 10, maxValue is 20, and currentValue is 15. Everything is >> great. Now type in 500 in the NSTextField, and out pops a sheet! >> >> I am going to see about validation. Perhaps that is how this is happening. >> >> bob.. >> >> >> >> On Dec 17, 2011, at 11:10 AM, Peter wrote: >> >>> >>> Am 17.12.2011 um 19:59 schrieb Robert Monaghan: >>> Hi Everyone, Perhaps someone can help point me in the right direction on this: I have an NSObjectController that maintains a UI for me. I have an NSTextField which contains numerical value. You could type in a number, which populates an NSNumber object deep inside my code.. Magically, my NSObjectController does its thing and maintains the UI. Very cool stuff! I just recently updated my bindings for this NSTextField, so that a a Min and Max Value is respected. >>> >>> Interesting! How did you do that via bindings? >>> As a test, I typed a value which is outside the Min/Max value, to see what I need to implement. To my surprise, a sheet is created saying "The Value 500 is too large." It prompts the user to Discard or Keep Change. Where did this come from? And how do I override this? >>> >>> Implement a KVC validation method for your property. I guess. >>> See >>> file:///Library/Developer/Shared/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/Validation.html#//apple_ref/doc/uid/20002173 >>> I can't find info in the docs. I do see a vague reference to a "sheet" in the NSObjectController Docs, with add/remove selectors, etc. But nothing concrete. Ideas? Thanks! bob. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/magnard%40web.de This email sent to magn...@web.de >>> >> >> ___ >> >> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) >> >> Please do not post admin requests or moderator comments to the list. >> Contact the moderators at cocoa-dev-admins(at)lists.apple.com >> >> Help/Unsubscribe/Update your Subscription: >> http://lists.apple.com/mailman/options/cocoa-dev/magnard%40web.de >> >> This email sent to magn...@web.de >> > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Handling UTIs from a Cocoa protocol
This is how I have my code set up: an Objective-C protocol that has a class function that returns an NSArray of UTIs that it can handle, and a member function that handles the file type: @protocol PcsxrFileHandle + (NSArray *)utisCanHandle; - (BOOL)handleFile:(NSString *)theFile; @end However, as my code is currently set up, the UTIs are used in a few special cases and are not called in determining what UTI opens what file. The code is set up like so: - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename { NSString *utiFile = [[NSWorkspace sharedWorkspace] typeOfFile:filename error:nil]; NSObject *hand = nil; BOOL isHandled = NO; if(UTTypeEqual(CFSTR("com.codeplex.pcsxr.plugin"), (CFStringRef)utiFile)) { hand = [[PcsxrPluginHandler alloc] init]; isHandled = [hand handleFile:filename]; } else if(UTTypeEqual(CFSTR("com.codeplex.pcsxr.memcard"), (CFStringRef)utiFile)) { hand = [[PcsxrMemCardHandler alloc] init]; isHandled = [hand handleFile:filename]; } else if(UTTypeEqual(CFSTR("com.codeplex.pcsxr.freeze"), (CFStringRef)utiFile)) { hand = [[PcsxrFreezeStateHandler alloc] init]; isHandled = [hand handleFile:filename]; } else if(UTTypeEqual(CFSTR("com.alcohol-soft.mdfdisc"), (CFStringRef)utiFile) || UTTypeEqual(CFSTR("com.apple.disk-image-ndif"), (CFStringRef)utiFile) || UTTypeEqual(CFSTR("public.iso-image"), (CFStringRef)utiFile) || UTTypeEqual(CFSTR("com.codeplex.pcsxr.cuefile"), (CFStringRef)utiFile)) { hand = [[PcsxrDiscHandler alloc] init]; isHandled = [hand handleFile:HandleBinCue(filename)]; } if (hand) [hand release]; return isHandled; } The PcsxrPluginHandler, PcsxrMemCardHandler, PcsxrFreezeStateHandler, and PcsxrDiscHandler all implement the PcsxrFileHandle protocol. Is there a way to put classes into some sort of array to go through and check if the UTI of a file matches up to any of the UTIs that the class can handle? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Handling UTIs from a Cocoa protocol
On Dec 17, 2011, at 6:02 PM, C.W. Betts wrote: > Is there a way to put classes into some sort of array to go through and check > if the UTI of a file matches up to any of the UTIs that the class can handle? Classes are objects too, so you can put them in arrays and so on. -- Chris ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Handling UTIs from a Cocoa protocol
On Dec 17, 2011, at 8:02 PM, C.W. Betts wrote: > This is how I have my code set up: an Objective-C protocol that has a class > function that returns an NSArray of UTIs that it can handle, and a member > function that handles the file type: > > @protocol PcsxrFileHandle > > + (NSArray *)utisCanHandle; > - (BOOL)handleFile:(NSString *)theFile; > > @end > > However, as my code is currently set up, the UTIs are used in a few special > cases and are not called in determining what UTI opens what file. The code is > set up like so: > > - (BOOL)application:(NSApplication *)theApplication openFile:(NSString > *)filename > { > NSString *utiFile = [[NSWorkspace sharedWorkspace] typeOfFile:filename > error:nil]; > NSObject *hand = nil; > BOOL isHandled = NO; > if(UTTypeEqual(CFSTR("com.codeplex.pcsxr.plugin"), > (CFStringRef)utiFile)) { > hand = [[PcsxrPluginHandler alloc] init]; > isHandled = [hand handleFile:filename]; > } else if(UTTypeEqual(CFSTR("com.codeplex.pcsxr.memcard"), > (CFStringRef)utiFile)) { > hand = [[PcsxrMemCardHandler alloc] init]; > isHandled = [hand handleFile:filename]; > } else if(UTTypeEqual(CFSTR("com.codeplex.pcsxr.freeze"), > (CFStringRef)utiFile)) { > hand = [[PcsxrFreezeStateHandler alloc] init]; > isHandled = [hand handleFile:filename]; > } else if(UTTypeEqual(CFSTR("com.alcohol-soft.mdfdisc"), > (CFStringRef)utiFile) || UTTypeEqual(CFSTR("com.apple.disk-image-ndif"), > (CFStringRef)utiFile) || UTTypeEqual(CFSTR("public.iso-image"), > (CFStringRef)utiFile) || UTTypeEqual(CFSTR("com.codeplex.pcsxr.cuefile"), > (CFStringRef)utiFile)) { > hand = [[PcsxrDiscHandler alloc] init]; > isHandled = [hand handleFile:HandleBinCue(filename)]; > } > if (hand) [hand release]; > return isHandled; > } > > The PcsxrPluginHandler, PcsxrMemCardHandler, PcsxrFreezeStateHandler, and > PcsxrDiscHandler all implement the PcsxrFileHandle protocol. > Is there a way to put classes into some sort of array to go through and check > if the UTI of a file matches up to any of the UTIs that the class can handle? Chris already answered your main question, but I’d just like to add that it’s probably better to use UTTypeConformsTo() instead of UTTypeEqual() to test UTIs. This way, in the hypothetical case that you encounter a subtype of one of those types, things will still work, whereas with the code above, it won’t. Also, something like ‘supportedTypes’ or ‘supportedUTIs’ would probably be a clearer name than ‘utisCanHandle’. Charles___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Handling UTIs from a Cocoa protocol
On Dec 17, 2011, at 11:13 PM, Charles Srstka wrote: > Chris already answered your main question, but I’d just like to add that it’s > probably better to use UTTypeConformsTo() instead of UTTypeEqual() to test > UTIs. This way, in the hypothetical case that you encounter a subtype of one > of those types, things will still work, whereas with the code above, it won’t. And, since you're already working with NSWorkspace, use -[NSWorkspace type:conformsToType:]. Cheers, Ken ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com