forked from qt-creator/qt-creator
Show progress indicator while reloading diff
Change-Id: Ieefdb885682f01e0e1c8cec90f4769e832650a0c Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -328,6 +328,7 @@ QString DiffEditorDocument::plainText() const
|
|||||||
void DiffEditorDocument::beginReload()
|
void DiffEditorDocument::beginReload()
|
||||||
{
|
{
|
||||||
emit aboutToReload();
|
emit aboutToReload();
|
||||||
|
m_isReloading = true;
|
||||||
const bool blocked = blockSignals(true);
|
const bool blocked = blockSignals(true);
|
||||||
setDiffFiles(QList<FileData>(), QString());
|
setDiffFiles(QList<FileData>(), QString());
|
||||||
setDescription(QString());
|
setDescription(QString());
|
||||||
@@ -336,6 +337,7 @@ void DiffEditorDocument::beginReload()
|
|||||||
|
|
||||||
void DiffEditorDocument::endReload(bool success)
|
void DiffEditorDocument::endReload(bool success)
|
||||||
{
|
{
|
||||||
|
m_isReloading = false;
|
||||||
emit reloadFinished(success);
|
emit reloadFinished(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ public:
|
|||||||
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
|
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
|
||||||
OpenResult open(QString *errorString, const QString &fileName,
|
OpenResult open(QString *errorString, const QString &fileName,
|
||||||
const QString &realFileName) override;
|
const QString &realFileName) override;
|
||||||
|
bool isReloading() const { return m_isReloading; }
|
||||||
|
|
||||||
QString plainText() const;
|
QString plainText() const;
|
||||||
|
|
||||||
@@ -101,6 +102,7 @@ private:
|
|||||||
int m_contextLineCount;
|
int m_contextLineCount;
|
||||||
bool m_isContextLineCountForced;
|
bool m_isContextLineCountForced;
|
||||||
bool m_ignoreWhitespace;
|
bool m_ignoreWhitespace;
|
||||||
|
bool m_isReloading = false;
|
||||||
|
|
||||||
friend class ::DiffEditor::DiffEditorController;
|
friend class ::DiffEditor::DiffEditorController;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
#include <cpaster/codepasterservice.h>
|
#include <cpaster/codepasterservice.h>
|
||||||
|
|
||||||
|
#include <utils/progressindicator.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@@ -56,11 +57,64 @@ DiffEditorWidgetController::DiffEditorWidgetController(QWidget *diffEditorWidget
|
|||||||
: QObject(diffEditorWidget)
|
: QObject(diffEditorWidget)
|
||||||
, m_diffEditorWidget(diffEditorWidget)
|
, m_diffEditorWidget(diffEditorWidget)
|
||||||
{
|
{
|
||||||
|
m_timer.setSingleShot(true);
|
||||||
|
m_timer.setInterval(100);
|
||||||
|
connect(&m_timer, &QTimer::timeout, this, &DiffEditorWidgetController::showProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditorWidgetController::setDocument(DiffEditorDocument *document)
|
void DiffEditorWidgetController::setDocument(DiffEditorDocument *document)
|
||||||
{
|
{
|
||||||
|
if (!m_progressIndicator) {
|
||||||
|
m_progressIndicator = new Utils::ProgressIndicator(Utils::ProgressIndicator::Large);
|
||||||
|
m_progressIndicator->attachToWidget(m_diffEditorWidget);
|
||||||
|
m_progressIndicator->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_document == document)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (m_document) {
|
||||||
|
disconnect(m_document, &IDocument::aboutToReload, this, &DiffEditorWidgetController::scheduleShowProgress);
|
||||||
|
disconnect(m_document, &IDocument::reloadFinished, this, &DiffEditorWidgetController::hideProgress);
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool wasRunning = m_document && m_document->isReloading();
|
||||||
|
|
||||||
m_document = document;
|
m_document = document;
|
||||||
|
|
||||||
|
if (m_document) {
|
||||||
|
connect(m_document, &IDocument::aboutToReload, this, &DiffEditorWidgetController::scheduleShowProgress);
|
||||||
|
connect(m_document, &IDocument::reloadFinished, this, &DiffEditorWidgetController::hideProgress);
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool isRunning = m_document && m_document->isReloading();
|
||||||
|
|
||||||
|
if (wasRunning == isRunning)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (isRunning)
|
||||||
|
scheduleShowProgress();
|
||||||
|
else
|
||||||
|
hideProgress();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditorWidgetController::scheduleShowProgress()
|
||||||
|
{
|
||||||
|
m_timer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditorWidgetController::showProgress()
|
||||||
|
{
|
||||||
|
m_timer.stop();
|
||||||
|
if (m_progressIndicator)
|
||||||
|
m_progressIndicator->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditorWidgetController::hideProgress()
|
||||||
|
{
|
||||||
|
m_timer.stop();
|
||||||
|
if (m_progressIndicator)
|
||||||
|
m_progressIndicator->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditorWidgetController::patch(bool revert)
|
void DiffEditorWidgetController::patch(bool revert)
|
||||||
|
|||||||
@@ -29,11 +29,13 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QTextCharFormat>
|
#include <QTextCharFormat>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QMenu)
|
QT_FORWARD_DECLARE_CLASS(QMenu)
|
||||||
|
|
||||||
namespace Core { class IDocument; }
|
namespace Core { class IDocument; }
|
||||||
namespace TextEditor { class FontSettings; }
|
namespace TextEditor { class FontSettings; }
|
||||||
|
namespace Utils { class ProgressIndicator; }
|
||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
|
|
||||||
@@ -74,12 +76,19 @@ private:
|
|||||||
bool setAndVerifyIndexes(QMenu *menu, int diffFileIndex, int chunkIndex);
|
bool setAndVerifyIndexes(QMenu *menu, int diffFileIndex, int chunkIndex);
|
||||||
bool fileNamesAreDifferent() const;
|
bool fileNamesAreDifferent() const;
|
||||||
|
|
||||||
|
void scheduleShowProgress();
|
||||||
|
void showProgress();
|
||||||
|
void hideProgress();
|
||||||
|
|
||||||
QWidget *m_diffEditorWidget;
|
QWidget *m_diffEditorWidget;
|
||||||
|
|
||||||
DiffEditorDocument *m_document = nullptr;
|
DiffEditorDocument *m_document = nullptr;
|
||||||
|
|
||||||
int m_contextMenuFileIndex = -1;
|
int m_contextMenuFileIndex = -1;
|
||||||
int m_contextMenuChunkIndex = -1;
|
int m_contextMenuChunkIndex = -1;
|
||||||
|
|
||||||
|
Utils::ProgressIndicator *m_progressIndicator = nullptr;
|
||||||
|
QTimer m_timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user