File indexing completed on 2024-05-05 04:41:03

0001 /*
0002     SPDX-FileCopyrightText: 2010 Aleix Pol <aleixpol@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "vcschangesviewplugin.h"
0008 
0009 #include <QAction>
0010 
0011 #include <KActionCollection>
0012 #include <KLocalizedString>
0013 #include <KPluginFactory>
0014 
0015 #include <interfaces/icore.h>
0016 #include <interfaces/iprojectcontroller.h>
0017 #include <interfaces/iproject.h>
0018 #include <interfaces/iuicontroller.h>
0019 #include <project/projectchangesmodel.h>
0020 #include <project/projectmodel.h>
0021 #include "vcschangesview.h"
0022 
0023 K_PLUGIN_FACTORY_WITH_JSON(VcsProjectIntegrationFactory, "kdevvcschangesview.json", registerPlugin<VcsProjectIntegrationPlugin>();)
0024 
0025 using namespace KDevelop;
0026 
0027 class VCSProjectToolViewFactory : public KDevelop::IToolViewFactory
0028 {
0029 public:
0030     explicit VCSProjectToolViewFactory(VcsProjectIntegrationPlugin *plugin): m_plugin(plugin) {}
0031 
0032     QWidget* create(QWidget *parent = nullptr) override
0033     {
0034         auto* modif = new VcsChangesView(m_plugin, parent);
0035         modif->setModel(m_plugin->model());
0036         QObject::connect(modif, QOverload<const QList<KDevelop::IProject*>&>::of(&VcsChangesView::reload),
0037                          m_plugin->model(), QOverload<const QList<KDevelop::IProject*>&>::of(&ProjectChangesModel::reload));
0038         QObject::connect(modif, QOverload<const QList<KDevelop::IProject*>&>::of(&VcsChangesView::reload),
0039                          m_plugin->model(), QOverload<const QList<KDevelop::IProject*>&>::of(&ProjectChangesModel::reload));
0040         QObject::connect(modif, &VcsChangesView::activated, m_plugin, &VcsProjectIntegrationPlugin::activated);
0041         return modif;
0042     }
0043 
0044     Qt::DockWidgetArea defaultPosition() const override
0045     {
0046         return Qt::RightDockWidgetArea;
0047     }
0048 
0049     QString id() const override
0050     {
0051         return QStringLiteral("org.kdevelop.VCSProject");
0052     }
0053 
0054 private:
0055     VcsProjectIntegrationPlugin *m_plugin;
0056 };
0057 
0058 VcsProjectIntegrationPlugin::VcsProjectIntegrationPlugin(QObject* parent, const QVariantList&)
0059     : KDevelop::IPlugin(QStringLiteral("kdevvcsprojectintegration"), parent)
0060     , m_model(nullptr)
0061 {
0062     ICore::self()->uiController()->addToolView(i18nc("@title:window", "Project Changes"), new VCSProjectToolViewFactory(this));
0063 
0064     QAction* synaction = actionCollection()->addAction(QStringLiteral("locate_document"));
0065     synaction->setText(i18nc("@action", "Locate Current Document"));
0066     synaction->setIcon(QIcon::fromTheme(QStringLiteral("dirsync")));
0067     synaction->setToolTip(i18nc("@info:tooltip", "Locate the current document and select it"));
0068 
0069     QAction* reloadaction = actionCollection()->addAction(QStringLiteral("reload_view"));
0070     reloadaction->setText(i18nc("@action", "Reload View"));
0071     reloadaction->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh")));
0072     reloadaction->setToolTip(i18nc("@info:tooltip", "Refresh the view for all projects, in case anything changed"));
0073 }
0074 
0075 void VcsProjectIntegrationPlugin::activated(const QModelIndex& /*idx*/)
0076 {
0077 
0078 }
0079 
0080 ProjectChangesModel* VcsProjectIntegrationPlugin::model()
0081 {
0082     if(!m_model) {
0083         m_model = ICore::self()->projectController()->changesModel();
0084         connect(actionCollection()->action(QStringLiteral("reload_view")), &QAction::triggered, m_model, &ProjectChangesModel::reloadAll);
0085     }
0086 
0087     return m_model;
0088 }
0089 
0090 #include "vcschangesviewplugin.moc"
0091 #include "moc_vcschangesviewplugin.cpp"