Commit e99f9156 authored by Christian Kamm's avatar Christian Kamm

C++: Trigger function signature change via quick fix.

This way we don't need to override Return and Escape.

Change-Id: I1548118c06ee7338ba3dd9d84b82b9314ab16782
Reviewed-on: http://codereview.qt.nokia.com/4183Reviewed-by: default avatarLeandro T. C. Melo <leandro.melo@nokia.com>
parent b96b5606
......@@ -1473,10 +1473,9 @@ bool CPPEditorWidget::event(QEvent *e)
{
switch (e->type()) {
case QEvent::ShortcutOverride:
// handle escape manually if a rename or func decl/def link is active
// handle escape manually if a rename is active
if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape
&& (m_currentRenameSelection != NoCurrentRenameSelection
|| m_declDefLink)) {
&& m_currentRenameSelection != NoCurrentRenameSelection) {
e->accept();
return true;
}
......@@ -1551,23 +1550,6 @@ void CPPEditorWidget::contextMenuEvent(QContextMenuEvent *e)
void CPPEditorWidget::keyPressEvent(QKeyEvent *e)
{
if (m_currentRenameSelection == NoCurrentRenameSelection) {
// key handling for linked function declarations/definitions
if (m_declDefLink && m_declDefLink->isMarkerVisible()) {
switch (e->key()) {
case Qt::Key_Enter:
case Qt::Key_Return:
applyDeclDefLinkChanges(/*jump tp change*/ e->modifiers() & Qt::ShiftModifier);
e->accept();
return;
case Qt::Key_Escape:
abortDeclDefLink();
e->accept();
return;
default:
break;
}
}
TextEditor::BaseTextEditorWidget::keyPressEvent(e);
return;
}
......@@ -2151,6 +2133,11 @@ TextEditor::IAssistInterface *CPPEditorWidget::createAssistInterface(
return 0;
}
QSharedPointer<FunctionDeclDefLink> CPPEditorWidget::declDefLink() const
{
return m_declDefLink;
}
void CPPEditorWidget::onRefactorMarkerClicked(const TextEditor::RefactorMarker &marker)
{
if (marker.data.canConvert<FunctionDeclDefLink::Marker>())
......@@ -2207,7 +2194,6 @@ void CPPEditorWidget::onFunctionDeclDefLinkFound(QSharedPointer<FunctionDeclDefL
{
abortDeclDefLink();
m_declDefLink = link;
setProperty(Constants::FUNCTION_DECL_DEF_LINK_PROPERTY_NAME, true);
// disable the link if content of the target editor changes
TextEditor::BaseTextEditorWidget *targetEditor =
......@@ -2240,7 +2226,6 @@ void CPPEditorWidget::abortDeclDefLink()
this, SLOT(abortDeclDefLink()));
}
setProperty(Constants::FUNCTION_DECL_DEF_LINK_PROPERTY_NAME, false);
m_declDefLink->hideMarker(this);
m_declDefLink.clear();
}
......
......@@ -195,6 +195,9 @@ public:
virtual TextEditor::IAssistInterface *createAssistInterface(TextEditor::AssistKind kind,
TextEditor::AssistReason reason) const;
QSharedPointer<FunctionDeclDefLink> declDefLink() const;
void applyDeclDefLinkChanges(bool jumpToMatch);
Q_SIGNALS:
void outlineModelIndexChanged(const QModelIndex &index);
......@@ -268,7 +271,6 @@ private:
void finishRename();
void abortRename();
void applyDeclDefLinkChanges(bool jumpToMatch);
Q_SLOT void abortDeclDefLink();
Link attemptFuncDeclDef(const QTextCursor &cursor,
......
......@@ -65,8 +65,6 @@ const char * const WIZARD_TR_CATEGORY = QT_TRANSLATE_NOOP("CppEditor", "C++");
const char * const CPP_SNIPPETS_GROUP_ID = "C++";
const char * const FUNCTION_DECL_DEF_LINK_PROPERTY_NAME = "inCppFunctionDeclDefLink";
} // namespace Constants
} // namespace CppEditor
......
......@@ -33,6 +33,7 @@
#include "cppfunctiondecldeflink.h"
#include "cppeditor.h"
#include "cppquickfixassistant.h"
#include <cplusplus/CppRewriter.h>
#include <cplusplus/ASTPath.h>
......@@ -671,3 +672,48 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targ
return changes;
}
class ApplyDeclDefLinkOperation : public CppQuickFixOperation
{
public:
explicit ApplyDeclDefLinkOperation(
const QSharedPointer<const Internal::CppQuickFixAssistInterface> &interface,
const QSharedPointer<FunctionDeclDefLink> &link,
int priority = -1)
: CppQuickFixOperation(interface, priority)
, m_link(link)
{}
virtual void perform()
{
CPPEditorWidget *editor = assistInterface()->editor();
QSharedPointer<FunctionDeclDefLink> link = editor->declDefLink();
if (link != m_link)
return;
return editor->applyDeclDefLinkChanges(true);
}
protected:
virtual void performChanges(const CppTools::CppRefactoringFilePtr &, const CppTools::CppRefactoringChanges &)
{ /* never called since perform is overridden */ }
private:
QSharedPointer<FunctionDeclDefLink> m_link;
};
QList<CppQuickFixOperation::Ptr> ApplyDeclDefLinkChanges::match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
{
QList<CppQuickFixOperation::Ptr> results;
QSharedPointer<FunctionDeclDefLink> link = interface->editor()->declDefLink();
if (!link || !link->isMarkerVisible())
return results;
QSharedPointer<ApplyDeclDefLinkOperation> op(new ApplyDeclDefLinkOperation(interface, link));
op->setDescription(FunctionDeclDefLink::tr("Apply function signature changes"));
op->setPriority(0);
results += op;
return results;
}
......@@ -33,6 +33,8 @@
#ifndef CPPFUNCTIONDECLDEFLINK_H
#define CPPFUNCTIONDECLDEFLINK_H
#include "cppquickfix.h"
#include <cplusplus/CppDocument.h>
#include <cplusplus/ASTfwd.h>
......@@ -121,6 +123,13 @@ private:
friend class FunctionDeclDefLinkFinder;
};
class ApplyDeclDefLinkChanges: public CppQuickFixFactory
{
public:
virtual QList<CppQuickFixOperation::Ptr>
match(const QSharedPointer<const Internal::CppQuickFixAssistInterface> &interface);
};
} // namespace Internal
} // namespace CppEditor
......
......@@ -37,6 +37,7 @@
#include "cppinsertqtpropertymembers.h"
#include "cppquickfixassistant.h"
#include "cppcompleteswitch.h"
#include "cppfunctiondecldeflink.h"
#include <ASTVisitor.h>
#include <AST.h>
......@@ -1693,4 +1694,5 @@ void registerQuickFixes(ExtensionSystem::IPlugin *plugIn)
plugIn->addAutoReleasedObject(new InsertQtPropertyMembers);
plugIn->addAutoReleasedObject(new DeclFromDef);
plugIn->addAutoReleasedObject(new DefFromDecl);
plugIn->addAutoReleasedObject(new ApplyDeclDefLinkChanges);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment