File indexing completed on 2024-04-21 05:41:00

0001 /*
0002     SPDX-FileCopyrightText: 2011 Vishesh Yadav <vishesh3y@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef HGCOMMITDIALOG_H
0008 #define HGCOMMITDIALOG_H
0009 
0010 #include "statuslist.h"
0011 
0012 #include <QString>
0013 #include "dialogbase.h"
0014 
0015 
0016 class QPlainTextEdit;
0017 class QAction;
0018 class QMenu;
0019 class QLabel;
0020 class QLineEdit;
0021 class QSplitter;
0022 
0023 namespace KTextEditor {
0024     class View;
0025     class Document;
0026 };
0027 
0028 // TODO: Filter in HgStatusList.
0029 
0030 /**
0031  * Implements dialog for Commit changes. User is presented with a list of
0032  * changes/added/removed files, their diffs, a TextEdit to enter 
0033  * commit message, options to change/create/close branch and last 5 commit
0034  * messages.
0035  */
0036 class HgCommitDialog : public DialogBase
0037 {
0038     Q_OBJECT
0039 
0040 public:
0041     explicit HgCommitDialog(QWidget *parent = nullptr);
0042 
0043 private Q_SLOTS:
0044     /**
0045      * Shows diff of selected file in a KTextEditor widget when user selects
0046      * one of the entry in HgStatusList widget.
0047      */
0048     void slotItemSelectionChanged(const char status, const QString &fileName);
0049 
0050     /**
0051      * Will enable 'Ok' button of dialog if some message text is available or 
0052      * disables it.
0053      */
0054     void slotMessageChanged();
0055     void saveGeometry();
0056     void slotBranchActions(QAction *action);
0057 
0058     /**
0059      * Shows diff of whole working directory together in KTextEditor widget.
0060      * Equivalent to plain 'hg diff'
0061      */
0062     void slotInitDiffOutput();
0063     void slotInsertCopyMessage(QAction *action);
0064 
0065 private:
0066     QString getParentForLabel();
0067     void createCopyMessageMenu();
0068     void done(int r) override;
0069 
0070 private:
0071     QString                      m_hgBaseDir;
0072 
0073     KTextEditor::Document       *m_commitMessage;
0074     HgStatusList                *m_statusList;
0075 
0076     KTextEditor::View           *m_fileDiffView;
0077     KTextEditor::Document       *m_fileDiffDoc;
0078 
0079     QPushButton                 *m_branchButton;
0080     QPushButton                 *m_copyMessageButton;
0081 
0082     QAction                     *m_closeBranch;
0083     QAction                     *m_newBranch;
0084     QAction                     *m_useCurrentBranch;
0085     QMenu                       *m_branchMenu;
0086     QMenu                       *m_copyMessageMenu;
0087 
0088     QSplitter                   *m_verticalSplitter; // Divides file list and editors
0089     QSplitter                   *m_horizontalSplitter; // Divides commit editor and diff editor
0090 
0091     /** What will commit do with branch. 
0092      *
0093      * CloseBranch: Close the current branch
0094      * NewBranch  : Creates new branch for this commit
0095      * NoChanges  : No changes to branch are made. 
0096      */
0097     enum {CloseBranch, NewBranch, NoChanges} m_branchAction;
0098     QString m_newBranchName;
0099 };
0100 
0101 /**
0102  * Dialog which asks for the new branch name in commit dialog
0103  */
0104 class NewBranchDialog : public QDialog
0105 {
0106         Q_OBJECT
0107 
0108     public:
0109         explicit NewBranchDialog(QWidget *parent = nullptr);
0110         QString getBranchName() const;
0111 
0112     private Q_SLOTS:
0113         void slotTextChanged(const QString &text);
0114 
0115     private:
0116         QLabel            *m_errorLabel;
0117         QLineEdit         *m_branchNameInput;
0118         QStringList        m_branchList;
0119         QPushButton       *m_okButton;
0120 
0121 };
0122 
0123 #endif // HGCOMMITDIALOG_H
0124 
0125