From 06023df8be189278b089f2bab6e80b136aa38f1e Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 14 Jul 2022 10:34:39 +0200 Subject: [PATCH] VcsCommand: Move the class into vcsbaseclient.cpp No need for a separate header. Change-Id: I870ea0d9547829037644d79a286d87d4c77dc4ae Reviewed-by: Orgad Shaneh --- src/plugins/vcsbase/CMakeLists.txt | 1 - src/plugins/vcsbase/vcsbase.qbs | 2 - src/plugins/vcsbase/vcsbaseclient.cpp | 114 +++++++++++++++++++++--- src/plugins/vcsbase/vcscommand.cpp | 120 -------------------------- src/plugins/vcsbase/vcscommand.h | 46 ---------- 5 files changed, 102 insertions(+), 181 deletions(-) delete mode 100644 src/plugins/vcsbase/vcscommand.cpp delete mode 100644 src/plugins/vcsbase/vcscommand.h diff --git a/src/plugins/vcsbase/CMakeLists.txt b/src/plugins/vcsbase/CMakeLists.txt index 1d879a127d4..28eb593f1a8 100644 --- a/src/plugins/vcsbase/CMakeLists.txt +++ b/src/plugins/vcsbase/CMakeLists.txt @@ -25,7 +25,6 @@ add_qtc_plugin(VcsBase vcsbaseeditorconfig.cpp vcsbaseeditorconfig.h vcsbaseplugin.cpp vcsbaseplugin.h vcsbasesubmiteditor.cpp vcsbasesubmiteditor.h - vcscommand.cpp vcscommand.h vcsoutputformatter.cpp vcsoutputformatter.h vcsoutputwindow.cpp vcsoutputwindow.h vcsplugin.cpp vcsplugin.h diff --git a/src/plugins/vcsbase/vcsbase.qbs b/src/plugins/vcsbase/vcsbase.qbs index 0fc0d8c805f..ce857eeba71 100644 --- a/src/plugins/vcsbase/vcsbase.qbs +++ b/src/plugins/vcsbase/vcsbase.qbs @@ -61,8 +61,6 @@ QtcPlugin { "vcsbaseplugin.h", "vcsbasesubmiteditor.cpp", "vcsbasesubmiteditor.h", - "vcscommand.cpp", - "vcscommand.h", "vcsoutputformatter.cpp", "vcsoutputformatter.h", "vcsoutputwindow.cpp", diff --git a/src/plugins/vcsbase/vcsbaseclient.cpp b/src/plugins/vcsbase/vcsbaseclient.cpp index 1c591bf0d7f..ea3e4fabd0f 100644 --- a/src/plugins/vcsbase/vcsbaseclient.cpp +++ b/src/plugins/vcsbase/vcsbaseclient.cpp @@ -24,19 +24,22 @@ ****************************************************************************/ #include "vcsbaseclient.h" -#include "vcscommand.h" #include "vcsbaseclientsettings.h" #include "vcsbaseeditorconfig.h" +#include "vcsplugin.h" #include #include #include #include #include +#include #include +#include #include #include +#include #include #include @@ -44,10 +47,12 @@ #include #include +#include #include #include #include +using namespace Core; using namespace Utils; /*! @@ -61,22 +66,107 @@ using namespace Utils; \sa VcsBase::VcsJobRunner */ -static Core::IEditor *locateEditor(const char *property, const QString &entry) +static IEditor *locateEditor(const char *property, const QString &entry) { - const QList documents = Core::DocumentModel::openedDocuments(); - for (Core::IDocument *document : documents) + const QList documents = DocumentModel::openedDocuments(); + for (IDocument *document : documents) if (document->property(property).toString() == entry) - return Core::DocumentModel::editorsForDocument(document).constFirst(); + return DocumentModel::editorsForDocument(document).constFirst(); return nullptr; } namespace VcsBase { +class VcsCommand : public ShellCommand +{ +public: + VcsCommand(const FilePath &defaultWorkingDirectory, const Environment &environment); + +private: + void addTask(const QFuture &future); + void postRunCommand(const Utils::FilePath &workDirectory); +}; + +VcsCommand::VcsCommand(const FilePath &workingDirectory, const Environment &environment) + : ShellCommand(workingDirectory, environment) +{ + Environment env = environment; + VcsBase::setProcessEnvironment(&env); + setEnvironment(env); + + VcsOutputWindow::setRepository(workingDirectory.toString()); + setDisableUnixTerminal(); + + connect(this, &ShellCommand::started, this, [this] { + if (flags() & ExpectRepoChanges) + GlobalFileChangeBlocker::instance()->forceBlocked(true); + }); + connect(this, &ShellCommand::finished, this, [this] { + if (flags() & ExpectRepoChanges) + GlobalFileChangeBlocker::instance()->forceBlocked(false); + }); + + VcsOutputWindow *outputWindow = VcsOutputWindow::instance(); + connect(this, &ShellCommand::append, outputWindow, [outputWindow](const QString &t) { + outputWindow->append(t); + }); + connect(this, &ShellCommand::appendSilently, outputWindow, &VcsOutputWindow::appendSilently); + connect(this, &ShellCommand::appendError, outputWindow, &VcsOutputWindow::appendError); + connect(this, &ShellCommand::appendCommand, outputWindow, &VcsOutputWindow::appendCommand); + connect(this, &ShellCommand::appendMessage, outputWindow, &VcsOutputWindow::appendMessage); + + connect(this, &ShellCommand::executedAsync, this, &VcsCommand::addTask); + const auto connection = connect(this, &ShellCommand::runCommandFinished, + this, &VcsCommand::postRunCommand); + + connect(ICore::instance(), &ICore::coreAboutToClose, this, [this, connection] { + disconnect(connection); + abort(); + }); +} + +void VcsCommand::addTask(const QFuture &future) +{ + if ((flags() & SuppressCommandLogging)) + return; + + const QString name = displayName(); + const auto id = Id::fromString(name + QLatin1String(".action")); + if (hasProgressParser()) { + ProgressManager::addTask(future, name, id); + } else { + // add a timed tasked based on timeout + // we cannot access the future interface directly, so we need to create a new one + // with the same lifetime + auto fi = new QFutureInterface(); + auto watcher = new QFutureWatcher(); + connect(watcher, &QFutureWatcherBase::finished, [fi, watcher] { + fi->reportFinished(); + delete fi; + watcher->deleteLater(); + }); + watcher->setFuture(future); + ProgressManager::addTimedTask(*fi, name, id, qMax(2, timeoutS() / 5)/*itsmagic*/); + } + + Internal::VcsPlugin::addFuture(future); +} + +void VcsCommand::postRunCommand(const FilePath &workingDirectory) +{ + if (!(flags() & ShellCommand::ExpectRepoChanges)) + return; + // TODO tell the document manager that the directory now received all expected changes + // Core::DocumentManager::unexpectDirectoryChange(d->m_workingDirectory); + VcsManager::emitRepositoryChanged(workingDirectory); +} + + VcsBaseClientImpl::VcsBaseClientImpl(VcsBaseSettings *baseSettings) : m_baseSettings(baseSettings) { - m_baseSettings->readSettings(Core::ICore::settings()); - connect(Core::ICore::instance(), &Core::ICore::saveSettingsRequested, + m_baseSettings->readSettings(ICore::settings()); + connect(ICore::instance(), &ICore::saveSettingsRequested, this, &VcsBaseClientImpl::saveSettings); } @@ -177,7 +267,7 @@ void VcsBaseClientImpl::vcsFullySynchronousExec(QtcProcess &proc, void VcsBaseClientImpl::resetCachedVcsInfo(const FilePath &workingDir) { - Core::VcsManager::resetVersionControlForDirectory(workingDir); + VcsManager::resetVersionControlForDirectory(workingDir); } void VcsBaseClientImpl::annotateRevisionRequested(const FilePath &workingDirectory, @@ -239,16 +329,16 @@ VcsBaseEditorWidget *VcsBaseClientImpl::createVcsEditor(Id kind, QString title, const QString &dynamicPropertyValue) const { VcsBaseEditorWidget *baseEditor = nullptr; - Core::IEditor *outputEditor = locateEditor(registerDynamicProperty, dynamicPropertyValue); + IEditor *outputEditor = locateEditor(registerDynamicProperty, dynamicPropertyValue); const QString progressMsg = tr("Working..."); if (outputEditor) { // Exists already outputEditor->document()->setContents(progressMsg.toUtf8()); baseEditor = VcsBaseEditor::getVcsBaseEditor(outputEditor); QTC_ASSERT(baseEditor, return nullptr); - Core::EditorManager::activateEditor(outputEditor); + EditorManager::activateEditor(outputEditor); } else { - outputEditor = Core::EditorManager::openEditorWithContents(kind, &title, progressMsg.toUtf8()); + outputEditor = EditorManager::openEditorWithContents(kind, &title, progressMsg.toUtf8()); outputEditor->document()->setProperty(registerDynamicProperty, dynamicPropertyValue); baseEditor = VcsBaseEditor::getVcsBaseEditor(outputEditor); QTC_ASSERT(baseEditor, return nullptr); @@ -265,7 +355,7 @@ VcsBaseEditorWidget *VcsBaseClientImpl::createVcsEditor(Id kind, QString title, void VcsBaseClientImpl::saveSettings() { - m_baseSettings->writeSettings(Core::ICore::settings()); + m_baseSettings->writeSettings(ICore::settings()); } VcsBaseClient::VcsBaseClient(VcsBaseSettings *baseSettings) diff --git a/src/plugins/vcsbase/vcscommand.cpp b/src/plugins/vcsbase/vcscommand.cpp deleted file mode 100644 index 5c15c2cc464..00000000000 --- a/src/plugins/vcsbase/vcscommand.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Brian McGillion and Hugues Delorme -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "vcscommand.h" -#include "vcsbaseplugin.h" -#include "vcsoutputwindow.h" -#include "vcsplugin.h" - -#include -#include -#include - -#include -#include -#include - -#include - -using namespace Core; -using namespace Utils; - -namespace VcsBase { - -VcsCommand::VcsCommand(const FilePath &workingDirectory, const Environment &environment) - : ShellCommand(workingDirectory, environment) -{ - Environment env = environment; - VcsBase::setProcessEnvironment(&env); - setEnvironment(env); - - VcsOutputWindow::setRepository(workingDirectory.toString()); - setDisableUnixTerminal(); - - connect(this, &ShellCommand::started, this, [this] { - if (flags() & ExpectRepoChanges) - GlobalFileChangeBlocker::instance()->forceBlocked(true); - }); - connect(this, &ShellCommand::finished, this, [this] { - if (flags() & ExpectRepoChanges) - GlobalFileChangeBlocker::instance()->forceBlocked(false); - }); - - VcsOutputWindow *outputWindow = VcsOutputWindow::instance(); - connect(this, &ShellCommand::append, outputWindow, [outputWindow](const QString &t) { - outputWindow->append(t); - }); - connect(this, &ShellCommand::appendSilently, outputWindow, &VcsOutputWindow::appendSilently); - connect(this, &ShellCommand::appendError, outputWindow, &VcsOutputWindow::appendError); - connect(this, &ShellCommand::appendCommand, outputWindow, &VcsOutputWindow::appendCommand); - connect(this, &ShellCommand::appendMessage, outputWindow, &VcsOutputWindow::appendMessage); - - connect(this, &ShellCommand::executedAsync, this, &VcsCommand::addTask); - const auto connection = connect(this, &ShellCommand::runCommandFinished, - this, &VcsCommand::postRunCommand); - - connect(ICore::instance(), &ICore::coreAboutToClose, this, [this, connection] { - disconnect(connection); - abort(); - }); -} - -void VcsCommand::addTask(const QFuture &future) -{ - if ((flags() & SuppressCommandLogging)) - return; - - const QString name = displayName(); - const auto id = Id::fromString(name + QLatin1String(".action")); - if (hasProgressParser()) { - ProgressManager::addTask(future, name, id); - } else { - // add a timed tasked based on timeout - // we cannot access the future interface directly, so we need to create a new one - // with the same lifetime - auto fi = new QFutureInterface(); - auto watcher = new QFutureWatcher(); - connect(watcher, &QFutureWatcherBase::finished, [fi, watcher] { - fi->reportFinished(); - delete fi; - watcher->deleteLater(); - }); - watcher->setFuture(future); - ProgressManager::addTimedTask(*fi, name, id, qMax(2, timeoutS() / 5)/*itsmagic*/); - } - - Internal::VcsPlugin::addFuture(future); -} - -void VcsCommand::postRunCommand(const FilePath &workingDirectory) -{ - if (!(flags() & ShellCommand::ExpectRepoChanges)) - return; - // TODO tell the document manager that the directory now received all expected changes - // Core::DocumentManager::unexpectDirectoryChange(d->m_workingDirectory); - VcsManager::emitRepositoryChanged(workingDirectory); -} - -} // namespace VcsBase diff --git a/src/plugins/vcsbase/vcscommand.h b/src/plugins/vcsbase/vcscommand.h deleted file mode 100644 index 9c0c6ba05e4..00000000000 --- a/src/plugins/vcsbase/vcscommand.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Brian McGillion and Hugues Delorme -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include - -namespace VcsBase { - -class VcsCommand : public Utils::ShellCommand -{ - Q_OBJECT - -private: - VcsCommand(const Utils::FilePath &defaultWorkingDirectory, - const Utils::Environment &environment); - - void addTask(const QFuture &future); - void postRunCommand(const Utils::FilePath &workDirectory); - - friend class VcsBaseClientImpl; -}; - -} // namespace VcsBase