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};
|
||||
m_process->setCommand(cmd);
|
||||
m_process->setEnvironment(m_resolvedEnvironment);
|
||||
MessageManager::writeWithTime(tr("Starting external tool \"%1\"")
|
||||
.arg(cmd.toUserOutput()), MessageManager::Silent);
|
||||
MessageManager::writeDisrupting(tr("Starting external tool \"%1\"").arg(cmd.toUserOutput()));
|
||||
m_process->start();
|
||||
}
|
||||
|
||||
@@ -687,8 +686,7 @@ void ExternalToolRunner::finished(int exitCode, QProcess::ExitStatus status)
|
||||
}
|
||||
if (m_tool->modifiesCurrentDocument())
|
||||
DocumentManager::unexpectFileChange(m_expectedFileName);
|
||||
MessageManager::writeWithTime(tr("\"%1\" finished")
|
||||
.arg(m_resolvedExecutable.toUserOutput()), MessageManager::Silent);
|
||||
MessageManager::writeFlashing(tr("\"%1\" finished").arg(m_resolvedExecutable.toUserOutput()));
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
@@ -705,10 +703,12 @@ void ExternalToolRunner::readStandardOutput()
|
||||
{
|
||||
if (m_tool->outputHandling() == ExternalTool::Ignore)
|
||||
return;
|
||||
QByteArray data = m_process->readAllStandardOutput();
|
||||
QString output = m_outputCodec->toUnicode(data.constData(), data.length(), &m_outputCodecState);
|
||||
const QByteArray data = m_process->readAllStandardOutput();
|
||||
const QString output = m_outputCodec->toUnicode(data.constData(),
|
||||
data.length(),
|
||||
&m_outputCodecState);
|
||||
if (m_tool->outputHandling() == ExternalTool::ShowInPane)
|
||||
MessageManager::write(output);
|
||||
MessageManager::writeSilently(output);
|
||||
else if (m_tool->outputHandling() == ExternalTool::ReplaceSelection)
|
||||
m_processOutput.append(output);
|
||||
}
|
||||
@@ -717,10 +717,12 @@ void ExternalToolRunner::readStandardError()
|
||||
{
|
||||
if (m_tool->errorHandling() == ExternalTool::Ignore)
|
||||
return;
|
||||
QByteArray data = m_process->readAllStandardError();
|
||||
QString output = m_outputCodec->toUnicode(data.constData(), data.length(), &m_errorCodecState);
|
||||
const QByteArray data = m_process->readAllStandardError();
|
||||
const QString output = m_outputCodec->toUnicode(data.constData(),
|
||||
data.length(),
|
||||
&m_errorCodecState);
|
||||
if (m_tool->errorHandling() == ExternalTool::ShowInPane)
|
||||
MessageManager::write(output);
|
||||
MessageManager::writeSilently(output);
|
||||
else if (m_tool->errorHandling() == ExternalTool::ReplaceSelection)
|
||||
m_processOutput.append(output);
|
||||
}
|
||||
|
@@ -231,7 +231,7 @@ void ExternalToolManager::setToolsByCategory(const QMap<QString, QList<ExternalT
|
||||
connect(action, &QAction::triggered, tool, [tool] {
|
||||
auto runner = new ExternalToolRunner(tool);
|
||||
if (runner->hasError())
|
||||
MessageManager::write(runner->errorString());
|
||||
MessageManager::writeFlashing(runner->errorString());
|
||||
});
|
||||
|
||||
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
|
||||
continue;
|
||||
if (!file.remove()) {
|
||||
MessageManager::write(QCoreApplication::translate(
|
||||
"Core::Internal",
|
||||
"Failed to remove file \"%1\")1.").
|
||||
arg(fp.toUserOutput()), MessageManager::ModeSwitch);
|
||||
MessageManager::writeDisrupting(
|
||||
QCoreApplication::translate("Core::Internal", "Failed to remove file \"%1\")1.")
|
||||
.arg(fp.toUserOutput()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -226,8 +225,8 @@ bool FileUtils::renameFile(const QString &orgFilePath, const QString &newFilePat
|
||||
QFileInfo fi(orgFilePath);
|
||||
bool headerUpdateSuccess = updateHeaderFileGuardAfterRename(newFilePath, fi.baseName());
|
||||
if (!headerUpdateSuccess) {
|
||||
Core::MessageManager::write(QCoreApplication::translate(
|
||||
"Core::FileUtils",
|
||||
Core::MessageManager::writeDisrupting(
|
||||
QCoreApplication::translate("Core::FileUtils",
|
||||
"Failed to rename the include guard in file \"%1\".")
|
||||
.arg(newFilePath));
|
||||
}
|
||||
|
@@ -134,7 +134,7 @@ void ExecuteFilter::finished(int exitCode, QProcess::ExitStatus status)
|
||||
message = tr("Command \"%1\" finished.").arg(commandName);
|
||||
else
|
||||
message = tr("Command \"%1\" failed.").arg(commandName);
|
||||
MessageManager::writeWithTime(message);
|
||||
MessageManager::writeFlashing(message);
|
||||
|
||||
m_taskQueue.dequeue();
|
||||
if (!m_taskQueue.isEmpty())
|
||||
@@ -143,17 +143,17 @@ void ExecuteFilter::finished(int exitCode, QProcess::ExitStatus status)
|
||||
|
||||
void ExecuteFilter::readStandardOutput()
|
||||
{
|
||||
QByteArray data = m_process->readAllStandardOutput();
|
||||
MessageManager::write(QTextCodec::codecForLocale()->toUnicode(data.constData(), data.size(),
|
||||
&m_stdoutState));
|
||||
const QByteArray data = m_process->readAllStandardOutput();
|
||||
MessageManager::writeSilently(
|
||||
QTextCodec::codecForLocale()->toUnicode(data.constData(), data.size(), &m_stdoutState));
|
||||
}
|
||||
|
||||
void ExecuteFilter::readStandardError()
|
||||
{
|
||||
static QTextCodec::ConverterState state;
|
||||
QByteArray data = m_process->readAllStandardError();
|
||||
MessageManager::write(QTextCodec::codecForLocale()->toUnicode(data.constData(), data.size(),
|
||||
&m_stderrState));
|
||||
MessageManager::writeSilently(
|
||||
QTextCodec::codecForLocale()->toUnicode(data.constData(), data.size(), &m_stderrState));
|
||||
}
|
||||
|
||||
void ExecuteFilter::runHeadCommand()
|
||||
@@ -162,18 +162,20 @@ void ExecuteFilter::runHeadCommand()
|
||||
const ExecuteData &d = m_taskQueue.head();
|
||||
const Utils::FilePath fullPath = Utils::Environment::systemEnvironment().searchInPath(d.executable);
|
||||
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();
|
||||
runHeadCommand();
|
||||
return;
|
||||
}
|
||||
MessageManager::writeWithTime(tr("Starting command \"%1\".").arg(headCommand()));
|
||||
MessageManager::writeDisrupting(tr("Starting command \"%1\".").arg(headCommand()));
|
||||
m_process->setWorkingDirectory(d.workingDirectory);
|
||||
m_process->setCommand({fullPath, d.arguments, Utils::CommandLine::Raw});
|
||||
m_process->start();
|
||||
m_process->closeWriteChannel();
|
||||
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();
|
||||
runHeadCommand();
|
||||
}
|
||||
|
@@ -58,7 +58,7 @@ void ExternalToolsFilter::accept(LocatorFilterEntry selection,
|
||||
|
||||
auto runner = new ExternalToolRunner(tool);
|
||||
if (runner->hasError())
|
||||
MessageManager::write(runner->errorString());
|
||||
MessageManager::writeFlashing(runner->errorString());
|
||||
}
|
||||
|
||||
void ExternalToolsFilter::refresh(QFutureInterface<void> &)
|
||||
|
@@ -84,13 +84,18 @@ static bool runPatchHelper(const QByteArray &input, const QString &workingDirect
|
||||
{
|
||||
const QString patch = PatchTool::patchCommand();
|
||||
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;
|
||||
}
|
||||
|
||||
if (!Utils::FilePath::fromString(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;
|
||||
}
|
||||
|
||||
@@ -113,12 +118,16 @@ static bool runPatchHelper(const QByteArray &input, const QString &workingDirect
|
||||
args << QLatin1String("-R");
|
||||
if (withCrlf)
|
||||
args << QLatin1String("--binary");
|
||||
MessageManager::write(QApplication::translate("Core::PatchTool", "Running in %1: %2 %3").
|
||||
arg(QDir::toNativeSeparators(workingDirectory),
|
||||
QDir::toNativeSeparators(patch), args.join(QLatin1Char(' '))));
|
||||
MessageManager::writeDisrupting(
|
||||
QApplication::translate("Core::PatchTool", "Running in %1: %2 %3")
|
||||
.arg(QDir::toNativeSeparators(workingDirectory),
|
||||
QDir::toNativeSeparators(patch),
|
||||
args.join(QLatin1Char(' '))));
|
||||
patchProcess.start(patch, args);
|
||||
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;
|
||||
}
|
||||
patchProcess.write(input);
|
||||
@@ -127,7 +136,9 @@ static bool runPatchHelper(const QByteArray &input, const QString &workingDirect
|
||||
QByteArray stdErr;
|
||||
if (!Utils::SynchronousProcess::readDataFromProcess(patchProcess, 30, &stdOut, &stdErr, true)) {
|
||||
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;
|
||||
|
||||
}
|
||||
@@ -137,18 +148,22 @@ static bool runPatchHelper(const QByteArray &input, const QString &workingDirect
|
||||
crlfInput.replace('\n', "\r\n");
|
||||
return runPatchHelper(crlfInput, workingDirectory, strip, reverse, true);
|
||||
} else {
|
||||
MessageManager::write(QString::fromLocal8Bit(stdOut));
|
||||
MessageManager::writeFlashing(QString::fromLocal8Bit(stdOut));
|
||||
}
|
||||
}
|
||||
if (!stdErr.isEmpty())
|
||||
MessageManager::write(QString::fromLocal8Bit(stdErr));
|
||||
MessageManager::writeFlashing(QString::fromLocal8Bit(stdErr));
|
||||
|
||||
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;
|
||||
}
|
||||
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 true;
|
||||
|
Reference in New Issue
Block a user