From 6d9e3c8a8eff0ad2c6b07882a970a69948d67c89 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com>
Date: Fri, 19 Feb 2010 11:25:30 +0100
Subject: [PATCH] Dropping files into the editor shouldn't insert file:///...

On some desktop environments, dragging and dropping a file gives us
the url to the file in multiple mime types, including text/plain. This
causes the url to be inserted as text by default.

Work around this issue by explicitly ignoring drop events for the text
editor when they also come with urls.

Task-number: QTCREATORBUG-728
Reviewed-by: Friedemann Kleint
---
 src/plugins/coreplugin/mainwindow.cpp     |  4 +---
 src/plugins/texteditor/basetexteditor.cpp | 11 +++++++++++
 src/plugins/texteditor/basetexteditor.h   |  2 ++
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp
index 5211236145d..82a076e81e0 100644
--- a/src/plugins/coreplugin/mainwindow.cpp
+++ b/src/plugins/coreplugin/mainwindow.cpp
@@ -101,8 +101,6 @@ extern "C" void handleSigInt(int sig)
 using namespace Core;
 using namespace Core::Internal;
 
-static const char *uriListMimeFormatC = "text/uri-list";
-
 enum { debugMainWindow = 0 };
 
 MainWindow::MainWindow() :
@@ -358,7 +356,7 @@ static bool isDesktopFileManagerDrop(const QMimeData *d, QStringList *files = 0)
     if (files)
         files->clear();
     // Extract dropped files from Mime data.
-    if (!d->hasFormat(QLatin1String(uriListMimeFormatC)))
+    if (!d->hasUrls())
         return false;
     const QList<QUrl> urls = d->urls();
     if (urls.empty())
diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index 3bc8283b1b0..bac82bf82a5 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -3388,6 +3388,17 @@ void BaseTextEditor::keyReleaseEvent(QKeyEvent *e)
     QPlainTextEdit::keyReleaseEvent(e);
 }
 
+void BaseTextEditor::dragEnterEvent(QDragEnterEvent *e)
+{
+    // If the drag event contains URLs, we don't want to insert them as text
+    if (e->mimeData()->hasUrls()) {
+        e->ignore();
+        return;
+    }
+
+    QPlainTextEdit::dragEnterEvent(e);
+}
+
 void BaseTextEditor::extraAreaLeaveEvent(QEvent *)
 {
     // fake missing mouse move event from Qt
diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h
index ba4e9f1003b..e24d73edd26 100644
--- a/src/plugins/texteditor/basetexteditor.h
+++ b/src/plugins/texteditor/basetexteditor.h
@@ -530,6 +530,8 @@ protected:
     void leaveEvent(QEvent *);
     void keyReleaseEvent(QKeyEvent *);
 
+    void dragEnterEvent(QDragEnterEvent *e);
+
 public:
     // Returns true if key triggers an indent.
     virtual bool isElectricCharacter(const QChar &ch) const;
-- 
GitLab