2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2009-12-08 14:30:47 +01:00
|
|
|
|
|
|
|
|
#include "vcsplugin.h"
|
2014-02-24 12:36:47 +01:00
|
|
|
|
2021-03-23 13:57:54 +01:00
|
|
|
#include "commonvcssettings.h"
|
2009-12-08 14:30:47 +01:00
|
|
|
#include "nicknamedialog.h"
|
2022-08-01 18:35:07 +02:00
|
|
|
#include "vcsbaseconstants.h"
|
|
|
|
|
#include "vcsbasesubmiteditor.h"
|
2014-08-26 00:02:47 +02:00
|
|
|
#include "vcsoutputwindow.h"
|
2015-05-05 13:03:43 +02:00
|
|
|
#include "wizard/vcscommandpage.h"
|
2015-01-19 14:42:43 +01:00
|
|
|
#include "wizard/vcsconfigurationpage.h"
|
2015-01-19 15:42:22 +01:00
|
|
|
#include "wizard/vcsjsextension.h"
|
2009-12-08 14:30:47 +01:00
|
|
|
|
2015-08-26 14:39:15 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
2014-02-24 12:36:47 +01:00
|
|
|
#include <coreplugin/iversioncontrol.h>
|
2015-01-19 15:42:22 +01:00
|
|
|
#include <coreplugin/jsexpander.h>
|
2014-02-24 12:36:47 +01:00
|
|
|
#include <coreplugin/vcsmanager.h>
|
2014-10-13 18:49:44 +02:00
|
|
|
|
2015-01-19 14:42:43 +01:00
|
|
|
#include <projectexplorer/jsonwizard/jsonwizardfactory.h>
|
2014-02-24 12:36:47 +01:00
|
|
|
#include <projectexplorer/project.h>
|
2014-11-19 17:58:33 +01:00
|
|
|
#include <projectexplorer/projecttree.h>
|
2009-12-08 14:30:47 +01:00
|
|
|
|
2022-12-12 14:40:56 +01:00
|
|
|
#include <utils/futuresynchronizer.h>
|
2014-10-13 18:49:44 +02:00
|
|
|
#include <utils/macroexpander.h>
|
2022-09-01 09:18:16 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2014-10-13 18:49:44 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
2009-12-08 14:30:47 +01:00
|
|
|
|
2014-06-23 16:57:56 +02:00
|
|
|
using namespace Core;
|
|
|
|
|
using namespace ProjectExplorer;
|
2021-07-29 09:31:09 +02:00
|
|
|
using namespace Utils;
|
2014-06-23 16:57:56 +02:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
namespace VcsBase {
|
2009-12-08 14:30:47 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2018-02-19 14:15:05 +01:00
|
|
|
class VcsPluginPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CommonOptionsPage m_settingsPage;
|
|
|
|
|
QStandardItemModel *m_nickNameModel = nullptr;
|
2022-12-12 14:40:56 +01:00
|
|
|
FutureSynchronizer m_futureSynchronizer;
|
2018-02-19 14:15:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static VcsPlugin *m_instance = nullptr;
|
2009-12-08 14:30:47 +01:00
|
|
|
|
2018-02-19 14:15:05 +01:00
|
|
|
VcsPlugin::VcsPlugin()
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
|
|
|
|
m_instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsPlugin::~VcsPlugin()
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
2022-09-01 09:18:16 +02:00
|
|
|
QTC_ASSERT(d, return);
|
2018-02-19 14:15:05 +01:00
|
|
|
VcsOutputWindow::destroy();
|
|
|
|
|
m_instance = nullptr;
|
2020-01-22 17:29:51 +01:00
|
|
|
delete d;
|
2009-12-08 14:30:47 +01:00
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
bool VcsPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(arguments)
|
2015-02-04 09:32:46 +01:00
|
|
|
Q_UNUSED(errorMessage)
|
2009-12-08 14:30:47 +01:00
|
|
|
|
2018-02-19 14:15:05 +01:00
|
|
|
d = new VcsPluginPrivate;
|
|
|
|
|
|
2015-08-26 14:39:15 +02:00
|
|
|
EditorManager::addCloseEditorListener([this](IEditor *editor) -> bool {
|
|
|
|
|
bool result = true;
|
|
|
|
|
if (auto se = qobject_cast<VcsBaseSubmitEditor *>(editor))
|
|
|
|
|
emit submitEditorAboutToClose(se, &result);
|
|
|
|
|
return result;
|
|
|
|
|
});
|
2009-12-08 14:30:47 +01:00
|
|
|
|
2018-02-19 14:15:05 +01:00
|
|
|
connect(&d->m_settingsPage, &CommonOptionsPage::settingsChanged,
|
2015-03-04 15:51:32 +01:00
|
|
|
this, &VcsPlugin::settingsChanged);
|
2018-02-19 14:15:05 +01:00
|
|
|
connect(&d->m_settingsPage, &CommonOptionsPage::settingsChanged,
|
2015-03-04 15:51:32 +01:00
|
|
|
this, &VcsPlugin::slotSettingsChanged);
|
2009-12-08 14:30:47 +01:00
|
|
|
slotSettingsChanged();
|
2014-02-24 12:36:47 +01:00
|
|
|
|
2015-01-19 14:42:43 +01:00
|
|
|
JsonWizardFactory::registerPageFactory(new Internal::VcsConfigurationPageFactory);
|
2015-05-05 13:03:43 +02:00
|
|
|
JsonWizardFactory::registerPageFactory(new Internal::VcsCommandPageFactory);
|
2015-01-19 14:42:43 +01:00
|
|
|
|
2019-04-16 16:46:36 +02:00
|
|
|
JsExpander::registerGlobalObject<VcsJsExtension>("Vcs");
|
2015-01-19 15:42:22 +01:00
|
|
|
|
2022-07-12 17:23:56 +02:00
|
|
|
MacroExpander *expander = globalMacroExpander();
|
2014-10-13 12:49:05 +02:00
|
|
|
expander->registerVariable(Constants::VAR_VCS_NAME,
|
2014-06-23 16:57:56 +02:00
|
|
|
tr("Name of the version control system in use by the current project."),
|
|
|
|
|
[]() -> QString {
|
2018-09-20 01:32:36 +03:00
|
|
|
IVersionControl *vc = nullptr;
|
2014-11-19 17:58:33 +01:00
|
|
|
if (Project *project = ProjectTree::currentProject())
|
2021-07-30 16:46:27 +02:00
|
|
|
vc = VcsManager::findVersionControlForDirectory(project->projectDirectory());
|
2014-06-23 16:57:56 +02:00
|
|
|
return vc ? vc->displayName() : QString();
|
|
|
|
|
});
|
|
|
|
|
|
2014-10-13 12:49:05 +02:00
|
|
|
expander->registerVariable(Constants::VAR_VCS_TOPIC,
|
2014-06-23 16:57:56 +02:00
|
|
|
tr("The current version control topic (branch or tag) identification of the current project."),
|
|
|
|
|
[]() -> QString {
|
2018-09-20 01:32:36 +03:00
|
|
|
IVersionControl *vc = nullptr;
|
2022-10-04 12:54:55 +02:00
|
|
|
FilePath topLevel;
|
2014-11-19 17:58:33 +01:00
|
|
|
if (Project *project = ProjectTree::currentProject())
|
2021-07-30 16:46:27 +02:00
|
|
|
vc = VcsManager::findVersionControlForDirectory(project->projectDirectory(), &topLevel);
|
2022-10-04 12:54:55 +02:00
|
|
|
return vc ? vc->vcsTopic(topLevel) : QString();
|
2014-06-23 16:57:56 +02:00
|
|
|
});
|
|
|
|
|
|
2014-10-13 12:49:05 +02:00
|
|
|
expander->registerVariable(Constants::VAR_VCS_TOPLEVELPATH,
|
2014-06-23 16:57:56 +02:00
|
|
|
tr("The top level path to the repository the current project is in."),
|
|
|
|
|
[]() -> QString {
|
2014-11-19 17:58:33 +01:00
|
|
|
if (Project *project = ProjectTree::currentProject())
|
2021-07-30 16:46:27 +02:00
|
|
|
return VcsManager::findTopLevelForDirectory(project->projectDirectory()).toString();
|
2014-07-02 22:52:53 +03:00
|
|
|
return QString();
|
2014-06-23 16:57:56 +02:00
|
|
|
});
|
2014-02-24 12:36:47 +01:00
|
|
|
|
2018-03-06 12:44:09 +10:00
|
|
|
// Just touch VCS Output Pane before initialization
|
|
|
|
|
VcsOutputWindow::instance();
|
|
|
|
|
|
2009-12-08 14:30:47 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsPlugin *VcsPlugin::instance()
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-23 13:57:54 +01:00
|
|
|
CommonVcsSettings &VcsPlugin::settings() const
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
2018-02-19 14:15:05 +01:00
|
|
|
return d->m_settingsPage.settings();
|
2009-12-08 14:30:47 +01:00
|
|
|
}
|
|
|
|
|
|
2022-12-12 14:40:56 +01:00
|
|
|
FutureSynchronizer *VcsPlugin::futureSynchronizer()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_instance, return nullptr);
|
|
|
|
|
return &m_instance->d->m_futureSynchronizer;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-08 14:30:47 +01:00
|
|
|
/* Delayed creation/update of the nick name model. */
|
2012-01-07 12:31:48 +01:00
|
|
|
QStandardItemModel *VcsPlugin::nickNameModel()
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
2018-02-19 14:15:05 +01:00
|
|
|
if (!d->m_nickNameModel) {
|
|
|
|
|
d->m_nickNameModel = NickNameDialog::createModel(this);
|
2009-12-08 14:30:47 +01:00
|
|
|
populateNickNameModel();
|
|
|
|
|
}
|
2018-02-19 14:15:05 +01:00
|
|
|
return d->m_nickNameModel;
|
2009-12-08 14:30:47 +01:00
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsPlugin::populateNickNameModel()
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
|
|
|
|
QString errorMessage;
|
2022-10-04 17:44:50 +02:00
|
|
|
if (!NickNameDialog::populateModelFromMailCapFile(settings().nickNameMailMap.filePath(),
|
2018-02-19 14:15:05 +01:00
|
|
|
d->m_nickNameModel,
|
2009-12-08 14:30:47 +01:00
|
|
|
&errorMessage)) {
|
2010-04-12 16:34:21 +02:00
|
|
|
qWarning("%s", qPrintable(errorMessage));
|
|
|
|
|
}
|
2009-12-08 14:30:47 +01:00
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsPlugin::slotSettingsChanged()
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
2018-02-19 14:15:05 +01:00
|
|
|
if (d->m_nickNameModel)
|
2009-12-08 14:30:47 +01:00
|
|
|
populateNickNameModel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
2012-01-07 12:31:48 +01:00
|
|
|
} // namespace VcsBase
|