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 <IDiffWidget.h>
27
28#include <QFrame>
29#include <DiffInfo.h>
30
31class FileDiffView;
32class QPushButton;
33class CheckBox;
34class FileEditor;
35class QStackedWidget;
36class QLabel;
37class QLineEdit;
38class QPlainTextEdit;
39
40/*!
41 \brief The FileDiffWidget creates the layout that contains all the widgets related with the creation of the diff of a
42 specific file.
43
44 \class FileDiffWidget FileDiffWidget.h "FileDiffWidget.h"
45*/
46class FileDiffWidget : public IDiffWidget
47{
48 Q_OBJECT
49
50signals:
51 /**
52 * @brief exitRequested Signal triggered when the user clicks the back button to return to the graph view.
53 */
54 void exitRequested();
55
56 /**
57 * @brief fileStaged
58 * @param fileName
59 */
60 void fileStaged(const QString &fileName);
61
62 /**
63 * @brief fileReverted Signal triggered when the user reverts all the changes of the current file.
64 * @param fileName The filename
65 */
66 void fileReverted(const QString &fileName);
67
68public:
69 /*!
70 \brief Default constructor.
71
72 \param git The git object to perform Git operations.
73 \param parent The parent widget if needed.
74 */
75 explicit FileDiffWidget(const QSharedPointer<GitBase> &git, QSharedPointer<GitCache> cache,
76 QWidget *parent = nullptr);
77
78 /*!
79 \brief Clears the current information on the diff view.
80 */
81 void clear();
82 /*!
83 \brief Reloads the information currently displayed in the diff view. The relaod only is applied if the current file
84 could change, that is if the user is watching the work in progress state. \return bool Returns true if the reload
85 was done, otherwise false.
86 */
87 bool reload() override;
88 /*!
89 \brief Configures the diff view with the two commits that will be compared and the file that will be applied.
90
91 \param currentSha The base SHA.
92 \param previousSha The SHA to compare to.
93 \param file The file that will show the diff.
94 \param editMode Enters edit mode directly.
95 \return bool Returns true if the configuration was applied, otherwise false.
96 */
97 bool configure(const QString &currentSha, const QString &previousSha, const QString &file, bool isCached,
98 bool editMode = false);
99
100 /**
101 * @brief setFileVsFileEnable Enables the widget to show file vs file view.
102 * @param enable If true, enables the file vs file view.
103 */
104 void setSplitViewEnabled(bool enable);
105
106 /**
107 * @brief setFullViewEnabled Sets the full file view enabled.
108 * @param enable True to enable, otherwise false.
109 */
110 void setFullViewEnabled(bool enable);
111
112 /**
113 * @brief hideBackButton Hides the back button.
114 */
115 void hideBackButton() const;
116
117 /**
118 * @brief getCurrentFile Gets the current loaded file.
119 * @return The current file name.
120 */
121 QString getCurrentFile() const { return mCurrentFile; }
122
123private:
124 QString mCurrentFile;
125 bool mIsCached = false;
126 QPushButton *mBack = nullptr;
127 QPushButton *mGoPrevious = nullptr;
128 QPushButton *mGoNext = nullptr;
129 QPushButton *mEdition = nullptr;
130 QPushButton *mFullView = nullptr;
131 QPushButton *mSplitView = nullptr;
132 QPushButton *mSave = nullptr;
133 QPushButton *mStage = nullptr;
134 QPushButton *mRevert = nullptr;
135 QLabel *mFileNameLabel = nullptr;
136 QFrame *mTitleFrame = nullptr;
137 FileDiffView *mNewFile = nullptr;
138 QLineEdit *mSearchOld = nullptr;
139 FileDiffView *mOldFile = nullptr;
140 QVector<int> mModifications;
141 bool mFileVsFile = false;
142 DiffInfo mChunks;
143 int mCurrentChunkLine = 0;
144 FileEditor *mFileEditor = nullptr;
145 QStackedWidget *mViewStackedWidget = nullptr;
146
147 /**
148 * @brief moveChunkUp Moves to the previous diff chunk.
149 */
150 void moveChunkUp();
151 /**
152 * @brief moveChunkDown Moves to the following diff chunk.
153 */
154 void moveChunkDown();
155
156 /**
157 * @brief enterEditionMode Enters edition mode
158 * @param enter
159 */
160 void enterEditionMode(bool enter);
161
162 /**
163 * @brief endEditFile Closes the file editor.
164 */
165 void endEditFile();
166 /**
167 * @brief stageFile Stages the file.
168 */
169 void stageFile();
170 /**
171 * @brief revertFile Revert all the changes to the file.
172 */
173 void revertFile();
174
175 void stageChunk(const QString &id);
176};
177