File indexing completed on 2025-05-04 05:17:23

0001 /*
0002 Copyright (C) 2020 Hamed Masafi <hamed.masafi@gmail.com>
0003 SPDX-License-Identifier: GPL-3.0-or-later
0004 */
0005 
0006 #pragma once
0007 
0008 #include "appmainwindow.h"
0009 #include "ui_kommitmergeview.h"
0010 #include <diff.h>
0011 
0012 #include "libkommitwidgets_export.h"
0013 
0014 namespace Git
0015 {
0016 class Manager;
0017 };
0018 
0019 class SegmentsMapper;
0020 class QLabel;
0021 class LIBKOMMITWIDGETS_EXPORT MergeWindow : public AppMainWindow
0022 {
0023     Q_OBJECT
0024 public:
0025     enum Mode { NoParams, MergeByParams };
0026 
0027     explicit MergeWindow(Git::Manager *git, Mode mode = NoParams, QWidget *parent = nullptr);
0028     ~MergeWindow() override;
0029 
0030     void load();
0031 
0032     Q_REQUIRED_RESULT const QString &filePathLocal() const;
0033     void setFilePathLocal(const QString &newFilePathLocal);
0034 
0035     Q_REQUIRED_RESULT const QString &filePathRemote() const;
0036     void setFilePathRemote(const QString &newFilePathRemote);
0037 
0038     Q_REQUIRED_RESULT const QString &filePathBase() const;
0039     void setFilePathBase(const QString &newFilePathBase);
0040 
0041     Q_REQUIRED_RESULT const QString &filePathResult() const;
0042     void setFilePathResult(const QString &newFilePathResult);
0043 
0044 private Q_SLOTS:
0045     void fileSave();
0046     void fileOpen();
0047     void fillSegments();
0048 
0049     void actionKeepMine_clicked();
0050     void actionKeepTheir_clicked();
0051     void actionKeepMineBeforeTheir_clicked();
0052     void actionKeepTheirBeforeMine_clicked();
0053     void actionKeepMyFile_clicked();
0054     void actionKeepTheirFile_clicked();
0055     void actionGotoPrevDiff_clicked();
0056     void actionGotoNextDiff_clicked();
0057 
0058     void actionViewFiles_clicked();
0059     void actionViewBlocks_clicked();
0060 
0061     void codeEditors_customContextMenuRequested(QPoint pos);
0062 
0063     void slotPlainTextEditResultTextChanged();
0064     void slotPlainTextEditResultBlockSelected();
0065 
0066 private:
0067     Git::Manager *const mGit;
0068     Ui::MainMergeWidget m_ui;
0069     void updateResult();
0070     void initActions();
0071     void init();
0072     void doMergeAction(Diff::MergeType type);
0073     bool isFullyResolved() const;
0074 
0075     QList<Diff::MergeSegment *> mDiffs;
0076     QMenu *mCodeEditorContextMenu = nullptr;
0077     SegmentsMapper *mMapper = nullptr;
0078 
0079     QString mFilePathLocal;
0080     QString mFilePathRemote;
0081     QString mFilePathBase;
0082     QString mFilePathResult;
0083     QLabel *mConflictsLabel = nullptr;
0084     QAction *mActionBlocksView = nullptr;
0085     QAction *mActionFilesView = nullptr;
0086     QAction *actionKeepMine = nullptr;
0087     QAction *actionKeepTheir = nullptr;
0088     QAction *actionKeepMineBeforeTheir = nullptr;
0089     QAction *actionKeepTheirBeforeMine = nullptr;
0090     QAction *actionKeepMyFile = nullptr;
0091     QAction *actionKeepTheirFile = nullptr;
0092     QAction *actionGotoPrevDiff = nullptr;
0093     QAction *actionGotoNextDiff = nullptr;
0094     QAction *actionViewSameSizeBlocks = nullptr;
0095 
0096 protected:
0097     void closeEvent(QCloseEvent *event) override;
0098 };