简体   繁体   English

是否可以将数据从 gtk 应用程序拖到 Windows 下的其他应用程序? 像文件资源管理器?

[英]Is it possible to drag data from a gtk app to other application under Windows? Like File Explorer?

I'm currently trying to make an application in gtk+3 for managing files.我目前正在尝试在 gtk+3 中创建一个用于管理文件的应用程序。 The goal is to have a file manager that is specialized in my own workflow, since I find Windows File Explorer for example too generic.目标是拥有一个专门用于我自己的工作流程的文件管理器,因为我发现 Windows 文件资源管理器太通用了。

GTK of course supports drag and drop functionality, these are the things already set up and working: GTK 当然支持拖放功能,这些是已经设置和工作的东西:

  • A file listview as drag source, encodes selected files into a file uri list on "drag-get"作为拖动源的文件列表视图,将选定的文件编码为“拖动获取”上的文件 uri 列表
  • A drop target within the same app right next to the file listview for testing purposes.用于测试目的的文件列表视图旁边的同一应用程序中的放置目标。 Prints drag data to std::cout.将拖动数据打印到 std::cout。
  • Dropping from the file listview shows the file-uri's in the output window, so this is OK从文件列表视图中删除显示 output window 中的文件 uri,所以这没关系
  • Dropping from Windows File Explorer shows the file-uri's in the output windows as well!从 Windows 文件资源管理器中删除也会显示 output windows 中的文件 uri! So OK那么好吧

But as the title suggests, dragging from my file listview and dropping into Windows File Explorer or any other application for that matter won't work, the mouse cursor keeps showing a 'blocked' symbol.但正如标题所暗示的,从我的文件列表视图中拖放到 Windows 文件资源管理器或任何其他与此相关的应用程序都不起作用,鼠标 cursor 一直显示“阻止”符号。

I also want to support Linux.我也想支持 Linux。 So I've tried this in a Manjaro vm that runs KDE Plasma.所以我在运行 KDE Plasma 的 Manjaro 虚拟机中尝试了这个。 And dropping into the Dolphin file manager works fine.并且放入 Dolphin 文件管理器工作正常。

On Windows, after some searching, I figured it was a security issue.在 Windows 上,经过一番搜索,我认为这是一个安全问题。 Maybe Windows doesn't allow 'untrusted' apps to drag and drop between other applications.也许 Windows 不允许“不受信任”的应用程序在其他应用程序之间拖放。 But I made a release build, signed it with a trusted self-signed certificate and put my application it in C:\Program Files.但是我做了一个发布版本,使用受信任的自签名证书对其进行签名,并将我的应用程序放在 C:\Program Files 中。 From there I run it, but it still does not work.从那里我运行它,但它仍然不起作用。

This is the code that sets the selection data这是设置选择数据的代码

#define _BYTE   8

static void
drag_data_get_handl
(GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data,
        guint target_type, guint time, gpointer user_data)
{
    const auto* unmarshalledUserdata = static_cast<DragAndDrop::GetDragData_Userdata*>(user_data);

        const gchar *name = gtk_widget_get_name (widget);
        const auto string_data = unmarshalledUserdata == nullptr ? "": unmarshalledUserdata->GetData();

        g_print ("%s: drag_data_get_handl\n", name);
        g_assert (selection_data != NULL);

        g_print (" Sending ");
        switch (target_type)
        {
                /* case TARGET_SOME_OBJECT:
                 * Serialize the object and send as a string of bytes.
                 * Pixbufs, (UTF-8) text, and URIs have their own convenience
                 * setter functions */

        case TARGET_STRING:
                g_print ("string: %s", string_data.c_str());
                gtk_selection_data_set
                (
                        selection_data,
                        gtk_selection_data_get_target(selection_data),
                        _BYTE,
                        (guchar*) string_data.c_str(), //for example file:///C:/Projects/tabspls_build_msvc/TabsPlsMain/TabsPlsMain.sln
                        static_cast<gint>(string_data.size())
                );
                break;

        default:
                /* Default to some a safe target instead of fail. */
                g_assert_not_reached ();
        }

        g_print (".\n");
}

I don't know if this is necessary, but the entire project can be found on github .我不知道这是否有必要,但整个项目可以在 github 上找到 This links to the revision that I am currently writing about.这链接到我目前正在写的修订版。

I've been looking through the gtk sources and docs myself and I think I found the answer.我自己一直在查看 gtk 源和文档,我想我找到了答案。

For starters, the docs state that the OLE2 drag and drop protocol is not implemented.对于初学者, 文档state 未实现 OLE2 拖放协议。 This would be required to drag and drop between applications on Windows.这将需要在 Windows 上的应用程序之间拖放。

So why then can my gtk app receive files but not send them under Windows?那么为什么我的 gtk 应用程序可以接收文件但不能在 Windows 下发送它们? The docs state that the WM_DROPFILES protocol is supported, I can confirm this protocol is chosen by calling gdk_drag_context_get_protocol on the context in my drop receive callback.支持 WM_DROPFILES 协议的文档 state 可以通过在我的 drop 接收回调的上下文中调用gdk_drag_context_get_protocol来确认选择了此协议。

So if I would like to support this in my own app, I would have to use WM_DROPFILES for sending data (I don't think this can be done throught the gtk library).因此,如果我想在自己的应用程序中支持这一点,我将不得不使用 WM_DROPFILES 来发送数据(我认为这不能通过 gtk 库来完成)。 Or I would need to implement my own OLE2 drag and drop separately from gtk.或者我需要从 gtk 单独实现我自己的 OLE2 拖放。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MFC CListCtrl拖动文件到Windows资源管理器 - MFC CListCtrl drag file to Windows Explorer 从我的应用程序的ListView拖放到外部应用程序(例如Windows资源管理器) - Drag and drop from my app's ListView to external apps (such as Windows Explorer) Qt如何防止将项目从应用程序拖放到Windows File Explorer - Qt How to Prevent dropping item FROM application TO Windows File Explorer (Qt或其他)在Windows桌面或explorer.exe上使用协议http或ftp拖放mime类型uri-list的数据 - (Qt or other) drag and drop data of mime-type uri-list with protocole http or ftp on Windows desktop or explorer.exe 从Windows中的其他应用程序GUI中提取数据 - Extract data from other app gui in Windows 是否可以删除Windows下进程打开的文件? - Is it possible to delete a file that is opened by a process under windows? 在Windows Universal App上拖放文件 - Drag and drop a file on Windows Universal App 如何从 Windows 文件资源管理器中选择文件 - How to select a file from windows file explorer Qt应用程序中的Windows资源管理器 - Windows Explorer in Qt Application 是否可以在Windows资源管理器的“属性/详细信息”中显示的文件中添加版本号 - Is it possible to add a version number to a file that will be visible in Properties/Details in windows explorer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM