forked from qt-creator/qt-creator
Get rid of OutputProxy in ShellCommand
Before we have used the OutputProxyFactory, which was called in the non-gui thread. The factory, when run, created the connection between the thread and outside world (e.g. VersionControl output window). Instead of setting the factory we provide a set of virtual functions called directly from non-gui threads. We also provide overrides for them in VcsCommand class. Their implementation safely redirects the calls directly to the VcsOutputWindow through the QMetaObject::invokeMethod() with auto connection as a default. Task-number: QTCREATORBUG-25744 Change-Id: I09f2da278003b71095e953a51499a5513cb8f03f Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -42,23 +42,8 @@ VcsCommand::VcsCommand(const QString &workingDirectory, const Environment &envir
|
||||
{
|
||||
VcsOutputWindow::setRepository(workingDirectory);
|
||||
setDisableUnixTerminal();
|
||||
setOutputProxyFactory([this] {
|
||||
auto proxy = new OutputProxy;
|
||||
VcsOutputWindow *outputWindow = VcsOutputWindow::instance();
|
||||
m_outputWindow = VcsOutputWindow::instance();
|
||||
|
||||
connect(proxy, &OutputProxy::append,
|
||||
outputWindow, [](const QString &txt) { VcsOutputWindow::append(txt); });
|
||||
connect(proxy, &OutputProxy::appendSilently,
|
||||
outputWindow, &VcsOutputWindow::appendSilently);
|
||||
connect(proxy, &OutputProxy::appendError,
|
||||
outputWindow, &VcsOutputWindow::appendError);
|
||||
connect(proxy, &OutputProxy::appendCommand,
|
||||
outputWindow, &VcsOutputWindow::appendCommand);
|
||||
connect(proxy, &OutputProxy::appendMessage,
|
||||
outputWindow, &VcsOutputWindow::appendMessage);
|
||||
|
||||
return proxy;
|
||||
});
|
||||
connect(this, &VcsCommand::started, this, [this] {
|
||||
if (flags() & ExpectRepoChanges)
|
||||
Utils::GlobalFileChangeBlocker::instance()->forceBlocked(true);
|
||||
@@ -84,6 +69,41 @@ void VcsCommand::runCommand(SynchronousProcess &proc,
|
||||
emitRepositoryChanged(workingDirectory);
|
||||
}
|
||||
|
||||
void VcsCommand::append(const QString &text)
|
||||
{
|
||||
QMetaObject::invokeMethod(m_outputWindow, [this, text] {
|
||||
m_outputWindow->append(text);
|
||||
});
|
||||
}
|
||||
|
||||
void VcsCommand::appendSilently(const QString &text)
|
||||
{
|
||||
QMetaObject::invokeMethod(m_outputWindow, [this, text] {
|
||||
m_outputWindow->appendSilently(text);
|
||||
});
|
||||
}
|
||||
|
||||
void VcsCommand::appendError(const QString &text)
|
||||
{
|
||||
QMetaObject::invokeMethod(m_outputWindow, [this, text] {
|
||||
m_outputWindow->appendError(text);
|
||||
});
|
||||
}
|
||||
|
||||
void VcsCommand::appendCommand(const QString &workingDirectory, const Utils::CommandLine &command)
|
||||
{
|
||||
QMetaObject::invokeMethod(m_outputWindow, [this, workingDirectory, command] {
|
||||
m_outputWindow->appendCommand(workingDirectory, command);
|
||||
});
|
||||
}
|
||||
|
||||
void VcsCommand::appendMessage(const QString &text)
|
||||
{
|
||||
QMetaObject::invokeMethod(m_outputWindow, [this, text] {
|
||||
m_outputWindow->appendMessage(text);
|
||||
});
|
||||
}
|
||||
|
||||
void VcsCommand::emitRepositoryChanged(const QString &workingDirectory)
|
||||
{
|
||||
if (m_preventRepositoryChanged || !(flags() & VcsCommand::ExpectRepoChanges))
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
|
||||
namespace VcsBase {
|
||||
|
||||
class VcsOutputWindow;
|
||||
|
||||
class VCSBASE_EXPORT VcsCommand : public Core::ShellCommand
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -49,12 +51,20 @@ public:
|
||||
const Utils::CommandLine &command,
|
||||
const QString &workDirectory = {}) override;
|
||||
|
||||
protected:
|
||||
void append(const QString &text) override;
|
||||
void appendSilently(const QString &text) override;
|
||||
void appendError(const QString &text) override;
|
||||
void appendCommand(const QString &workingDirectory, const Utils::CommandLine &command) override;
|
||||
void appendMessage(const QString &text) override;
|
||||
|
||||
private:
|
||||
void emitRepositoryChanged(const QString &workingDirectory);
|
||||
|
||||
void coreAboutToClose() override;
|
||||
|
||||
bool m_preventRepositoryChanged;
|
||||
VcsOutputWindow *m_outputWindow = nullptr;
|
||||
};
|
||||
|
||||
} // namespace VcsBase
|
||||
|
||||
Reference in New Issue
Block a user