Commit 6b8c3aac authored by loh.tar's avatar loh.tar
Browse files

Update Git-Widget on file save

Witch this patch is the Git-Widget always up-todate regarding modified
files. No need to manual reload when the widget is already shown
parent e239cb31
......@@ -128,6 +128,8 @@ KateProjectPluginView::KateProjectPluginView(KateProjectPlugin *plugin, KTextEdi
}
});
m_gitWidgetReloadGuard.start();
/**
* create views for all already existing projects
* will create toolviews on demand!
......@@ -429,7 +431,8 @@ void KateProjectPluginView::slotViewChanged()
* update pointer, maybe disconnect before
*/
if (m_activeTextEditorView) {
m_activeTextEditorView->document()->disconnect(this);
// but only url changed
disconnect(m_activeTextEditorView->document(), &KTextEditor::Document::documentUrlChanged, this, &KateProjectPluginView::slotDocumentUrlChanged);
}
m_activeTextEditorView = activeView;
......@@ -445,12 +448,38 @@ void KateProjectPluginView::slotViewChanged()
*/
connect(m_activeTextEditorView->document(), &KTextEditor::Document::documentUrlChanged, this, &KateProjectPluginView::slotDocumentUrlChanged);
/**
* Watch any document, as long as we live, if it's saved
*/
connect(m_activeTextEditorView->document(),
&KTextEditor::Document::documentSavedOrUploaded,
this,
&KateProjectPluginView::slotDocumentSaved,
Qt::UniqueConnection);
/**
* trigger slot once
*/
slotDocumentUrlChanged(m_activeTextEditorView->document());
}
void KateProjectPluginView::slotDocumentSaved()
{
if (!m_gitWidgetReloadGuard.hasExpired(500)) {
return;
}
m_gitWidgetReloadGuard.restart();
// We need to wait to be sure all files are saved,
// or the update may to early and we miss something
QTimer::singleShot(500, this, [=] {
if (QWidget *current = m_stackedgitViews->currentWidget()) {
static_cast<GitWidget *>(current)->getStatus();
}
});
}
void KateProjectPluginView::slotCurrentChanged(int index)
{
// trigger change of stacked widgets
......
......@@ -9,6 +9,7 @@
#define _KATE_PROJECT_PLUGIN_VIEW_H_
#include <QComboBox>
#include <QElapsedTimer>
#include <QMenu>
#include <QPointer>
#include <QStackedWidget>
......@@ -288,6 +289,11 @@ private Q_SLOTS:
*/
void slotDocumentUrlChanged(KTextEditor::Document *document);
/**
* A helper to trigger an update of the git-widget.
*/
void slotDocumentSaved();
/**
* Show context menu
*/
......@@ -325,6 +331,12 @@ private:
QString currentWord() const;
private:
/**
* Helper to avoid multiple reloads at a time
* @see slotDocumentSaved
*/
QElapsedTimer m_gitWidgetReloadGuard;
/**
* 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