| 1081 | } |
| 1082 | |
| 1083 | QString ChangesManager::readFileContent(const QString &filePath) const |
| 1084 | { |
| 1085 | LOG_MESSAGE(QString("Reading current file content: %1").arg(filePath)); |
| 1086 | |
| 1087 | auto editors = Core::EditorManager::visibleEditors(); |
| 1088 | for (auto *editor : editors) { |
| 1089 | if (!editor || !editor->document()) { |
| 1090 | continue; |
| 1091 | } |
| 1092 | |
| 1093 | QString editorPath = editor->document()->filePath().toFSPathString(); |
| 1094 | if (editorPath == filePath) { |
| 1095 | QByteArray contentBytes = editor->document()->contents(); |
| 1096 | QString content = QString::fromUtf8(contentBytes); |
| 1097 | LOG_MESSAGE(QString(" Read from open editor: %1 bytes").arg(content.size())); |
| 1098 | return content; |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | QFile file(filePath); |
| 1103 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
| 1104 | LOG_MESSAGE(QString(" Failed to read file: %1").arg(file.errorString())); |
| 1105 | return QString(); |
| 1106 | } |
| 1107 | |
| 1108 | QString content = QString::fromUtf8(file.readAll()); |
| 1109 | file.close(); |
| 1110 | |
| 1111 | LOG_MESSAGE(QString(" Read from disk: %1 bytes").arg(content.size())); |
| 1112 | return content; |
| 1113 | } |
| 1114 | |
| 1115 | bool ChangesManager::performFileEditWithDiff( |
| 1116 | const QString &filePath, |