对于任何因我所做的挫折而来到这个问题的人,我在这里记录了能够为您的 custom 获取锚点的步骤NSPreferencePane
。
最大的提示来自@geowar:
谷歌 GPGPreferences.searchTerms 字典revealElementForKey 获取一些线索……(AFAIK 这在任何地方都没有记录……)
我第一次来这个问题时忽略了这个评论,第二次我查看GPGPreferences.m
文件时,更具体地说是revealElementForKey
方法,但无法弄清楚函数实际上是如何被调用的。
关键字是searchTerms
。
当我终于找到这篇文章SearchablePreferencePanes时,我才意识到这一点。
脚步:
- 将一个
NSPrefPaneSearchParameters
键添加到Info.plist
您的首选项窗格捆绑包中,其值类似于MyPreferencePane
.
- 创建一个
MyPreferencePane.searchTerms
在您的 Xcode 项目中调用的文件。该文件的内容应该是一个属性列表,其中包含一个类似于下面的字典(取自Sound
首选项窗格)。这不仅允许用户在搜索指定术语时获得您的首选项窗格的命中,而且还将为首选项窗格生成锚点。
revealElementForKey(key: String)
在您的类中实现继承自NSPreferencePane
. 当用户在搜索术语后打开窗格时以及在调用reveal()
ScriptingBridge 锚类的方法时都会调用此方法。
- 繁荣!
享受生活。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>effects</key>
<dict>
<key>localizableStrings</key>
<array>
<dict>
<key>comments</key>
<string>Localizable index words</string>
<key>index</key>
<string>noises, audio, hear, level, volume, louder, softer, quieter, increase, decrease, raise, lower, speaker, beep, warning, bell, ding, ring, hearing, beeping, dinging, ringing</string>
<key>title</key>
<string>Alerts and sound effects</string>
</dict>
<dict>
<key>comments</key>
<string>Localizable index words</string>
<key>index</key>
<string>audio, hear, level, volume, louder, softer, quieter, increase, decrease, raise, lower, music, speakers, hearing</string>
<key>title</key>
<string>Sound volume</string>
</dict>
<dict>
<key>comments</key>
<string>Localizable index words</string>
<key>index</key>
<string>audio, hear, level, volume, louder, softer, quieter, increase, decrease, raise, lower, quiet, silent, silence, turn off, hearing, muting</string>
<key>title</key>
<string>Mute the sound</string>
</dict>
<dict>
<key>comments</key>
<string>Localizable index words</string>
<key>index</key>
<string>menubar</string>
<key>title</key>
<string>Show volume in menu bar</string>
</dict>
</array>
</dict>
<key>input</key>
<dict>
<key>localizableStrings</key>
<array>
<dict>
<key>comments</key>
<string>Localizable index words</string>
<key>index</key>
<string>audio, hear, level, volume, louder, softer, quieter, increase, decrease, raise, lower, devices, sources, microphones, instruments, MIDI, record, line in, hearing, recording</string>
<key>title</key>
<string>Sound input</string>
</dict>
</array>
</dict>
<key>output</key>
<dict>
<key>localizableStrings</key>
<array>
<dict>
<key>comments</key>
<string>Localizable index words</string>
<key>index</key>
<string>devices, headphones, headsets, speakers, hear, balance, hearing, head phones, head sets</string>
<key>title</key>
<string>Sound output</string>
</dict>
<dict>
<key>comments</key>
<string>Localizable index words</string>
<key>index</key>
<string>airplay, speakers</string>
<key>title</key>
<string>AirPlay audio streaming</string>
</dict>
</array>
</dict>
</dict>
</plist>