File indexing completed on 2024-12-01 08:17:32

0001 // clang-format off
0002 /*
0003  * KDiff3 - Text Diff And Merge Tool
0004  *
0005  * SPDX-FileCopyrightText: 2002-2011 Joachim Eibl, joachim.eibl at gmx.de
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 // clang-format on
0009 
0010 #ifndef SMALLDIALOGS_H
0011 #define SMALLDIALOGS_H
0012 
0013 #include "LineRef.h"
0014 #include "ui_opendialog.h"
0015 
0016 #include "Logging.h"
0017 
0018 #include <memory>
0019 
0020 #include <QCheckBox>
0021 #include <QComboBox>
0022 #include <QDialog>
0023 
0024 class Options;
0025 class QLineEdit;
0026 class KDiff3App;
0027 
0028 enum class eWindowIndex
0029 {
0030     None = 0,
0031     A,
0032     B,
0033     C,
0034     Output,
0035     invalid
0036 };
0037 
0038 class OpenDialog: public QDialog
0039 {
0040     Q_OBJECT
0041   public:
0042     OpenDialog( // krazy:exclude=explicit
0043         KDiff3App* pParent, const QString& n1, const QString& n2, const QString& n3,
0044         bool bMerge, const QString& outputName);
0045 
0046     [[nodiscard]] const QString getFileA() const { return dialogUi.lineA->currentText(); }
0047     [[nodiscard]] const QString getFileB() const { return dialogUi.lineB->currentText(); }
0048     [[nodiscard]] const QString getFileC() const { return dialogUi.lineC->currentText(); }
0049 
0050     [[nodiscard]] const QString getOutputFile() const { return dialogUi.lineOut->currentText(); }
0051 
0052     [[nodiscard]] bool merge() const { return dialogUi.mergeCheckBox->isChecked(); }
0053 
0054     void accept() override;
0055   private:
0056     void selectURL(QComboBox* pLine, bool bDir, qint32 i, bool bSave);
0057 
0058     void fixCurrentText(QComboBox* pCB);
0059     bool m_bInputFileNameChanged;
0060 
0061     enum SwapCopyActions
0062     {
0063         swapAB,
0064         swapBC,
0065         swapCA,
0066         copyAToOut,
0067         copyBToOut,
0068         copyCToOut,
0069         swapAOut,
0070         swapBOut,
0071         swapCOut,
0072     };
0073 
0074     Ui::OpenDialog dialogUi;
0075   private Q_SLOTS:
0076     void selectFileA();
0077     void selectFileB();
0078     void selectFileC();
0079     void selectDirA();
0080     void selectDirB();
0081     void selectDirC();
0082     void selectOutputName();
0083     void selectOutputDir();
0084     void internalSlot(qint32);
0085     void inputFilenameChanged();
0086     void slotSwapCopyNames(QAction*) const;
0087   Q_SIGNALS:
0088     void internalSignal(bool);
0089 };
0090 
0091 class FindDialog: public QDialog
0092 {
0093     Q_OBJECT
0094   public:
0095     explicit FindDialog(QWidget* pParent);
0096     void setVisible(bool) override;
0097 
0098     void restartFind();
0099     inline void nextWindow()
0100     {
0101         currentLine = 0;
0102         currentPos = 0;
0103 
0104         switch(currentWindow)
0105         {
0106             case eWindowIndex::invalid:
0107                 qCWarning(kdiffMain) << "FindDialog::nextWindow called with invalid state.";
0108                 Q_FALLTHROUGH();
0109             case eWindowIndex::None:
0110                 currentWindow = eWindowIndex::A;
0111                 break;
0112             case eWindowIndex::A:
0113                 currentWindow = eWindowIndex::B;
0114                 break;
0115             case eWindowIndex::B:
0116                 currentWindow = eWindowIndex::C;
0117                 break;
0118             case eWindowIndex::C:
0119                 currentWindow = eWindowIndex::Output;
0120                 break;
0121             case eWindowIndex::Output:
0122                 currentWindow = eWindowIndex::invalid;
0123                 break;
0124         }
0125     }
0126 
0127     inline eWindowIndex getCurrentWindow() { return currentWindow; }
0128 
0129   Q_SIGNALS:
0130     void findNext();
0131 
0132   public:
0133     QLineEdit* m_pSearchString;
0134     QCheckBox* m_pSearchInA;
0135     QCheckBox* m_pSearchInB;
0136     QCheckBox* m_pSearchInC;
0137     QCheckBox* m_pSearchInOutput;
0138     QCheckBox* m_pCaseSensitive;
0139 
0140     LineRef currentLine = 0;
0141     QtSizeType currentPos = 0;
0142 
0143   private:
0144     eWindowIndex currentWindow = eWindowIndex::None;
0145 };
0146 
0147 class RegExpTester: public QDialog
0148 {
0149     Q_OBJECT
0150   private:
0151     QLineEdit* m_pAutoMergeRegExpEdit;
0152     QLineEdit* m_pAutoMergeMatchResult;
0153     QLineEdit* m_pAutoMergeExampleEdit;
0154     QLineEdit* m_pHistoryStartRegExpEdit;
0155     QLineEdit* m_pHistoryStartMatchResult;
0156     QLineEdit* m_pHistoryStartExampleEdit;
0157     QLineEdit* m_pHistoryEntryStartRegExpEdit;
0158     QLineEdit* m_pHistorySortKeyOrderEdit;
0159     QLineEdit* m_pHistoryEntryStartExampleEdit;
0160     QLineEdit* m_pHistoryEntryStartMatchResult;
0161     QLineEdit* m_pHistorySortKeyResult;
0162 
0163   public:
0164     RegExpTester(QWidget* pParent, const QString& autoMergeRegExpToolTip, const QString& historyStartRegExpToolTip,
0165         const QString& historyEntryStartRegExpToolTip, const QString& historySortKeyOrderToolTip);
0166     void init(const QString& autoMergeRegExp, const QString& historyStartRegExp, const QString& historyEntryStartRegExp, const QString& sortKeyOrder);
0167     [[nodiscard]] QString autoMergeRegExp() const;
0168     [[nodiscard]] QString historyStartRegExp() const;
0169     [[nodiscard]] QString historyEntryStartRegExp() const;
0170     [[nodiscard]] QString historySortKeyOrder() const;
0171   public Q_SLOTS:
0172     void slotRecalc();
0173 };
0174 
0175 #endif