forked from qt-creator/qt-creator
CppEditor: Insert/move member definition right after enclosing class
When triggering move or insert definition outside and no other class symbol is found in the file, the definition is moved or inserted right after the enclosing Class. Change-Id: I74ffa872015753ba7372e21b868d3cf7fa49e84a Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
committed by
Nikolai Kosjar
parent
6558df08d0
commit
a338851a10
@@ -161,15 +161,28 @@ InsertionLocation insertLocationForMethodDefinition(Symbol *symbol,
|
||||
}
|
||||
}
|
||||
|
||||
// ...failed, so return location at end of file
|
||||
// ...failed,
|
||||
// if class member try to get position right after class
|
||||
CppRefactoringFilePtr file = refactoring.file(fileName);
|
||||
unsigned line = 0, column = 0;
|
||||
if (Class *clazz = symbol->enclosingClass()) {
|
||||
if (symbol->fileName() == fileName.toUtf8()) {
|
||||
file->cppDocument()->translationUnit()->getPosition(clazz->endOffset(), &line, &column);
|
||||
if (line != 0) {
|
||||
++column; // Skipping the ";"
|
||||
return InsertionLocation(fileName, QLatin1String("\n\n"), QLatin1String(""),
|
||||
line, column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fall through: position at end of file
|
||||
const QTextDocument *doc = file->document();
|
||||
int pos = qMax(0, doc->characterCount() - 1);
|
||||
|
||||
//TODO watch for matching namespace
|
||||
//TODO watch for moc-includes
|
||||
|
||||
unsigned line, column;
|
||||
file->lineAndColumn(pos, &line, &column);
|
||||
return InsertionLocation(fileName, QLatin1String("\n\n"), QLatin1String("\n"), line, column);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user