问题标签 [nspasteboard]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
380 浏览

objective-c - 如何将图像从浏览器拖放到 Cocoa 应用程序

我需要将图像从浏览器拖到 mac 应用程序。从 img 标签拖动图像时,它可以正常工作,但是当 img 之间有链接时,它就不起作用了。NSPasteboard 从链接接收 NSURL,而不是从 img 源。拖动反馈显示图像,所以我认为它正在发送图像数据。我从 NSPasteboard 检查了 propertyListForType,它只包含链接 href。

0 投票
2 回答
797 浏览

objective-c - 如何检测粘贴板项目类型

我试图识别三种类型的对象:

  1. 如果是文件的 URL
  2. 如果是目录的 URL
  3. 如果它是一个简单的字符串

到目前为止,我只有这个代码,它不起作用!

现在我尝试获取数组copyedItems 的第一个对象并尝试调用“types”属性,但我遇到了崩溃!

0 投票
2 回答
183 浏览

objective-c - 偷看 NSPasteboard?

是否有一些开发工具或其他开源应用程序允许我们查看(或者更确切地说:任何)NSPasteboard实例的当前内容?

浏览 Xcode 目录(/DeveloperXcode 4 之前的文件夹的内容)并没有找到任何看起来有用的东西。

我们目前正在为我们的应用程序开发复制和粘贴功能,以及一些方便地调试粘贴板中当前内容的方法将是非常宝贵的,并且可以节省大量的开发时间。

0 投票
1 回答
278 浏览

objective-c - 如何从所有类的通用粘贴板上读取数据?

目前我正在使用 readObjectsForClasses: 从可可中的通用粘贴板中检索对象列表,只要我只想检索某个类的对象,例如 NSString 或 NSImage 等,它就可以工作。

但是,我希望能够读取其中的每个对象,而不必创建一个包含所有类的数组,这样返回的数组将包含粘贴板中的每个项目。

这可能吗?

0 投票
1 回答
93 浏览

objective-c - Is this possible to check back which application paste the NSPasteboardItem on the Pasteboard?

I would like to know how can I get this information? I can keep polling, and checking which application is running, and see the pasteboard count at the same time. But I am afraid this way is not 100% accurate. For example, if the user go to app A, and copy things, in the pasteboard, the pasteboard count increase. But the second poll request did not started yet, and the user switch to to app B, then, the poll start, it may mess up the logic. So, any way suggested to find out the NSPasteboard is from which app? Thanks.

0 投票
2 回答
525 浏览

macos - 无法写入一般粘贴板

我有一个自定义 NSView 可以拖动自定义核心数据对象。我通过调用此方法开始拖动过程​​:

在调用上面的方法之前,我抓取通用粘贴板并设置如下标题:

但是在我设置字符串之后,如果我调用:

我什么都得不到。

如果我创建这样的粘贴板:

它确实有效。所以,我试着买另一个标准的粘贴板

但是这个也是,不会让我向它写入数据。

我从 mouseDragged:(NSEvent *)event; 调用这个方法 我的应用程序是沙盒的。有任何想法吗 ?

0 投票
1 回答
1080 浏览

objective-c - NSPasteboard unable to read text when RTF data is copied to the pasteboard

I am using the NSPasteboard to read data off it and perform actions with the received data.

Specifically, I am interested in information of the types listed below in order of priority.

  1. File path
  2. Text data
  3. Image data (this is not copying the image file, but actual parts of the image, for e.g. when you open an image in an editor, make a selection and press command+v)

This is what I have in code

Right now, I am simply testing if I am able to get the required data or not. So When I select some files on the Destkop then files contains the selected file URLs. So that works.

Similarly when I select some parts of an image and copy it to the clipboard then imageData contains some data, which I then write to another file and can see that only the selected potion was copied, so that is OK too. Also, I understand that when I copy an image "file" to the clipboard then too imageData will not be nil, but that is ok because topmost priority goes to file URL and that is the case that will do what needs to be done.

The problem that I have run into is with the lines related to reading text from the pasteboard.

The Problem Descriptio:

  1. I copied the URL of this page and both "text" and "text2" contain the string from the pasteboard. So it good here :)

  2. I copy some lines from a .cs code file opened in TextEdit, the clipboard shows that I have "public.utf8-plain-text" and "NSStringPboardType" but "text" and "text2" are both nil;

  3. From the same C#.NET .cs file, I select a single word, without any breaks for eg. "System.Threading", the clipboard shows that I have "public.utf8-plain-text" and "NSStringPboardType" and both "text" and "text2" have the copied text but any thing copied with spaces or lines will not. "myProject.Core.Helpers" will work but "namespace myProject.Core.Helpers" wont.

  4. Similarly, I copy some text from a RTF file, the clipboard shows that I have a lot of RTF related information along with the same old "public.utf8-plain-text" and "NSStringPboardType" types too, but again "text", "text2" and, this time, "rtfText" are all nil.

So, how do I get the text that I need in all cases from the clipboard? I know that RTF data can contain a lot more then text but I am just concerned with getting the text out in a string file.

Any help will be greatly appreciated.

Thanks!

0 投票
0 回答
133 浏览

objective-c - 使用 NSPasteboard 避免使用大图像

我正在开发一个使用 NSPasteboard 作为媒介的应用程序,以允许用户从其他应用程序中获取图像文件。

有时用户会想要复制一个非常大的图像,这可能会导致主线程非常糟糕,因为粘贴板会阻塞 30MB 文件。

有没有办法设置粘贴板数据大小的限制(超过时会出错)或在不接触数据的情况下获取数据大小的方法?我们不能从粘贴板请求数据大小,因为这样做粘贴板已经需要包含大图像数据(这为时已晚)。

谢谢!

0 投票
0 回答
269 浏览

drag-and-drop - 将 NSDraggingSource 与 NSMatrix 耦合的问题

想象一下这个人口稀少的NSMatrix五个彩色列 (0-4),最近添加的列是橙色的。这些填充有带有 (x,y) 坐标的替代对象(随机数)。“空白”单元格具有替代的 NULL 对象。这有点工作。

在此处输入图像描述

我在顶部有四个数据“源”(AD),我想将它们拖到矩阵上。它们标有代表目标行 (0-3) 的数字。 即使我认为我做得对,我也无法让这些拖动NSDragSource

示例行为:

如果我将单元格 B(带有 0,2)拖到列(4,y)的“中心”区域,它的内容将与两个空单元格(第 0 行和第 2 行)合并。如果我拖到列的左侧或右侧区域,我将得到一个前置或附加列——在这种情况下,是一个稀疏列。

如果我将单元格 A(带有 0,1,2,3)拖到任何单元格上,它将创建一个新列。

如果我将单元格 D 拖到 (0,y) 或 (4,y) 列上,它将合并;将其拖动到其他任何地方将创建新的稀疏列。在任何地方使用 C 执行此操作将创建一个新的稀疏列。

可以推测,这种复杂的合并行为将我带到了这里,而不是说,NSTableView.

我没有太多识别左/中/右区域或合并数据或创建新列的问题——我需要帮助创建正确的NSPasteboard交互和/或NSDragging设置:( 我最终想NSManagedObject在将识别填充哪些行的核心数据,但我从这里开始)。

  1. 我正在尝试制作一个NSStringPboardType附加到四个NSTextFields可拖动的原型。没有骰子。
  2. 我可以从粘贴板上NSMatrix接收字符串(或)。NSFilenamesPboardType那里没问题。

一旦我收到适当的传入单元格(字符串),我就可以浏览它并确定是与当前列合并还是创建一个新列——同样,这不是问题。

我做过的事情...

1) 子类化 NSTextField...

2)注册文本字段的拖动类型并尝试拖动会话...

我的draggingSession:sourceOperationMaskForDraggingContext:方法甚至从未被调用过。

我是这个NSPasteboard东西的新手,所以任何帮助将不胜感激。

0 投票
1 回答
840 浏览

macos - 为什么 -[NSPasteboard readObjectsForClasses:options:] 从拖动中只返回 1 个项目?

我正在向 NSPasteboard 写入一些对象以进行拖动操作beginDraggingSessionWithItems:event:source:

在拖动目的地(在同一个应用程序中),我尝试使用 接收这些项目readObjectsForClasses:options:,但我只收到其中一个。

(请注意,如果您通过@[[NSPasteboardItem class]]了课程,您将获得所有未修改的项目。)

知道为什么会发生这种情况吗?此处提供示例项目(包含大量 NSLogs 以查看项目实际上正在写入粘贴板)。