forked from qt-creator/qt-creator
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:
@@ -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);
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user