1#include "StashesContextMenu.h"
2
3#include <BranchDlg.h>
4#include <GitQlientStyles.h>
5#include <GitStashes.h>
6
7#include <QMessageBox>
8
9StashesContextMenu::StashesContextMenu(const QSharedPointer<GitBase> &git, const QString &stashId, QWidget *parent)
10 : QMenu(parent)
11 , mGit(git)
12 , mStashId(stashId)
13{
14 setAttribute(Qt::WA_DeleteOnClose);
15
16 connect(addAction(tr("Branch")), &QAction::triggered, this, &StashesContextMenu::branch);
17 connect(addAction(tr("Drop")), &QAction::triggered, this, &StashesContextMenu::drop);
18 connect(addAction(tr("Clear all")), &QAction::triggered, this, &StashesContextMenu::clear);
19}
20
21void StashesContextMenu::branch()
22{
23 BranchDlg dlg({ mStashId, BranchDlgMode::STASH_BRANCH, nullptr, mGit });
24 const auto ret = dlg.exec();
25
26 if (ret == QDialog::Accepted)
27 emit signalUpdateView();
28}
29
30void StashesContextMenu::drop()
31{
32 QScopedPointer<GitStashes> git(new GitStashes(mGit));
33 const auto ret = git->stashDrop(mStashId);
34
35 if (ret.success)
36 emit signalUpdateView();
37 else
38 {
39 QMessageBox msgBox(QMessageBox::Critical, tr("Error while dropping stash"),
40 tr("There were problems during the stash drop operation. Please, see the detailed "
41 "description for more information."),
42 QMessageBox::Ok, this);
43 msgBox.setDetailedText(ret.output);
44 msgBox.setStyleSheet(GitQlientStyles::getStyles());
45 msgBox.exec();
46 }
47}
48
49void StashesContextMenu::clear()
50{
51 QScopedPointer<GitStashes> git(new GitStashes(mGit));
52 const auto ret = git->stashClear();
53
54 if (ret.success)
55 emit signalUpdateView();
56 else
57 {
58 QMessageBox msgBox(QMessageBox::Critical, tr("Error while branch stash"),
59 tr("There were problems during the branch stash operation. Please, see the detailed "
60 "description for more information."),
61 QMessageBox::Ok, this);
62 msgBox.setDetailedText(ret.output);
63 msgBox.setStyleSheet(GitQlientStyles::getStyles());
64 msgBox.exec();
65 }
66}
67