diff options
author | hjk <hjk@qt.io> | 2023-02-07 18:02:53 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2023-02-08 07:34:30 +0000 |
commit | 432d918329d873e4b89b07670312e63d4121ba99 (patch) | |
tree | b300349e615114a9c7e4490e8e109d99bfa7f327 /src | |
parent | 012a2a6cd828188837a1d9d2b060e8718c7e2775 (diff) |
TextEditor: Use FilePath in Command
Change-Id: I0916204eefb49713f241dd43da662f258f8c99f7
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/beautifier/artisticstyle/artisticstyle.cpp | 2 | ||||
-rw-r--r-- | src/plugins/beautifier/clangformat/clangformat.cpp | 2 | ||||
-rw-r--r-- | src/plugins/beautifier/uncrustify/uncrustify.cpp | 2 | ||||
-rw-r--r-- | src/plugins/cmakeprojectmanager/cmakeformatter.cpp | 6 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljseditorplugin.cpp | 2 | ||||
-rw-r--r-- | src/plugins/texteditor/command.cpp | 4 | ||||
-rw-r--r-- | src/plugins/texteditor/command.h | 9 | ||||
-rw-r--r-- | src/plugins/texteditor/formattexteditor.cpp | 12 |
8 files changed, 19 insertions, 20 deletions
diff --git a/src/plugins/beautifier/artisticstyle/artisticstyle.cpp b/src/plugins/beautifier/artisticstyle/artisticstyle.cpp index a27b73bfff..610f636d74 100644 --- a/src/plugins/beautifier/artisticstyle/artisticstyle.cpp +++ b/src/plugins/beautifier/artisticstyle/artisticstyle.cpp @@ -124,7 +124,7 @@ bool ArtisticStyle::isApplicable(const Core::IDocument *document) const Command ArtisticStyle::command(const QString &cfgFile) const { Command command; - command.setExecutable(m_settings.command().toString()); + command.setExecutable(m_settings.command()); command.addOption("-q"); command.addOption("--options=" + cfgFile); diff --git a/src/plugins/beautifier/clangformat/clangformat.cpp b/src/plugins/beautifier/clangformat/clangformat.cpp index f97fb515af..c1833a77f1 100644 --- a/src/plugins/beautifier/clangformat/clangformat.cpp +++ b/src/plugins/beautifier/clangformat/clangformat.cpp @@ -187,7 +187,7 @@ void ClangFormat::disableFormattingSelectedText() Command ClangFormat::command() const { Command command; - command.setExecutable(m_settings.command().toString()); + command.setExecutable(m_settings.command()); command.setProcessing(Command::PipeProcessing); if (m_settings.usePredefinedStyle()) { diff --git a/src/plugins/beautifier/uncrustify/uncrustify.cpp b/src/plugins/beautifier/uncrustify/uncrustify.cpp index 1ce90fbeff..2e6f6d67d5 100644 --- a/src/plugins/beautifier/uncrustify/uncrustify.cpp +++ b/src/plugins/beautifier/uncrustify/uncrustify.cpp @@ -159,7 +159,7 @@ bool Uncrustify::isApplicable(const Core::IDocument *document) const Command Uncrustify::command(const QString &cfgFile, bool fragment) const { Command command; - command.setExecutable(m_settings.command().toString()); + command.setExecutable(m_settings.command()); command.setProcessing(Command::PipeProcessing); if (m_settings.version() >= QVersionNumber(0, 62)) { command.addOption("--assume"); diff --git a/src/plugins/cmakeprojectmanager/cmakeformatter.cpp b/src/plugins/cmakeprojectmanager/cmakeformatter.cpp index 0b330a5dda..17fbb65fbb 100644 --- a/src/plugins/cmakeprojectmanager/cmakeformatter.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeformatter.cpp @@ -13,15 +13,15 @@ #include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/ieditor.h> #include <coreplugin/idocument.h> + #include <projectexplorer/project.h> #include <projectexplorer/projectnodes.h> #include <projectexplorer/projecttree.h> + #include <texteditor/formattexteditor.h> #include <texteditor/texteditor.h> -#include <utils/fileutils.h> #include <QAction> -#include <QMenu> #include <QVersionNumber> using namespace TextEditor; @@ -43,7 +43,7 @@ void CMakeFormatter::formatFile() Command CMakeFormatter::command() const { Command command; - command.setExecutable(CMakeFormatterSettings::instance()->command().toString()); + command.setExecutable(CMakeFormatterSettings::instance()->command()); command.setProcessing(Command::FileProcessing); command.addOption("--in-place"); command.addOption("%file"); diff --git a/src/plugins/qmljseditor/qmljseditorplugin.cpp b/src/plugins/qmljseditor/qmljseditorplugin.cpp index 84f303ec18..884670c4fa 100644 --- a/src/plugins/qmljseditor/qmljseditorplugin.cpp +++ b/src/plugins/qmljseditor/qmljseditorplugin.cpp @@ -244,7 +244,7 @@ void QmlJSEditorPluginPrivate::reformatFile() QmlJsEditingSettings::get().formatCommandOptions()); const CommandLine commandLine(exe, args, CommandLine::Raw); TextEditor::Command command; - command.setExecutable(commandLine.executable().toString()); + command.setExecutable(commandLine.executable()); command.setProcessing(TextEditor::Command::FileProcessing); command.addOptions(commandLine.splitArguments()); command.addOption("--inplace"); diff --git a/src/plugins/texteditor/command.cpp b/src/plugins/texteditor/command.cpp index 6da71ccfff..ca5cdfb02d 100644 --- a/src/plugins/texteditor/command.cpp +++ b/src/plugins/texteditor/command.cpp @@ -10,12 +10,12 @@ bool Command::isValid() const return !m_executable.isEmpty(); } -QString Command::executable() const +Utils::FilePath Command::executable() const { return m_executable; } -void Command::setExecutable(const QString &executable) +void Command::setExecutable(const Utils::FilePath &executable) { m_executable = executable; } diff --git a/src/plugins/texteditor/command.h b/src/plugins/texteditor/command.h index 5196fc72e1..7efe32788a 100644 --- a/src/plugins/texteditor/command.h +++ b/src/plugins/texteditor/command.h @@ -5,8 +5,7 @@ #include "texteditor_global.h" -#include <QString> -#include <QStringList> +#include <utils/filepath.h> namespace TextEditor { @@ -20,8 +19,8 @@ public: bool isValid() const; - QString executable() const; - void setExecutable(const QString &executable); + Utils::FilePath executable() const; + void setExecutable(const Utils::FilePath &executable); QStringList options() const; void addOption(const QString &option); @@ -37,7 +36,7 @@ public: void setReturnsCRLF(bool returnsCRLF); private: - QString m_executable; + Utils::FilePath m_executable; QStringList m_options; Processing m_processing = FileProcessing; bool m_pipeAddsNewline = false; diff --git a/src/plugins/texteditor/formattexteditor.cpp b/src/plugins/texteditor/formattexteditor.cpp index 5265cc0288..8f2fc35844 100644 --- a/src/plugins/texteditor/formattexteditor.cpp +++ b/src/plugins/texteditor/formattexteditor.cpp @@ -43,7 +43,7 @@ static FormatTask format(FormatTask task) task.error.clear(); task.formattedData.clear(); - const QString executable = task.command.executable(); + const FilePath executable = task.command.executable(); if (executable.isEmpty()) return task; @@ -66,7 +66,7 @@ static FormatTask format(FormatTask task) options.replaceInStrings(QLatin1String("%file"), sourceFile.filePath().toString()); QtcProcess process; process.setTimeoutS(5); - process.setCommand({FilePath::fromString(executable), options}); + process.setCommand({executable, options}); process.runBlocking(); if (process.result() != ProcessResult::FinishedWithSuccess) { task.error = Tr::tr("TextEditor", "Failed to format: %1.") @@ -75,7 +75,7 @@ static FormatTask format(FormatTask task) } const QString output = process.cleanedStdErr(); if (!output.isEmpty()) - task.error = executable + QLatin1String(": ") + output; + task.error = executable.toUserOutput() + ": " + output; // Read text back Utils::FileReader reader; @@ -93,18 +93,18 @@ static FormatTask format(FormatTask task) QStringList options = task.command.options(); options.replaceInStrings("%filename", task.filePath.fileName()); options.replaceInStrings("%file", task.filePath.toString()); - process.setCommand({FilePath::fromString(executable), options}); + process.setCommand({executable, options}); process.setWriteData(task.sourceData.toUtf8()); process.start(); if (!process.waitForFinished(5000)) { task.error = Tr::tr("Cannot call %1 or some other error occurred. Timeout " "reached while formatting file %2.") - .arg(executable, task.filePath.displayName()); + .arg(executable.toUserOutput(), task.filePath.displayName()); return task; } const QString errorText = process.readAllStandardError(); if (!errorText.isEmpty()) { - task.error = QString::fromLatin1("%1: %2").arg(executable, errorText); + task.error = QString("%1: %2").arg(executable.toUserOutput(), errorText); return task; } |