Commit cd940be9 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Add refresh + checkout option to gitwidget-menu

parent ac383bea
......@@ -69,6 +69,7 @@ target_sources(
tools/kateprojectcodeanalysisselector.cpp
git/gitutils.cpp
git/gitstatus.cpp
plugin.qrc
)
......
......@@ -14,6 +14,7 @@
#include <QProcess>
#include <QPushButton>
#include <QStringListModel>
#include <QToolButton>
#include <QTreeView>
#include <QVBoxLayout>
#include <QtConcurrentRun>
......@@ -30,10 +31,16 @@ GitWidget::GitWidget(KateProject *project, QWidget *parent, KTextEditor::MainWin
, m_project(project)
, m_mainWin(mainWindow)
{
m_menuBtn = new QPushButton(this);
m_menuBtn = new QToolButton(this);
m_commitBtn = new QPushButton(this);
m_treeView = new QTreeView(this);
buildMenu();
m_menuBtn->setMenu(m_gitMenu);
connect(m_menuBtn, &QToolButton::clicked, this, [this](bool) {
m_menuBtn->showMenu();
});
m_menuBtn->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
m_commitBtn->setIcon(QIcon(QStringLiteral(":/kxmlgui5/kateproject/git-commit-dark.svg")));
m_commitBtn->setText(i18n("Commit"));
......@@ -265,6 +272,17 @@ bool GitWidget::eventFilter(QObject *o, QEvent *e)
return QWidget::eventFilter(o, e);
}
void GitWidget::buildMenu()
{
m_gitMenu = new QMenu(this);
m_gitMenu->addAction(i18n("Refresh"), this, [this] {
if (m_project) {
getStatus(m_project->baseDir());
}
});
m_gitMenu->addAction(i18n("Checkout Branch"), this, &GitWidget::checkoutBranch);
}
void GitWidget::treeViewContextMenuEvent(QContextMenuEvent *e)
{
// discard=>git checkout -q -- /home/waqar/Projects/syntest/App.js
......
......@@ -13,6 +13,8 @@ class QStringListModel;
class GitStatusModel;
class KateProject;
class QItemSelection;
class QMenu;
class QToolButton;
namespace KTextEditor
{
......@@ -28,8 +30,7 @@ public:
bool eventFilter(QObject *o, QEvent *e) override;
private:
QPushButton *m_menuBtn;
QToolButton *m_menuBtn;
QPushButton *m_commitBtn;
QTreeView *m_treeView;
GitStatusModel *m_model;
......@@ -38,7 +39,9 @@ private:
QFutureWatcher<GitUtils::GitParsedStatus> m_gitStatusWatcher;
QString m_commitMessage;
KTextEditor::MainWindow *m_mainWin;
QMenu *m_gitMenu;
void buildMenu();
void getStatus(const QString &repo, bool untracked = true, bool submodules = false);
void stage(const QStringList &files, bool = false);
void unstage(const QStringList &files);
......@@ -52,6 +55,10 @@ private:
Q_SLOT void gitStatusReady(int exit, QProcess::ExitStatus);
Q_SLOT void parseStatusReady();
Q_SLOT void opencommitChangesDialog();
// signals
public:
Q_SIGNAL void checkoutBranch();
};
#endif // GITWIDGET_H
......@@ -113,6 +113,9 @@ KateProjectView::KateProjectView(KateProjectPluginView *pluginView, KateProject
connect(&m_branchChangedWatcher, &QFileSystemWatcher::fileChanged, this, [this] {
m_project->reload(true);
});
connect(m_gitWidget, &GitWidget::checkoutBranch, this, [this] {
m_branchesDialog->openDialog();
});
}
KateProjectView::~KateProjectView()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment