forked from qt-creator/qt-creator
Core: Use new MessageManager API
Bring messages pane to front when triggering an external tool or command, write output silently and flash when tool finishes or fails. Also bring pane to front if file renaming or removing fails (this should happen only as a direct consequence of the user choosing this action). Task-number: QTCREATORBUG-24430 Change-Id: Ib47431bd57a9c05bfdbfb03ad4c7cd38bdf3ddd1 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -666,8 +666,7 @@ void ExternalToolRunner::run()
|
|||||||
const CommandLine cmd{m_resolvedExecutable, m_resolvedArguments, CommandLine::Raw};
|
const CommandLine cmd{m_resolvedExecutable, m_resolvedArguments, CommandLine::Raw};
|
||||||
m_process->setCommand(cmd);
|
m_process->setCommand(cmd);
|
||||||
m_process->setEnvironment(m_resolvedEnvironment);
|
m_process->setEnvironment(m_resolvedEnvironment);
|
||||||
MessageManager::writeWithTime(tr("Starting external tool \"%1\"")
|
MessageManager::writeDisrupting(tr("Starting external tool \"%1\"").arg(cmd.toUserOutput()));
|
||||||
.arg(cmd.toUserOutput()), MessageManager::Silent);
|
|
||||||
m_process->start();
|
m_process->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -687,8 +686,7 @@ void ExternalToolRunner::finished(int exitCode, QProcess::ExitStatus status)
|
|||||||
}
|
}
|
||||||
if (m_tool->modifiesCurrentDocument())
|
if (m_tool->modifiesCurrentDocument())
|
||||||
DocumentManager::unexpectFileChange(m_expectedFileName);
|
DocumentManager::unexpectFileChange(m_expectedFileName);
|
||||||
MessageManager::writeWithTime(tr("\"%1\" finished")
|
MessageManager::writeFlashing(tr("\"%1\" finished").arg(m_resolvedExecutable.toUserOutput()));
|
||||||
.arg(m_resolvedExecutable.toUserOutput()), MessageManager::Silent);
|
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -705,10 +703,12 @@ void ExternalToolRunner::readStandardOutput()
|
|||||||
{
|
{
|
||||||
if (m_tool->outputHandling() == ExternalTool::Ignore)
|
if (m_tool->outputHandling() == ExternalTool::Ignore)
|
||||||
return;
|
return;
|
||||||
QByteArray data = m_process->readAllStandardOutput();
|
const QByteArray data = m_process->readAllStandardOutput();
|
||||||
QString output = m_outputCodec->toUnicode(data.constData(), data.length(), &m_outputCodecState);
|
const QString output = m_outputCodec->toUnicode(data.constData(),
|
||||||
|
data.length(),
|
||||||
|
&m_outputCodecState);
|
||||||
if (m_tool->outputHandling() == ExternalTool::ShowInPane)
|
if (m_tool->outputHandling() == ExternalTool::ShowInPane)
|
||||||
MessageManager::write(output);
|
MessageManager::writeSilently(output);
|
||||||
else if (m_tool->outputHandling() == ExternalTool::ReplaceSelection)
|
else if (m_tool->outputHandling() == ExternalTool::ReplaceSelection)
|
||||||
m_processOutput.append(output);
|
m_processOutput.append(output);
|
||||||
}
|
}
|
||||||
@@ -717,10 +717,12 @@ void ExternalToolRunner::readStandardError()
|
|||||||
{
|
{
|
||||||
if (m_tool->errorHandling() == ExternalTool::Ignore)
|
if (m_tool->errorHandling() == ExternalTool::Ignore)
|
||||||
return;
|
return;
|
||||||
QByteArray data = m_process->readAllStandardError();
|
const QByteArray data = m_process->readAllStandardError();
|
||||||
QString output = m_outputCodec->toUnicode(data.constData(), data.length(), &m_errorCodecState);
|
const QString output = m_outputCodec->toUnicode(data.constData(),
|
||||||
|
data.length(),
|
||||||
|
&m_errorCodecState);
|
||||||
if (m_tool->errorHandling() == ExternalTool::ShowInPane)
|
if (m_tool->errorHandling() == ExternalTool::ShowInPane)
|
||||||
MessageManager::write(output);
|
MessageManager::writeSilently(output);
|
||||||
else if (m_tool->errorHandling() == ExternalTool::ReplaceSelection)
|
else if (m_tool->errorHandling() == ExternalTool::ReplaceSelection)
|
||||||
m_processOutput.append(output);
|
m_processOutput.append(output);
|
||||||
}
|
}
|
||||||
|
@@ -231,7 +231,7 @@ void ExternalToolManager::setToolsByCategory(const QMap<QString, QList<ExternalT
|
|||||||
connect(action, &QAction::triggered, tool, [tool] {
|
connect(action, &QAction::triggered, tool, [tool] {
|
||||||
auto runner = new ExternalToolRunner(tool);
|
auto runner = new ExternalToolRunner(tool);
|
||||||
if (runner->hasError())
|
if (runner->hasError())
|
||||||
MessageManager::write(runner->errorString());
|
MessageManager::writeFlashing(runner->errorString());
|
||||||
});
|
});
|
||||||
|
|
||||||
command = ActionManager::registerAction(action, externalToolsPrefix.withSuffix(toolId));
|
command = ActionManager::registerAction(action, externalToolsPrefix.withSuffix(toolId));
|
||||||
|
@@ -187,10 +187,9 @@ void FileUtils::removeFiles(const FilePaths &filePaths, bool deleteFromFS)
|
|||||||
if (!file.exists()) // could have been deleted by vc
|
if (!file.exists()) // could have been deleted by vc
|
||||||
continue;
|
continue;
|
||||||
if (!file.remove()) {
|
if (!file.remove()) {
|
||||||
MessageManager::write(QCoreApplication::translate(
|
MessageManager::writeDisrupting(
|
||||||
"Core::Internal",
|
QCoreApplication::translate("Core::Internal", "Failed to remove file \"%1\")1.")
|
||||||
"Failed to remove file \"%1\")1.").
|
.arg(fp.toUserOutput()));
|
||||||
arg(fp.toUserOutput()), MessageManager::ModeSwitch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -226,8 +225,8 @@ bool FileUtils::renameFile(const QString &orgFilePath, const QString &newFilePat
|
|||||||
QFileInfo fi(orgFilePath);
|
QFileInfo fi(orgFilePath);
|
||||||
bool headerUpdateSuccess = updateHeaderFileGuardAfterRename(newFilePath, fi.baseName());
|
bool headerUpdateSuccess = updateHeaderFileGuardAfterRename(newFilePath, fi.baseName());
|
||||||
if (!headerUpdateSuccess) {
|
if (!headerUpdateSuccess) {
|
||||||
Core::MessageManager::write(QCoreApplication::translate(
|
Core::MessageManager::writeDisrupting(
|
||||||
"Core::FileUtils",
|
QCoreApplication::translate("Core::FileUtils",
|
||||||
"Failed to rename the include guard in file \"%1\".")
|
"Failed to rename the include guard in file \"%1\".")
|
||||||
.arg(newFilePath));
|
.arg(newFilePath));
|
||||||
}
|
}
|
||||||
|
@@ -134,7 +134,7 @@ void ExecuteFilter::finished(int exitCode, QProcess::ExitStatus status)
|
|||||||
message = tr("Command \"%1\" finished.").arg(commandName);
|
message = tr("Command \"%1\" finished.").arg(commandName);
|
||||||
else
|
else
|
||||||
message = tr("Command \"%1\" failed.").arg(commandName);
|
message = tr("Command \"%1\" failed.").arg(commandName);
|
||||||
MessageManager::writeWithTime(message);
|
MessageManager::writeFlashing(message);
|
||||||
|
|
||||||
m_taskQueue.dequeue();
|
m_taskQueue.dequeue();
|
||||||
if (!m_taskQueue.isEmpty())
|
if (!m_taskQueue.isEmpty())
|
||||||
@@ -143,17 +143,17 @@ void ExecuteFilter::finished(int exitCode, QProcess::ExitStatus status)
|
|||||||
|
|
||||||
void ExecuteFilter::readStandardOutput()
|
void ExecuteFilter::readStandardOutput()
|
||||||
{
|
{
|
||||||
QByteArray data = m_process->readAllStandardOutput();
|
const QByteArray data = m_process->readAllStandardOutput();
|
||||||
MessageManager::write(QTextCodec::codecForLocale()->toUnicode(data.constData(), data.size(),
|
MessageManager::writeSilently(
|
||||||
&m_stdoutState));
|
QTextCodec::codecForLocale()->toUnicode(data.constData(), data.size(), &m_stdoutState));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecuteFilter::readStandardError()
|
void ExecuteFilter::readStandardError()
|
||||||
{
|
{
|
||||||
static QTextCodec::ConverterState state;
|
static QTextCodec::ConverterState state;
|
||||||
QByteArray data = m_process->readAllStandardError();
|
QByteArray data = m_process->readAllStandardError();
|
||||||
MessageManager::write(QTextCodec::codecForLocale()->toUnicode(data.constData(), data.size(),
|
MessageManager::writeSilently(
|
||||||
&m_stderrState));
|
QTextCodec::codecForLocale()->toUnicode(data.constData(), data.size(), &m_stderrState));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecuteFilter::runHeadCommand()
|
void ExecuteFilter::runHeadCommand()
|
||||||
@@ -162,18 +162,20 @@ void ExecuteFilter::runHeadCommand()
|
|||||||
const ExecuteData &d = m_taskQueue.head();
|
const ExecuteData &d = m_taskQueue.head();
|
||||||
const Utils::FilePath fullPath = Utils::Environment::systemEnvironment().searchInPath(d.executable);
|
const Utils::FilePath fullPath = Utils::Environment::systemEnvironment().searchInPath(d.executable);
|
||||||
if (fullPath.isEmpty()) {
|
if (fullPath.isEmpty()) {
|
||||||
MessageManager::writeWithTime(tr("Could not find executable for \"%1\".").arg(d.executable));
|
MessageManager::writeDisrupting(
|
||||||
|
tr("Could not find executable for \"%1\".").arg(d.executable));
|
||||||
m_taskQueue.dequeue();
|
m_taskQueue.dequeue();
|
||||||
runHeadCommand();
|
runHeadCommand();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MessageManager::writeWithTime(tr("Starting command \"%1\".").arg(headCommand()));
|
MessageManager::writeDisrupting(tr("Starting command \"%1\".").arg(headCommand()));
|
||||||
m_process->setWorkingDirectory(d.workingDirectory);
|
m_process->setWorkingDirectory(d.workingDirectory);
|
||||||
m_process->setCommand({fullPath, d.arguments, Utils::CommandLine::Raw});
|
m_process->setCommand({fullPath, d.arguments, Utils::CommandLine::Raw});
|
||||||
m_process->start();
|
m_process->start();
|
||||||
m_process->closeWriteChannel();
|
m_process->closeWriteChannel();
|
||||||
if (!m_process->waitForStarted(1000)) {
|
if (!m_process->waitForStarted(1000)) {
|
||||||
MessageManager::writeWithTime(tr("Could not start process: %1.").arg(m_process->errorString()));
|
MessageManager::writeFlashing(
|
||||||
|
tr("Could not start process: %1.").arg(m_process->errorString()));
|
||||||
m_taskQueue.dequeue();
|
m_taskQueue.dequeue();
|
||||||
runHeadCommand();
|
runHeadCommand();
|
||||||
}
|
}
|
||||||
|
@@ -58,7 +58,7 @@ void ExternalToolsFilter::accept(LocatorFilterEntry selection,
|
|||||||
|
|
||||||
auto runner = new ExternalToolRunner(tool);
|
auto runner = new ExternalToolRunner(tool);
|
||||||
if (runner->hasError())
|
if (runner->hasError())
|
||||||
MessageManager::write(runner->errorString());
|
MessageManager::writeFlashing(runner->errorString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExternalToolsFilter::refresh(QFutureInterface<void> &)
|
void ExternalToolsFilter::refresh(QFutureInterface<void> &)
|
||||||
|
@@ -84,13 +84,18 @@ static bool runPatchHelper(const QByteArray &input, const QString &workingDirect
|
|||||||
{
|
{
|
||||||
const QString patch = PatchTool::patchCommand();
|
const QString patch = PatchTool::patchCommand();
|
||||||
if (patch.isEmpty()) {
|
if (patch.isEmpty()) {
|
||||||
MessageManager::write(QApplication::translate("Core::PatchTool", "There is no patch-command configured in the general \"Environment\" settings."));
|
MessageManager::writeDisrupting(QApplication::translate(
|
||||||
|
"Core::PatchTool",
|
||||||
|
"There is no patch-command configured in the general \"Environment\" settings."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Utils::FilePath::fromString(patch).exists()
|
if (!Utils::FilePath::fromString(patch).exists()
|
||||||
&& !Utils::Environment::systemEnvironment().searchInPath(patch).exists()) {
|
&& !Utils::Environment::systemEnvironment().searchInPath(patch).exists()) {
|
||||||
MessageManager::write(QApplication::translate("Core::PatchTool", "The patch-command configured in the general \"Environment\" settings does not exist."));
|
MessageManager::writeDisrupting(
|
||||||
|
QApplication::translate("Core::PatchTool",
|
||||||
|
"The patch-command configured in the general \"Environment\" "
|
||||||
|
"settings does not exist."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,12 +118,16 @@ static bool runPatchHelper(const QByteArray &input, const QString &workingDirect
|
|||||||
args << QLatin1String("-R");
|
args << QLatin1String("-R");
|
||||||
if (withCrlf)
|
if (withCrlf)
|
||||||
args << QLatin1String("--binary");
|
args << QLatin1String("--binary");
|
||||||
MessageManager::write(QApplication::translate("Core::PatchTool", "Running in %1: %2 %3").
|
MessageManager::writeDisrupting(
|
||||||
arg(QDir::toNativeSeparators(workingDirectory),
|
QApplication::translate("Core::PatchTool", "Running in %1: %2 %3")
|
||||||
QDir::toNativeSeparators(patch), args.join(QLatin1Char(' '))));
|
.arg(QDir::toNativeSeparators(workingDirectory),
|
||||||
|
QDir::toNativeSeparators(patch),
|
||||||
|
args.join(QLatin1Char(' '))));
|
||||||
patchProcess.start(patch, args);
|
patchProcess.start(patch, args);
|
||||||
if (!patchProcess.waitForStarted()) {
|
if (!patchProcess.waitForStarted()) {
|
||||||
MessageManager::write(QApplication::translate("Core::PatchTool", "Unable to launch \"%1\": %2").arg(patch, patchProcess.errorString()));
|
MessageManager::writeFlashing(
|
||||||
|
QApplication::translate("Core::PatchTool", "Unable to launch \"%1\": %2")
|
||||||
|
.arg(patch, patchProcess.errorString()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
patchProcess.write(input);
|
patchProcess.write(input);
|
||||||
@@ -127,7 +136,9 @@ static bool runPatchHelper(const QByteArray &input, const QString &workingDirect
|
|||||||
QByteArray stdErr;
|
QByteArray stdErr;
|
||||||
if (!Utils::SynchronousProcess::readDataFromProcess(patchProcess, 30, &stdOut, &stdErr, true)) {
|
if (!Utils::SynchronousProcess::readDataFromProcess(patchProcess, 30, &stdOut, &stdErr, true)) {
|
||||||
Utils::SynchronousProcess::stopProcess(patchProcess);
|
Utils::SynchronousProcess::stopProcess(patchProcess);
|
||||||
MessageManager::write(QApplication::translate("Core::PatchTool", "A timeout occurred running \"%1\"").arg(patch));
|
MessageManager::writeFlashing(
|
||||||
|
QApplication::translate("Core::PatchTool", "A timeout occurred running \"%1\"")
|
||||||
|
.arg(patch));
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -137,18 +148,22 @@ static bool runPatchHelper(const QByteArray &input, const QString &workingDirect
|
|||||||
crlfInput.replace('\n', "\r\n");
|
crlfInput.replace('\n', "\r\n");
|
||||||
return runPatchHelper(crlfInput, workingDirectory, strip, reverse, true);
|
return runPatchHelper(crlfInput, workingDirectory, strip, reverse, true);
|
||||||
} else {
|
} else {
|
||||||
MessageManager::write(QString::fromLocal8Bit(stdOut));
|
MessageManager::writeFlashing(QString::fromLocal8Bit(stdOut));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!stdErr.isEmpty())
|
if (!stdErr.isEmpty())
|
||||||
MessageManager::write(QString::fromLocal8Bit(stdErr));
|
MessageManager::writeFlashing(QString::fromLocal8Bit(stdErr));
|
||||||
|
|
||||||
if (patchProcess.exitStatus() != QProcess::NormalExit) {
|
if (patchProcess.exitStatus() != QProcess::NormalExit) {
|
||||||
MessageManager::write(QApplication::translate("Core::PatchTool", "\"%1\" crashed.").arg(patch));
|
MessageManager::writeFlashing(
|
||||||
|
QApplication::translate("Core::PatchTool", "\"%1\" crashed.").arg(patch));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (patchProcess.exitCode() != 0) {
|
if (patchProcess.exitCode() != 0) {
|
||||||
MessageManager::write(QApplication::translate("Core::PatchTool", "\"%1\" failed (exit code %2).").arg(patch).arg(patchProcess.exitCode()));
|
MessageManager::writeFlashing(
|
||||||
|
QApplication::translate("Core::PatchTool", "\"%1\" failed (exit code %2).")
|
||||||
|
.arg(patch)
|
||||||
|
.arg(patchProcess.exitCode()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user