forked from qt-creator/qt-creator
Pass this context object to the connect()
Otherwise when "this" instance gets deleted and the sender still exists, the lambda expression is still invoked for the deleted object. Task-number: QTCREATORBUG-20223 Change-Id: Ifd5c9e6ce1fe7fde71698c6683cdfcd7566e8d35 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -44,7 +44,7 @@ DescriptionWidgetWatcher::DescriptionWidgetWatcher(DiffEditorController *control
|
|||||||
m_widgets.append(widget);
|
m_widgets.append(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(EditorManager::instance(), &EditorManager::editorOpened,
|
connect(EditorManager::instance(), &EditorManager::editorOpened, this,
|
||||||
[this](IEditor *editor) {
|
[this](IEditor *editor) {
|
||||||
if (TextEditor::TextEditorWidget *widget = descriptionWidget(editor)) {
|
if (TextEditor::TextEditorWidget *widget = descriptionWidget(editor)) {
|
||||||
m_widgets.append(widget);
|
m_widgets.append(widget);
|
||||||
@@ -52,7 +52,7 @@ DescriptionWidgetWatcher::DescriptionWidgetWatcher(DiffEditorController *control
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(EditorManager::instance(), &EditorManager::editorAboutToClose,
|
connect(EditorManager::instance(), &EditorManager::editorAboutToClose, this,
|
||||||
[this](IEditor *editor) {
|
[this](IEditor *editor) {
|
||||||
if (TextEditor::TextEditorWidget *widget = descriptionWidget(editor)) {
|
if (TextEditor::TextEditorWidget *widget = descriptionWidget(editor)) {
|
||||||
emit descriptionWidgetRemoved(widget);
|
emit descriptionWidgetRemoved(widget);
|
||||||
|
@@ -227,7 +227,7 @@ void DiffEditorWidgetController::addCodePasterAction(QMenu *menu, int fileIndex,
|
|||||||
if (ExtensionSystem::PluginManager::getObject<CodePaster::Service>()) {
|
if (ExtensionSystem::PluginManager::getObject<CodePaster::Service>()) {
|
||||||
// optional code pasting service
|
// optional code pasting service
|
||||||
QAction *sendChunkToCodePasterAction = menu->addAction(tr("Send Chunk to CodePaster..."));
|
QAction *sendChunkToCodePasterAction = menu->addAction(tr("Send Chunk to CodePaster..."));
|
||||||
connect(sendChunkToCodePasterAction, &QAction::triggered, [this, fileIndex, chunkIndex]() {
|
connect(sendChunkToCodePasterAction, &QAction::triggered, this, [this, fileIndex, chunkIndex]() {
|
||||||
sendChunkToCodePaster(fileIndex, chunkIndex);
|
sendChunkToCodePaster(fileIndex, chunkIndex);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -253,7 +253,7 @@ bool DiffEditorWidgetController::fileNamesAreDifferent(int fileIndex) const
|
|||||||
void DiffEditorWidgetController::addApplyAction(QMenu *menu, int fileIndex, int chunkIndex)
|
void DiffEditorWidgetController::addApplyAction(QMenu *menu, int fileIndex, int chunkIndex)
|
||||||
{
|
{
|
||||||
QAction *applyAction = menu->addAction(tr("Apply Chunk..."));
|
QAction *applyAction = menu->addAction(tr("Apply Chunk..."));
|
||||||
connect(applyAction, &QAction::triggered, [this, fileIndex, chunkIndex]() {
|
connect(applyAction, &QAction::triggered, this, [this, fileIndex, chunkIndex]() {
|
||||||
patch(false, fileIndex, chunkIndex);
|
patch(false, fileIndex, chunkIndex);
|
||||||
});
|
});
|
||||||
applyAction->setEnabled(chunkExists(fileIndex, chunkIndex) && fileNamesAreDifferent(fileIndex));
|
applyAction->setEnabled(chunkExists(fileIndex, chunkIndex) && fileNamesAreDifferent(fileIndex));
|
||||||
@@ -262,7 +262,7 @@ void DiffEditorWidgetController::addApplyAction(QMenu *menu, int fileIndex, int
|
|||||||
void DiffEditorWidgetController::addRevertAction(QMenu *menu, int fileIndex, int chunkIndex)
|
void DiffEditorWidgetController::addRevertAction(QMenu *menu, int fileIndex, int chunkIndex)
|
||||||
{
|
{
|
||||||
QAction *revertAction = menu->addAction(tr("Revert Chunk..."));
|
QAction *revertAction = menu->addAction(tr("Revert Chunk..."));
|
||||||
connect(revertAction, &QAction::triggered, [this, fileIndex, chunkIndex]() {
|
connect(revertAction, &QAction::triggered, this, [this, fileIndex, chunkIndex]() {
|
||||||
patch(true, fileIndex, chunkIndex);
|
patch(true, fileIndex, chunkIndex);
|
||||||
});
|
});
|
||||||
revertAction->setEnabled(chunkExists(fileIndex, chunkIndex));
|
revertAction->setEnabled(chunkExists(fileIndex, chunkIndex));
|
||||||
|
@@ -166,7 +166,7 @@ SideDiffEditorWidget::SideDiffEditorWidget(QWidget *parent)
|
|||||||
settings.m_highlightBlocks = false;
|
settings.m_highlightBlocks = false;
|
||||||
SelectableTextEditorWidget::setDisplaySettings(settings);
|
SelectableTextEditorWidget::setDisplaySettings(settings);
|
||||||
|
|
||||||
connect(this, &TextEditorWidget::tooltipRequested, [this](const QPoint &point, int position) {
|
connect(this, &TextEditorWidget::tooltipRequested, this, [this](const QPoint &point, int position) {
|
||||||
const int block = document()->findBlock(position).blockNumber();
|
const int block = document()->findBlock(position).blockNumber();
|
||||||
const auto it = m_fileInfo.constFind(block);
|
const auto it = m_fileInfo.constFind(block);
|
||||||
if (it != m_fileInfo.constEnd())
|
if (it != m_fileInfo.constEnd())
|
||||||
@@ -648,10 +648,10 @@ SideBySideDiffEditorWidget::SideBySideDiffEditorWidget(QWidget *parent)
|
|||||||
};
|
};
|
||||||
|
|
||||||
setupHighlightController();
|
setupHighlightController();
|
||||||
connect(m_leftEditor, &SideDiffEditorWidget::gotDisplaySettings, setupHighlightController);
|
connect(m_leftEditor, &SideDiffEditorWidget::gotDisplaySettings, this, setupHighlightController);
|
||||||
|
|
||||||
m_rightEditor->verticalScrollBar()->setFocusProxy(m_leftEditor);
|
m_rightEditor->verticalScrollBar()->setFocusProxy(m_leftEditor);
|
||||||
connect(m_leftEditor, &SideDiffEditorWidget::gotFocus, [this]() {
|
connect(m_leftEditor, &SideDiffEditorWidget::gotFocus, this, [this]() {
|
||||||
if (m_rightEditor->verticalScrollBar()->focusProxy() == m_leftEditor)
|
if (m_rightEditor->verticalScrollBar()->focusProxy() == m_leftEditor)
|
||||||
return; // We already did it before.
|
return; // We already did it before.
|
||||||
|
|
||||||
@@ -672,7 +672,7 @@ SideBySideDiffEditorWidget::SideBySideDiffEditorWidget(QWidget *parent)
|
|||||||
// too. We bring back the original policy to keep tab focus working.
|
// too. We bring back the original policy to keep tab focus working.
|
||||||
m_leftEditor->setFocusPolicy(Qt::StrongFocus);
|
m_leftEditor->setFocusPolicy(Qt::StrongFocus);
|
||||||
});
|
});
|
||||||
connect(m_rightEditor, &SideDiffEditorWidget::gotFocus, [this]() {
|
connect(m_rightEditor, &SideDiffEditorWidget::gotFocus, this, [this]() {
|
||||||
// Unhack #1.
|
// Unhack #1.
|
||||||
m_rightEditor->verticalScrollBar()->setFocusProxy(nullptr);
|
m_rightEditor->verticalScrollBar()->setFocusProxy(nullptr);
|
||||||
// Unhack #2.
|
// Unhack #2.
|
||||||
|
@@ -304,7 +304,7 @@ void GitDiffEditorController::updateBranchList()
|
|||||||
VcsCommand *command = GitPlugin::client()->vcsExec(
|
VcsCommand *command = GitPlugin::client()->vcsExec(
|
||||||
workingDirectory, {"branch", noColorOption, "-a", "--contains", revision}, nullptr,
|
workingDirectory, {"branch", noColorOption, "-a", "--contains", revision}, nullptr,
|
||||||
false, 0, workingDirectory);
|
false, 0, workingDirectory);
|
||||||
connect(command, &VcsCommand::stdOutText, [this](const QString &text) {
|
connect(command, &VcsCommand::stdOutText, this, [this](const QString &text) {
|
||||||
const QString remotePrefix = "remotes/";
|
const QString remotePrefix = "remotes/";
|
||||||
const QString localPrefix = "<Local>";
|
const QString localPrefix = "<Local>";
|
||||||
const int prefixLength = remotePrefix.length();
|
const int prefixLength = remotePrefix.length();
|
||||||
@@ -830,12 +830,12 @@ void GitClient::chunkActionsRequested(QMenu *menu, int fileIndex, int chunkIndex
|
|||||||
|
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
QAction *stageChunkAction = menu->addAction(tr("Stage Chunk"));
|
QAction *stageChunkAction = menu->addAction(tr("Stage Chunk"));
|
||||||
connect(stageChunkAction, &QAction::triggered,
|
connect(stageChunkAction, &QAction::triggered, this,
|
||||||
[this, stageChunk, diffController, fileIndex, chunkIndex]() {
|
[this, stageChunk, diffController, fileIndex, chunkIndex]() {
|
||||||
stageChunk(diffController, fileIndex, chunkIndex, false);
|
stageChunk(diffController, fileIndex, chunkIndex, false);
|
||||||
});
|
});
|
||||||
QAction *unstageChunkAction = menu->addAction(tr("Unstage Chunk"));
|
QAction *unstageChunkAction = menu->addAction(tr("Unstage Chunk"));
|
||||||
connect(unstageChunkAction, &QAction::triggered,
|
connect(unstageChunkAction, &QAction::triggered, this,
|
||||||
[this, stageChunk, diffController, fileIndex, chunkIndex]() {
|
[this, stageChunk, diffController, fileIndex, chunkIndex]() {
|
||||||
stageChunk(diffController, fileIndex, chunkIndex, true);
|
stageChunk(diffController, fileIndex, chunkIndex, true);
|
||||||
});
|
});
|
||||||
@@ -1001,7 +1001,7 @@ void GitClient::log(const QString &workingDirectory, const QString &fileName,
|
|||||||
if (!argWidget) {
|
if (!argWidget) {
|
||||||
argWidget = new GitLogArgumentsWidget(settings(), editor->toolBar());
|
argWidget = new GitLogArgumentsWidget(settings(), editor->toolBar());
|
||||||
argWidget->setBaseArguments(args);
|
argWidget->setBaseArguments(args);
|
||||||
connect(argWidget, &VcsBaseEditorConfig::commandExecutionRequested,
|
connect(argWidget, &VcsBaseEditorConfig::commandExecutionRequested, this,
|
||||||
[=]() { this->log(workingDir, fileName, enableAnnotationContextMenu, args); });
|
[=]() { this->log(workingDir, fileName, enableAnnotationContextMenu, args); });
|
||||||
editor->setEditorConfig(argWidget);
|
editor->setEditorConfig(argWidget);
|
||||||
}
|
}
|
||||||
@@ -1087,7 +1087,7 @@ VcsBaseEditorWidget *GitClient::annotate(
|
|||||||
if (!argWidget) {
|
if (!argWidget) {
|
||||||
argWidget = new GitBlameArgumentsWidget(settings(), editor->toolBar());
|
argWidget = new GitBlameArgumentsWidget(settings(), editor->toolBar());
|
||||||
argWidget->setBaseArguments(extraOptions);
|
argWidget->setBaseArguments(extraOptions);
|
||||||
connect(argWidget, &VcsBaseEditorConfig::commandExecutionRequested,
|
connect(argWidget, &VcsBaseEditorConfig::commandExecutionRequested, this,
|
||||||
[=] {
|
[=] {
|
||||||
const int line = VcsBaseEditor::lineNumberOfCurrentEditor();
|
const int line = VcsBaseEditor::lineNumberOfCurrentEditor();
|
||||||
annotate(workingDir, file, revision, line, extraOptions);
|
annotate(workingDir, file, revision, line, extraOptions);
|
||||||
|
Reference in New Issue
Block a user