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 "stasheswidget.h"
0008 #include "actions/stashactions.h"
0009 #include "gitmanager.h"
0010 #include "models/stashesmodel.h"
0011 
0012 StashesWidget::StashesWidget(Git::Manager *git, AppWindow *parent)
0013     : WidgetBase(git, parent)
0014 {
0015     setupUi(this);
0016     init(git);
0017 }
0018 
0019 void StashesWidget::init(Git::Manager *git)
0020 {
0021     mActions = new StashActions(git, this);
0022 
0023     pushButtonApply->setAction(mActions->actionApply());
0024     pushButtonRemoveSelected->setAction(mActions->actionDrop());
0025     pushButtonCreateNew->setAction(mActions->actionNew());
0026 
0027     mModel = git->stashesModel();
0028     treeView->setModel(mModel);
0029 
0030     connect(treeView, &QTreeView::customContextMenuRequested, this, &StashesWidget::slotTreeViewCustomContextMenuRequested);
0031     connect(treeView, &TreeView::itemActivated, this, &StashesWidget::slotTreeViewItemActivated);
0032 }
0033 
0034 void StashesWidget::slotTreeViewCustomContextMenuRequested(const QPoint &pos)
0035 {
0036     Q_UNUSED(pos)
0037 
0038     auto stash = mModel->fromIndex(treeView->currentIndex());
0039 
0040     if (!stash)
0041         return;
0042 
0043     mActions->setStash(stash);
0044     mActions->popup();
0045 }
0046 
0047 void StashesWidget::slotTreeViewItemActivated(const QModelIndex &index)
0048 {
0049     auto stash = mModel->fromIndex(index);
0050 
0051     if (!stash)
0052         return;
0053 
0054     mActions->setStash(stash);
0055 }
0056 
0057 void StashesWidget::saveState(QSettings &settings) const
0058 {
0059     save(settings, treeView);
0060 }
0061 
0062 void StashesWidget::restoreState(QSettings &settings)
0063 {
0064     restore(settings, treeView);
0065 }
0066 
0067 #include "moc_stasheswidget.cpp"