forked from qt-creator/qt-creator
Core: Use Utils::CommandLine in ExecuteFilter
... using a new CommandLine::fromUserInput convenience function. Change-Id: Ic786530af89ec80f4211e66f36caa22cb705effe Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include "commandline.h"
|
||||
|
||||
#include "environment.h"
|
||||
#include "macroexpander.h"
|
||||
#include "qtcassert.h"
|
||||
#include "stringutils.h"
|
||||
|
||||
@@ -1434,6 +1435,21 @@ CommandLine::CommandLine(const FilePath &exe, const QString &args, RawType)
|
||||
addArgs(args, Raw);
|
||||
}
|
||||
|
||||
CommandLine CommandLine::fromUserInput(const QString &cmdline, MacroExpander *expander)
|
||||
{
|
||||
CommandLine cmd;
|
||||
const int pos = cmdline.indexOf(' ');
|
||||
if (pos == -1) {
|
||||
cmd.m_executable = FilePath::fromString(cmdline);
|
||||
} else {
|
||||
cmd.m_executable = FilePath::fromString(cmdline.left(pos));
|
||||
cmd.m_arguments = cmdline.right(cmdline.length() - pos - 1);
|
||||
if (expander)
|
||||
cmd.m_arguments = expander->expand(cmd.m_arguments);
|
||||
}
|
||||
return cmd;
|
||||
}
|
||||
|
||||
void CommandLine::addArg(const QString &arg)
|
||||
{
|
||||
ProcessArgs::addArg(&m_arguments, arg, m_executable.osType());
|
||||
|
@@ -37,6 +37,7 @@ namespace Utils {
|
||||
class AbstractMacroExpander;
|
||||
class CommandLine;
|
||||
class Environment;
|
||||
class MacroExpander;
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT ProcessArgs
|
||||
{
|
||||
@@ -138,6 +139,8 @@ public:
|
||||
CommandLine(const FilePath &exe, const QStringList &args);
|
||||
CommandLine(const FilePath &exe, const QString &unparsedArgs, RawType);
|
||||
|
||||
static CommandLine fromUserInput(const QString &cmdline, MacroExpander *expander = nullptr);
|
||||
|
||||
void addArg(const QString &arg);
|
||||
void addArgs(const QStringList &inArgs);
|
||||
|
||||
|
@@ -102,15 +102,8 @@ void ExecuteFilter::accept(LocatorFilterEntry selection,
|
||||
workingDirectory = Utils::globalMacroExpander()->value("CurrentDocument:Project:Path", &found);
|
||||
|
||||
ExecuteData d;
|
||||
d.workingDirectory = workingDirectory;
|
||||
const int pos = value.indexOf(' ');
|
||||
if (pos == -1) {
|
||||
d.executable = value;
|
||||
} else {
|
||||
d.executable = value.left(pos);
|
||||
d.arguments = Utils::globalMacroExpander()->expand(
|
||||
value.right(value.length() - pos - 1));
|
||||
}
|
||||
d.command = CommandLine::fromUserInput(value, Utils::globalMacroExpander());
|
||||
d.workingDirectory = FilePath::fromString(workingDirectory);
|
||||
|
||||
if (m_process) {
|
||||
const QString info(tr("Previous command is still running (\"%1\").\nDo you want to kill it?")
|
||||
@@ -166,10 +159,9 @@ void ExecuteFilter::runHeadCommand()
|
||||
{
|
||||
if (!m_taskQueue.isEmpty()) {
|
||||
const ExecuteData &d = m_taskQueue.head();
|
||||
const Utils::FilePath fullPath = Utils::Environment::systemEnvironment().searchInPath(d.executable);
|
||||
if (fullPath.isEmpty()) {
|
||||
if (d.command.executable().isEmpty()) {
|
||||
MessageManager::writeDisrupting(
|
||||
tr("Could not find executable for \"%1\".").arg(d.executable));
|
||||
tr("Could not find executable for \"%1\".").arg(d.command.executable().toUserOutput()));
|
||||
m_taskQueue.dequeue();
|
||||
runHeadCommand();
|
||||
return;
|
||||
@@ -178,7 +170,7 @@ void ExecuteFilter::runHeadCommand()
|
||||
QTC_CHECK(!m_process);
|
||||
createProcess();
|
||||
m_process->setWorkingDirectory(d.workingDirectory);
|
||||
m_process->setCommand({fullPath, d.arguments, Utils::CommandLine::Raw});
|
||||
m_process->setCommand(d.command);
|
||||
m_process->start();
|
||||
if (!m_process->waitForStarted(1000)) {
|
||||
MessageManager::writeFlashing(
|
||||
@@ -221,7 +213,5 @@ QString ExecuteFilter::headCommand() const
|
||||
if (m_taskQueue.isEmpty())
|
||||
return QString();
|
||||
const ExecuteData &data = m_taskQueue.head();
|
||||
if (data.arguments.isEmpty())
|
||||
return data.executable;
|
||||
return data.executable + ' ' + data.arguments;
|
||||
return data.command.toUserOutput();
|
||||
}
|
||||
|
@@ -39,11 +39,11 @@ namespace Internal {
|
||||
class ExecuteFilter : public Core::ILocatorFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
struct ExecuteData
|
||||
{
|
||||
QString executable;
|
||||
QString arguments;
|
||||
QString workingDirectory;
|
||||
Utils::CommandLine command;
|
||||
Utils::FilePath workingDirectory;
|
||||
};
|
||||
|
||||
public:
|
||||
|
Reference in New Issue
Block a user