From 1daa0aa79c210e99dadba1ccd9c020b1a493d73c Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 5 Mar 2019 10:20:50 +0100 Subject: [PATCH] improve Copy&Paste handling in Python console --- src/Gui/PythonConsole.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Gui/PythonConsole.cpp b/src/Gui/PythonConsole.cpp index d478474747..5a95e64ab9 100644 --- a/src/Gui/PythonConsole.cpp +++ b/src/Gui/PythonConsole.cpp @@ -1027,29 +1027,34 @@ void PythonConsole::insertFromMimeData (const QMimeData * source) return; // First check on urls instead of text otherwise it may happen that a url // is handled as text + bool existingFile = false; if (source->hasUrls()) { QList uri = source->urls(); for (QList::ConstIterator it = uri.begin(); it != uri.end(); ++it) { // get the file name and check the extension QFileInfo info((*it).toLocalFile()); QString ext = info.suffix().toLower(); - if (info.exists() && info.isFile() && - (ext == QLatin1String("py") || ext == QLatin1String("fcmacro"))) { - // load the file and read-in the source code - QFile file(info.absoluteFilePath()); - if (file.open(QIODevice::ReadOnly)) { - QTextStream str(&file); - runSourceFromMimeData(str.readAll()); + if (info.exists()) { + existingFile = true; + if (info.isFile() && (ext == QLatin1String("py") || ext == QLatin1String("fcmacro"))) { + // load the file and read-in the source code + QFile file(info.absoluteFilePath()); + if (file.open(QIODevice::ReadOnly)) { + QTextStream str(&file); + runSourceFromMimeData(str.readAll()); + } + file.close(); } - file.close(); } } - - return; } - if (source->hasText()) { + + // Some applications copy text into the clipboard with the formats + // 'text/plain' and 'text/uri-list'. In case the url is not an existing + // file we can handle it as normal text, then. See forum thread: + // https://forum.freecadweb.org/viewtopic.php?f=3&t=34618 + if (source->hasText() && !existingFile) { runSourceFromMimeData(source->text()); - return; } }