拖曳放弃在Mac上无法工作 [英] Drag & drop not working on Mac

查看:96
本文介绍了拖曳放弃在Mac上无法工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件从Finder拖到我的SWT应用程序中。在Windows和Ubuntu上,以下代码的作用如下:

I'm trying to make it possible to drag files from the Finder into my SWT application. On Windows and Ubuntu, the following bit of code works:

public class DndTest {

    public static void main(final String[] args) {
        final Display display = new Display();
        final Shell shell = new Shell(display, SWT.DIALOG_TRIM);
        shell.setText("Drag & drop test");
        shell.setSize(200, 200);
        final FormLayout layout = new FormLayout();
        shell.setLayout(layout);
        final Label lbl = new Label(shell, SWT.NORMAL);
        lbl.setAlignment(SWT.CENTER);
        lbl.setText("Drop files here");
        final FormData layoutData = new FormData();
        layoutData.left = new FormAttachment(50, -100);
        layoutData.top = new FormAttachment(50, -15);
        layoutData.right = new FormAttachment(50, 100);
        layoutData.bottom = new FormAttachment(50, 15);
        lbl.setLayoutData(layoutData);

        final DropTarget dt = new DropTarget(shell,
                DND.DROP_DEFAULT | DND.DROP_MOVE);
        final FileTransfer fileTransfer = FileTransfer.getInstance();
        dt.setTransfer(new Transfer[] { fileTransfer });
        dt.addDropListener(new DropTargetAdapter() {
            @Override
            public void drop(final DropTargetEvent event) {
                System.out.println(event);
                String fileList[] = null;
                final FileTransfer ft = FileTransfer.getInstance();
                if (ft.isSupportedType(event.currentDataType)) {
                    fileList = (String[]) event.data;
                }
                for (final String file : fileList) {
                    System.out.println("- " + file);
                }
            }
        });

        shell.open();

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();

    }

}

我的应用程序没有将自己注册为Mac上的放置目标,因为悬停在其上的文件不会给我一个删除光标。

I get the impression that my application is not registering itself as a drop target on Mac, because hovering files over it does not give me a drop cursor.

我正在使用最新的SWT 3.5(我不能使用3.6,因为兼容性我需要坚持Carbon&Java 1.5)。

I'm using the latest SWT 3.5 (I cannot use 3.6 because for compatibility I need to stick with Carbon & Java 1.5).

任何想法这里有什么问题?

Any idea what's wrong here?

编辑:我修改了代码,这是一个完全封闭的例子。它在Windows和Ubuntu上将丢弃的文件名打印到控制台,但在Mac上没有任何操作。

Edit: I revised the code so that it's a fully enclosed example. It prints the dropped filenames to the console on Windows and Ubuntu, but does nothing on Mac.

推荐答案

这是SWT中的一个错误(问题#267381 相关,但可能不是实际问题)

This was a bug in SWT (issue #267381 is related, but might not be the actual issue).

正如Mike L.在一则评论中指出的那样,在SWT 3.7M4中修复了。

As Mike L. pointed out in a comment, it was fixed in SWT 3.7M4.

这篇关于拖曳放弃在Mac上无法工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆