forked from qt-creator/qt-creator
CppEditor: Move two functions to cpptoolsreuse.{h,cpp}
They do not really depend on CppEditorWidget and will be re-used in a
follow-up change.
CppEditorWidget::identifierUnderCursor()
CppEditorWidget::findCanonicalMacro()
Change-Id: I553bb68694fb4b5f1baa331debf33ae234e3dedf
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
committed by
Erik Verbruggen
parent
a87fa1e223
commit
fa4e839bbe
@@ -30,16 +30,16 @@
|
||||
#include "cpptoolsreuse.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <texteditor/convenience.h>
|
||||
|
||||
#include <cplusplus/Overview.h>
|
||||
#include <cplusplus/LookupContext.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QSet>
|
||||
#include <QTextDocument>
|
||||
#include <QTextCursor>
|
||||
#include <QStringRef>
|
||||
|
||||
#include <QTextCursor>
|
||||
#include <QTextDocument>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
|
||||
@@ -200,4 +200,30 @@ void switchHeaderSource()
|
||||
Core::EditorManager::openEditor(otherFile);
|
||||
}
|
||||
|
||||
QString identifierUnderCursor(QTextCursor *cursor)
|
||||
{
|
||||
cursor->movePosition(QTextCursor::StartOfWord);
|
||||
cursor->movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
||||
return cursor->selectedText();
|
||||
}
|
||||
|
||||
const Macro *findCanonicalMacro(const QTextCursor &cursor, Document::Ptr document)
|
||||
{
|
||||
QTC_ASSERT(document, return 0);
|
||||
|
||||
int line, column;
|
||||
TextEditor::Convenience::convertPosition(cursor.document(), cursor.position(), &line, &column);
|
||||
|
||||
if (const Macro *macro = document->findMacroDefinitionAt(line)) {
|
||||
QTextCursor macroCursor = cursor;
|
||||
const QByteArray name = CppTools::identifierUnderCursor(¯oCursor).toUtf8();
|
||||
if (macro->name() == name)
|
||||
return macro;
|
||||
} else if (const Document::MacroUse *use = document->findMacroUseAt(cursor.position())) {
|
||||
return &use->macro();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // CppTools
|
||||
|
||||
Reference in New Issue
Block a user