| 61 | } |
| 62 | |
| 63 | void ClangRefactoring::fillContextMenu(ContextMenuExtension& extension, Context* context, QWidget* parent) |
| 64 | { |
| 65 | auto declContext = dynamic_cast<DeclarationContext*>(context); |
| 66 | if (!declContext) { |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | DUChainReadLocker lock; |
| 71 | |
| 72 | auto declaration = declContext->declaration().data(); |
| 73 | if (!declaration) { |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | QFileInfo fileInfo(declaration->topContext()->url().str()); |
| 78 | if (!fileInfo.isWritable()) { |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | auto action = new QAction(i18nc("@action", "Rename %1", declaration->qualifiedIdentifier().toString()), parent); |
| 83 | action->setData(QVariant::fromValue(IndexedDeclaration(declaration))); |
| 84 | action->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); |
| 85 | connect(action, &QAction::triggered, this, &ClangRefactoring::executeRenameAction); |
| 86 | |
| 87 | extension.addAction(ContextMenuExtension::RefactorGroup, action); |
| 88 | |
| 89 | if (!validCandidateToMoveIntoSource(declaration)) { |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | action = new QAction( |
| 94 | i18n("Create separate definition for %1", declaration->qualifiedIdentifier().toString()), parent); |
| 95 | action->setData(QVariant::fromValue(IndexedDeclaration(declaration))); |
| 96 | connect(action, &QAction::triggered, this, &ClangRefactoring::executeMoveIntoSourceAction); |
| 97 | extension.addAction(ContextMenuExtension::RefactorGroup, action); |
| 98 | } |
| 99 | |
| 100 | bool ClangRefactoring::validCandidateToMoveIntoSource(Declaration* decl) |
| 101 | { |
no test coverage detected