forked from qt-creator/qt-creator
Utils: filepathify TextFileFormat
Change-Id: I6a4e2d38b0bbdec661a4a492901d9182a9f2e502 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -198,7 +198,7 @@ bool TextFileFormat::decode(const QByteArray &data, QStringList *target) const
|
||||
|
||||
// Read text file contents to string or stringlist.
|
||||
template <class Target>
|
||||
TextFileFormat::ReadResult readTextFile(const QString &fileName, const QTextCodec *defaultCodec,
|
||||
TextFileFormat::ReadResult readTextFile(const FilePath &filePath, const QTextCodec *defaultCodec,
|
||||
Target *target, TextFileFormat *format, QString *errorString,
|
||||
QByteArray *decodingErrorSampleIn = nullptr)
|
||||
{
|
||||
@@ -208,7 +208,7 @@ TextFileFormat::ReadResult readTextFile(const QString &fileName, const QTextCode
|
||||
QByteArray data;
|
||||
try {
|
||||
FileReader reader;
|
||||
if (!reader.fetch(fileName, errorString))
|
||||
if (!reader.fetch(filePath.toString(), errorString))
|
||||
return TextFileFormat::ReadIOError;
|
||||
data = reader.data();
|
||||
} catch (const std::bad_alloc &) {
|
||||
@@ -236,15 +236,15 @@ TextFileFormat::ReadResult readTextFile(const QString &fileName, const QTextCode
|
||||
*/
|
||||
|
||||
TextFileFormat::ReadResult
|
||||
TextFileFormat::readFile(const QString &fileName, const QTextCodec *defaultCodec,
|
||||
TextFileFormat::readFile(const FilePath &filePath, const QTextCodec *defaultCodec,
|
||||
QStringList *plainTextList, TextFileFormat *format, QString *errorString,
|
||||
QByteArray *decodingErrorSample /* = 0 */)
|
||||
{
|
||||
const TextFileFormat::ReadResult result =
|
||||
readTextFile(fileName, defaultCodec,
|
||||
readTextFile(filePath, defaultCodec,
|
||||
plainTextList, format, errorString, decodingErrorSample);
|
||||
if (debug)
|
||||
qDebug().nospace() << Q_FUNC_INFO << fileName << ' ' << *format
|
||||
qDebug().nospace() << Q_FUNC_INFO << filePath << ' ' << *format
|
||||
<< " returns " << result << '/' << plainTextList->size() << " chunks";
|
||||
return result;
|
||||
}
|
||||
@@ -254,27 +254,27 @@ TextFileFormat::ReadResult
|
||||
*/
|
||||
|
||||
TextFileFormat::ReadResult
|
||||
TextFileFormat::readFile(const QString &fileName, const QTextCodec *defaultCodec,
|
||||
TextFileFormat::readFile(const FilePath &filePath, const QTextCodec *defaultCodec,
|
||||
QString *plainText, TextFileFormat *format, QString *errorString,
|
||||
QByteArray *decodingErrorSample /* = 0 */)
|
||||
{
|
||||
const TextFileFormat::ReadResult result =
|
||||
readTextFile(fileName, defaultCodec,
|
||||
readTextFile(filePath, defaultCodec,
|
||||
plainText, format, errorString, decodingErrorSample);
|
||||
if (debug)
|
||||
qDebug().nospace() << Q_FUNC_INFO << fileName << ' ' << *format
|
||||
qDebug().nospace() << Q_FUNC_INFO << filePath << ' ' << *format
|
||||
<< " returns " << result << '/' << plainText->size() << " characters";
|
||||
return result;
|
||||
}
|
||||
|
||||
TextFileFormat::ReadResult TextFileFormat::readFileUTF8(const QString &fileName,
|
||||
TextFileFormat::ReadResult TextFileFormat::readFileUTF8(const FilePath &filePath,
|
||||
const QTextCodec *defaultCodec,
|
||||
QByteArray *plainText, QString *errorString)
|
||||
{
|
||||
QByteArray data;
|
||||
try {
|
||||
FileReader reader;
|
||||
if (!reader.fetch(fileName, errorString))
|
||||
if (!reader.fetch(filePath.toString(), errorString))
|
||||
return TextFileFormat::ReadIOError;
|
||||
data = reader.data();
|
||||
} catch (const std::bad_alloc &) {
|
||||
@@ -302,7 +302,7 @@ TextFileFormat::ReadResult TextFileFormat::readFileUTF8(const QString &fileName,
|
||||
Writes out a text file.
|
||||
*/
|
||||
|
||||
bool TextFileFormat::writeFile(const QString &fileName, QString plainText, QString *errorString) const
|
||||
bool TextFileFormat::writeFile(const FilePath &filePath, QString plainText, QString *errorString) const
|
||||
{
|
||||
QTC_ASSERT(codec, return false);
|
||||
|
||||
@@ -313,7 +313,7 @@ bool TextFileFormat::writeFile(const QString &fileName, QString plainText, QStri
|
||||
if (lineTerminationMode == CRLFLineTerminator)
|
||||
plainText.replace(QLatin1Char('\n'), QLatin1String("\r\n"));
|
||||
|
||||
FileSaver saver(fileName, fileMode);
|
||||
FileSaver saver(filePath.toString(), fileMode);
|
||||
if (!saver.hasError()) {
|
||||
if (hasUtf8Bom && codec->name() == "UTF-8")
|
||||
saver.write("\xef\xbb\xbf", 3);
|
||||
@@ -321,7 +321,7 @@ bool TextFileFormat::writeFile(const QString &fileName, QString plainText, QStri
|
||||
}
|
||||
const bool ok = saver.finalize(errorString);
|
||||
if (debug)
|
||||
qDebug().nospace() << Q_FUNC_INFO << fileName << ' ' << *this << ' ' << plainText.size()
|
||||
qDebug().nospace() << Q_FUNC_INFO << filePath << ' ' << *this << ' ' << plainText.size()
|
||||
<< " bytes, returns " << ok;
|
||||
return ok;
|
||||
}
|
||||
|
@@ -36,6 +36,8 @@ QT_END_NAMESPACE
|
||||
|
||||
namespace Utils {
|
||||
|
||||
class FilePath;
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT TextFileFormat {
|
||||
public:
|
||||
enum LineTerminationMode
|
||||
@@ -65,16 +67,16 @@ public:
|
||||
bool decode(const QByteArray &data, QString *target) const;
|
||||
bool decode(const QByteArray &data, QStringList *target) const;
|
||||
|
||||
static ReadResult readFile(const QString &fileName, const QTextCodec *defaultCodec,
|
||||
static ReadResult readFile(const FilePath &filePath, const QTextCodec *defaultCodec,
|
||||
QStringList *plainText, TextFileFormat *format, QString *errorString,
|
||||
QByteArray *decodingErrorSample = nullptr);
|
||||
static ReadResult readFile(const QString &fileName, const QTextCodec *defaultCodec,
|
||||
static ReadResult readFile(const FilePath &filePath, const QTextCodec *defaultCodec,
|
||||
QString *plainText, TextFileFormat *format, QString *errorString,
|
||||
QByteArray *decodingErrorSample = nullptr);
|
||||
static ReadResult readFileUTF8(const QString &fileName, const QTextCodec *defaultCodec,
|
||||
static ReadResult readFileUTF8(const FilePath &filePath, const QTextCodec *defaultCodec,
|
||||
QByteArray *plainText, QString *errorString);
|
||||
|
||||
bool writeFile(const QString &fileName, QString plainText, QString *errorString) const;
|
||||
bool writeFile(const FilePath &filePath, QString plainText, QString *errorString) const;
|
||||
|
||||
static QByteArray decodingErrorSample(const QByteArray &data);
|
||||
|
||||
|
@@ -60,8 +60,11 @@ QByteArray CppParser::getFileContent(const QString &filePath) const
|
||||
} else {
|
||||
QString error;
|
||||
const QTextCodec *codec = Core::EditorManager::defaultTextCodec();
|
||||
if (Utils::TextFileFormat::readFileUTF8(filePath, codec, &fileContent, &error)
|
||||
!= Utils::TextFileFormat::ReadSuccess) {
|
||||
if (Utils::TextFileFormat::readFileUTF8(Utils::FilePath::fromString(filePath),
|
||||
codec,
|
||||
&fileContent,
|
||||
&error)
|
||||
!= Utils::TextFileFormat::ReadSuccess) {
|
||||
qDebug() << "Failed to read file" << filePath << ":" << error;
|
||||
}
|
||||
}
|
||||
|
@@ -122,7 +122,9 @@ bool FixitsRefactoringFile::apply()
|
||||
|
||||
QString error;
|
||||
for (auto it = m_documents.begin(); it != m_documents.end(); ++it) {
|
||||
if (!m_textFileFormat.writeFile(it.key(), it.value()->toPlainText(), &error)) {
|
||||
if (!m_textFileFormat.writeFile(FilePath::fromString(it.key()),
|
||||
it.value()->toPlainText(),
|
||||
&error)) {
|
||||
qCDebug(fixitsLog) << "ERROR: Could not write file" << it.key() << ":" << error;
|
||||
return false; // Error writing file
|
||||
}
|
||||
@@ -163,10 +165,12 @@ QTextDocument *FixitsRefactoringFile::document(const QString &filePath) const
|
||||
if (!filePath.isEmpty()) {
|
||||
QString error;
|
||||
QTextCodec *defaultCodec = Core::EditorManager::defaultTextCodec();
|
||||
TextFileFormat::ReadResult result = TextFileFormat::readFile(
|
||||
filePath, defaultCodec,
|
||||
&fileContents, &m_textFileFormat,
|
||||
&error);
|
||||
TextFileFormat::ReadResult result = TextFileFormat::readFile(FilePath::fromString(
|
||||
filePath),
|
||||
defaultCodec,
|
||||
&fileContents,
|
||||
&m_textFileFormat,
|
||||
&error);
|
||||
if (result != TextFileFormat::ReadSuccess) {
|
||||
qCDebug(fixitsLog) << "ERROR: Could not read " << filePath << ":" << error;
|
||||
m_textFileFormat.codec = nullptr;
|
||||
|
@@ -165,7 +165,7 @@ bool GeneratedFile::write(QString *errorMessage) const
|
||||
Utils::TextFileFormat format;
|
||||
format.codec = EditorManager::defaultTextCodec();
|
||||
format.lineTerminationMode = EditorManager::defaultLineEnding();
|
||||
return format.writeFile(m_d->path, contents(), errorMessage);
|
||||
return format.writeFile(Utils::FilePath::fromString(m_d->path), contents(), errorMessage);
|
||||
}
|
||||
|
||||
GeneratedFile::Attributes GeneratedFile::attributes() const
|
||||
|
@@ -110,7 +110,7 @@ bool BaseTextDocument::write(const QString &fileName, const Utils::TextFileForma
|
||||
{
|
||||
if (debug)
|
||||
qDebug() << Q_FUNC_INFO << this << fileName;
|
||||
return format.writeFile(fileName, data, errorMessage);
|
||||
return format.writeFile(Utils::FilePath::fromString(fileName), data, errorMessage);
|
||||
}
|
||||
|
||||
void BaseTextDocument::setSupportsUtf8Bom(bool value)
|
||||
@@ -136,7 +136,7 @@ void BaseTextDocument::setLineTerminationMode(Utils::TextFileFormat::LineTermina
|
||||
BaseTextDocument::ReadResult BaseTextDocument::read(const QString &fileName, QStringList *plainTextList, QString *errorString)
|
||||
{
|
||||
d->m_readResult =
|
||||
Utils::TextFileFormat::readFile(fileName, codec(),
|
||||
Utils::TextFileFormat::readFile(Utils::FilePath::fromString(fileName), codec(),
|
||||
plainTextList, &d->m_format, errorString, &d->m_decodingErrorSample);
|
||||
return d->m_readResult;
|
||||
}
|
||||
@@ -154,7 +154,7 @@ BaseTextDocument::ReadResult BaseTextDocument::read(const QString &fileName, QSt
|
||||
BaseTextDocument::ReadResult BaseTextDocument::read(const QString &fileName, QString *plainText, QString *errorString)
|
||||
{
|
||||
d->m_readResult =
|
||||
Utils::TextFileFormat::readFile(fileName, codec(),
|
||||
Utils::TextFileFormat::readFile(Utils::FilePath::fromString(fileName), codec(),
|
||||
plainText, &d->m_format, errorString, &d->m_decodingErrorSample);
|
||||
return d->m_readResult;
|
||||
}
|
||||
|
@@ -361,8 +361,12 @@ static std::unique_ptr<QTextDocument> getCurrentDocument(const QString &path)
|
||||
QString contents;
|
||||
Utils::TextFileFormat format;
|
||||
QString error;
|
||||
if (Utils::TextFileFormat::readFile(path, defaultCodec, &contents, &format, &error)
|
||||
!= Utils::TextFileFormat::ReadSuccess) {
|
||||
if (Utils::TextFileFormat::readFile(Utils::FilePath::fromString(path),
|
||||
defaultCodec,
|
||||
&contents,
|
||||
&format,
|
||||
&error)
|
||||
!= Utils::TextFileFormat::ReadSuccess) {
|
||||
qWarning() << "Error reading file " << path << " : " << error;
|
||||
return {};
|
||||
}
|
||||
|
@@ -140,7 +140,7 @@ static QByteArray getSource(const Utils::FilePath &fileName,
|
||||
QString error;
|
||||
QTextCodec *defaultCodec = EditorManager::defaultTextCodec();
|
||||
Utils::TextFileFormat::ReadResult result = Utils::TextFileFormat::readFile(
|
||||
fileName.toString(), defaultCodec, &fileContents, &format, &error);
|
||||
fileName, defaultCodec, &fileContents, &format, &error);
|
||||
if (result != Utils::TextFileFormat::ReadSuccess)
|
||||
qWarning() << "Could not read " << fileName << ". Error: " << error;
|
||||
|
||||
|
@@ -220,8 +220,11 @@ bool CppSourceProcessor::getFileContents(const QString &absoluteFilePath,
|
||||
// Get from file
|
||||
*revision = 0;
|
||||
QString error;
|
||||
if (Utils::TextFileFormat::readFileUTF8(absoluteFilePath, m_defaultCodec, contents, &error)
|
||||
!= Utils::TextFileFormat::ReadSuccess) {
|
||||
if (Utils::TextFileFormat::readFileUTF8(Utils::FilePath::fromString(absoluteFilePath),
|
||||
m_defaultCodec,
|
||||
contents,
|
||||
&error)
|
||||
!= Utils::TextFileFormat::ReadSuccess) {
|
||||
qWarning("Error reading file \"%s\": \"%s\".", qPrintable(absoluteFilePath),
|
||||
qPrintable(error));
|
||||
return false;
|
||||
|
@@ -199,7 +199,7 @@ QList<ReloadInput> DiffCurrentFileController::reloadInputList() const
|
||||
QList<ReloadInput> result;
|
||||
|
||||
auto textDocument = qobject_cast<TextEditor::TextDocument *>(
|
||||
DocumentModel::documentForFilePath(Utils::FilePath::fromString(m_fileName)));
|
||||
DocumentModel::documentForFilePath(FilePath::fromString(m_fileName)));
|
||||
|
||||
if (textDocument && textDocument->isModified()) {
|
||||
QString errorString;
|
||||
@@ -207,7 +207,7 @@ QList<ReloadInput> DiffCurrentFileController::reloadInputList() const
|
||||
|
||||
QString leftText;
|
||||
const Utils::TextFileFormat::ReadResult leftResult
|
||||
= Utils::TextFileFormat::readFile(m_fileName, format.codec,
|
||||
= Utils::TextFileFormat::readFile(FilePath::fromString(m_fileName), format.codec,
|
||||
&leftText, &format, &errorString);
|
||||
|
||||
const QString rightText = textDocument->plainText();
|
||||
@@ -262,9 +262,8 @@ QList<ReloadInput> DiffOpenFilesController::reloadInputList() const
|
||||
|
||||
QString leftText;
|
||||
const QString fileName = textDocument->filePath().toString();
|
||||
const Utils::TextFileFormat::ReadResult leftResult
|
||||
= Utils::TextFileFormat::readFile(fileName, format.codec,
|
||||
&leftText, &format, &errorString);
|
||||
const Utils::TextFileFormat::ReadResult leftResult = Utils::TextFileFormat::readFile(
|
||||
FilePath::fromString(fileName), format.codec, &leftText, &format, &errorString);
|
||||
|
||||
const QString rightText = textDocument->plainText();
|
||||
|
||||
@@ -321,9 +320,8 @@ QList<ReloadInput> DiffModifiedFilesController::reloadInputList() const
|
||||
|
||||
QString leftText;
|
||||
const QString fileName = textDocument->filePath().toString();
|
||||
const Utils::TextFileFormat::ReadResult leftResult
|
||||
= Utils::TextFileFormat::readFile(fileName, format.codec,
|
||||
&leftText, &format, &errorString);
|
||||
const Utils::TextFileFormat::ReadResult leftResult = Utils::TextFileFormat::readFile(
|
||||
FilePath::fromString(fileName), format.codec, &leftText, &format, &errorString);
|
||||
|
||||
const QString rightText = textDocument->plainText();
|
||||
|
||||
@@ -378,12 +376,10 @@ QList<ReloadInput> DiffExternalFilesController::reloadInputList() const
|
||||
QString leftText;
|
||||
QString rightText;
|
||||
|
||||
const Utils::TextFileFormat::ReadResult leftResult
|
||||
= Utils::TextFileFormat::readFile(m_leftFileName, format.codec,
|
||||
&leftText, &format, &errorString);
|
||||
const Utils::TextFileFormat::ReadResult rightResult
|
||||
= Utils::TextFileFormat::readFile(m_rightFileName, format.codec,
|
||||
&rightText, &format, &errorString);
|
||||
const Utils::TextFileFormat::ReadResult leftResult = Utils::TextFileFormat::readFile(
|
||||
FilePath::fromString(m_leftFileName), format.codec, &leftText, &format, &errorString);
|
||||
const Utils::TextFileFormat::ReadResult rightResult = Utils::TextFileFormat::readFile(
|
||||
FilePath::fromString(m_rightFileName), format.codec, &rightText, &format, &errorString);
|
||||
|
||||
ReloadInput reloadInput;
|
||||
reloadInput.leftText = leftText;
|
||||
|
@@ -3836,8 +3836,11 @@ IEditor *GitClient::openShowEditor(const QString &workingDirectory, const QStrin
|
||||
if (content.isEmpty())
|
||||
return nullptr;
|
||||
QByteArray fileContent;
|
||||
if (TextFileFormat::readFileUTF8(path, nullptr, &fileContent, nullptr)
|
||||
== TextFileFormat::ReadSuccess) {
|
||||
if (TextFileFormat::readFileUTF8(Utils::FilePath::fromString(path),
|
||||
nullptr,
|
||||
&fileContent,
|
||||
nullptr)
|
||||
== TextFileFormat::ReadSuccess) {
|
||||
if (fileContent == content)
|
||||
return nullptr; // open the file for read/write
|
||||
}
|
||||
|
@@ -146,7 +146,7 @@ QStringList SymbolSupport::getFileContents(const Utils::FilePath &filePath)
|
||||
format.lineTerminationMode = Utils::TextFileFormat::LFLineTerminator;
|
||||
QString error;
|
||||
const QTextCodec *codec = Core::EditorManager::defaultTextCodec();
|
||||
if (Utils::TextFileFormat::readFile(filePath.toString(), codec, &fileContent, &format, &error)
|
||||
if (Utils::TextFileFormat::readFile(filePath, codec, &fileContent, &format, &error)
|
||||
!= Utils::TextFileFormat::ReadSuccess) {
|
||||
qDebug() << "Failed to read file" << filePath << ":" << error;
|
||||
}
|
||||
|
@@ -770,12 +770,12 @@ QPair<ProFile *, QStringList> QmakePriFile::readProFile()
|
||||
QString contents;
|
||||
{
|
||||
QString errorMsg;
|
||||
if (TextFileFormat::readFile(
|
||||
filePath().toString(),
|
||||
Core::EditorManager::defaultTextCodec(),
|
||||
&contents,
|
||||
&m_textFormat,
|
||||
&errorMsg) != TextFileFormat::ReadSuccess) {
|
||||
if (TextFileFormat::readFile(filePath(),
|
||||
Core::EditorManager::defaultTextCodec(),
|
||||
&contents,
|
||||
&m_textFormat,
|
||||
&errorMsg)
|
||||
!= TextFileFormat::ReadSuccess) {
|
||||
QmakeBuildSystem::proFileParseError(errorMsg, filePath());
|
||||
return qMakePair(includeFile, lines);
|
||||
}
|
||||
@@ -932,7 +932,7 @@ void QmakePriFile::save(const QStringList &lines)
|
||||
QTC_ASSERT(m_textFormat.codec, return);
|
||||
FileChangeBlocker changeGuard(filePath().toString());
|
||||
QString errorMsg;
|
||||
if (!m_textFormat.writeFile(filePath().toString(), lines.join('\n'), &errorMsg)) {
|
||||
if (!m_textFormat.writeFile(filePath(), lines.join('\n'), &errorMsg)) {
|
||||
QMessageBox::critical(Core::ICore::dialogParent(), QCoreApplication::translate(
|
||||
"QmakePriFile", "File Error"), errorMsg);
|
||||
}
|
||||
|
@@ -302,7 +302,7 @@ bool DocumentManager::createFile(const QString &filePath, const QString &content
|
||||
textFileFormat.codec = Core::EditorManager::defaultTextCodec();
|
||||
QString errorMessage;
|
||||
|
||||
return textFileFormat.writeFile(filePath, contents, &errorMessage);
|
||||
return textFileFormat.writeFile(Utils::FilePath::fromString(filePath), contents, &errorMessage);
|
||||
}
|
||||
|
||||
void DocumentManager::addFileToVersionControl(const QString &directoryPath, const QString &newFilePath)
|
||||
|
@@ -543,7 +543,7 @@ bool QmlBuildSystem::renameFile(Node * context, const QString &filePath, const Q
|
||||
QString error;
|
||||
Utils::TextFileFormat textFileFormat;
|
||||
const QTextCodec *codec = QTextCodec::codecForName("UTF-8"); // qml files are defined to be utf-8
|
||||
if (Utils::TextFileFormat::readFile(qmlProjectFilePath.toString(), codec, &fileContent, &textFileFormat, &error)
|
||||
if (Utils::TextFileFormat::readFile(qmlProjectFilePath, codec, &fileContent, &textFileFormat, &error)
|
||||
!= Utils::TextFileFormat::ReadSuccess) {
|
||||
qWarning() << "Failed to read file" << qmlProjectFilePath << ":" << error;
|
||||
}
|
||||
@@ -556,7 +556,7 @@ bool QmlBuildSystem::renameFile(Node * context, const QString &filePath, const Q
|
||||
|
||||
fileContent.replace(match.capturedStart(1), match.capturedLength(1), QFileInfo(newFilePath).fileName());
|
||||
|
||||
if (!textFileFormat.writeFile(qmlProjectFilePath.toString(), fileContent, &error))
|
||||
if (!textFileFormat.writeFile(qmlProjectFilePath, fileContent, &error))
|
||||
qWarning() << "Failed to write file" << qmlProjectFilePath << ":" << error;
|
||||
|
||||
refresh(Everything);
|
||||
|
@@ -242,7 +242,9 @@ bool ResourceFile::save()
|
||||
return false;
|
||||
}
|
||||
|
||||
return m_textFileFormat.writeFile(m_file_name, contents(), &m_error_message);
|
||||
return m_textFileFormat.writeFile(Utils::FilePath::fromString(m_file_name),
|
||||
contents(),
|
||||
&m_error_message);
|
||||
}
|
||||
|
||||
void ResourceFile::refresh()
|
||||
|
@@ -98,7 +98,7 @@ bool RefactoringChanges::createFile(const QString &fileName, const QString &cont
|
||||
TextFileFormat format;
|
||||
format.codec = EditorManager::defaultTextCodec();
|
||||
QString error;
|
||||
bool saveOk = format.writeFile(fileName, document->toPlainText(), &error);
|
||||
bool saveOk = format.writeFile(Utils::FilePath::fromString(fileName), document->toPlainText(), &error);
|
||||
delete document;
|
||||
if (!saveOk)
|
||||
return false;
|
||||
@@ -198,10 +198,12 @@ QTextDocument *RefactoringFile::mutableDocument() const
|
||||
if (!m_fileName.isEmpty()) {
|
||||
QString error;
|
||||
QTextCodec *defaultCodec = EditorManager::defaultTextCodec();
|
||||
TextFileFormat::ReadResult result = TextFileFormat::readFile(
|
||||
m_fileName, defaultCodec,
|
||||
&fileContents, &m_textFileFormat,
|
||||
&error);
|
||||
TextFileFormat::ReadResult result = TextFileFormat::readFile(FilePath::fromString(
|
||||
m_fileName),
|
||||
defaultCodec,
|
||||
&fileContents,
|
||||
&m_textFileFormat,
|
||||
&error);
|
||||
if (result != TextFileFormat::ReadSuccess) {
|
||||
qWarning() << "Could not read " << m_fileName << ". Error: " << error;
|
||||
m_textFileFormat.codec = nullptr;
|
||||
@@ -372,7 +374,9 @@ bool RefactoringFile::apply()
|
||||
QString error;
|
||||
// suppress "file has changed" warnings if the file is open in a read-only editor
|
||||
Core::FileChangeBlocker block(m_fileName);
|
||||
if (!m_textFileFormat.writeFile(m_fileName, doc->toPlainText(), &error)) {
|
||||
if (!m_textFileFormat.writeFile(FilePath::fromString(m_fileName),
|
||||
doc->toPlainText(),
|
||||
&error)) {
|
||||
qWarning() << "Could not apply changes to" << m_fileName << ". Error: " << error;
|
||||
result = false;
|
||||
}
|
||||
|
@@ -34,9 +34,10 @@
|
||||
#include "unsavedfile.h"
|
||||
|
||||
#include <clangsupport/sourcerangecontainer.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/textfileformat.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <utf8string.h>
|
||||
|
||||
@@ -487,7 +488,10 @@ UnsavedFile ToolTipInfoCollector::unsavedFile(const Utf8String &filePath) const
|
||||
QString errorString;
|
||||
using namespace Utils;
|
||||
const TextFileFormat::ReadResult readResult
|
||||
= TextFileFormat::readFileUTF8(filePath.toString(), codec, &fileContent, &errorString);
|
||||
= TextFileFormat::readFileUTF8(Utils::FilePath::fromString(filePath),
|
||||
codec,
|
||||
&fileContent,
|
||||
&errorString);
|
||||
if (readResult != TextFileFormat::ReadSuccess) {
|
||||
qWarning() << "Failed to read file" << filePath << ":" << errorString;
|
||||
return UnsavedFile();
|
||||
|
Reference in New Issue
Block a user