问题
I'm adding an NSPredicateEditor to my app to allow the user to seach for specific files and categories of files.
The default NSPredicateEditor template from Inteface Builder adds a control containing only "name", "address", and "sign" categories. I'm looking for more specific categories.
I know that I can add menu items to these menus in Interface Builder, but I would greatly prefer not to maintain a list myself of all of the various categories and values for file searches.
In Finder, a great variety of categories and values can be added to searches.
Using saving this search then using "Get Info" on the saved seach folder reveals the predicate used to generate the Finder's NSPredicateEditor:
((** = "this*"cdw) &&
(kMDItemContentTypeTree = "public.png"cd) &&
InRange(kMDItemLastUsedDate,$time.today(-2d),$time.today(+1d)) &&
InRange(kMDItemContentModificationDate,$time.today(-4d),$time.today(+1d)) &&
InRange(kMDItemContentCreationDate,$time.today(-8d),$time.today(+1d)) &&
(kMDItemDisplayName = "*screenshot*"cd) && (kMDItemTextContent = "content*"cdw))
Clicking the "Other" category type brings up a menu with a wide variety of even more specific categories.
My question is if this same complicated and customized NSPredicateEditor from Finder be added "for free" to my app? Or will I need to declare and then maintain a list of all of the search types my app supports?
回答1:
My question is if this same complicated and customized NSPredicateEditor from Finder be added "for free" to my app?
No, this NSRuleEditor
is part of the app Finder.
Yes, with a few extra's. A similar editor is in the Open/Save File panel.
回答2:
A little late, but you should look at MDSchema.h. MDSchemaCopyAllAttributes will return the entire supported Spotlight schema, MDSchemaCopyDisplayNameForAttribute will return the display name for the list, and MDSchemaCopyDisplayDescriptionForAttribute will return the value types for each item in the schema. From this you can build your own NSRuleEditor. NSPredicateEditor would be harder, since you are getting a lot of behavior built in that you then have to override, but probably still possible.
来源:https://stackoverflow.com/questions/40311255/using-nspredicateeditor-is-there-a-way-to-get-all-of-the-finder-search-categori