| 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 <QFrame> |
| 27 | #include <QMap> |
| 28 | |
| 29 | class GitBase; |
| 30 | class QVBoxLayout; |
| 31 | class QPushButton; |
| 32 | class MergeInfoWidget; |
| 33 | class QLineEdit; |
| 34 | class QTextEdit; |
| 35 | class FileDiffWidget; |
| 36 | class RevisionFiles; |
| 37 | class GitCache; |
| 38 | class QListWidget; |
| 39 | class QListWidgetItem; |
| 40 | class QStackedWidget; |
| 41 | |
| 42 | /** |
| 43 | * @brief The MergeWidget class creates the layout for when a merge happens. The layout is composed by two lists of |
| 44 | * ConflictButton in the left side: one for the conflict files and the other for the auto-merged files. Below this lists |
| 45 | * appears the description for the merge message and two buttons: abort merge and commit. |
| 46 | * |
| 47 | * In the center and right part of the view, there are shown the files that the user selects using the ConflictButton |
| 48 | * buttons. |
| 49 | * |
| 50 | */ |
| 51 | class MergeWidget : public QFrame |
| 52 | { |
| 53 | Q_OBJECT |
| 54 | |
| 55 | signals: |
| 56 | /** |
| 57 | * @brief Signal triggered when the merge ends. It can be by aborting it or by committing it. |
| 58 | * |
| 59 | */ |
| 60 | void signalMergeFinished(); |
| 61 | |
| 62 | public: |
| 63 | enum class ConflictReason |
| 64 | { |
| 65 | Merge, |
| 66 | CherryPick, |
| 67 | Pull |
| 68 | }; |
| 69 | |
| 70 | /** |
| 71 | * @brief Default constructor. |
| 72 | * |
| 73 | * @param gitQlientCache The internal cache for the current repository. |
| 74 | * @param git The git object to perform Git operations. |
| 75 | * @param parent The parent widget if needed. |
| 76 | */ |
| 77 | explicit MergeWidget(const QSharedPointer<GitCache> &gitQlientCache, const QSharedPointer<GitBase> &git, |
| 78 | QWidget *parent = nullptr); |
| 79 | |
| 80 | /** |
| 81 | * @brief Configures the merge widget by giving the current revisions files that are part of the merge. |
| 82 | * |
| 83 | * @param files The RevisionFiles data. |
| 84 | */ |
| 85 | void configure(const RevisionFiles &files, ConflictReason reason); |
| 86 | |
| 87 | /** |
| 88 | * @brief Configures the merge widget by giving the current revisions files that are part of the merge. |
| 89 | * |
| 90 | * @param files The RevisionFiles data. |
| 91 | */ |
| 92 | void configureForCherryPick(const RevisionFiles &files, const QStringList &pendingShas = QStringList()); |
| 93 | |
| 94 | private: |
| 95 | QSharedPointer<GitCache> mGitQlientCache; |
| 96 | QSharedPointer<GitBase> mGit; |
| 97 | QListWidget *mConflictFiles = nullptr; |
| 98 | QListWidget *mMergedFiles = nullptr; |
| 99 | QLineEdit *mCommitTitle = nullptr; |
| 100 | QTextEdit *mDescription = nullptr; |
| 101 | QPushButton *mMergeBtn = nullptr; |
| 102 | QPushButton *mAbortBtn = nullptr; |
| 103 | ConflictReason mReason = ConflictReason::Merge; |
| 104 | QStackedWidget *mStacked = nullptr; |
| 105 | FileDiffWidget *mFileDiff = nullptr; |
| 106 | QStringList mPendingShas; |
| 107 | |
| 108 | /** |
| 109 | * @brief Fills both lists of ConflictButton. |
| 110 | * |
| 111 | * @param files The RevisionFiles data that contains the list of files. |
| 112 | */ |
| 113 | void fillButtonFileList(const RevisionFiles &files); |
| 114 | /** |
| 115 | * @brief Changes the current diff view of a file when a file in the list is clicked. |
| 116 | * |
| 117 | * @param item The selected item of the list. |
| 118 | */ |
| 119 | void changeDiffView(QListWidgetItem *item); |
| 120 | /** |
| 121 | * @brief Aborts the current merge. |
| 122 | * |
| 123 | */ |
| 124 | void abort(); |
| 125 | /** |
| 126 | * @brief Commits the current merge. |
| 127 | * |
| 128 | */ |
| 129 | void commit(); |
| 130 | /** |
| 131 | * @brief This method removes all the handmade components before closing the merge view. |
| 132 | * |
| 133 | */ |
| 134 | void removeMergeComponents(); |
| 135 | /** |
| 136 | * @brief When a conflict is marked as resolved the button is moved to the solved list. This action is triggered by a |
| 137 | * ConflictButton. |
| 138 | * @param fileName The file name of the file whose conflict is resolved. |
| 139 | */ |
| 140 | void onConflictResolved(const QString &fileName); |
| 141 | |
| 142 | void cherryPickCommit(); |
| 143 | }; |
| 144 | |