Commit c0352906 authored by mae's avatar mae

add standard cut/copy/paste actions (if available) to the cpp editor's context menu

at a later stage we will look into harmonizing context menu among different editors.
The cpp editor had the biggest need, because its context menu features all sorts of
extra refactoring operations, thus the standard Qt context menu became too large.
parent b8bd20dd
......@@ -1643,14 +1643,6 @@ void CPPEditor::contextMenuEvent(QContextMenuEvent *e)
QMenu *menu = new QMenu();
// QMenu *menu = createStandardContextMenu();
//
// // Remove insert unicode control character
// QAction *lastAction = menu->actions().last();
// if (lastAction->menu() && QLatin1String(lastAction->menu()->metaObject()->className()) == QLatin1String("QUnicodeControlCharacterMenu"))
// menu->removeAction(lastAction);
Core::ActionManager *am = Core::ICore::instance()->actionManager();
Core::ActionContainer *mcontext = am->actionContainer(CppEditor::Constants::M_CONTEXT);
QMenu *contextMenu = mcontext->menu();
......@@ -1661,6 +1653,8 @@ void CPPEditor::contextMenuEvent(QContextMenuEvent *e)
const QList<QTextEdit::ExtraSelection> selections =
extraSelections(BaseTextEditor::CodeSemanticsSelection);
appendStandardContextMenuActions(menu);
menu->exec(e->globalPos());
delete menu;
}
......
......@@ -43,6 +43,8 @@
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/manhattanstyle.h>
#include <coreplugin/icore.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <extensionsystem/pluginmanager.h>
#include <find/basetextfind.h>
#include <utils/stylehelper.h>
......@@ -4711,6 +4713,23 @@ BaseTextEditorEditable::BaseTextEditorEditable(BaseTextEditor *editor)
connect(editor, SIGNAL(cursorPositionChanged()), this, SLOT(updateCursorPosition()));
}
void BaseTextEditor::appendStandardContextMenuActions(QMenu *menu)
{
menu->addSeparator();
Core::ActionManager *am = Core::ICore::instance()->actionManager();
QAction *a = am->command(Core::Constants::CUT)->action();
if (a && a->isEnabled())
menu->addAction(a);
a = am->command(Core::Constants::COPY)->action();
if (a && a->isEnabled())
menu->addAction(a);
a = am->command(Core::Constants::PASTE)->action();
if (a && a->isEnabled())
menu->addAction(a);
}
BaseTextEditorEditable::~BaseTextEditorEditable()
{
delete m_toolBar;
......
......@@ -321,6 +321,8 @@ public:
void setMimeType(const QString &mt);
void appendStandardContextMenuActions(QMenu *menu);
// Works only in conjunction with a syntax highlighter that puts
// parentheses into text block user data
void setParenthesesMatchingEnabled(bool b);
......
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