如何在osx版本10.10和10.11上添加侧边栏图标

时间:2016-06-21 12:48:01

标签: macos sidebar

我想在侧边栏(收藏夹)中添加自定义图标。 我尝试了下一个链接 - https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Finder.html 但我看不出任何变化。 我还尝试添加目标c:

的文件夹
LSSharedFileListRef favoriteList = NULL;
CFStringRef urlStringRef = NULL;
CFURLRef url = NULL;
IconRef icon = NULL;
CFStringRef displayName = NULL;
LSSharedFileListItemRef item = NULL;
favoriteList = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL);
urlStringRef = CFStringCreateWithCString(NULL, (path.toUtf8().data()), kCFStringEncodingUTF8 );
url = CFURLCreateWithFileSystemPath(NULL, urlStringRef , kCFURLPOSIXPathStyle, NULL);
std::string str = "/Users/mac-templates/Package_Insert.icns";
FSPathMakeRef((const UInt8*) str.c_str(), &fsRef, &isDirectory);
RegisterIconRefFromFSRef(NULL, NULL, &fsRef, &icon);
displayName = CFStringCreateWithCString(NULL, FAVORITES_OSX_DISPLAY_NAME, kCFStringEncodingUTF8 );
item = LSSharedFileListInsertItemURL(favoriteList, kLSSharedFileListItemBeforeFirst, displayName, icon, url, NULL, NULL);

运行波纹管代码后,我可以在侧栏中看到新文件夹,但图标是标准文件夹图标。 它意味着命令  kLSSharedFileListItemBeforeFirst'部分工作,它将文件夹添加到侧边栏但没有图标。

有人在边栏上添加了图标吗?

THX

0 个答案:

没有答案