1#pragma once
2
3/****************************************************************************************
4 ** GitQlient is an application to manage and operate one or several Git repositories. With
5 ** GitQlient you will be able to add commits, branches and manage all the options Git provides.
6 ** Copyright (C) 2021 Francesc Martinez
7 **
8 ** LinkedIn: www.linkedin.com/in/cescmm/
9 ** Web: www.francescmm.com
10 **
11 ** This program is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU Lesser General Public
13 ** License as published by the Free Software Foundation; either
14 ** version 2 of the License, or (at your option) any later version.
15 **
16 ** This program is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** Lesser General Public License for more details.
20 **
21 ** You should have received a copy of the GNU Lesser General Public
22 ** License along with this library; if not, write to the Free Software
23 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 ***************************************************************************************/
25
26#include <QMenu>
27
28class GitCache;
29class GitBase;
30class GitTags;
31class GitServerCache;
32
33/*!
34 \brief This class configures the context menu that will be shown when the user right-click over a commit in the
35 repository view.
36
37 \class CommitHistoryContextMenu CommitHistoryContextMenu.h "CommitHistoryContextMenu.h"
38*/
39class CommitHistoryContextMenu : public QMenu
40{
41 Q_OBJECT
42
43signals:
44 void fullReload();
45 void referencesReload();
46 void logReload();
47
48 /*!
49 \brief Signal triggered when the user wants to open the diff of a commit compared to its parent.
50
51 \param sha The SHA to diff.
52 */
53 void signalOpenDiff(const QString &sha);
54 /*!
55 \brief Signal triggered when the user wants to diff the shas in the list. This signal is only emitted if the user
56 selected two SHAs.
57
58 \param sha The shas to diff between.
59 */
60 void signalOpenCompareDiff(const QStringList &sha);
61 /*!
62 \brief Signal triggered when the user wants to amend a commit.
63
64 \param sha The SHA of the commit to amend.
65 */
66 void signalAmendCommit(const QString &sha);
67 /*!
68 \brief Signal triggered when a merge has been requested. Since it involves a lot of changes at UI level this action
69 is not performed here.
70
71 \param origin The branch to merge from.
72 \param destination The branch to merge into.
73 */
74 void signalMergeRequired(const QString &origin, const QString &destination);
75
76 /**
77 * @brief Signal triggered when a merge with squash behavior has been requested. Since it involves a lot of changes
78 * at UI level this action is not performed here.
79 *
80 * @param origin The branch to merge from.
81 * @param destination The branch to merge into.
82 */
83 void mergeSqushRequested(const QString &origin, const QString &destination);
84
85 /*!
86 * \brief signalConflict Signal triggered when trying to cherry-pick and a conflict happens.
87 */
88 void signalCherryPickConflict(const QStringList &pendingShas = QStringList());
89 /*!
90 * \brief signalPullConflict Signal triggered when trying to pull and a conflict happens.
91 */
92 void signalPullConflict();
93 /**
94 * @brief signalRefreshPRsCache Signal that refreshes PRs cache.
95 */
96 void signalRefreshPRsCache();
97 /**
98 * @brief showPrDetailedView Signal that makes the view change to the Pull Request detailed view
99 * @param pr The pull request number to show.
100 */
101 void showPrDetailedView(int pr);
102
103public:
104 /*!
105 \brief Default constructor.
106
107 \param cache The cache for the current repository.
108 \param git The git object to execute Git commands.
109 \param shas The list of SHAs selected.
110 \param parent The parent widget if needed.
111 */
112 explicit CommitHistoryContextMenu(const QSharedPointer<GitCache> &cache, const QSharedPointer<GitBase> &git,
113 const QSharedPointer<GitServerCache> &gitServerCache, const QStringList &shas,
114 QWidget *parent = nullptr);
115
116private:
117 QSharedPointer<GitCache> mCache;
118 QSharedPointer<GitBase> mGit;
119 QSharedPointer<GitServerCache> mGitServerCache;
120 QSharedPointer<GitTags> mGitTags;
121 QStringList mShas;
122
123 /*!
124 \brief This method creates all the actions that will appear when only one SHA is selected.
125 */
126 void createIndividualShaMenu();
127 /*!
128 \brief This method creates all the actions that will appear when more than one SHA is selected.
129 */
130 void createMultipleShasMenu();
131 /*!
132 \brief Pushes the changes to a stash.
133 */
134 void stashPush();
135 /*!
136 \brief Pops the changes stored in a stash.
137 */
138 void stashPop();
139 /*!
140 \brief Creates a branch at the selected commit.
141 */
142 void createBranch();
143 /*!
144 \brief Creates a tag at the selected commit.
145 */
146 void createTag();
147 /*!
148 \brief Export the selected commit/s as patches. If multiple commits are selected they are enumerated sequentially.
149 */
150 void exportAsPatch();
151 /*!
152 \brief Checks out to the selected branch.
153 */
154 void checkoutBranch();
155 /**
156 * @brief createCheckoutBranch Creates and checks out a branch.
157 */
158 void createCheckoutBranch();
159 /*!
160 \brief Checks out to the selected commit.
161 */
162 void checkoutCommit();
163 /*!
164 \brief Cherry-picks the selected commit into the current branch.
165 */
166 void cherryPickCommit();
167 /*!
168 \brief Applies a patch loaded by the user but doesn't commit it.
169 */
170 void applyPatch();
171 /*!
172 \brief Applies the changes from a patch in the form of a commit.
173 */
174 void applyCommit();
175 /*!
176 \brief Pushes the local commits into remote.
177 */
178 void push();
179 /*!
180 \brief Pulls the changes from remote.
181 */
182 void pull();
183 /*!
184 \brief Fetches the changes from remote.
185 */
186 void fetch();
187 /*!
188 \brief Resets the current branch reference into the selected commit keeping all changes.
189 */
190 void resetSoft();
191 /*!
192 \brief Resets the current branch reference into the selected commit.
193 */
194 void resetMixed();
195 /*!
196 \brief Resets the current branch reference into the selected commit overriding all changes.
197 */
198 void resetHard();
199 /*!
200 \brief Merges the \p branchFrom into the current branch.
201
202 \param branchFrom The branch that will be merge into the current one.
203 */
204 void merge();
205
206 /**
207 * @brief mergeSquash Merges the @p branchFrom into the current branch squashing all the commits.
208 * @param branchFrom The branch that will be merge into the current one.
209 */
210 void mergeSquash();
211 /*!
212 \brief Method that adds all the branch related actions.
213
214 \param sha The SHA of the current commit.
215 */
216 void addBranchActions(const QString &sha);
217
218 void showSquashDialog();
219};
220