summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@digia.com>2013-07-18 09:40:50 +0200
committerEike Ziller <eike.ziller@digia.com>2013-07-18 11:50:11 +0200
commit7b4895d7ec9c04df01837bbcbdd77779dd091cf7 (patch)
treea13b0127ccf38f93db948231eba3fc22b89f2890
parente782e723419dd0004e9d25cdf6878882ecaeb1f1 (diff)
downloadqt-creator-7b4895d7ec9c04df01837bbcbdd77779dd091cf7.tar.gz
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 <erik.verbruggen@digia.com> Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
-rw-r--r--src/plugins/cppeditor/cppeditor.cpp26
-rw-r--r--src/plugins/cppeditor/cppquickfixes.cpp4
-rw-r--r--src/plugins/texteditor/refactoringchanges.cpp22
-rw-r--r--src/plugins/texteditor/refactoringchanges.h3
4 files changed, 24 insertions, 31 deletions
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp
index 17cf49bc86..2a375ac26f 100644
--- a/src/plugins/cppeditor/cppeditor.cpp
+++ b/src/plugins/cppeditor/cppeditor.cpp
@@ -2188,14 +2188,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 && 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<TextEditor::BaseTextDocument *>(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<TextEditor::BaseTextDocument *>(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 fdc931e50a..2b91bc5b80 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 f5e43b32ac..4d1cf13688 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<Core::IEditor *> editors = editorManager->editorsForFileName(fileName);
- foreach (Core::IEditor *editor, editors) {
- BaseTextEditorWidget *textEditor = qobject_cast<BaseTextEditorWidget *>(editor->widget());
- if (textEditor != 0)
- return textEditor;
- }
- return 0;
-}
-
QList<QPair<QTextCursor, QTextCursor > > RefactoringChanges::rangesToSelections(QTextDocument *document,
const QList<Range> &ranges)
{
@@ -190,7 +177,9 @@ RefactoringFile::RefactoringFile(const QString &fileName, const QSharedPointer<R
, m_editorCursorPosition(-1)
, m_appliedOnce(false)
{
- m_editor = RefactoringChanges::editorForFile(fileName);
+ QList<Core::IEditor *> editors = Core::EditorManager::documentModel()->editorsForFilePath(fileName);
+ if (!editors.isEmpty())
+ m_editor = qobject_cast<TextEditor::BaseTextEditorWidget *>(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 3a33901b0a..f97056777e 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);