* Allow one to paste plain text or urls of text files. */
| 1135 | * Allow one to paste plain text or urls of text files. |
| 1136 | */ |
| 1137 | void PythonConsole::insertFromMimeData(const QMimeData* source) |
| 1138 | { |
| 1139 | if (!source) { |
| 1140 | return; |
| 1141 | } |
| 1142 | // First check on urls instead of text otherwise it may happen that a url |
| 1143 | // is handled as text |
| 1144 | bool existingFile = false; |
| 1145 | if (source->hasUrls()) { |
| 1146 | QList<QUrl> uri = source->urls(); |
| 1147 | for (const auto& it : uri) { |
| 1148 | // get the file name and check the extension |
| 1149 | QFileInfo info(it.toLocalFile()); |
| 1150 | QString ext = info.suffix().toLower(); |
| 1151 | if (info.exists()) { |
| 1152 | existingFile = true; |
| 1153 | if (info.isFile() && (ext == QLatin1String("py") || ext == QLatin1String("fcmacro"))) { |
| 1154 | // load the file and read-in the source code |
| 1155 | QFile file(info.absoluteFilePath()); |
| 1156 | if (file.open(QIODevice::ReadOnly)) { |
| 1157 | QTextStream str(&file); |
| 1158 | runSourceFromMimeData(str.readAll()); |
| 1159 | } |
| 1160 | file.close(); |
| 1161 | } |
| 1162 | } |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | // Some applications copy text into the clipboard with the formats |
| 1167 | // 'text/plain' and 'text/uri-list'. In case the url is not an existing |
| 1168 | // file we can handle it as normal text, then. See forum thread: |
| 1169 | // https://forum.freecad.org/viewtopic.php?f=3&t=34618 |
| 1170 | if (source->hasText() && !existingFile) { |
| 1171 | runSourceFromMimeData(source->text()); |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | QTextCursor PythonConsole::inputBegin() const |
| 1176 | { |