diff --git a/src/plugins/cppeditor/cppeditorplugin.cpp b/src/plugins/cppeditor/cppeditorplugin.cpp index e74e926d7f4..b9c66de4a1c 100644 --- a/src/plugins/cppeditor/cppeditorplugin.cpp +++ b/src/plugins/cppeditor/cppeditorplugin.cpp @@ -333,39 +333,39 @@ ExtensionSystem::IPlugin::ShutdownFlag CppEditorPlugin::aboutToShutdown() return SynchronousShutdown; } +static CPPEditorWidget *currentCppEditorWidget() +{ + return qobject_cast(EditorManager::currentEditor()->widget()); +} + void CppEditorPlugin::switchDeclarationDefinition() { - CPPEditorWidget *editor = qobject_cast(EditorManager::currentEditor()->widget()); - if (editor) - editor->switchDeclarationDefinition(/*inNextSplit*/ false); + if (CPPEditorWidget *editorWidget = currentCppEditorWidget()) + editorWidget->switchDeclarationDefinition(/*inNextSplit*/ false); } void CppEditorPlugin::openDeclarationDefinitionInNextSplit() { - CPPEditorWidget *editor = qobject_cast(EditorManager::currentEditor()->widget()); - if (editor) - editor->switchDeclarationDefinition(/*inNextSplit*/ true); + if (CPPEditorWidget *editorWidget = currentCppEditorWidget()) + editorWidget->switchDeclarationDefinition(/*inNextSplit*/ true); } void CppEditorPlugin::renameSymbolUnderCursor() { - CPPEditorWidget *editor = qobject_cast(EditorManager::currentEditor()->widget()); - if (editor) - editor->renameSymbolUnderCursor(); + if (CPPEditorWidget *editorWidget = currentCppEditorWidget()) + editorWidget->renameSymbolUnderCursor(); } void CppEditorPlugin::findUsages() { - CPPEditorWidget *editor = qobject_cast(EditorManager::currentEditor()->widget()); - if (editor) - editor->findUsages(); + if (CPPEditorWidget *editorWidget = currentCppEditorWidget()) + editorWidget->findUsages(); } void CppEditorPlugin::showPreProcessorDialog() { - CPPEditorWidget *editor = qobject_cast(EditorManager::currentEditor()->widget()); - if (editor) - editor->showPreProcessorWidget(); + if (CPPEditorWidget *editorWidget = currentCppEditorWidget()) + editorWidget->showPreProcessorWidget(); } void CppEditorPlugin::onTaskStarted(Core::Id type) @@ -395,14 +395,13 @@ void CppEditorPlugin::currentEditorChanged(IEditor *editor) if (!editor) return; - if (CPPEditorWidget *textEditor = qobject_cast(editor->widget())) - textEditor->semanticRehighlight(/*force = */ true); + if (CPPEditorWidget *editorWidget = currentCppEditorWidget()) + editorWidget->semanticRehighlight(/*force = */ true); } void CppEditorPlugin::openTypeHierarchy() { - CPPEditorWidget *editor = qobject_cast(EditorManager::currentEditor()->widget()); - if (editor) { + if (currentCppEditorWidget()) { NavigationWidget *navigation = NavigationWidget::instance(); navigation->activateSubWidget(Constants::TYPE_HIERARCHY_ID); emit typeHierarchyRequested(); @@ -411,9 +410,7 @@ void CppEditorPlugin::openTypeHierarchy() void CppEditorPlugin::openIncludeHierarchy() { - CPPEditorWidget *editor - = qobject_cast(Core::EditorManager::currentEditor()->widget()); - if (editor) { + if (currentCppEditorWidget()) { Core::NavigationWidget *navigation = Core::NavigationWidget::instance(); navigation->activateSubWidget(Core::Id(Constants::INCLUDE_HIERARCHY_ID)); emit includeHierarchyRequested();