From 7b4895d7ec9c04df01837bbcbdd77779dd091cf7 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 18 Jul 2013 09:40:50 +0200 Subject: [PATCH] Remove TextEditor::RefactoringChanges::editorForFile This also fixes a bug with setting text cursor in InsertDefOperation in case of split editors (where the cursor could be set in a non-active editor on the target file). Change-Id: I1c011386537bc88a89d4d66bec79dfe06faac3c6 Reviewed-by: Erik Verbruggen Reviewed-by: Nikolai Kosjar --- src/plugins/cppeditor/cppeditor.cpp | 26 +++++++++---------- src/plugins/cppeditor/cppquickfixes.cpp | 4 +-- src/plugins/texteditor/refactoringchanges.cpp | 22 ++++++---------- src/plugins/texteditor/refactoringchanges.h | 3 +-- 4 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 17cf49bc866..2a375ac26f7 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -2188,14 +2188,14 @@ void CPPEditorWidget::onFunctionDeclDefLinkFound(QSharedPointertargetFile->fileName()); - if (targetEditor && targetEditor != this) { - connect(targetEditor, SIGNAL(textChanged()), - this, SLOT(abortDeclDefLink())); + Core::IDocument *targetDocument = Core::EditorManager::documentModel()->documentForFilePath( + m_declDefLink->targetFile->fileName()); + if (editorDocument() != targetDocument) { + if (TextEditor::BaseTextDocument *baseTextDocument = qobject_cast(targetDocument)) + connect(baseTextDocument->document(), SIGNAL(contentsChanged()), + this, SLOT(abortDeclDefLink())); } + } void CPPEditorWidget::applyDeclDefLinkChanges(bool jumpToMatch) @@ -2218,12 +2218,12 @@ void CPPEditorWidget::abortDeclDefLink() if (!m_declDefLink) return; - // undo connect from onFunctionDeclDefLinkFound - TextEditor::BaseTextEditorWidget *targetEditor = - TextEditor::RefactoringChanges::editorForFile(m_declDefLink->targetFile->fileName()); - if (targetEditor && targetEditor != this) { - disconnect(targetEditor, SIGNAL(textChanged()), - this, SLOT(abortDeclDefLink())); + Core::IDocument *targetDocument = Core::EditorManager::documentModel()->documentForFilePath( + m_declDefLink->targetFile->fileName()); + if (editorDocument() != targetDocument) { + if (TextEditor::BaseTextDocument *baseTextDocument = qobject_cast(targetDocument)) + disconnect(baseTextDocument->document(), SIGNAL(contentsChanged()), + this, SLOT(abortDeclDefLink())); } m_declDefLink->hideMarker(this); diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index fdc931e50a8..2b91bc5b802 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -2592,8 +2592,8 @@ public: m_loc.prefix().count(QLatin1String("\n")) + 2); c.movePosition(QTextCursor::EndOfLine); if (m_defpos == DefPosImplementationFile) { - if (BaseTextEditorWidget *editor = refactoring.editorForFile(m_loc.fileName())) - editor->setTextCursor(c); + if (targetFile->editor()) + targetFile->editor()->setTextCursor(c); } else { assistInterface()->editor()->setTextCursor(c); } diff --git a/src/plugins/texteditor/refactoringchanges.cpp b/src/plugins/texteditor/refactoringchanges.cpp index f5e43b32ac6..4d1cf136881 100644 --- a/src/plugins/texteditor/refactoringchanges.cpp +++ b/src/plugins/texteditor/refactoringchanges.cpp @@ -56,19 +56,6 @@ RefactoringChanges::RefactoringChanges(RefactoringChangesData *data) RefactoringChanges::~RefactoringChanges() {} -BaseTextEditorWidget *RefactoringChanges::editorForFile(const QString &fileName) -{ - Core::EditorManager *editorManager = Core::EditorManager::instance(); - - const QList editors = editorManager->editorsForFileName(fileName); - foreach (Core::IEditor *editor, editors) { - BaseTextEditorWidget *textEditor = qobject_cast(editor->widget()); - if (textEditor != 0) - return textEditor; - } - return 0; -} - QList > RefactoringChanges::rangesToSelections(QTextDocument *document, const QList &ranges) { @@ -190,7 +177,9 @@ RefactoringFile::RefactoringFile(const QString &fileName, const QSharedPointer editors = Core::EditorManager::documentModel()->editorsForFilePath(fileName); + if (!editors.isEmpty()) + m_editor = qobject_cast(editors.first()->widget()); } RefactoringFile::~RefactoringFile() @@ -251,6 +240,11 @@ QString RefactoringFile::fileName() const return m_fileName; } +BaseTextEditorWidget *RefactoringFile::editor() const +{ + return m_editor; +} + int RefactoringFile::position(unsigned line, unsigned column) const { QTC_ASSERT(line != 0, return -1); diff --git a/src/plugins/texteditor/refactoringchanges.h b/src/plugins/texteditor/refactoringchanges.h index 3a33901b0aa..f97056777e1 100644 --- a/src/plugins/texteditor/refactoringchanges.h +++ b/src/plugins/texteditor/refactoringchanges.h @@ -66,6 +66,7 @@ public: // mustn't use the cursor to change the document const QTextCursor cursor() const; QString fileName() const; + BaseTextEditorWidget *editor() const; // converts 1-based line and column into 0-based source offset int position(unsigned line, unsigned column) const; @@ -134,8 +135,6 @@ public: bool createFile(const QString &fileName, const QString &contents, bool reindent = true, bool openEditor = true) const; bool removeFile(const QString &fileName) const; - static BaseTextEditorWidget *editorForFile(const QString &fileName); - protected: explicit RefactoringChanges(RefactoringChangesData *data);