File indexing completed on 2024-05-05 04:40:11

0001 /*
0002     SPDX-FileCopyrightText: 2006 David Nolden <david.nolden.kdevelop@art-master.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_PLUGIN_PATCHREVIEW_H
0008 #define KDEVPLATFORM_PLUGIN_PATCHREVIEW_H
0009 
0010 #include <QPointer>
0011 
0012 #include <interfaces/iplugin.h>
0013 #include <interfaces/ipatchsource.h>
0014 #include <interfaces/ilanguagesupport.h>
0015 
0016 class PatchHighlighter;
0017 class PatchReviewToolViewFactory;
0018 
0019 class QTimer;
0020 
0021 namespace KDevelop {
0022 class IDocument;
0023 }
0024 namespace Sublime {
0025 class Area;
0026 }
0027 
0028 namespace Diff2
0029 {
0030 class KompareModelList;
0031 class DiffModel;
0032 }
0033 namespace Kompare
0034 {
0035 struct Info;
0036 }
0037 
0038 class DiffSettings;
0039 class PatchReviewPlugin;
0040 
0041 class PatchReviewPlugin : public KDevelop::IPlugin, public KDevelop::IPatchReview, public KDevelop::ILanguageSupport
0042 {
0043     Q_OBJECT
0044     Q_INTERFACES( KDevelop::IPatchReview )
0045     Q_INTERFACES( KDevelop::ILanguageSupport )
0046 
0047 public :
0048     explicit PatchReviewPlugin( QObject *parent, const QVariantList & = QVariantList() );
0049     ~PatchReviewPlugin() override;
0050     void unload() override;
0051 
0052     KDevelop::IPatchSource::Ptr patch() const {
0053         return m_patch;
0054     }
0055 
0056     Diff2::KompareModelList* modelList() const {
0057         return m_modelList.data();
0058     }
0059 
0060     QString name() const override {
0061       return QStringLiteral("diff");
0062     }
0063 
0064     KDevelop::ParseJob *createParseJob(const KDevelop::IndexedString &) override {
0065       return nullptr;
0066     }
0067 
0068     void seekHunk( bool forwards, const QUrl& file = QUrl() );
0069 
0070     void setPatch( KDevelop::IPatchSource* patch );
0071 
0072     void startReview( KDevelop::IPatchSource* patch, ReviewMode mode ) override;
0073 
0074     void finishReview(const QList<QUrl>& selection);
0075 
0076     QUrl urlForFileModel( const Diff2::DiffModel* model );
0077     QAction* finishReviewAction() const { return m_finishReview; }
0078 
0079     KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent) override;
0080 
0081 Q_SIGNALS:
0082     void startingNewReview();
0083     void patchChanged();
0084 
0085 public Q_SLOTS :
0086     //Does parts of the review-starting that are problematic to do directly in startReview, as they may open dialogs etc.
0087     void updateReview();
0088 
0089     void cancelReview();
0090     void notifyPatchChanged();
0091     void highlightPatch();
0092     void updateKompareModel();
0093     void forceUpdate();
0094     void areaChanged(Sublime::Area* area);
0095     void executeFileReviewAction();
0096 
0097 private Q_SLOTS :
0098     void documentClosed( KDevelop::IDocument* );
0099     void textDocumentCreated( KDevelop::IDocument* );
0100     void documentSaved( KDevelop::IDocument* );
0101     void closeReview();
0102 
0103 private:
0104     void switchToEmptyReviewArea();
0105 
0106     /// Makes sure that this working set is active only in the @p area, and that its name starts with "review".
0107     void setUniqueEmptyWorkingSet(Sublime::Area* area);
0108 
0109     void addHighlighting( const QUrl& file, KDevelop::IDocument* document = nullptr );
0110     void removeHighlighting( const QUrl& file = QUrl() );
0111 
0112     KDevelop::IPatchSource::Ptr m_patch;
0113 
0114     QTimer* m_updateKompareTimer;
0115 
0116     PatchReviewToolViewFactory* m_factory;
0117     QAction* m_finishReview;
0118 
0119     #if 0
0120     void determineState();
0121     #endif
0122 
0123     QPointer< DiffSettings > m_diffSettings;
0124     QScopedPointer< Kompare::Info > m_kompareInfo;
0125     QScopedPointer< Diff2::KompareModelList > m_modelList;
0126     uint m_depth = 0; // depth of the patch represented by m_modelList
0127     using HighlightMap = QMap<QUrl, QPointer<PatchHighlighter>>;
0128     HighlightMap m_highlighters;
0129     QString m_lastArea;
0130 
0131     friend class PatchReviewToolView; // to access slot exporterSelected();
0132 };
0133 
0134 #endif