2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-12-08 14:30:47 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2009-12-08 14:30:47 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-12-08 14:30:47 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2009-12-08 14:30:47 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-12-08 14:30:47 +01:00
|
|
|
|
|
|
|
|
#include "vcsplugin.h"
|
2014-02-24 12:36:47 +01:00
|
|
|
|
|
|
|
|
#include "vcsbaseconstants.h"
|
|
|
|
|
|
2010-04-12 16:34:21 +02:00
|
|
|
#include "commonsettingspage.h"
|
2009-12-08 14:30:47 +01:00
|
|
|
#include "nicknamedialog.h"
|
2014-08-26 00:02:47 +02:00
|
|
|
#include "vcsoutputwindow.h"
|
2015-02-20 11:35:36 +01:00
|
|
|
#include "vcsprojectcache.h"
|
2009-12-08 14:30:47 +01:00
|
|
|
#include "corelistener.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
|
|
|
|
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
|
|
|
|
2014-10-13 18:49:44 +02:00
|
|
|
#include <utils/macroexpander.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QtPlugin>
|
|
|
|
|
#include <QDebug>
|
2009-12-08 14:30:47 +01:00
|
|
|
|
2014-06-23 16:57:56 +02:00
|
|
|
using namespace Core;
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
namespace VcsBase {
|
2009-12-08 14:30:47 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsPlugin *VcsPlugin::m_instance = 0;
|
2009-12-08 14:30:47 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsPlugin::VcsPlugin() :
|
2009-12-08 14:30:47 +01:00
|
|
|
m_settingsPage(0),
|
|
|
|
|
m_nickNameModel(0),
|
|
|
|
|
m_coreListener(0)
|
|
|
|
|
{
|
|
|
|
|
m_instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsPlugin::~VcsPlugin()
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
2015-02-20 11:35:36 +01:00
|
|
|
VcsProjectCache::destroy();
|
2009-12-08 14:30:47 +01:00
|
|
|
m_instance = 0;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
m_coreListener = new CoreListener;
|
|
|
|
|
addAutoReleasedObject(m_coreListener);
|
|
|
|
|
|
2010-04-12 16:34:21 +02:00
|
|
|
m_settingsPage = new CommonOptionsPage;
|
2009-12-08 14:30:47 +01:00
|
|
|
addAutoReleasedObject(m_settingsPage);
|
2014-08-26 00:02:47 +02:00
|
|
|
addAutoReleasedObject(VcsOutputWindow::instance());
|
2015-03-04 15:51:32 +01:00
|
|
|
connect(m_settingsPage, &CommonOptionsPage::settingsChanged,
|
|
|
|
|
this, &VcsPlugin::settingsChanged);
|
|
|
|
|
connect(m_settingsPage, &CommonOptionsPage::settingsChanged,
|
|
|
|
|
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-01-19 15:42:22 +01:00
|
|
|
JsExpander::registerQObjectForJs(QLatin1String("Vcs"), new VcsJsExtension);
|
|
|
|
|
|
2014-10-13 18:49:44 +02:00
|
|
|
Utils::MacroExpander *expander = Utils::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 {
|
|
|
|
|
IVersionControl *vc = 0;
|
2014-11-19 17:58:33 +01:00
|
|
|
if (Project *project = ProjectTree::currentProject())
|
2014-06-23 16:57:56 +02:00
|
|
|
vc = VcsManager::findVersionControlForDirectory(project->projectDirectory().toString());
|
|
|
|
|
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 {
|
|
|
|
|
IVersionControl *vc = 0;
|
|
|
|
|
QString topLevel;
|
2014-11-19 17:58:33 +01:00
|
|
|
if (Project *project = ProjectTree::currentProject())
|
2014-06-23 16:57:56 +02:00
|
|
|
vc = VcsManager::findVersionControlForDirectory(project->projectDirectory().toString(), &topLevel);
|
|
|
|
|
return vc ? vc->vcsTopic(topLevel) : QString();
|
|
|
|
|
});
|
|
|
|
|
|
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())
|
2014-07-02 22:52:53 +03:00
|
|
|
return VcsManager::findTopLevelForDirectory(project->projectDirectory().toString());
|
|
|
|
|
return QString();
|
2014-06-23 16:57:56 +02:00
|
|
|
});
|
2014-02-24 12:36:47 +01:00
|
|
|
|
2009-12-08 14:30:47 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsPlugin::extensionsInitialized()
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
2015-02-20 11:35:36 +01:00
|
|
|
VcsProjectCache::create();
|
2009-12-08 14:30:47 +01:00
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsPlugin *VcsPlugin::instance()
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
CoreListener *VcsPlugin::coreListener() const
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
|
|
|
|
return m_coreListener;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
CommonVcsSettings VcsPlugin::settings() const
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
|
|
|
|
return m_settingsPage->settings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
{
|
|
|
|
|
if (!m_nickNameModel) {
|
|
|
|
|
m_nickNameModel = NickNameDialog::createModel(this);
|
|
|
|
|
populateNickNameModel();
|
|
|
|
|
}
|
|
|
|
|
return m_nickNameModel;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsPlugin::populateNickNameModel()
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
|
|
|
|
QString errorMessage;
|
|
|
|
|
if (!NickNameDialog::populateModelFromMailCapFile(settings().nickNameMailMap,
|
|
|
|
|
m_nickNameModel,
|
|
|
|
|
&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
|
|
|
{
|
|
|
|
|
if (m_nickNameModel)
|
|
|
|
|
populateNickNameModel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
2012-01-07 12:31:48 +01:00
|
|
|
} // namespace VcsBase
|