Commit 90e7bac4 authored by Roberto Raggi's avatar Roberto Raggi

Made `Rename Symbol under Cursor' a command/action.

parent 2356bdc7
......@@ -543,9 +543,6 @@ CPPEditor::CPPEditor(QWidget *parent)
setCodeFoldingVisible(true);
baseTextDocument()->setSyntaxHighlighter(new CppHighlighter);
new QShortcut(QKeySequence(tr("CTRL+SHIFT+r")), this, SLOT(renameInPlace()),
/*ambiguousMember=*/ 0, Qt::WidgetShortcut);
#ifdef WITH_TOKEN_MOVE_POSITION
new QShortcut(QKeySequence::MoveToPreviousWord, this, SLOT(moveToPreviousToken()),
/*ambiguousMember=*/ 0, Qt::WidgetShortcut);
......@@ -829,7 +826,7 @@ void CPPEditor::reformatDocument()
c.insertText(QString::fromUtf8(str.c_str(), str.length()));
}
void CPPEditor::renameInPlace()
void CPPEditor::renameSymbolUnderCursor()
{
updateSemanticInfo(m_semanticHighlighter->semanticInfo(currentSource()));
......@@ -1331,8 +1328,8 @@ void CPPEditor::contextMenuEvent(QContextMenuEvent *e)
if (lastAction->menu() && QLatin1String(lastAction->menu()->metaObject()->className()) == QLatin1String("QUnicodeControlCharacterMenu"))
menu->removeAction(lastAction);
Core::ActionContainer *mcontext =
Core::ICore::instance()->actionManager()->actionContainer(CppEditor::Constants::M_CONTEXT);
Core::ActionManager *am = Core::ICore::instance()->actionManager();
Core::ActionContainer *mcontext = am->actionContainer(CppEditor::Constants::M_CONTEXT);
QMenu *contextMenu = mcontext->menu();
foreach (QAction *action, contextMenu->actions())
......@@ -1341,13 +1338,6 @@ void CPPEditor::contextMenuEvent(QContextMenuEvent *e)
const QList<QTextEdit::ExtraSelection> selections =
extraSelections(BaseTextEditor::CodeSemanticsSelection);
if (! selections.isEmpty()) {
const QString name = selections.first().cursor.selectedText();
QAction *renameAction = new QAction(tr("Rename '%1'").arg(name), menu);
connect(renameAction, SIGNAL(triggered()), this, SLOT(renameInPlace()));
menu->addAction(renameAction);
}
menu->exec(e->globalPos());
delete menu;
}
......
......@@ -197,6 +197,7 @@ public Q_SLOTS:
void setSortedMethodOverview(bool sort);
void switchDeclarationDefinition();
void jumpToDefinition();
void renameSymbolUnderCursor();
void moveToPreviousToken();
void moveToNextToken();
......@@ -228,7 +229,6 @@ private Q_SLOTS:
void updateUsesNow();
void onDocumentUpdated(CPlusPlus::Document::Ptr doc);
void reformatDocument();
void renameInPlace();
void onContentsChanged(int position, int charsRemoved, int charsAdded);
void semanticRehighlight();
......
......@@ -38,6 +38,7 @@ const char * const M_CONTEXT = "CppEditor.ContextMenu";
const char * const C_CPPEDITOR = "C++ Editor";
const char * const CPPEDITOR_KIND = QT_TRANSLATE_NOOP("OpenWith::Editors", "C++ Editor");
const char * const SWITCH_DECLARATION_DEFINITION = "CppEditor.SwitchDeclarationDefinition";
const char * const RENAME_SYMBOL_UNDER_CURSOR = "CppEditor.RenameSymbolUnderCursor";
const char * const JUMP_TO_DEFINITION = "CppEditor.JumpToDefinition";
const char * const HEADER_FILE_TYPE = "CppHeaderFiles";
......
......@@ -212,6 +212,14 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
am->actionContainer(CppEditor::Constants::M_CONTEXT)->addAction(cmd);
am->actionContainer(CppTools::Constants::M_TOOLS_CPP)->addAction(cmd);
QAction *renameSymbolUnderCursorAction = new QAction(tr("Rename Symbol under Cursor"), this);
cmd = am->registerAction(renameSymbolUnderCursorAction,
Constants::RENAME_SYMBOL_UNDER_CURSOR, context);
cmd->setDefaultKeySequence(QKeySequence("CTRL+SHIFT+R"));
connect(renameSymbolUnderCursorAction, SIGNAL(triggered()), this, SLOT(renameSymbolUnderCursor()));
am->actionContainer(CppEditor::Constants::M_CONTEXT)->addAction(cmd);
am->actionContainer(CppTools::Constants::M_TOOLS_CPP)->addAction(cmd);
m_actionHandler = new TextEditor::TextEditorActionHandler(CppEditor::Constants::C_CPPEDITOR,
TextEditor::TextEditorActionHandler::Format
| TextEditor::TextEditorActionHandler::UnCommentSelection
......@@ -265,4 +273,12 @@ void CppPlugin::jumpToDefinition()
editor->jumpToDefinition();
}
void CppPlugin::renameSymbolUnderCursor()
{
Core::EditorManager *em = Core::EditorManager::instance();
CPPEditor *editor = qobject_cast<CPPEditor*>(em->currentEditor()->widget());
if (editor)
editor->renameSymbolUnderCursor();
}
Q_EXPORT_PLUGIN(CppPlugin)
......@@ -73,6 +73,7 @@ public slots:
private slots:
void switchDeclarationDefinition();
void jumpToDefinition();
void renameSymbolUnderCursor();
private:
Core::IEditor *createEditor(QWidget *parent);
......
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