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>
This commit is contained in:
Eike Ziller
2013-07-18 09:40:50 +02:00
parent e782e72341
commit 7b4895d7ec
4 changed files with 24 additions and 31 deletions

View File

@@ -2188,14 +2188,14 @@ void CPPEditorWidget::onFunctionDeclDefLinkFound(QSharedPointer<FunctionDeclDefL
{ {
abortDeclDefLink(); abortDeclDefLink();
m_declDefLink = link; m_declDefLink = link;
Core::IDocument *targetDocument = Core::EditorManager::documentModel()->documentForFilePath(
// disable the link if content of the target editor changes m_declDefLink->targetFile->fileName());
TextEditor::BaseTextEditorWidget *targetEditor = if (editorDocument() != targetDocument) {
TextEditor::RefactoringChanges::editorForFile(link->targetFile->fileName()); if (TextEditor::BaseTextDocument *baseTextDocument = qobject_cast<TextEditor::BaseTextDocument *>(targetDocument))
if (targetEditor && targetEditor != this) { connect(baseTextDocument->document(), SIGNAL(contentsChanged()),
connect(targetEditor, SIGNAL(textChanged()),
this, SLOT(abortDeclDefLink())); this, SLOT(abortDeclDefLink()));
} }
} }
void CPPEditorWidget::applyDeclDefLinkChanges(bool jumpToMatch) void CPPEditorWidget::applyDeclDefLinkChanges(bool jumpToMatch)
@@ -2218,11 +2218,11 @@ void CPPEditorWidget::abortDeclDefLink()
if (!m_declDefLink) if (!m_declDefLink)
return; return;
// undo connect from onFunctionDeclDefLinkFound Core::IDocument *targetDocument = Core::EditorManager::documentModel()->documentForFilePath(
TextEditor::BaseTextEditorWidget *targetEditor = m_declDefLink->targetFile->fileName());
TextEditor::RefactoringChanges::editorForFile(m_declDefLink->targetFile->fileName()); if (editorDocument() != targetDocument) {
if (targetEditor && targetEditor != this) { if (TextEditor::BaseTextDocument *baseTextDocument = qobject_cast<TextEditor::BaseTextDocument *>(targetDocument))
disconnect(targetEditor, SIGNAL(textChanged()), disconnect(baseTextDocument->document(), SIGNAL(contentsChanged()),
this, SLOT(abortDeclDefLink())); this, SLOT(abortDeclDefLink()));
} }

View File

@@ -2592,8 +2592,8 @@ public:
m_loc.prefix().count(QLatin1String("\n")) + 2); m_loc.prefix().count(QLatin1String("\n")) + 2);
c.movePosition(QTextCursor::EndOfLine); c.movePosition(QTextCursor::EndOfLine);
if (m_defpos == DefPosImplementationFile) { if (m_defpos == DefPosImplementationFile) {
if (BaseTextEditorWidget *editor = refactoring.editorForFile(m_loc.fileName())) if (targetFile->editor())
editor->setTextCursor(c); targetFile->editor()->setTextCursor(c);
} else { } else {
assistInterface()->editor()->setTextCursor(c); assistInterface()->editor()->setTextCursor(c);
} }

View File

@@ -56,19 +56,6 @@ RefactoringChanges::RefactoringChanges(RefactoringChangesData *data)
RefactoringChanges::~RefactoringChanges() 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, QList<QPair<QTextCursor, QTextCursor > > RefactoringChanges::rangesToSelections(QTextDocument *document,
const QList<Range> &ranges) const QList<Range> &ranges)
{ {
@@ -190,7 +177,9 @@ RefactoringFile::RefactoringFile(const QString &fileName, const QSharedPointer<R
, m_editorCursorPosition(-1) , m_editorCursorPosition(-1)
, m_appliedOnce(false) , 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() RefactoringFile::~RefactoringFile()
@@ -251,6 +240,11 @@ QString RefactoringFile::fileName() const
return m_fileName; return m_fileName;
} }
BaseTextEditorWidget *RefactoringFile::editor() const
{
return m_editor;
}
int RefactoringFile::position(unsigned line, unsigned column) const int RefactoringFile::position(unsigned line, unsigned column) const
{ {
QTC_ASSERT(line != 0, return -1); QTC_ASSERT(line != 0, return -1);

View File

@@ -66,6 +66,7 @@ public:
// mustn't use the cursor to change the document // mustn't use the cursor to change the document
const QTextCursor cursor() const; const QTextCursor cursor() const;
QString fileName() const; QString fileName() const;
BaseTextEditorWidget *editor() const;
// converts 1-based line and column into 0-based source offset // converts 1-based line and column into 0-based source offset
int position(unsigned line, unsigned column) const; 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 createFile(const QString &fileName, const QString &contents, bool reindent = true, bool openEditor = true) const;
bool removeFile(const QString &fileName) const; bool removeFile(const QString &fileName) const;
static BaseTextEditorWidget *editorForFile(const QString &fileName);
protected: protected:
explicit RefactoringChanges(RefactoringChangesData *data); explicit RefactoringChanges(RefactoringChangesData *data);