forked from qt-creator/qt-creator
DiffEditor: Fix jumping to context line immediately on git show
Fixes: QTCREATORBUG-29081 Change-Id: I7a4658209f95e98cb485e725dee07074dae5c163 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -185,7 +185,7 @@ DiffEditor::DiffEditor()
|
|||||||
policy.setHorizontalPolicy(QSizePolicy::Expanding);
|
policy.setHorizontalPolicy(QSizePolicy::Expanding);
|
||||||
m_entriesComboBox->setSizePolicy(policy);
|
m_entriesComboBox->setSizePolicy(policy);
|
||||||
connect(m_entriesComboBox, &QComboBox::currentIndexChanged,
|
connect(m_entriesComboBox, &QComboBox::currentIndexChanged,
|
||||||
this, &DiffEditor::setCurrentDiffFileIndex);
|
this, &DiffEditor::currentIndexChanged);
|
||||||
m_toolBar->addWidget(m_entriesComboBox);
|
m_toolBar->addWidget(m_entriesComboBox);
|
||||||
|
|
||||||
QLabel *contextLabel = new QLabel(m_toolBar);
|
QLabel *contextLabel = new QLabel(m_toolBar);
|
||||||
@@ -309,7 +309,6 @@ TextEditorWidget *DiffEditor::sideEditorWidget(DiffSide side) const
|
|||||||
return m_sideBySideView->sideEditorWidget(side);
|
return m_sideBySideView->sideEditorWidget(side);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DiffEditor::documentHasChanged()
|
void DiffEditor::documentHasChanged()
|
||||||
{
|
{
|
||||||
GuardLocker guard(m_ignoreChanges);
|
GuardLocker guard(m_ignoreChanges);
|
||||||
@@ -319,7 +318,10 @@ void DiffEditor::documentHasChanged()
|
|||||||
currentView()->setDiff(diffFileList);
|
currentView()->setDiff(diffFileList);
|
||||||
|
|
||||||
m_entriesComboBox->clear();
|
m_entriesComboBox->clear();
|
||||||
for (const FileData &diffFile : diffFileList) {
|
const QString startupFile = m_document->startupFile();
|
||||||
|
int startupFileIndex = -1;
|
||||||
|
for (int i = 0, total = diffFileList.count(); i < total; ++i) {
|
||||||
|
const FileData &diffFile = diffFileList.at(i);
|
||||||
const DiffFileInfo &leftEntry = diffFile.fileInfo[LeftSide];
|
const DiffFileInfo &leftEntry = diffFile.fileInfo[LeftSide];
|
||||||
const DiffFileInfo &rightEntry = diffFile.fileInfo[RightSide];
|
const DiffFileInfo &rightEntry = diffFile.fileInfo[RightSide];
|
||||||
const QString leftShortFileName = FilePath::fromString(leftEntry.fileName).fileName();
|
const QString leftShortFileName = FilePath::fromString(leftEntry.fileName).fileName();
|
||||||
@@ -332,30 +334,20 @@ void DiffEditor::documentHasChanged()
|
|||||||
if (leftEntry.typeInfo.isEmpty() && rightEntry.typeInfo.isEmpty()) {
|
if (leftEntry.typeInfo.isEmpty() && rightEntry.typeInfo.isEmpty()) {
|
||||||
itemToolTip = leftEntry.fileName;
|
itemToolTip = leftEntry.fileName;
|
||||||
} else {
|
} else {
|
||||||
itemToolTip = Tr::tr("[%1] vs. [%2] %3")
|
itemToolTip = Tr::tr("[%1] vs. [%2] %3").arg(
|
||||||
.arg(leftEntry.typeInfo,
|
leftEntry.typeInfo, rightEntry.typeInfo, leftEntry.fileName);
|
||||||
rightEntry.typeInfo,
|
|
||||||
leftEntry.fileName);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (leftShortFileName == rightShortFileName) {
|
if (leftShortFileName == rightShortFileName)
|
||||||
itemText = leftShortFileName;
|
itemText = leftShortFileName;
|
||||||
} else {
|
else
|
||||||
itemText = Tr::tr("%1 vs. %2")
|
itemText = Tr::tr("%1 vs. %2").arg(leftShortFileName, rightShortFileName);
|
||||||
.arg(leftShortFileName,
|
|
||||||
rightShortFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (leftEntry.typeInfo.isEmpty() && rightEntry.typeInfo.isEmpty()) {
|
if (leftEntry.typeInfo.isEmpty() && rightEntry.typeInfo.isEmpty()) {
|
||||||
itemToolTip = Tr::tr("%1 vs. %2")
|
itemToolTip = Tr::tr("%1 vs. %2").arg(leftEntry.fileName, rightEntry.fileName);
|
||||||
.arg(leftEntry.fileName,
|
|
||||||
rightEntry.fileName);
|
|
||||||
} else {
|
} else {
|
||||||
itemToolTip = Tr::tr("[%1] %2 vs. [%3] %4")
|
itemToolTip = Tr::tr("[%1] %2 vs. [%3] %4").arg(leftEntry.typeInfo,
|
||||||
.arg(leftEntry.typeInfo,
|
leftEntry.fileName, rightEntry.typeInfo, rightEntry.fileName);
|
||||||
leftEntry.fileName,
|
|
||||||
rightEntry.typeInfo,
|
|
||||||
rightEntry.fileName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_entriesComboBox->addItem(itemText);
|
m_entriesComboBox->addItem(itemText);
|
||||||
@@ -365,7 +357,21 @@ void DiffEditor::documentHasChanged()
|
|||||||
rightEntry.fileName, Qt::UserRole + 1);
|
rightEntry.fileName, Qt::UserRole + 1);
|
||||||
m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1,
|
m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1,
|
||||||
itemToolTip, Qt::ToolTipRole);
|
itemToolTip, Qt::ToolTipRole);
|
||||||
|
if (startupFileIndex < 0) {
|
||||||
|
const bool isStartup = m_currentFileChunk.first.isEmpty()
|
||||||
|
&& m_currentFileChunk.second.isEmpty()
|
||||||
|
&& startupFile.endsWith(rightEntry.fileName);
|
||||||
|
const bool isSame = m_currentFileChunk.first == leftEntry.fileName
|
||||||
|
&& m_currentFileChunk.second == rightEntry.fileName;
|
||||||
|
if (isStartup || isSame)
|
||||||
|
startupFileIndex = i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentView()->endOperation();
|
||||||
|
m_currentFileChunk = {};
|
||||||
|
if (startupFileIndex >= 0)
|
||||||
|
setCurrentDiffFileIndex(startupFileIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditor::toggleDescription()
|
void DiffEditor::toggleDescription()
|
||||||
@@ -439,6 +445,7 @@ void DiffEditor::prepareForReload()
|
|||||||
m_whitespaceButtonAction->setChecked(m_document->ignoreWhitespace());
|
m_whitespaceButtonAction->setChecked(m_document->ignoreWhitespace());
|
||||||
}
|
}
|
||||||
currentView()->beginOperation();
|
currentView()->beginOperation();
|
||||||
|
currentView()->setMessage(Tr::tr("Waiting for data..."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditor::reloadHasFinished(bool success)
|
void DiffEditor::reloadHasFinished(bool success)
|
||||||
@@ -446,29 +453,8 @@ void DiffEditor::reloadHasFinished(bool success)
|
|||||||
if (!currentView())
|
if (!currentView())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
currentView()->endOperation(success);
|
if (!success)
|
||||||
|
currentView()->setMessage(Tr::tr("Retrieving data failed."));
|
||||||
int index = -1;
|
|
||||||
const QString startupFile = m_document->startupFile();
|
|
||||||
const QList<FileData> &diffFileList = m_document->diffFiles();
|
|
||||||
const int count = diffFileList.count();
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
const FileData &diffFile = diffFileList.at(i);
|
|
||||||
const DiffFileInfo &leftEntry = diffFile.fileInfo[LeftSide];
|
|
||||||
const DiffFileInfo &rightEntry = diffFile.fileInfo[RightSide];
|
|
||||||
if ((m_currentFileChunk.first.isEmpty()
|
|
||||||
&& m_currentFileChunk.second.isEmpty()
|
|
||||||
&& startupFile.endsWith(rightEntry.fileName))
|
|
||||||
|| (m_currentFileChunk.first == leftEntry.fileName
|
|
||||||
&& m_currentFileChunk.second == rightEntry.fileName)) {
|
|
||||||
index = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_currentFileChunk = {};
|
|
||||||
if (index >= 0)
|
|
||||||
setCurrentDiffFileIndex(index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditor::updateEntryToolTip()
|
void DiffEditor::updateEntryToolTip()
|
||||||
@@ -478,14 +464,19 @@ void DiffEditor::updateEntryToolTip()
|
|||||||
m_entriesComboBox->setToolTip(toolTip);
|
m_entriesComboBox->setToolTip(toolTip);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditor::setCurrentDiffFileIndex(int index)
|
void DiffEditor::currentIndexChanged(int index)
|
||||||
{
|
{
|
||||||
if (m_ignoreChanges.isLocked())
|
if (m_ignoreChanges.isLocked())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
GuardLocker guard(m_ignoreChanges);
|
||||||
|
setCurrentDiffFileIndex(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditor::setCurrentDiffFileIndex(int index)
|
||||||
|
{
|
||||||
QTC_ASSERT((index < 0) != (m_entriesComboBox->count() > 0), return);
|
QTC_ASSERT((index < 0) != (m_entriesComboBox->count() > 0), return);
|
||||||
|
|
||||||
GuardLocker guard(m_ignoreChanges);
|
|
||||||
m_currentDiffFileIndex = index;
|
m_currentDiffFileIndex = index;
|
||||||
currentView()->setCurrentDiffFileIndex(index);
|
currentView()->setCurrentDiffFileIndex(index);
|
||||||
|
|
||||||
@@ -563,7 +554,7 @@ void DiffEditor::addView(IDiffView *view)
|
|||||||
if (m_views.count() == 1)
|
if (m_views.count() == 1)
|
||||||
setCurrentView(view);
|
setCurrentView(view);
|
||||||
|
|
||||||
connect(view, &IDiffView::currentDiffFileIndexChanged, this, &DiffEditor::setCurrentDiffFileIndex);
|
connect(view, &IDiffView::currentDiffFileIndexChanged, this, &DiffEditor::currentIndexChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
IDiffView *DiffEditor::currentView() const
|
IDiffView *DiffEditor::currentView() const
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ private:
|
|||||||
void ignoreWhitespaceHasChanged();
|
void ignoreWhitespaceHasChanged();
|
||||||
void prepareForReload();
|
void prepareForReload();
|
||||||
void reloadHasFinished(bool success);
|
void reloadHasFinished(bool success);
|
||||||
|
void currentIndexChanged(int index);
|
||||||
void setCurrentDiffFileIndex(int index);
|
void setCurrentDiffFileIndex(int index);
|
||||||
void documentStateChanged();
|
void documentStateChanged();
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,6 @@ void UnifiedView::beginOperation()
|
|||||||
DiffEditorDocument *document = m_widget->diffDocument();
|
DiffEditorDocument *document = m_widget->diffDocument();
|
||||||
if (document && document->state() == DiffEditorDocument::LoadOK)
|
if (document && document->state() == DiffEditorDocument::LoadOK)
|
||||||
m_widget->saveState();
|
m_widget->saveState();
|
||||||
m_widget->clear(Tr::tr("Waiting for data..."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnifiedView::setDiff(const QList<FileData> &diffFileList)
|
void UnifiedView::setDiff(const QList<FileData> &diffFileList)
|
||||||
@@ -126,13 +125,15 @@ void UnifiedView::setDiff(const QList<FileData> &diffFileList)
|
|||||||
m_widget->setDiff(diffFileList);
|
m_widget->setDiff(diffFileList);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnifiedView::endOperation(bool success)
|
void UnifiedView::setMessage(const QString &message)
|
||||||
|
{
|
||||||
|
m_widget->clear(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnifiedView::endOperation()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_widget, return);
|
QTC_ASSERT(m_widget, return);
|
||||||
if (success)
|
m_widget->restoreState();
|
||||||
m_widget->restoreState();
|
|
||||||
else
|
|
||||||
m_widget->clear(Tr::tr("Retrieving data failed."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnifiedView::setCurrentDiffFileIndex(int index)
|
void UnifiedView::setCurrentDiffFileIndex(int index)
|
||||||
@@ -197,7 +198,6 @@ void SideBySideView::beginOperation()
|
|||||||
DiffEditorDocument *document = m_widget->diffDocument();
|
DiffEditorDocument *document = m_widget->diffDocument();
|
||||||
if (document && document->state() == DiffEditorDocument::LoadOK)
|
if (document && document->state() == DiffEditorDocument::LoadOK)
|
||||||
m_widget->saveState();
|
m_widget->saveState();
|
||||||
m_widget->clear(Tr::tr("Waiting for data..."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SideBySideView::setCurrentDiffFileIndex(int index)
|
void SideBySideView::setCurrentDiffFileIndex(int index)
|
||||||
@@ -212,13 +212,16 @@ void SideBySideView::setDiff(const QList<FileData> &diffFileList)
|
|||||||
m_widget->setDiff(diffFileList);
|
m_widget->setDiff(diffFileList);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SideBySideView::endOperation(bool success)
|
void SideBySideView::setMessage(const QString &message)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_widget, return);
|
QTC_ASSERT(m_widget, return);
|
||||||
if (success)
|
m_widget->clear(message);
|
||||||
m_widget->restoreState();
|
}
|
||||||
else
|
|
||||||
m_widget->clear(Tr::tr("Retrieving data failed."));
|
void SideBySideView::endOperation()
|
||||||
|
{
|
||||||
|
QTC_ASSERT(m_widget, return);
|
||||||
|
m_widget->restoreState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SideBySideView::setSync(bool sync)
|
void SideBySideView::setSync(bool sync)
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ public:
|
|||||||
virtual void beginOperation() = 0;
|
virtual void beginOperation() = 0;
|
||||||
virtual void setCurrentDiffFileIndex(int index) = 0;
|
virtual void setCurrentDiffFileIndex(int index) = 0;
|
||||||
virtual void setDiff(const QList<FileData> &diffFileList) = 0;
|
virtual void setDiff(const QList<FileData> &diffFileList) = 0;
|
||||||
virtual void endOperation(bool success) = 0;
|
virtual void setMessage(const QString &message) = 0;
|
||||||
|
virtual void endOperation() = 0;
|
||||||
|
|
||||||
virtual void setSync(bool) = 0;
|
virtual void setSync(bool) = 0;
|
||||||
|
|
||||||
@@ -81,7 +82,8 @@ public:
|
|||||||
void beginOperation() override;
|
void beginOperation() override;
|
||||||
void setCurrentDiffFileIndex(int index) override;
|
void setCurrentDiffFileIndex(int index) override;
|
||||||
void setDiff(const QList<FileData> &diffFileList) override;
|
void setDiff(const QList<FileData> &diffFileList) override;
|
||||||
void endOperation(bool success) override;
|
void setMessage(const QString &message) override;
|
||||||
|
void endOperation() override;
|
||||||
|
|
||||||
void setSync(bool sync) override;
|
void setSync(bool sync) override;
|
||||||
|
|
||||||
@@ -104,7 +106,8 @@ public:
|
|||||||
void beginOperation() override;
|
void beginOperation() override;
|
||||||
void setCurrentDiffFileIndex(int index) override;
|
void setCurrentDiffFileIndex(int index) override;
|
||||||
void setDiff(const QList<FileData> &diffFileList) override;
|
void setDiff(const QList<FileData> &diffFileList) override;
|
||||||
void endOperation(bool success) override;
|
void setMessage(const QString &message) override;
|
||||||
|
void endOperation() override;
|
||||||
|
|
||||||
void setSync(bool sync) override;
|
void setSync(bool sync) override;
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ Tasking::TaskItem VcsBaseDiffEditorController::postProcessTask()
|
|||||||
};
|
};
|
||||||
const auto onDiffProcessorDone = [this](const AsyncTask<QList<FileData>> &async) {
|
const auto onDiffProcessorDone = [this](const AsyncTask<QList<FileData>> &async) {
|
||||||
setDiffFiles(async.isResultAvailable() ? async.result() : QList<FileData>());
|
setDiffFiles(async.isResultAvailable() ? async.result() : QList<FileData>());
|
||||||
|
// TODO: We should set the right starting line here
|
||||||
};
|
};
|
||||||
const auto onDiffProcessorError = [this](const AsyncTask<QList<FileData>> &) {
|
const auto onDiffProcessorError = [this](const AsyncTask<QList<FileData>> &) {
|
||||||
setDiffFiles({});
|
setDiffFiles({});
|
||||||
|
|||||||
Reference in New Issue
Block a user