Commit b13df6e4 authored by loh.tar's avatar loh.tar
Browse files

Move reload protection from KPPluginView to GitWidget

parent 9dd6678f
......@@ -302,10 +302,13 @@ GitWidget::GitWidget(KateProject *project, KTextEditor::MainWindow *mainWindow,
this->layout()->addWidget(m_stackWidget);
this->layout()->setContentsMargins(0, 0, 0, 0);
// Setup update protection
m_updateTrigger.setSingleShot(true);
m_updateTrigger.setInterval(500);
connect(&m_updateTrigger, &QTimer::timeout, this, &GitWidget::slotUpdateStatus);
// Ensure we are looks good
QTimer::singleShot(0, this, [this] {
updateStatus();
});
QTimer::singleShot(0, this, &GitWidget::updateStatus);
}
GitWidget::~GitWidget()
......@@ -365,21 +368,18 @@ QProcess *GitWidget::gitp(const QStringList &arguments)
return git;
}
void GitWidget::updateStatus(bool untracked, bool submodules)
void GitWidget::updateStatus()
{
if (!isVisible()) {
return; // No need to update
}
auto args = QStringList{QStringLiteral("status"), QStringLiteral("-z")};
if (!untracked) {
args.append(QStringLiteral("-uno"));
} else {
args.append(QStringLiteral("-u"));
}
if (!submodules) {
args.append(QStringLiteral("--ignore-submodules"));
}
m_updateTrigger.start();
}
void GitWidget::slotUpdateStatus()
{
const auto args = QStringList{QStringLiteral("status"), QStringLiteral("-z"), QStringLiteral("-u"), QStringLiteral("--ignore-submodules")};
auto git = gitp(args);
connect(git, &QProcess::finished, this, [this, git](int exitCode, QProcess::ExitStatus es) {
......
......@@ -9,6 +9,7 @@
#include <QFutureWatcher>
#include <QPointer>
#include <QProcess>
#include <QTimer>
#include <QWidget>
#include "git/gitstatus.h"
......@@ -44,7 +45,13 @@ public:
~GitWidget();
bool eventFilter(QObject *o, QEvent *e) override;
void updateStatus(bool untracked = true, bool submodules = false);
/**
* Trigger the GitWidget to update itself.
* It is safe to call it repeatedly in a short time, due to delayed update after the last call.
*/
void updateStatus();
KTextEditor::MainWindow *mainWindow();
// will just proxy the message to the plugin view
......@@ -56,6 +63,12 @@ public:
}
private:
/**
* Helper to avoid multiple reloads at a time
* @see slotUpdateStatus
*/
QTimer m_updateTrigger;
QToolButton *m_menuBtn;
QToolButton *m_commitBtn;
QToolButton *m_pushBtn;
......@@ -109,6 +122,11 @@ private:
void hideCancel();
private Q_SLOTS:
/**
* Does the real update
*/
void slotUpdateStatus();
void parseStatusReady();
void openCommitChangesDialog(bool amend = false);
void handleClick(const QModelIndex &idx, ClickAction clickAction);
......
......@@ -128,13 +128,8 @@ KateProjectPluginView::KateProjectPluginView(KateProjectPlugin *plugin, KTextEdi
}
});
m_gitWidgetReloadTrigger.setSingleShot(true);
m_gitWidgetReloadTrigger.setInterval(500);
connect(&m_gitWidgetReloadTrigger, &QTimer::timeout, this, [this] {
slotUpdateStatus(true);
});
connect(&m_gitChangedWatcher, &QFileSystemWatcher::fileChanged, this, [this] {
m_gitWidgetReloadTrigger.start();
slotUpdateStatus(true);
});
/**
......@@ -483,7 +478,7 @@ void KateProjectPluginView::slotViewChanged()
void KateProjectPluginView::slotDocumentSaved()
{
m_gitWidgetReloadTrigger.start();
slotUpdateStatus(true);
}
void KateProjectPluginView::slotCurrentChanged(int index)
......
......@@ -345,12 +345,6 @@ private:
*/
QFileSystemWatcher m_gitChangedWatcher;
/**
* Helper to avoid multiple reloads at a time
* @see slotDocumentSaved
*/
QTimer m_gitWidgetReloadTrigger;
/**
* our plugin
*/
......
Supports Markdown
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