diff --git a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp index be382322fad5d9b962e4078f6bf666621e544597..dd37968d7fc1ec1989e259b5d367c7b16c031995 100644 --- a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp @@ -142,18 +142,7 @@ void CMakeEditorWidget::unCommentSelection() void CMakeEditorWidget::contextMenuEvent(QContextMenuEvent *e) { - QMenu *menu = new QMenu(); - - Core::ActionContainer *mcontext = Core::ActionManager::actionContainer(Constants::M_CONTEXT); - QMenu *contextMenu = mcontext->menu(); - - foreach (QAction *action, contextMenu->actions()) - menu->addAction(action); - - appendStandardContextMenuActions(menu); - - menu->exec(e->globalPos()); - delete menu; + showDefaultContextMenu(e, Constants::M_CONTEXT); } void CMakeEditorWidget::setFontSettings(const TextEditor::FontSettings &fs) diff --git a/src/plugins/qt4projectmanager/profileeditor.cpp b/src/plugins/qt4projectmanager/profileeditor.cpp index 62af3f9af1a8fa69841f6d0b976d3d40bf35d726..ff93c868feb9ee425fdffd718578988135273c15 100644 --- a/src/plugins/qt4projectmanager/profileeditor.cpp +++ b/src/plugins/qt4projectmanager/profileeditor.cpp @@ -196,19 +196,7 @@ TextEditor::BaseTextEditor *ProFileEditorWidget::createEditor() void ProFileEditorWidget::contextMenuEvent(QContextMenuEvent *e) { - QMenu *menu = new QMenu(); - - Core::ActionContainer *mcontext = - Core::ActionManager::actionContainer(Qt4ProjectManager::Constants::M_CONTEXT); - QMenu *contextMenu = mcontext->menu(); - - foreach (QAction *action, contextMenu->actions()) - menu->addAction(action); - - appendStandardContextMenuActions(menu); - - menu->exec(e->globalPos()); - delete menu; + showDefaultContextMenu(e, Constants::M_CONTEXT); } void ProFileEditorWidget::setFontSettings(const TextEditor::FontSettings &fs) diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 508c38804dcee43256b76819004523f3cf9a827a..5c17d0716099235f0ee0bb5240f59f3fcd469d9c 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -4327,6 +4327,14 @@ void BaseTextEditorWidget::dragEnterEvent(QDragEnterEvent *e) QPlainTextEdit::dragEnterEvent(e); } +void BaseTextEditorWidget::showDefaultContextMenu(QContextMenuEvent *e, const Core::Id menuContextId) +{ + QMenu menu; + appendMenuActionsFromContext(&menu, menuContextId); + appendStandardContextMenuActions(&menu); + menu.exec(e->globalPos()); +} + void BaseTextEditorWidget::extraAreaLeaveEvent(QEvent *) { // fake missing mouse move event from Qt @@ -6059,6 +6067,15 @@ QMimeData *BaseTextEditorWidget::duplicateMimeData(const QMimeData *source) cons return mimeData; } +void BaseTextEditorWidget::appendMenuActionsFromContext(QMenu *menu, const Core::Id menuContextId) +{ + Core::ActionContainer *mcontext = Core::ActionManager::actionContainer(menuContextId); + QMenu *contextMenu = mcontext->menu(); + + foreach (QAction *action, contextMenu->actions()) + menu->addAction(action); +} + void BaseTextEditorWidget::appendStandardContextMenuActions(QMenu *menu) { menu->addSeparator(); diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index dd260ebc67e358bbdacd2b8f66b0f3f553ad35b5..461d0a8e40f25000005eb2666cd1afa6a2cbef61 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -166,7 +166,7 @@ public: QString mimeType() const; virtual void setMimeType(const QString &mt); - + void appendMenuActionsFromContext(QMenu *menu, const Core::Id menuContextId); void appendStandardContextMenuActions(QMenu *menu); // Works only in conjunction with a syntax highlighter that puts @@ -469,6 +469,8 @@ protected: void dragEnterEvent(QDragEnterEvent *e); + void showDefaultContextMenu(QContextMenuEvent *e, const Core::Id menuContextId); + public: void indentInsertedText(const QTextCursor &tc); void indent(QTextDocument *doc, const QTextCursor &cursor, QChar typedChar);