From 4e1d92fddc4c03fe87415421fd70e59db23a9c29 Mon Sep 17 00:00:00 2001
From: Christian Kamm <christian.d.kamm@nokia.com>
Date: Wed, 17 Aug 2011 12:21:04 +0200
Subject: [PATCH] C++ function link: Disable link if target editor changes.

Change-Id: I7041f3c520e88b4376c5cbac08ed79aa44641f0f
Reviewed-on: http://codereview.qt.nokia.com/3088
Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com>
---
 src/plugins/cppeditor/cppeditor.cpp         | 17 +++++++++++++++++
 src/plugins/cppeditor/cppeditor.h           |  2 +-
 src/plugins/texteditor/refactoringchanges.h |  3 +--
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp
index c15f1e04e7c..8998fa3aa57 100644
--- a/src/plugins/cppeditor/cppeditor.cpp
+++ b/src/plugins/cppeditor/cppeditor.cpp
@@ -2302,6 +2302,14 @@ void CPPEditorWidget::onFunctionDeclDefLinkFound(QSharedPointer<FunctionDeclDefL
 {
     abortDeclDefLink();
     m_declDefLink = link;
+
+    // disable the link if content of the target editor changes
+    TextEditor::BaseTextEditorWidget *targetEditor =
+            TextEditor::RefactoringChanges::editorForFile(link->targetFile->fileName());
+    if (targetEditor) {
+        connect(targetEditor, SIGNAL(textChanged()),
+                this, SLOT(abortDeclDefLink()));
+    }
 }
 
 void CPPEditorWidget::applyDeclDefLinkChanges(bool jumpToMatch)
@@ -2317,6 +2325,15 @@ void CPPEditorWidget::abortDeclDefLink()
 {
     if (!m_declDefLink)
         return;
+
+    // undo connect from onFunctionDeclDefLinkFound
+    TextEditor::BaseTextEditorWidget *targetEditor =
+            TextEditor::RefactoringChanges::editorForFile(m_declDefLink->targetFile->fileName());
+    if (targetEditor) {
+        disconnect(targetEditor, SIGNAL(textChanged()),
+                   this, SLOT(abortDeclDefLink()));
+    }
+
     m_declDefLink->hideMarker(this);
     m_declDefLink.clear();
 }
diff --git a/src/plugins/cppeditor/cppeditor.h b/src/plugins/cppeditor/cppeditor.h
index d07e53d99fd..55278badf86 100644
--- a/src/plugins/cppeditor/cppeditor.h
+++ b/src/plugins/cppeditor/cppeditor.h
@@ -269,7 +269,7 @@ private:
     void abortRename();
 
     void applyDeclDefLinkChanges(bool jumpToMatch);
-    void abortDeclDefLink();
+    Q_SLOT void abortDeclDefLink();
 
     Link attemptFuncDeclDef(const QTextCursor &cursor,
                             const CPlusPlus::Document::Ptr &doc,
diff --git a/src/plugins/texteditor/refactoringchanges.h b/src/plugins/texteditor/refactoringchanges.h
index 6dae8c57d8b..4b2bc197645 100644
--- a/src/plugins/texteditor/refactoringchanges.h
+++ b/src/plugins/texteditor/refactoringchanges.h
@@ -120,11 +120,10 @@ public:
      */
     void activateEditor(const QString &fileName, int line, int column);
 
-
-private:
     static BaseTextEditorWidget *editorForFile(const QString &fileName,
                                          bool openIfClosed = false);
 
+private:
     static QList<QTextCursor> rangesToSelections(QTextDocument *document, const QList<Range> &ranges);
     virtual void indentSelection(const QTextCursor &selection,
                                  const QString &fileName,
-- 
GitLab