forked from qt-creator/qt-creator
DiffEditor: Share "failed" state among multiple views
Change-Id: Id049ce8eafcb21d5e60fae17c47df8657c0e5779 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -205,7 +205,7 @@ QString DiffEditorDocument::fallbackSaveAsPath() const
|
|||||||
|
|
||||||
bool DiffEditorDocument::isSaveAsAllowed() const
|
bool DiffEditorDocument::isSaveAsAllowed() const
|
||||||
{
|
{
|
||||||
return !isReloading();
|
return state() == LoadOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DiffEditorDocument::save(QString *errorString, const QString &fileName, bool autoSave)
|
bool DiffEditorDocument::save(QString *errorString, const QString &fileName, bool autoSave)
|
||||||
@@ -213,7 +213,7 @@ bool DiffEditorDocument::save(QString *errorString, const QString &fileName, boo
|
|||||||
Q_UNUSED(errorString)
|
Q_UNUSED(errorString)
|
||||||
Q_UNUSED(autoSave)
|
Q_UNUSED(autoSave)
|
||||||
|
|
||||||
if (isReloading())
|
if (state() != LoadOK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const bool ok = write(fileName, format(), plainText(), errorString);
|
const bool ok = write(fileName, format(), plainText(), errorString);
|
||||||
@@ -337,7 +337,7 @@ QString DiffEditorDocument::plainText() const
|
|||||||
void DiffEditorDocument::beginReload()
|
void DiffEditorDocument::beginReload()
|
||||||
{
|
{
|
||||||
emit aboutToReload();
|
emit aboutToReload();
|
||||||
m_isReloading = true;
|
m_state = Reloading;
|
||||||
emit changed();
|
emit changed();
|
||||||
const bool blocked = blockSignals(true);
|
const bool blocked = blockSignals(true);
|
||||||
setDiffFiles(QList<FileData>(), QString());
|
setDiffFiles(QList<FileData>(), QString());
|
||||||
@@ -347,7 +347,7 @@ void DiffEditorDocument::beginReload()
|
|||||||
|
|
||||||
void DiffEditorDocument::endReload(bool success)
|
void DiffEditorDocument::endReload(bool success)
|
||||||
{
|
{
|
||||||
m_isReloading = false;
|
m_state = success ? LoadOK : LoadFailed;
|
||||||
emit changed();
|
emit changed();
|
||||||
emit reloadFinished(success);
|
emit reloadFinished(success);
|
||||||
}
|
}
|
||||||
|
@@ -46,6 +46,12 @@ public:
|
|||||||
|
|
||||||
DiffEditorController *controller() const;
|
DiffEditorController *controller() const;
|
||||||
|
|
||||||
|
enum State {
|
||||||
|
LoadOK,
|
||||||
|
Reloading,
|
||||||
|
LoadFailed
|
||||||
|
};
|
||||||
|
|
||||||
QString makePatch(int fileIndex, int chunkIndex,
|
QString makePatch(int fileIndex, int chunkIndex,
|
||||||
bool revert, bool addPrefix = false,
|
bool revert, bool addPrefix = false,
|
||||||
const QString &overriddenFileName = QString()) const;
|
const QString &overriddenFileName = QString()) const;
|
||||||
@@ -76,7 +82,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; }
|
State state() const { return m_state; }
|
||||||
void beginReload();
|
void beginReload();
|
||||||
void endReload(bool success);
|
void endReload(bool success);
|
||||||
|
|
||||||
@@ -100,7 +106,7 @@ private:
|
|||||||
int m_contextLineCount;
|
int m_contextLineCount;
|
||||||
bool m_isContextLineCountForced;
|
bool m_isContextLineCountForced;
|
||||||
bool m_ignoreWhitespace;
|
bool m_ignoreWhitespace;
|
||||||
bool m_isReloading = false;
|
State m_state = LoadOK;
|
||||||
|
|
||||||
friend class ::DiffEditor::DiffEditorController;
|
friend class ::DiffEditor::DiffEditorController;
|
||||||
};
|
};
|
||||||
|
@@ -78,7 +78,7 @@ void DiffEditorWidgetController::setDocument(DiffEditorDocument *document)
|
|||||||
disconnect(m_document, &IDocument::reloadFinished, this, &DiffEditorWidgetController::hideProgress);
|
disconnect(m_document, &IDocument::reloadFinished, this, &DiffEditorWidgetController::hideProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool wasRunning = m_document && m_document->isReloading();
|
const bool wasRunning = m_document && m_document->state() == DiffEditorDocument::Reloading;
|
||||||
|
|
||||||
m_document = document;
|
m_document = document;
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ void DiffEditorWidgetController::setDocument(DiffEditorDocument *document)
|
|||||||
connect(m_document, &IDocument::reloadFinished, this, &DiffEditorWidgetController::hideProgress);
|
connect(m_document, &IDocument::reloadFinished, this, &DiffEditorWidgetController::hideProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool isRunning = m_document && m_document->isReloading();
|
const bool isRunning = m_document && m_document->state() == DiffEditorDocument::Reloading;
|
||||||
|
|
||||||
if (wasRunning == isRunning)
|
if (wasRunning == isRunning)
|
||||||
return;
|
return;
|
||||||
|
@@ -117,15 +117,26 @@ void UnifiedView::setDocument(DiffEditorDocument *document)
|
|||||||
{
|
{
|
||||||
QTC_ASSERT(m_widget, return);
|
QTC_ASSERT(m_widget, return);
|
||||||
m_widget->setDocument(document);
|
m_widget->setDocument(document);
|
||||||
if (document && document->isReloading())
|
if (!document)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (document->state()) {
|
||||||
|
case DiffEditorDocument::Reloading:
|
||||||
m_widget->clear(tr("Waiting for data..."));
|
m_widget->clear(tr("Waiting for data..."));
|
||||||
|
break;
|
||||||
|
case DiffEditorDocument::LoadFailed:
|
||||||
|
m_widget->clear(tr("Retrieving data failed."));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnifiedView::beginOperation()
|
void UnifiedView::beginOperation()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_widget, return);
|
QTC_ASSERT(m_widget, return);
|
||||||
DiffEditorDocument *document = m_widget->diffDocument();
|
DiffEditorDocument *document = m_widget->diffDocument();
|
||||||
if (document && !document->isReloading())
|
if (document && document->state() == DiffEditorDocument::LoadOK)
|
||||||
m_widget->saveState();
|
m_widget->saveState();
|
||||||
m_widget->clear(tr("Waiting for data..."));
|
m_widget->clear(tr("Waiting for data..."));
|
||||||
}
|
}
|
||||||
@@ -142,7 +153,7 @@ void UnifiedView::endOperation(bool success)
|
|||||||
if (success)
|
if (success)
|
||||||
m_widget->restoreState();
|
m_widget->restoreState();
|
||||||
else
|
else
|
||||||
m_widget->clear(tr("Failed"));
|
m_widget->clear(tr("Retrieving data failed."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnifiedView::setCurrentDiffFileIndex(int index)
|
void UnifiedView::setCurrentDiffFileIndex(int index)
|
||||||
@@ -192,15 +203,26 @@ void SideBySideView::setDocument(DiffEditorDocument *document)
|
|||||||
{
|
{
|
||||||
QTC_ASSERT(m_widget, return);
|
QTC_ASSERT(m_widget, return);
|
||||||
m_widget->setDocument(document);
|
m_widget->setDocument(document);
|
||||||
if (document && document->isReloading())
|
if (!document)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (document->state()) {
|
||||||
|
case DiffEditorDocument::Reloading:
|
||||||
m_widget->clear(tr("Waiting for data..."));
|
m_widget->clear(tr("Waiting for data..."));
|
||||||
|
break;
|
||||||
|
case DiffEditorDocument::LoadFailed:
|
||||||
|
m_widget->clear(tr("Retrieving data failed."));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SideBySideView::beginOperation()
|
void SideBySideView::beginOperation()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_widget, return);
|
QTC_ASSERT(m_widget, return);
|
||||||
DiffEditorDocument *document = m_widget->diffDocument();
|
DiffEditorDocument *document = m_widget->diffDocument();
|
||||||
if (document && !document->isReloading())
|
if (document && document->state() == DiffEditorDocument::LoadOK)
|
||||||
m_widget->saveState();
|
m_widget->saveState();
|
||||||
m_widget->clear(tr("Waiting for data..."));
|
m_widget->clear(tr("Waiting for data..."));
|
||||||
}
|
}
|
||||||
@@ -223,7 +245,7 @@ void SideBySideView::endOperation(bool success)
|
|||||||
if (success)
|
if (success)
|
||||||
m_widget->restoreState();
|
m_widget->restoreState();
|
||||||
else
|
else
|
||||||
m_widget->clear(tr("Failed"));
|
m_widget->clear(tr("Retrieving data failed."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SideBySideView::setSync(bool sync)
|
void SideBySideView::setSync(bool sync)
|
||||||
|
@@ -615,7 +615,7 @@ void SideBySideDiffEditorWidget::setDiff(const QList<FileData> &diffFileList,
|
|||||||
|
|
||||||
m_controller.m_contextFileData = diffFileList;
|
m_controller.m_contextFileData = diffFileList;
|
||||||
if (m_controller.m_contextFileData.isEmpty()) {
|
if (m_controller.m_contextFileData.isEmpty()) {
|
||||||
const QString msg = tr("No difference");
|
const QString msg = tr("No difference.");
|
||||||
m_leftEditor->setPlainText(msg);
|
m_leftEditor->setPlainText(msg);
|
||||||
m_rightEditor->setPlainText(msg);
|
m_rightEditor->setPlainText(msg);
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user