Use convenience BaseTextEditor::currentEditor a bit more

Less noise in user code.

Change-Id: I26b8084a1ba531871d61b41db3294c81c08f7536
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
hjk
2024-07-16 09:04:36 +02:00
parent a97dae449d
commit bf2f623b89
7 changed files with 10 additions and 18 deletions

View File

@@ -772,7 +772,7 @@ void ClangdTestTooltips::test()
TextEditor::TextDocument * const doc = document("tooltips.cpp");
QVERIFY(doc);
const auto editor = qobject_cast<TextEditor::BaseTextEditor *>(EditorManager::currentEditor());
const auto editor = TextEditor::BaseTextEditor::currentTextEditor();
QVERIFY(editor);
QCOMPARE(editor->document(), doc);
QVERIFY(editor->editorWidget());

View File

@@ -371,8 +371,7 @@ void Manager::gotoLocations(const QList<QVariant> &list)
if (locations.size() > 1) {
// The symbol has multiple locations. Check if we are already at one location,
// and if so, cycle to the "next" one
auto textEditor = qobject_cast<TextEditor::BaseTextEditor *>(EditorManager::currentEditor());
if (textEditor) {
if (auto textEditor = TextEditor::BaseTextEditor::currentTextEditor()) {
// check if current cursor position is a known location of the symbol
const FilePath filePath = textEditor->document()->filePath();
int line;

View File

@@ -85,8 +85,8 @@ void EditMode::grabEditorManager(Utils::Id mode)
if (mode != id())
return;
if (EditorManager::currentEditor())
EditorManager::currentEditor()->widget()->setFocus();
if (IEditor *editor = EditorManager::currentEditor())
editor->widget()->setFocus();
}
} // namespace Core::Internal

View File

@@ -42,7 +42,6 @@
#include <QTreeView>
#include <algorithm>
#include <numeric>
using namespace CPlusPlus;
using namespace Utils;
@@ -57,14 +56,9 @@ template <class T> void resizeColumns(QTreeView *view)
view->resizeColumnToContents(column);
}
TextEditor::BaseTextEditor *currentEditor()
{
return qobject_cast<TextEditor::BaseTextEditor*>(Core::EditorManager::currentEditor());
}
FilePath fileInCurrentEditor()
{
if (TextEditor::BaseTextEditor *editor = currentEditor())
if (auto editor = TextEditor::BaseTextEditor::currentTextEditor())
return editor->document()->filePath();
return {};
}
@@ -1660,9 +1654,8 @@ void CppCodeModelInspectorDialog::refresh()
m_snapshotSelector->addItem(globalSnapshotTitle);
dumper.dumpSnapshot(globalSnapshot, globalSnapshotTitle, /*isGlobalSnapshot=*/ true);
TextEditor::BaseTextEditor *editor = currentEditor();
CppEditorDocumentHandle *cppEditorDocument = nullptr;
if (editor) {
if (auto editor = TextEditor::BaseTextEditor::currentTextEditor()) {
const FilePath editorFilePath = editor->document()->filePath();
cppEditorDocument = CppModelManager::cppEditorDocument(editorFilePath);
if (auto documentProcessor = CppModelManager::cppEditorDocumentProcessor(editorFilePath)) {

View File

@@ -406,7 +406,7 @@ void CppIncludeHierarchyWidget::perform()
{
showNoIncludeHierarchyLabel();
m_editor = qobject_cast<BaseTextEditor *>(EditorManager::currentEditor());
m_editor = BaseTextEditor::currentTextEditor();
if (!m_editor)
return;
@@ -471,7 +471,7 @@ void CppIncludeHierarchyWidget::syncFromEditorManager()
if (!m_toggleSync->isChecked())
return;
const auto editor = qobject_cast<BaseTextEditor *>(EditorManager::currentEditor());
const auto editor = BaseTextEditor::currentTextEditor();
if (!editor)
return;

View File

@@ -221,7 +221,7 @@ void CppTypeHierarchyWidget::perform()
m_showOldClass = false;
auto editor = qobject_cast<TextEditor::BaseTextEditor *>(Core::EditorManager::currentEditor());
auto editor = TextEditor::BaseTextEditor::currentTextEditor();
if (!editor) {
showNoTypeHierarchyLabel();
return;

View File

@@ -337,7 +337,7 @@ void DisassemblerAgent::updateLocationMarker()
// Center cursor.
if (EditorManager::currentDocument() == d->document)
if (auto textEditor = qobject_cast<BaseTextEditor *>(EditorManager::currentEditor()))
if (auto textEditor = BaseTextEditor::currentTextEditor())
textEditor->gotoLine(lineNumber);
}