| 271 | } |
| 272 | |
| 273 | BasicRefactoring::NameAndCollector BasicRefactoring::newNameForDeclaration( |
| 274 | const KDevelop::DeclarationPointer& declaration) |
| 275 | { |
| 276 | DUChainReadLocker lock; |
| 277 | if (!declaration) { |
| 278 | return {}; |
| 279 | } |
| 280 | |
| 281 | QSharedPointer<BasicRefactoringCollector> collector(new BasicRefactoringCollector(declaration.data())); |
| 282 | |
| 283 | Ui::RenameDialog renameDialog; |
| 284 | QDialog dialog; |
| 285 | renameDialog.setupUi(&dialog); |
| 286 | |
| 287 | UsesWidget uses(declaration.data(), collector); |
| 288 | |
| 289 | //So the context-links work |
| 290 | auto* navigationWidget = declaration->context()->createNavigationWidget(declaration.data()); |
| 291 | if (navigationWidget) |
| 292 | connect(&uses, &UsesWidget::navigateDeclaration, navigationWidget, |
| 293 | &AbstractNavigationWidget::navigateDeclaration); |
| 294 | |
| 295 | QString declarationName = declaration->toString(); |
| 296 | dialog.setWindowTitle(i18nc("@title:window Renaming some declaration", "Rename \"%1\"", declarationName)); |
| 297 | renameDialog.edit->setText(declaration->identifier().identifier().str()); |
| 298 | renameDialog.edit->selectAll(); |
| 299 | |
| 300 | renameDialog.tabWidget->addTab(&uses, i18nc("@title:tab", "Uses")); |
| 301 | if (navigationWidget) |
| 302 | renameDialog.tabWidget->addTab(navigationWidget, i18nc("@title:tab", "Declaration Info")); |
| 303 | lock.unlock(); |
| 304 | |
| 305 | if (dialog.exec() != QDialog::Accepted) |
| 306 | return {}; |
| 307 | |
| 308 | const auto text = renameDialog.edit->text().trimmed(); |
| 309 | RefactoringProgressDialog refactoringProgress(i18n("Renaming \"%1\" to \"%2\"", declarationName, |
| 310 | text), collector.data()); |
| 311 | if (!collector->isReady()) { |
| 312 | if (refactoringProgress.exec() != QDialog::Accepted) { // krazy:exclude=crashy |
| 313 | return {}; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | //TODO: input validation |
| 318 | return { |
| 319 | text, collector |
| 320 | }; |
| 321 | } |
| 322 | |
| 323 | DocumentChangeSet BasicRefactoring::renameCollectedDeclarations(KDevelop::BasicRefactoringCollector* collector, |
| 324 | const QString& replacementName, |
nothing calls this directly
no test coverage detected