1 | #include "ConflictButton.h" |
2 | |
3 | #include <GitBase.h> |
4 | #include <GitLocal.h> |
5 | #include <QLogger.h> |
6 | |
7 | #include <QHBoxLayout> |
8 | #include <QProcess> |
9 | #include <QPushButton> |
10 | |
11 | using namespace QLogger; |
12 | |
13 | ConflictButton::ConflictButton(const QString &filename, bool inConflict, const QSharedPointer<GitBase> &git, |
14 | QWidget *parent) |
15 | : QFrame(parent) |
16 | , mGit(git) |
17 | , mFileName(filename) |
18 | , mFile(new QPushButton(mFileName)) |
19 | , mEdit(new QPushButton()) |
20 | , mResolve(new QPushButton()) |
21 | , mUpdate(new QPushButton()) |
22 | { |
23 | mFile->setCheckable(true); |
24 | mFile->setChecked(inConflict); |
25 | |
26 | mEdit->setIcon(QIcon(":/icons/edit" )); |
27 | mEdit->setFixedSize(30, 30); |
28 | mResolve->setIcon(QIcon(":/icons/check" )); |
29 | mResolve->setFixedSize(30, 30); |
30 | mUpdate->setIcon(QIcon(":/icons/refresh" )); |
31 | mUpdate->setFixedSize(30, 30); |
32 | |
33 | const auto layout = new QHBoxLayout(this); |
34 | layout->setSpacing(0); |
35 | layout->setContentsMargins(QMargins()); |
36 | layout->addWidget(mFile); |
37 | layout->addWidget(mEdit); |
38 | layout->addWidget(mUpdate); |
39 | layout->addWidget(mResolve); |
40 | |
41 | mUpdate->setVisible(inConflict); |
42 | mResolve->setVisible(inConflict); |
43 | |
44 | connect(mFile, &QPushButton::clicked, this, &ConflictButton::clicked); |
45 | connect(mEdit, &QPushButton::clicked, this, [this] { emit signalEditFile(getFileName(), 0, 0); }); |
46 | connect(mResolve, &QPushButton::clicked, this, &ConflictButton::resolveConflict); |
47 | connect(mUpdate, &QPushButton::clicked, this, [this]() { emit updateRequested(); }); |
48 | } |
49 | |
50 | void ConflictButton::setChecked(bool checked) |
51 | { |
52 | mFile->setChecked(checked); |
53 | } |
54 | |
55 | QString ConflictButton::getFileName() const |
56 | { |
57 | return mGit->getWorkingDir() + "/" + mFileName; |
58 | } |
59 | |
60 | void ConflictButton::setInConflict(bool inConflict) |
61 | { |
62 | mUpdate->setVisible(inConflict); |
63 | mResolve->setVisible(inConflict); |
64 | } |
65 | |
66 | void ConflictButton::resolveConflict() |
67 | { |
68 | QScopedPointer<GitLocal> git(new GitLocal(mGit)); |
69 | const auto ret = git->stageFile(mFileName); |
70 | |
71 | if (ret.success) |
72 | { |
73 | setInConflict(false); |
74 | emit resolved(); |
75 | } |
76 | } |
77 | |