File indexing completed on 2024-04-28 05:49:05

0001 /*
0002     SPDX-FileCopyrightText: 2023 Waqar Ahmed <waqar.17a@gmail.com>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 #pragma once
0006 
0007 #include <QFutureWatcher>
0008 #include <QTimer>
0009 #include <QToolButton>
0010 #include <QUrl>
0011 
0012 namespace KTextEditor
0013 {
0014 class MainWindow;
0015 class View;
0016 }
0017 
0018 /**
0019  * @brief a pushbutton that shows the active git branch of the "active view"
0020  */
0021 class CurrentGitBranchButton : public QToolButton
0022 {
0023     Q_OBJECT
0024 public:
0025     explicit CurrentGitBranchButton(KTextEditor::MainWindow *mainWindow, QWidget *parent = nullptr);
0026     ~CurrentGitBranchButton() override;
0027 
0028     enum BranchType { Branch = 0, Commit, Tag };
0029     struct BranchResult {
0030         QString branch;
0031         BranchType type;
0032     };
0033 
0034     void refresh();
0035 
0036 private:
0037     void onViewChanged(KTextEditor::View *v);
0038     void hideButton();
0039     void onBranchFetched();
0040 
0041     QUrl m_activeUrl;
0042     QFutureWatcher<BranchResult> m_watcher;
0043     QTimer m_viewChangedTimer;
0044 };