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 GitBase;
29class GitCache;
30
31/*!
32 \brief The BranchContextMenuConfig contains the necessary information to initialize the BranchContextMenu. It includes
33 information about the current branch, the selected branch in the view and the git object to perform the Git actions.
34
35*/
36struct BranchContextMenuConfig
37{
38 QString currentBranch;
39 QString branchSelected;
40 bool isLocal;
41 QSharedPointer<GitCache> mCache;
42 QSharedPointer<GitBase> mGit;
43};
44
45/*!
46 \brief The BranchContextMenuConfig creates the context menu for the BranchTreeWidget. In this context menu all the
47 possible actions regarding branches and it's workload are performed. This includes pushing pending commits to remote
48 branches.
49
50*/
51class BranchContextMenu : public QMenu
52{
53 Q_OBJECT
54
55signals:
56 void fullReload();
57 void logReload();
58
59 /*!
60 \brief Signal triggered when a branch has been checked out.
61
62 */
63 void signalCheckoutBranch();
64 /*!
65 \brief Signal triggered when the user wants to perform a merge. This action takes a \p fromBranch to merge it into
66 our \ref currentBranch. In case of conflict, it will be handle elsewhere.
67
68 \param currentBranch The current working branch.
69 \param fromBranch The branch to be merge into the current branch.
70 */
71 void signalMergeRequired(const QString &currentBranch, const QString &fromBranch);
72 /*!
73 * \brief signalPullConflict Signal triggered when trying to pull and a conflict happens.
74 */
75 void signalPullConflict();
76
77 /**
78 * @brief signalFetchPerformed Signal triggered when a deep fetch is performed.
79 */
80 void signalFetchPerformed();
81 /**
82 * @brief signalRefreshPRsCache Signal that refreshes PRs cache.
83 */
84 void signalRefreshPRsCache();
85
86 /**
87 * @brief Signal triggered when a merge with squash behavior has been requested. Since it involves a lot of changes
88 * at UI level this action is not performed here.
89 *
90 * @param origin The branch to merge from.
91 * @param destination The branch to merge into.
92 */
93 void mergeSqushRequested(const QString &origin, const QString &destination);
94
95public:
96 /*!
97 \brief Default constructor.
98
99 \param config The data to configure the context menu.
100 \param parent The parent widget if needed.
101 */
102 explicit BranchContextMenu(BranchContextMenuConfig config, QWidget *parent = nullptr);
103
104private:
105 BranchContextMenuConfig mConfig;
106
107 /*!
108 \brief Pulls the current branch.
109
110 */
111 void pull();
112 /*!
113 \brief Fetches all the changes from the remote repo. This includes gathering all tags as well, pruning and forcing
114 the pruning.
115
116 */
117 void fetch();
118 /*!
119 \brief Pushes all the local changes to the remote repo.
120
121 */
122 void push();
123 /*!
124 \brief Pushes force all the local changes into the remote repo.
125
126 */
127 void pushForce();
128 /*!
129 \brief Creates a branch locally.
130
131 */
132 void createBranch();
133 /*!
134 \brief Creates a new local branch and checks it out.
135
136 */
137 void createCheckoutBranch();
138 /*!
139 \brief Tries to merge the selected branch in the BranchTreeWidget into the current branch.
140
141 */
142 void merge();
143
144 void mergeSquash();
145 /*!
146 \brief Renames the selected branch.
147
148 */
149 void rename();
150 /*!
151 \brief Deletes the selected branch. It will fail if the branch to remove is the current one.
152
153 */
154 void deleteBranch();
155};
156