| 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 <QMap> |
| 27 | #include <QWidget> |
| 28 | |
| 29 | class QListWidget; |
| 30 | class QListWidgetItem; |
| 31 | class GitCache; |
| 32 | class GitBase; |
| 33 | class RevisionFiles; |
| 34 | class FileWidget; |
| 35 | |
| 36 | namespace Ui |
| 37 | { |
| 38 | class CommitChangesWidget; |
| 39 | } |
| 40 | |
| 41 | class CommitChangesWidget : public QWidget |
| 42 | { |
| 43 | Q_OBJECT |
| 44 | |
| 45 | signals: |
| 46 | void logReload(); |
| 47 | void changeReverted(const QString &revertedFile); |
| 48 | void signalShowDiff(const QString &sha, const QString &parentSha, const QString &fileName, bool isCached); |
| 49 | void changesCommitted(); |
| 50 | void signalCheckoutPerformed(); |
| 51 | void signalShowFileHistory(const QString &fileName); |
| 52 | void signalUpdateWip(); |
| 53 | void signalCancelAmend(const QString &commitSha); |
| 54 | |
| 55 | /** |
| 56 | * @brief signalEditFile Signal triggered when the user wants to edit a file and is running GitQlient from QtCreator. |
| 57 | * @param fileName The file name |
| 58 | * @param line The line |
| 59 | * @param column The column |
| 60 | */ |
| 61 | void signalEditFile(const QString &fileName); |
| 62 | |
| 63 | public: |
| 64 | explicit CommitChangesWidget(const QSharedPointer<GitCache> &cache, const QSharedPointer<GitBase> &git, |
| 65 | QWidget *parent = nullptr); |
| 66 | |
| 67 | ~CommitChangesWidget(); |
| 68 | |
| 69 | virtual void configure(const QString &sha) = 0; |
| 70 | virtual void reload() final; |
| 71 | virtual void clear() final; |
| 72 | virtual void clearStaged() final; |
| 73 | virtual void setCommitTitleMaxLength() final; |
| 74 | |
| 75 | protected: |
| 76 | struct WipCacheItem |
| 77 | { |
| 78 | bool keep = false; |
| 79 | QListWidgetItem *item = nullptr; |
| 80 | }; |
| 81 | |
| 82 | Ui::CommitChangesWidget *ui = nullptr; |
| 83 | QSharedPointer<GitCache> mCache; |
| 84 | QSharedPointer<GitBase> mGit; |
| 85 | QString mCurrentSha; |
| 86 | QMap<QString, WipCacheItem> mInternalCache; |
| 87 | int mTitleMaxLength = 50; |
| 88 | |
| 89 | virtual void commitChanges() = 0; |
| 90 | virtual void (const QPoint &pos) final; |
| 91 | |
| 92 | virtual void insertFiles(const RevisionFiles &files, QListWidget *fileList) final; |
| 93 | QPair<QListWidgetItem *, FileWidget *> fillFileItemInfo(const QString &file, bool isConflict, bool isUntracked, |
| 94 | const QString &icon, const QColor &color, |
| 95 | QListWidget *parent); |
| 96 | virtual void prepareCache() final; |
| 97 | virtual void clearCache() final; |
| 98 | virtual void addAllFilesToCommitList() final; |
| 99 | virtual void requestDiff(const QString &fileName) final; |
| 100 | virtual QString addFileToCommitList(QListWidgetItem *item, bool updateGit = true) final; |
| 101 | virtual void revertAllChanges() final; |
| 102 | virtual void removeFileFromCommitList(QListWidgetItem *item) final; |
| 103 | virtual QStringList getFiles() final; |
| 104 | virtual bool checkMsg(QString &msg) final; |
| 105 | virtual void updateCounter(const QString &text) final; |
| 106 | virtual bool hasConflicts() final; |
| 107 | virtual void resetFile(QListWidgetItem *item) final; |
| 108 | virtual QColor getColorForFile(const RevisionFiles &files, int index) const final; |
| 109 | virtual void deleteUntrackedFiles() final; |
| 110 | |
| 111 | static QString lastMsgBeforeError; |
| 112 | }; |
| 113 | |