diff --git a/src/plugins/texteditor/formattexteditor.cpp b/src/plugins/texteditor/formattexteditor.cpp index 392af456c92..9594d0d4f33 100644 --- a/src/plugins/texteditor/formattexteditor.cpp +++ b/src/plugins/texteditor/formattexteditor.cpp @@ -16,7 +16,6 @@ #include #include -#include #include #include #include @@ -50,10 +49,9 @@ static FormatTask format(FormatTask task) switch (task.command.processing()) { case Command::FileProcessing: { // Save text to temporary file - const QFileInfo fi(task.filePath); Utils::TempFileSaver sourceFile(Utils::TemporaryDirectory::masterDirectoryPath() + "/qtc_beautifier_XXXXXXXX." - + fi.suffix()); + + task.filePath.suffix()); sourceFile.setAutoRemove(true); sourceFile.write(task.sourceData.toUtf8()); if (!sourceFile.finalize()) { @@ -93,8 +91,8 @@ static FormatTask format(FormatTask task) case Command::PipeProcessing: { QtcProcess process; QStringList options = task.command.options(); - options.replaceInStrings("%filename", QFileInfo(task.filePath).fileName()); - options.replaceInStrings("%file", task.filePath); + options.replaceInStrings("%filename", task.filePath.fileName()); + options.replaceInStrings("%file", task.filePath.toString()); process.setCommand({FilePath::fromString(executable), options}); process.setWriteData(task.sourceData.toUtf8()); process.start(); @@ -102,7 +100,7 @@ static FormatTask format(FormatTask task) task.error = QString(QT_TRANSLATE_NOOP("TextEditor", "Cannot call %1 or some other error occurred. Timeout " "reached while formatting file %2.")) - .arg(executable, task.filePath); + .arg(executable, task.filePath.displayName()); return task; } const QByteArray errorText = process.readAllStandardError(); @@ -271,14 +269,14 @@ static void checkAndApplyTask(const FormatTask &task) if (task.formattedData.isEmpty()) { showError(QString(QT_TRANSLATE_NOOP("TextEditor", "Could not format file %1.")).arg( - task.filePath)); + task.filePath.displayName())); return; } QPlainTextEdit *textEditor = task.editor; if (!textEditor) { showError(QString(QT_TRANSLATE_NOOP("TextEditor", "File %1 was closed.")).arg( - task.filePath)); + task.filePath.displayName())); return; } @@ -304,7 +302,7 @@ void formatEditor(TextEditorWidget *editor, const Command &command, int startPos const QString sd = sourceData(editor, startPos, endPos); if (sd.isEmpty()) return; - checkAndApplyTask(format(FormatTask(editor, editor->textDocument()->filePath().toString(), sd, + checkAndApplyTask(format(FormatTask(editor, editor->textDocument()->filePath(), sd, command, startPos, endPos))); } @@ -329,7 +327,7 @@ void formatEditorAsync(TextEditorWidget *editor, const Command &command, int sta checkAndApplyTask(watcher->result()); watcher->deleteLater(); }); - watcher->setFuture(Utils::runAsync(&format, FormatTask(editor, doc->filePath().toString(), sd, + watcher->setFuture(Utils::runAsync(&format, FormatTask(editor, doc->filePath(), sd, command, startPos, endPos))); } diff --git a/src/plugins/texteditor/formattexteditor.h b/src/plugins/texteditor/formattexteditor.h index 6df1db45321..fc974ee9dba 100644 --- a/src/plugins/texteditor/formattexteditor.h +++ b/src/plugins/texteditor/formattexteditor.h @@ -7,6 +7,8 @@ #include "command.h" +#include + #include #include @@ -17,17 +19,18 @@ class TextEditorWidget; class TEXTEDITOR_EXPORT FormatTask { public: - FormatTask(QPlainTextEdit *_editor, const QString &_filePath, const QString &_sourceData, + FormatTask(QPlainTextEdit *_editor, const Utils::FilePath &_filePath, const QString &_sourceData, const Command &_command, int _startPos = -1, int _endPos = 0) : editor(_editor), filePath(_filePath), sourceData(_sourceData), command(_command), startPos(_startPos), - endPos(_endPos) {} + endPos(_endPos) + {} QPointer editor; - QString filePath; + Utils::FilePath filePath; QString sourceData; TextEditor::Command command; int startPos = -1;