取消过滤 NSPasteboard

发布于 2024-07-05 18:50:46 字数 729 浏览 3 评论 0原文

有没有办法取消对 NSPasteboard 的过滤,以获取源应用程序专门声明的它将提供的内容?

我正在尝试在我的应用程序中序列化粘贴板数据。 当另一个应用程序将 RTF 文件放在粘贴板上,然后我询问可用类型时,我会得到十一种不同风格的 RTF,从原始 RTF 到纯字符串再到 dyn.* 值。

将所有数据保存到 plist 或磁盘上的原始数据通常不是问题,因为它非常小,但是当将任何相当大尺寸的图像放置在粘贴板上时,生成的输出可能比源大数十倍数据(通过过滤提供多种类型的 TIFF 和 PICT 数据)。

如果可能的话,我希望能够保留原始应用程序提供的内容。


约翰,你比我自己或与我一起工作的那位自从恐龙在地球上漫游以来就一直在进行 Mac 编程的绅士要敏锐得多。 我们俩都没有注意到你突出显示的文字……我也不知道为什么。 显然,在这个问题上开始的时间太长了。

虽然我接受你的答案作为正确答案,但它并没有完全回答我原来的问题。 我正在寻找一种方法来识别可以变成其他口味的口味,只需将它们放在粘贴板上并且即可知道提供商最初提供了哪些类型。 虽然遍历类型列表将为我提供提供它们的应用程序的首选顺序,但它不会告诉我可以安全地忽略哪些类型,因为当我稍后重新填充粘贴板时将重新创建它们。

我得出的结论是,没有一个“好的”方法可以做到这一点。 [NSPasteboardclarifiedTypesFromOwner] 会很棒,但它不存在。

Is there a way to unfilter an NSPasteboard for what the source application specifically declared it would provide?

I'm attempting to serialize pasteboard data in my application. When another application places an RTF file on a pasteboard and then I ask for the available types, I get eleven different flavors of said RTF, everything from the original RTF to plain strings to dyn.* values.

Saving off all that data into a plist or raw data on disk isn't usually a problem as it's pretty small, but when an image of any considerable size is placed on the pasteboard, the resulting output can be tens of times larger than the source data (with multiple flavors of TIFF and PICT data being made available via filtering).

I'd like to just be able to save off what the original app made available if possible.


John, you are far more observant than myself or the gentleman I work with who's been doing Mac programming since dinosaurs roamed the earth. Neither of us ever noticed the text you highlighted... and I've not a clue why. Starting too long at the problem, apparently.

And while I accepted your answer as the correct answer, it doesn't exactly answer my original question. What I was looking for was a way to identify flavors that can become other flavors simply by placing them on the pasteboard AND to know which of these types were originally offered by the provider. While walking the types list will get me the preferred order for the application that provided them, it won't tell me which ones I can safely ignore as they'll be recreated when I refill the pasteboard later.

I've come to the conclusion that there isn't a "good" way to do this. [NSPasteboard declaredTypesFromOwner] would be fabulous, but it doesn't exist.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦初启 2024-07-12 18:50:46

-[NSPasteboard types] 将返回剪贴板上数据的所有可用类型,但它应该返回它们 " 按照声明的顺序。"

-[NSPasteboard declareTypes:owner:] 表示 "类型应根据源应用程序的偏好进行排序。"

因此,正确实现的粘贴板所有者应该声明作为第一类型的内容(可能是原始内容)的最丰富的表示; 所以合理的单一表示应该是:

[pb dataForType:[[pb types] objectAtIndex:0]]

-[NSPasteboard types] will return all the available types for the data on the clipboard, but it should return them "in the order they were declared."

The documentation for -[NSPasteboard declareTypes:owner:] says that "the types should be ordered according to the preference of the source application."

A properly implemented pasteboard owner should, therefore, declare the richest representation of the content (probably the original content) as the first type; so a reasonable single representation should be:

[pb dataForType:[[pb types] objectAtIndex:0]]
感悟人生的甜 2024-07-12 18:50:46

您也许可以使用 +[NSPasteboard typesFilterableTo:]。 我正在想象这样的片段:

NSArray *allTypes = [pb types];
NSAssert([allTypes count] > 0, @"expected at least one type");

// We always require the first declared type, as a starting point.
NSMutableSet *requiredTypes = [NSMutableSet setWithObject:[allTypes objectAtIndex:0]];

for (NSUInteger index = 1; index < [allTypes count]; index++) {
    NSString *aType = [allTypes objectAtIndex:index];
    NSSet *filtersFrom = [NSSet setWithArray:[NSPasteboard typesFilterableTo:aType]];

    // If this type can't be re-created with a filter we already use, add it to the
    // set of required types.
    if (![requiredTypes intersectsSet:filtersFrom])
        [requiredTypes addObject:aType];
}

但是,我不确定这在选择好的类型方面有多有效。

You may be able to get some use out of +[NSPasteboard typesFilterableTo:]. I'm picturing a snippet like this:

NSArray *allTypes = [pb types];
NSAssert([allTypes count] > 0, @"expected at least one type");

// We always require the first declared type, as a starting point.
NSMutableSet *requiredTypes = [NSMutableSet setWithObject:[allTypes objectAtIndex:0]];

for (NSUInteger index = 1; index < [allTypes count]; index++) {
    NSString *aType = [allTypes objectAtIndex:index];
    NSSet *filtersFrom = [NSSet setWithArray:[NSPasteboard typesFilterableTo:aType]];

    // If this type can't be re-created with a filter we already use, add it to the
    // set of required types.
    if (![requiredTypes intersectsSet:filtersFrom])
        [requiredTypes addObject:aType];
}

I'm not sure how effective this would be at picking good types, however.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文