File indexing completed on 2025-01-05 05:14:40

0001 /*
0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com>
0003 
0004 SPDX-License-Identifier: GPL-3.0-or-later
0005 */
0006 
0007 #include "submoduleswidget.h"
0008 #include "actions/submoduleactions.h"
0009 
0010 #include <entities/submodule.h>
0011 #include <gitmanager.h>
0012 #include <models/submodulesmodel.h>
0013 
0014 SubmodulesWidget::SubmodulesWidget(Git::Manager *git, AppWindow *parent)
0015     : WidgetBase(git, parent)
0016     , mActions(new SubmoduleActions(git, this))
0017 {
0018     setupUi(this);
0019 
0020     pushButtonAddNew->setAction(mActions->actionCreate());
0021     pushButtonUpdate->setAction(mActions->actionUpdate());
0022 
0023     mModel = git->submodulesModel();
0024     treeView->setModel(mModel);
0025 
0026     connect(treeView, &QTreeView::customContextMenuRequested, this, &SubmodulesWidget::slotTreeViewCustomContextMenuRequested);
0027     connect(treeView, &QTreeView::activated, this, &SubmodulesWidget::slotTreeViewActivated);
0028 }
0029 
0030 void SubmodulesWidget::saveState(QSettings &settings) const
0031 {
0032     save(settings, treeView);
0033 }
0034 
0035 void SubmodulesWidget::restoreState(QSettings &settings)
0036 {
0037     restore(settings, treeView);
0038 }
0039 
0040 void SubmodulesWidget::slotTreeViewCustomContextMenuRequested(const QPoint &pos)
0041 {
0042     Q_UNUSED(pos)
0043 
0044     if (!treeView->currentIndex().isValid())
0045         return;
0046 
0047     auto s = mModel->fromIndex(treeView->currentIndex());
0048     if (!s)
0049         return;
0050     mActions->setSubModuleName(s->path());
0051     mActions->popup();
0052 }
0053 
0054 void SubmodulesWidget::slotTreeViewActivated(const QModelIndex &index)
0055 {
0056     auto s = mModel->fromIndex(index);
0057     if (!s)
0058         return;
0059     mActions->setSubModuleName(s->path());
0060 }
0061 
0062 #include "moc_submoduleswidget.cpp"