Commit 89ab7440 authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Move git to separate toolview



Git is now moved from inside the project-toolview to a separate toolview.
Signed-off-by: Waqar Ahmed's avatarWaqar Ahmed <waqar.17a@gmail.com>
parent a09af2c4
......@@ -201,8 +201,6 @@ BranchesDialog::BranchesDialog(QWidget *parent, KTextEditor::MainWindow *mainWin
m_treeView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_treeView->setSelectionMode(QTreeView::SingleSelection);
setHidden(true);
connect(&m_checkoutWatcher, &QFutureWatcher<GitUtils::CheckoutResult>::finished, this, &BranchesDialog::onCheckoutDone);
}
......@@ -226,8 +224,8 @@ void BranchesDialog::openDialog()
reselectFirst();
updateViewGeometry();
show();
setFocus();
exec();
}
bool BranchesDialog::eventFilter(QObject *obj, QEvent *event)
......
......@@ -6,6 +6,8 @@
#include <QFutureWatcher>
#include <QMenu>
#include "git/gitutils.h"
class QTreeView;
class QLineEdit;
class BranchesDialogModel;
......@@ -18,11 +20,6 @@ namespace KTextEditor
class MainWindow;
}
namespace GitUtils
{
struct CheckoutResult;
}
class BranchesDialog : public QMenu
{
Q_OBJECT
......
......@@ -4,6 +4,7 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "gitwidget.h"
#include "branchesdialog.h"
#include "gitcommitdialog.h"
#include "gitstatusmodel.h"
#include "kateproject.h"
......@@ -35,10 +36,10 @@
#include <KTextEditor/Message>
#include <KTextEditor/View>
GitWidget::GitWidget(KateProject *project, QWidget *parent, KTextEditor::MainWindow *mainWindow)
: QWidget(parent)
, m_project(project)
GitWidget::GitWidget(KateProject *project, KTextEditor::MainWindow *mainWindow, KateProjectPluginView *pluginView)
: m_project(project)
, m_mainWin(mainWindow)
, m_pluginView(pluginView)
{
m_commitBtn = new QPushButton(this);
m_treeView = new QTreeView(this);
......@@ -47,6 +48,7 @@ GitWidget::GitWidget(KateProject *project, QWidget *parent, KTextEditor::MainWin
buildMenu();
m_menuBtn = new QToolButton(this);
m_menuBtn->setAutoRaise(true);
m_menuBtn->setMenu(m_gitMenu);
m_menuBtn->setArrowType(Qt::NoArrow);
m_menuBtn->setStyleSheet(QStringLiteral("QToolButton::menu-indicator{ image: none; }"));
......@@ -464,7 +466,10 @@ void GitWidget::buildMenu()
getStatus();
}
});
m_gitMenu->addAction(i18n("Checkout Branch"), this, &GitWidget::checkoutBranch);
m_gitMenu->addAction(i18n("Checkout Branch"), this, [this] {
BranchesDialog bd(this, m_mainWin, m_project->baseDir());
bd.openDialog();
});
m_gitMenu->addAction(i18n("Stash"))->setMenu(stashMenu());
}
......
......@@ -23,6 +23,7 @@ class QItemSelection;
class QMenu;
class QToolButton;
class QTemporaryFile;
class KateProjectPluginView;
namespace KTextEditor
{
......@@ -34,7 +35,7 @@ class GitWidget : public QWidget
{
Q_OBJECT
public:
explicit GitWidget(KateProject *project, QWidget *parent = nullptr, KTextEditor::MainWindow *mainWindow = nullptr);
explicit GitWidget(KateProject *project, KTextEditor::MainWindow *mainWindow = nullptr, KateProjectPluginView *pluginView = nullptr);
bool eventFilter(QObject *o, QEvent *e) override;
void getStatus(bool untracked = true, bool submodules = false);
......@@ -59,6 +60,7 @@ private:
KTextEditor::MainWindow *m_mainWin;
QMenu *m_gitMenu;
std::vector<TempFileViewPair> m_filesOpenAtHEAD;
KateProjectPluginView *m_pluginView;
void buildMenu();
void initGitExe();
......
......@@ -7,6 +7,7 @@
#include "kateprojectpluginview.h"
#include "fileutil.h"
#include "gitwidget.h"
#include "kateprojectinfoviewindex.h"
#include <ktexteditor/application.h>
......@@ -55,6 +56,11 @@ KateProjectPluginView::KateProjectPluginView(KateProjectPlugin *plugin, KTextEdi
KTextEditor::MainWindow::Left,
QIcon::fromTheme(QStringLiteral("project-open")),
i18n("Projects"));
m_gitToolView.reset(m_mainWindow->createToolView(m_plugin,
QStringLiteral("kateprojectgit"),
KTextEditor::MainWindow::Left,
QIcon(QStringLiteral(":/icons/icons/sc-apps-git.svg")),
i18n("Git")));
m_toolInfoView = m_mainWindow->createToolView(m_plugin,
QStringLiteral("kateprojectinfo"),
KTextEditor::MainWindow::Bottom,
......@@ -76,9 +82,21 @@ KateProjectPluginView::KateProjectPluginView(KateProjectPlugin *plugin, KTextEdi
m_toolView->layout()->addItem(layout);
m_toolView->layout()->setSpacing(0);
m_projectsComboGit = new QComboBox(m_gitToolView.get());
m_projectsComboGit->setFrame(false);
m_gitToolView->layout()->addWidget(m_projectsComboGit);
m_stackedProjectViews = new QStackedWidget(m_toolView);
m_stackedProjectInfoViews = new QStackedWidget(m_toolInfoView);
m_stackedgitViews = new QStackedWidget(m_gitToolView.get());
connect(m_projectsCombo,
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
m_projectsComboGit,
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged));
connect(m_projectsComboGit, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this](int index) {
m_projectsCombo->setCurrentIndex(index);
});
connect(m_projectsCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &KateProjectPluginView::slotCurrentChanged);
connect(m_reloadButton, &QToolButton::clicked, this, &KateProjectPluginView::slotProjectReload);
......@@ -221,6 +239,7 @@ QPair<KateProjectView *, KateProjectInfoView *> KateProjectPluginView::viewForPr
*/
KateProjectView *view = new KateProjectView(this, project, m_mainWindow);
KateProjectInfoView *infoView = new KateProjectInfoView(this, project);
GitWidget *gitView = new GitWidget(project, m_mainWindow, this);
/**
* attach to toolboxes
......@@ -228,7 +247,9 @@ QPair<KateProjectView *, KateProjectInfoView *> KateProjectPluginView::viewForPr
*/
m_stackedProjectViews->addWidget(view);
m_stackedProjectInfoViews->addWidget(infoView);
m_stackedgitViews->addWidget(gitView);
m_projectsCombo->addItem(QIcon::fromTheme(QStringLiteral("project-open")), project->name(), project->fileName());
m_projectsComboGit->addItem(QIcon::fromTheme(QStringLiteral("project-open")), project->name(), project->fileName());
/**
* remember and return it
......@@ -357,6 +378,12 @@ void KateProjectPluginView::slotCurrentChanged(int index)
// trigger change of stacked widgets
m_stackedProjectViews->setCurrentIndex(index);
m_stackedProjectInfoViews->setCurrentIndex(index);
m_stackedgitViews->setCurrentIndex(index);
{
const QSignalBlocker blocker(m_projectsComboGit);
m_projectsComboGit->setCurrentIndex(index);
}
// update focus proxy + open currently selected document
if (QWidget *current = m_stackedProjectViews->currentWidget()) {
......@@ -369,6 +396,12 @@ void KateProjectPluginView::slotCurrentChanged(int index)
m_stackedProjectInfoViews->setFocusProxy(current);
}
// update git focus proxy + update status
if (QWidget *current = m_stackedgitViews->currentWidget()) {
m_stackedgitViews->setFocusProxy(current);
static_cast<GitWidget *>(current)->getStatus();
}
// project file name might have changed
Q_EMIT projectFileNameChanged();
Q_EMIT projectMapChanged();
......
......@@ -20,6 +20,8 @@
#include <KXMLGUIClient>
#include <memory>
class QAction;
class KateProjectPluginView : public QObject, public KXMLGUIClient
......@@ -234,6 +236,11 @@ private:
*/
QWidget *m_toolInfoView;
/**
* our projects info toolview
*/
std::unique_ptr<QWidget> m_gitToolView;
/**
* our cross-projects toolview
*/
......@@ -244,6 +251,11 @@ private:
*/
QComboBox *m_projectsCombo;
/**
* combo box with all loaded projects inside
*/
QComboBox *m_projectsComboGit;
/**
* Reload button
*/
......@@ -259,6 +271,11 @@ private:
*/
QStackedWidget *m_stackedProjectInfoViews;
/**
* stacked widget will all currently created git views
*/
QStackedWidget *m_stackedgitViews;
/**
* project => view
*/
......
......@@ -30,38 +30,20 @@ KateProjectView::KateProjectView(KateProjectPluginView *pluginView, KateProject
, m_treeView(new KateProjectViewTree(pluginView, project))
, m_filter(new KLineEdit())
, m_branchBtn(new QPushButton)
, m_gitBtn(new QPushButton)
, m_stackWidget(new QStackedWidget)
, m_gitWidget(new GitWidget(project, this, mainWindow))
{
/**
* layout tree view and co.
*/
QVBoxLayout *layout = new QVBoxLayout();
QHBoxLayout *btnLayout = new QHBoxLayout();
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->addLayout(btnLayout);
layout->addWidget(m_stackWidget);
// layout->addWidget(m_treeView);
layout->addWidget(m_branchBtn);
layout->addWidget(m_treeView);
layout->addWidget(m_filter);
setLayout(layout);
btnLayout->addWidget(m_branchBtn);
btnLayout->setStretch(0, 2);
btnLayout->addWidget(m_gitBtn);
m_stackWidget->addWidget(m_treeView);
m_stackWidget->addWidget(m_gitWidget);
connect(m_gitBtn, &QPushButton::clicked, this, [this] {
m_gitWidget->getStatus();
m_stackWidget->setCurrentWidget(m_gitWidget);
});
m_branchBtn->setText(GitUtils::getCurrentBranchName(m_project->baseDir()));
m_branchBtn->setIcon(QIcon(QStringLiteral(":/icons/icons/sc-apps-git.svg")));
m_gitBtn->setIcon(QIcon(QStringLiteral(":/icons/icons/sc-apps-git.svg")));
// let tree get focus for keyboard selection of file to open
setFocusProxy(m_treeView);
......@@ -85,10 +67,6 @@ KateProjectView::KateProjectView(KateProjectPluginView *pluginView, KateProject
m_branchBtn->setHidden(true);
m_branchesDialog = new BranchesDialog(this, mainWindow, m_project->baseDir());
connect(m_branchBtn, &QPushButton::clicked, this, [this] {
if (m_stackWidget->currentWidget() != m_treeView) {
m_stackWidget->setCurrentWidget(m_treeView);
return;
}
m_branchesDialog->openDialog();
});
connect(m_branchesDialog, &BranchesDialog::branchChanged, this, [this](const QString &branch) {
......@@ -102,7 +80,6 @@ KateProjectView::KateProjectView(KateProjectPluginView *pluginView, KateProject
if (m_branchChangedWatcher.files().isEmpty()) {
m_branchChangedWatcher.addPath(m_project->baseDir() + QStringLiteral("/.git/HEAD"));
}
m_gitWidget->getStatus();
} else {
if (!m_branchChangedWatcher.files().isEmpty()) {
m_branchChangedWatcher.removePaths(m_branchChangedWatcher.files());
......@@ -113,9 +90,6 @@ 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()
......
......@@ -17,8 +17,6 @@ class KLineEdit;
class QPushButton;
class KateProjectPluginView;
class BranchesDialog;
class QStackedWidget;
class GitWidget;
class QToolButton;
/**
......@@ -95,11 +93,6 @@ private:
*/
QPushButton *m_branchBtn;
/**
checkout branch button
*/
QPushButton *m_gitBtn;
/**
* The dialog which displays git branches
*/
......@@ -109,10 +102,6 @@ private:
* watches for changes to .git/HEAD
*/
QFileSystemWatcher m_branchChangedWatcher;
QStackedWidget *m_stackWidget;
GitWidget *m_gitWidget;
};
#endif
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