diff options
author | con <qtc-committer@nokia.com> | 2010-12-09 14:57:22 +0100 |
---|---|---|
committer | con <qtc-committer@nokia.com> | 2011-02-18 17:15:36 +0100 |
commit | 10b6b2936be180001b7618fadf8c69c70c3a2e3e (patch) | |
tree | e6ca456ac8d0cf185834ec94b10863c7543e19d6 /src/plugins/coreplugin | |
parent | 6c69638711e4b5505b637e1926fffda0e0534bd3 (diff) | |
download | qt-creator-10b6b2936be180001b7618fadf8c69c70c3a2e3e.tar.gz |
Make the "sort selection" tool do something.
* Handle <input> tag.
* Pass input to running process.
* Search for executable in path.
* Add "CurrentSelection" variable.
Remaining issue: ReplaceSelection output handling.
Diffstat (limited to 'src/plugins/coreplugin')
-rw-r--r-- | src/plugins/coreplugin/externaltool.cpp | 42 | ||||
-rw-r--r-- | src/plugins/coreplugin/externaltool.h | 4 |
2 files changed, 38 insertions, 8 deletions
diff --git a/src/plugins/coreplugin/externaltool.cpp b/src/plugins/coreplugin/externaltool.cpp index 1a446cbcc1..b6fa8bdbc1 100644 --- a/src/plugins/coreplugin/externaltool.cpp +++ b/src/plugins/coreplugin/externaltool.cpp @@ -38,6 +38,7 @@ #include <coreplugin/messagemanager.h> #include <utils/qtcassert.h> #include <utils/stringutils.h> +#include <utils/environment.h> #include <QtCore/QXmlStreamReader> #include <QtCore/QDir> @@ -60,6 +61,7 @@ namespace { const char * const kExecutable = "executable"; const char * const kPath = "path"; const char * const kArguments = "arguments"; + const char * const kInput = "input"; const char * const kWorkingDirectory = "workingdirectory"; const char * const kXmlLang = "xml:lang"; @@ -120,6 +122,11 @@ QString ExternalTool::arguments() const return m_arguments; } +QString ExternalTool::input() const +{ + return m_input; +} + QString ExternalTool::workingDirectory() const { return m_workingDirectory; @@ -244,6 +251,12 @@ ExternalTool * ExternalTool::createFromXml(const QByteArray &xml, QString *error break; } tool->m_arguments = reader.readElementText(); + } else if (reader.name() == QLatin1String(kInput)) { + if (!tool->m_input.isEmpty()) { + reader.raiseError(QLatin1String("only one <input> element allowed")); + break; + } + tool->m_input = reader.readElementText(); } else if (reader.name() == QLatin1String(kWorkingDirectory)) { if (!tool->m_workingDirectory.isEmpty()) { reader.raiseError(QLatin1String("only one <workingdirectory> element allowed")); @@ -290,14 +303,10 @@ bool ExternalToolRunner::resolve() foreach (const QString &executable, m_tool->executables()) { QString resolved = Utils::expandMacros(executable, Core::VariableManager::instance()->macroExpander()); - QFileInfo info(resolved); - // TODO search in path - if (info.exists() && info.isExecutable()) { - m_resolvedExecutable = resolved; - break; - } + m_resolvedExecutable = + Utils::Environment::systemEnvironment().searchInPath(resolved); } - if (m_resolvedExecutable.isNull()) + if (m_resolvedExecutable.isEmpty()) return false; } { // arguments @@ -306,6 +315,10 @@ bool ExternalToolRunner::resolve() // TODO stupid, do it right m_resolvedArguments = resolved.split(QLatin1Char(' '), QString::SkipEmptyParts); } + { // input + m_resolvedInput = Utils::expandMacros(m_tool->input(), + Core::VariableManager::instance()->macroExpander()); + } { // working directory m_resolvedWorkingDirectory = Utils::expandMacros(m_tool->workingDirectory(), Core::VariableManager::instance()->macroExpander()); @@ -321,17 +334,30 @@ void ExternalToolRunner::run() } m_process = new QProcess; // TODO error handling, finish reporting, reading output, etc + connect(m_process, SIGNAL(started()), this, SLOT(started())); connect(m_process, SIGNAL(finished(int)), this, SLOT(finished())); connect(m_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(error(QProcess::ProcessError))); connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStandardOutput())); connect(m_process, SIGNAL(readyReadStandardError()), this, SLOT(readStandardError())); if (!m_resolvedWorkingDirectory.isEmpty()) m_process->setWorkingDirectory(m_resolvedWorkingDirectory); - m_process->start(m_resolvedExecutable, m_resolvedArguments, QIODevice::ReadOnly); + ICore::instance()->messageManager()->printToOutputPane( + tr("Starting external tool '%1'").arg(m_resolvedExecutable), false); + m_process->start(m_resolvedExecutable, m_resolvedArguments, QIODevice::ReadWrite); +} + +void ExternalToolRunner::started() +{ + if (!m_resolvedInput.isEmpty()) { + m_process->write(m_resolvedInput.toLocal8Bit()); + } + m_process->closeWriteChannel(); } void ExternalToolRunner::finished() { + ICore::instance()->messageManager()->printToOutputPane( + tr("'%1' finished").arg(m_resolvedExecutable), false); // TODO handle the ReplaceSelection and ReloadDocument flags m_process->deleteLater(); deleteLater(); diff --git a/src/plugins/coreplugin/externaltool.h b/src/plugins/coreplugin/externaltool.h index ffb1c8a491..d89fcdd55c 100644 --- a/src/plugins/coreplugin/externaltool.h +++ b/src/plugins/coreplugin/externaltool.h @@ -66,6 +66,7 @@ public: QStringList executables() const; QString arguments() const; + QString input() const; QString workingDirectory() const; static ExternalTool *createFromXml(const QByteArray &xml, QString *errorMessage = 0, const QString &locale = QString()); @@ -78,6 +79,7 @@ private: int m_order; QStringList m_executables; QString m_arguments; + QString m_input; QString m_workingDirectory; OutputHandling m_outputHandling; OutputHandling m_errorHandling; @@ -90,6 +92,7 @@ public: ExternalToolRunner(const ExternalTool *tool); private slots: + void started(); void finished(); void error(QProcess::ProcessError error); void readStandardOutput(); @@ -102,6 +105,7 @@ private: const ExternalTool *m_tool; QString m_resolvedExecutable; QStringList m_resolvedArguments; + QString m_resolvedInput; QString m_resolvedWorkingDirectory; QProcess *m_process; QTextCodec *m_outputCodec; |