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"); TextEditor::TextDocument * const doc = document("tooltips.cpp");
QVERIFY(doc); QVERIFY(doc);
const auto editor = qobject_cast<TextEditor::BaseTextEditor *>(EditorManager::currentEditor()); const auto editor = TextEditor::BaseTextEditor::currentTextEditor();
QVERIFY(editor); QVERIFY(editor);
QCOMPARE(editor->document(), doc); QCOMPARE(editor->document(), doc);
QVERIFY(editor->editorWidget()); QVERIFY(editor->editorWidget());

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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