void SimpleRefactoring::doContextMenu(KDevelop::ContextMenuExtension& extension, KDevelop::Context* context) { if(DeclarationContext* declContext = dynamic_cast<DeclarationContext*>(context)){ //Actions on declarations qRegisterMetaType<KDevelop::IndexedDeclaration>("KDevelop::IndexedDeclaration"); DUChainReadLocker lock(DUChain::lock()); Declaration* declaration = declContext->declaration().data(); if(declaration) { QFileInfo finfo(declaration->topContext()->url().str()); if (finfo.isWritable()) { QAction* action = new QAction(i18n("Rename %1", declaration->qualifiedIdentifier().toString()), this); action->setData(QVariant::fromValue(IndexedDeclaration(declaration))); action->setIcon(KIcon("edit-rename")); connect(action, SIGNAL(triggered(bool)), this, SLOT(executeRenameAction())); extension.addAction(ContextMenuExtension::RefactorGroup, action); if(declContext->use().isEmpty() && declaration->isFunctionDeclaration() && declaration->internalContext() && declaration->internalContext()->type() == DUContext::Other && !dynamic_cast<Cpp::TemplateDeclaration*>(declaration)) { AbstractFunctionDeclaration* funDecl = dynamic_cast<AbstractFunctionDeclaration*>(declaration); if(funDecl && !funDecl->isInline() && !dynamic_cast<FunctionDefinition*>(funDecl)) { //Is a candidate for moving into source QAction* action = new QAction(i18n("Create separate definition for %1", declaration->qualifiedIdentifier().toString()), this); action->setData(QVariant::fromValue(IndexedDeclaration(declaration))); // action->setIcon(KIcon("arrow-right")); connect(action, SIGNAL(triggered(bool)), this, SLOT(executeMoveIntoSourceAction())); extension.addAction(ContextMenuExtension::RefactorGroup, action); } }
void AdaptSignatureAssistant::textChanged(KTextEditor::View* view, const KTextEditor::Range& invocationRange, const QString& removedText) { reset(); m_view = view; //FIXME: update signature assistant to play well with the rename assistant KTextEditor::Range sigAssistRange = invocationRange; if (!removedText.isEmpty()) { sigAssistRange.setRange(sigAssistRange.start(), sigAssistRange.start()); } m_document = view->document()->url(); DUChainReadLocker lock(DUChain::lock(), 300); if(!lock.locked()) { qCDebug(CPP) << "failed to lock duchain in time"; return; } KTextEditor::Range simpleInvocationRange = KTextEditor::Range(sigAssistRange); Declaration* funDecl = getDeclarationAtCursor(simpleInvocationRange.start(), m_document); if(!funDecl || !funDecl->type<FunctionType>()) return; if(QtFunctionDeclaration* classFun = dynamic_cast<QtFunctionDeclaration*>(funDecl)) { if (classFun->isSignal()) { // do not offer to change signature of a signal, as the implementation will be generated by moc return; } } Declaration* otherSide = 0; FunctionDefinition* definition = dynamic_cast<FunctionDefinition*>(funDecl); if (definition) { m_editingDefinition = true; otherSide = definition->declaration(); } else if ((definition = FunctionDefinition::definition(funDecl))) { m_editingDefinition = false; otherSide = definition; } if (!otherSide) return; m_otherSideContext = DUContextPointer(DUChainUtils::getFunctionContext(otherSide)); if (!m_otherSideContext) return; m_declarationName = funDecl->identifier(); m_otherSideId = otherSide->id(); m_otherSideTopContext = ReferencedTopDUContext(otherSide->topContext()); m_oldSignature = getDeclarationSignature(otherSide, m_otherSideContext.data(), true); //Schedule an update, to make sure the ranges match DUChain::self()->updateContextForUrl(m_otherSideTopContext->url(), TopDUContext::AllDeclarationsAndContexts); }
QWidget* DUChainItemData::expandingWidget() const { DUChainReadLocker lock;; Declaration* decl = dynamic_cast<KDevelop::Declaration*>(m_item.m_item.data()); if( !decl || !decl->context() ) { return 0; } return decl->context()->createNavigationWidget( decl, decl->topContext(), m_item.m_project.isEmpty() ? QString() : ("<small><small>" + i18n("Project %1", m_item.m_project) + "<br></small></small>") ); }