2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-12-08 14:30:47 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2009-12-08 14:30:47 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
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"
|
2015-08-26 14:39:15 +02:00
|
|
|
#include "vcsbasesubmiteditor.h"
|
2014-02-24 12:36:47 +01:00
|
|
|
|
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-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
|
|
|
|
2014-10-13 18:49:44 +02:00
|
|
|
#include <utils/macroexpander.h>
|
|
|
|
|
|
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;
|
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
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
|
|
|
|
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 {
|
2018-09-20 01:32:36 +03:00
|
|
|
IVersionControl *vc = nullptr;
|
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 {
|
2018-09-20 01:32:36 +03:00
|
|
|
IVersionControl *vc = nullptr;
|
2014-06-23 16:57:56 +02:00
|
|
|
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
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
if (!NickNameDialog::populateModelFromMailCapFile(settings().nickNameMailMap,
|
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
|