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
|
||||
{
|
||||
return !isReloading();
|
||||
return state() == LoadOK;
|
||||
}
|
||||
|
||||
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(autoSave)
|
||||
|
||||
if (isReloading())
|
||||
if (state() != LoadOK)
|
||||
return false;
|
||||
|
||||
const bool ok = write(fileName, format(), plainText(), errorString);
|
||||
@@ -337,7 +337,7 @@ QString DiffEditorDocument::plainText() const
|
||||
void DiffEditorDocument::beginReload()
|
||||
{
|
||||
emit aboutToReload();
|
||||
m_isReloading = true;
|
||||
m_state = Reloading;
|
||||
emit changed();
|
||||
const bool blocked = blockSignals(true);
|
||||
setDiffFiles(QList<FileData>(), QString());
|
||||
@@ -347,7 +347,7 @@ void DiffEditorDocument::beginReload()
|
||||
|
||||
void DiffEditorDocument::endReload(bool success)
|
||||
{
|
||||
m_isReloading = false;
|
||||
m_state = success ? LoadOK : LoadFailed;
|
||||
emit changed();
|
||||
emit reloadFinished(success);
|
||||
}
|
||||
|
@@ -46,6 +46,12 @@ public:
|
||||
|
||||
DiffEditorController *controller() const;
|
||||
|
||||
enum State {
|
||||
LoadOK,
|
||||
Reloading,
|
||||
LoadFailed
|
||||
};
|
||||
|
||||
QString makePatch(int fileIndex, int chunkIndex,
|
||||
bool revert, bool addPrefix = false,
|
||||
const QString &overriddenFileName = QString()) const;
|
||||
@@ -76,7 +82,7 @@ public:
|
||||
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
|
||||
OpenResult open(QString *errorString, const QString &fileName,
|
||||
const QString &realFileName) override;
|
||||
bool isReloading() const { return m_isReloading; }
|
||||
State state() const { return m_state; }
|
||||
void beginReload();
|
||||
void endReload(bool success);
|
||||
|
||||
@@ -100,7 +106,7 @@ private:
|
||||
int m_contextLineCount;
|
||||
bool m_isContextLineCountForced;
|
||||
bool m_ignoreWhitespace;
|
||||
bool m_isReloading = false;
|
||||
State m_state = LoadOK;
|
||||
|
||||
friend class ::DiffEditor::DiffEditorController;
|
||||
};
|
||||
|
@@ -78,7 +78,7 @@ void DiffEditorWidgetController::setDocument(DiffEditorDocument *document)
|
||||
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;
|
||||
|
||||
@@ -87,7 +87,7 @@ void DiffEditorWidgetController::setDocument(DiffEditorDocument *document)
|
||||
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)
|
||||
return;
|
||||
|
@@ -117,15 +117,26 @@ void UnifiedView::setDocument(DiffEditorDocument *document)
|
||||
{
|
||||
QTC_ASSERT(m_widget, return);
|
||||
m_widget->setDocument(document);
|
||||
if (document && document->isReloading())
|
||||
if (!document)
|
||||
return;
|
||||
|
||||
switch (document->state()) {
|
||||
case DiffEditorDocument::Reloading:
|
||||
m_widget->clear(tr("Waiting for data..."));
|
||||
break;
|
||||
case DiffEditorDocument::LoadFailed:
|
||||
m_widget->clear(tr("Retrieving data failed."));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void UnifiedView::beginOperation()
|
||||
{
|
||||
QTC_ASSERT(m_widget, return);
|
||||
DiffEditorDocument *document = m_widget->diffDocument();
|
||||
if (document && !document->isReloading())
|
||||
if (document && document->state() == DiffEditorDocument::LoadOK)
|
||||
m_widget->saveState();
|
||||
m_widget->clear(tr("Waiting for data..."));
|
||||
}
|
||||
@@ -142,7 +153,7 @@ void UnifiedView::endOperation(bool success)
|
||||
if (success)
|
||||
m_widget->restoreState();
|
||||
else
|
||||
m_widget->clear(tr("Failed"));
|
||||
m_widget->clear(tr("Retrieving data failed."));
|
||||
}
|
||||
|
||||
void UnifiedView::setCurrentDiffFileIndex(int index)
|
||||
@@ -192,15 +203,26 @@ void SideBySideView::setDocument(DiffEditorDocument *document)
|
||||
{
|
||||
QTC_ASSERT(m_widget, return);
|
||||
m_widget->setDocument(document);
|
||||
if (document && document->isReloading())
|
||||
if (!document)
|
||||
return;
|
||||
|
||||
switch (document->state()) {
|
||||
case DiffEditorDocument::Reloading:
|
||||
m_widget->clear(tr("Waiting for data..."));
|
||||
break;
|
||||
case DiffEditorDocument::LoadFailed:
|
||||
m_widget->clear(tr("Retrieving data failed."));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SideBySideView::beginOperation()
|
||||
{
|
||||
QTC_ASSERT(m_widget, return);
|
||||
DiffEditorDocument *document = m_widget->diffDocument();
|
||||
if (document && !document->isReloading())
|
||||
if (document && document->state() == DiffEditorDocument::LoadOK)
|
||||
m_widget->saveState();
|
||||
m_widget->clear(tr("Waiting for data..."));
|
||||
}
|
||||
@@ -223,7 +245,7 @@ void SideBySideView::endOperation(bool success)
|
||||
if (success)
|
||||
m_widget->restoreState();
|
||||
else
|
||||
m_widget->clear(tr("Failed"));
|
||||
m_widget->clear(tr("Retrieving data failed."));
|
||||
}
|
||||
|
||||
void SideBySideView::setSync(bool sync)
|
||||
|
@@ -615,7 +615,7 @@ void SideBySideDiffEditorWidget::setDiff(const QList<FileData> &diffFileList,
|
||||
|
||||
m_controller.m_contextFileData = diffFileList;
|
||||
if (m_controller.m_contextFileData.isEmpty()) {
|
||||
const QString msg = tr("No difference");
|
||||
const QString msg = tr("No difference.");
|
||||
m_leftEditor->setPlainText(msg);
|
||||
m_rightEditor->setPlainText(msg);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user