forked from qt-creator/qt-creator
VcsBaseClient: Fix going to default line number
Since we are being connected to the same done() signal twice,
the order of slot invocations started to play a role.
We were connecting done() signal to
VcsBaseEditorWidget::reportCommandFinished() first
and to VcsBaseEditorWidget::setPlainText() afterwards,
so they were executed exactly in this order. However, this
order isn't desired, as we need to set text first and
jump to line afterwards.
In order to fix it so that we don't rely on connection
order we handle setting the content and jumping into
the default line in one common handler.
Amends c767f193ce
Change-Id: Iea17476cc25b54759457710ecb6b6de2f0f5caf7
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
|
||||
#include <texteditor/textdocument.h>
|
||||
|
||||
#include <utils/commandline.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -81,8 +83,14 @@ VcsCommand *VcsBaseClientImpl::createCommand(const FilePath &workingDirectory,
|
||||
if (editor) // assume that the commands output is the important thing
|
||||
cmd->addFlags(VcsCommand::SilentOutput);
|
||||
} else if (editor) {
|
||||
connect(cmd, &VcsCommand::done, editor,
|
||||
[editor, cmd] { editor->setPlainText(cmd->cleanedStdOut()); });
|
||||
connect(cmd, &VcsCommand::done, editor, [editor, cmd] {
|
||||
if (cmd->result() != ProcessResult::FinishedWithSuccess) {
|
||||
editor->textDocument()->setPlainText(tr("Failed to retrieve data."));
|
||||
return;
|
||||
}
|
||||
editor->setPlainText(cmd->cleanedStdOut());
|
||||
editor->gotoDefaultLine();
|
||||
});
|
||||
}
|
||||
|
||||
return cmd;
|
||||
|
||||
@@ -1211,15 +1211,6 @@ DiffChunk VcsBaseEditorWidget::diffChunk(QTextCursor cursor) const
|
||||
return rc;
|
||||
}
|
||||
|
||||
void VcsBaseEditorWidget::reportCommandFinished(bool success)
|
||||
{
|
||||
hideProgressIndicator();
|
||||
if (!success)
|
||||
textDocument()->setPlainText(tr("Failed to retrieve data."));
|
||||
else if (d->m_defaultLineNumber >= 0)
|
||||
gotoLine(d->m_defaultLineNumber);
|
||||
}
|
||||
|
||||
const VcsBaseEditorParameters *VcsBaseEditor::findType(const VcsBaseEditorParameters *array,
|
||||
int arraySize,
|
||||
EditorContentType et)
|
||||
@@ -1394,9 +1385,7 @@ void VcsBaseEditorWidget::setCommand(VcsCommand *command)
|
||||
if (command) {
|
||||
d->m_progressIndicator = new ProgressIndicator(ProgressIndicatorSize::Large);
|
||||
d->m_progressIndicator->attachToWidget(this);
|
||||
connect(command, &VcsCommand::done, this, [this] {
|
||||
reportCommandFinished(d->m_command->result() == ProcessResult::FinishedWithSuccess);
|
||||
});
|
||||
connect(command, &VcsCommand::done, this, &VcsBaseEditorWidget::hideProgressIndicator);
|
||||
QTimer::singleShot(100, this, &VcsBaseEditorWidget::showProgressIndicator);
|
||||
}
|
||||
}
|
||||
@@ -1406,6 +1395,12 @@ void VcsBaseEditorWidget::setDefaultLineNumber(int line)
|
||||
d->m_defaultLineNumber = line;
|
||||
}
|
||||
|
||||
void VcsBaseEditorWidget::gotoDefaultLine()
|
||||
{
|
||||
if (d->m_defaultLineNumber >= 0)
|
||||
gotoLine(d->m_defaultLineNumber);
|
||||
}
|
||||
|
||||
void VcsBaseEditorWidget::setPlainText(const QString &text)
|
||||
{
|
||||
textDocument()->setPlainText(text);
|
||||
|
||||
@@ -192,6 +192,7 @@ public:
|
||||
|
||||
void setCommand(VcsCommand *command);
|
||||
void setDefaultLineNumber(int line);
|
||||
void gotoDefaultLine();
|
||||
|
||||
virtual void setPlainText(const QString &text);
|
||||
|
||||
@@ -205,9 +206,6 @@ signals:
|
||||
void diffChunkApplied(const VcsBase::DiffChunk &dc);
|
||||
void diffChunkReverted(const VcsBase::DiffChunk &dc);
|
||||
|
||||
public slots:
|
||||
void reportCommandFinished(bool success);
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent *e) override;
|
||||
void mouseMoveEvent(QMouseEvent *e) override;
|
||||
|
||||
Reference in New Issue
Block a user