From 600fc9b218dfcf940895b1251b89079fb78c3af3 Mon Sep 17 00:00:00 2001 From: mae <qt-info@nokia.com> Date: Thu, 24 Sep 2009 14:50:22 +0200 Subject: [PATCH] cpp editor actions remove some standard actions from the cpp editor context menu, and enhance the advanced menu instead. --- src/plugins/coreplugin/coreconstants.h | 1 + .../editormanager/editormanager.cpp | 4 +++- src/plugins/cppeditor/cppeditor.cpp | 13 ++++++++----- src/plugins/cppeditor/cppeditorconstants.h | 1 + src/plugins/cppeditor/cppplugin.cpp | 19 ++++++++++++------- .../texteditor/texteditoractionhandler.cpp | 4 ++++ 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/plugins/coreplugin/coreconstants.h b/src/plugins/coreplugin/coreconstants.h index e950f528965..5e059aff768 100644 --- a/src/plugins/coreplugin/coreconstants.h +++ b/src/plugins/coreplugin/coreconstants.h @@ -181,6 +181,7 @@ const char * const G_EDIT_OTHER = "QtCreator.Group.Edit.Other"; const char * const G_EDIT_FORMAT = "QtCreator.Group.Edit.Format"; const char * const G_EDIT_COLLAPSING = "QtCreator.Group.Edit.Collapsing"; +const char * const G_EDIT_BLOCKS = "QtCreator.Group.Edit.Blocks"; const char * const G_EDIT_FONT = "QtCreator.Group.Edit.Font"; const char * const G_EDIT_EDITOR = "QtCreator.Group.Edit.Editor"; diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 3a0cf29d920..4d6552f4379 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -365,19 +365,21 @@ EditorManager::EditorManager(ICore *core, QWidget *parent) : mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT); connect(m_d->m_gotoOtherSplitAction, SIGNAL(triggered()), this, SLOT(gotoOtherSplit())); - ActionContainer *medit = am->actionContainer(Constants::M_EDIT); ActionContainer *advancedMenu = am->createMenu(Constants::M_EDIT_ADVANCED); medit->addMenu(advancedMenu, Constants::G_EDIT_ADVANCED); advancedMenu->menu()->setTitle(tr("&Advanced")); advancedMenu->appendGroup(Constants::G_EDIT_FORMAT); advancedMenu->appendGroup(Constants::G_EDIT_COLLAPSING); + advancedMenu->appendGroup(Constants::G_EDIT_BLOCKS); advancedMenu->appendGroup(Constants::G_EDIT_FONT); advancedMenu->appendGroup(Constants::G_EDIT_EDITOR); // Advanced menu separators cmd = createSeparator(am, this, QLatin1String("QtCreator.Edit.Sep.Collapsing"), editManagerContext); advancedMenu->addAction(cmd, Constants::G_EDIT_COLLAPSING); + cmd = createSeparator(am, this, QLatin1String("QtCreator.Edit.Sep.Blocks"), editManagerContext); + advancedMenu->addAction(cmd, Constants::G_EDIT_BLOCKS); cmd = createSeparator(am, this, QLatin1String("QtCreator.Edit.Sep.Font"), editManagerContext); advancedMenu->addAction(cmd, Constants::G_EDIT_FONT); cmd = createSeparator(am, this, QLatin1String("QtCreator.Edit.Sep.Editor"), editManagerContext); diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index d080f6e141b..024051d9ce4 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -1569,12 +1569,15 @@ void CPPEditor::contextMenuEvent(QContextMenuEvent *e) // ### enable // updateSemanticInfo(m_semanticHighlighter->semanticInfo(currentSource())); - QMenu *menu = createStandardContextMenu(); + QMenu *menu = new QMenu(); - // Remove insert unicode control character - QAction *lastAction = menu->actions().last(); - if (lastAction->menu() && QLatin1String(lastAction->menu()->metaObject()->className()) == QLatin1String("QUnicodeControlCharacterMenu")) - menu->removeAction(lastAction); + +// 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); diff --git a/src/plugins/cppeditor/cppeditorconstants.h b/src/plugins/cppeditor/cppeditorconstants.h index 60fb2ff8edd..24d1504caf7 100644 --- a/src/plugins/cppeditor/cppeditorconstants.h +++ b/src/plugins/cppeditor/cppeditorconstants.h @@ -39,6 +39,7 @@ 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 SEPARATOR = "CppEditor.Separator"; const char * const FIND_REFERENCES = "CppEditor.FindReferences"; const char * const JUMP_TO_DEFINITION = "CppEditor.JumpToDefinition"; diff --git a/src/plugins/cppeditor/cppplugin.cpp b/src/plugins/cppeditor/cppplugin.cpp index 504ed2490a7..834e32fcfd4 100644 --- a/src/plugins/cppeditor/cppplugin.cpp +++ b/src/plugins/cppeditor/cppplugin.cpp @@ -190,7 +190,7 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess context << core->uniqueIDManager()->uniqueIdentifier(CppEditor::Constants::C_CPPEDITOR); Core::ActionManager *am = core->actionManager(); - am->createMenu(CppEditor::Constants::M_CONTEXT); + Core::ActionContainer *contextMenu= am->createMenu(CppEditor::Constants::M_CONTEXT); Core::Command *cmd; @@ -200,7 +200,7 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess cmd->setDefaultKeySequence(QKeySequence(Qt::Key_F2)); connect(jumpToDefinition, SIGNAL(triggered()), this, SLOT(jumpToDefinition())); - am->actionContainer(CppEditor::Constants::M_CONTEXT)->addAction(cmd); + contextMenu->addAction(cmd); am->actionContainer(CppTools::Constants::M_TOOLS_CPP)->addAction(cmd); QAction *switchDeclarationDefinition = new QAction(tr("Switch between Method Declaration/Definition"), this); @@ -209,7 +209,7 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess cmd->setDefaultKeySequence(QKeySequence("Shift+F2")); connect(switchDeclarationDefinition, SIGNAL(triggered()), this, SLOT(switchDeclarationDefinition())); - am->actionContainer(CppEditor::Constants::M_CONTEXT)->addAction(cmd); + contextMenu->addAction(cmd); am->actionContainer(CppTools::Constants::M_TOOLS_CPP)->addAction(cmd); QAction *renameSymbolUnderCursorAction = new QAction(tr("Rename Symbol under Cursor"), this); @@ -217,7 +217,7 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess 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); + contextMenu->addAction(cmd); am->actionContainer(CppTools::Constants::M_TOOLS_CPP)->addAction(cmd); if (! qgetenv("QTCREATOR_REFERENCES").isEmpty()) { @@ -225,7 +225,7 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess cmd = am->registerAction(findReferencesAction, Constants::FIND_REFERENCES, context); connect(findReferencesAction, SIGNAL(triggered()), this, SLOT(findReferences())); - am->actionContainer(CppEditor::Constants::M_CONTEXT)->addAction(cmd); + contextMenu->addAction(cmd); am->actionContainer(CppTools::Constants::M_TOOLS_CPP)->addAction(cmd); } @@ -235,12 +235,17 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess | TextEditor::TextEditorActionHandler::UnCollapseAll); m_actionHandler->initializeActions(); + + QAction *separator = new QAction(this); + separator->setSeparator(true); + cmd = am->registerAction(separator, CppEditor::Constants::SEPARATOR, context); + contextMenu->addAction(cmd); cmd = am->command(TextEditor::Constants::AUTO_INDENT_SELECTION); - am->actionContainer(CppEditor::Constants::M_CONTEXT)->addAction(cmd); + contextMenu->addAction(cmd); cmd = am->command(TextEditor::Constants::UN_COMMENT_SELECTION); - am->actionContainer(CppEditor::Constants::M_CONTEXT)->addAction(cmd); + contextMenu->addAction(cmd); readSettings(); diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp index b432685b8f4..9a604771326 100644 --- a/src/plugins/texteditor/texteditoractionhandler.cpp +++ b/src/plugins/texteditor/texteditoractionhandler.cpp @@ -232,11 +232,13 @@ void TextEditorActionHandler::createActions() command = am->registerAction(m_gotoBlockStartAction, Constants::GOTO_BLOCK_START, m_contextId); command->setDefaultKeySequence(QKeySequence(tr("Ctrl+["))); connect(m_gotoBlockStartAction, SIGNAL(triggered()), this, SLOT(gotoBlockStart())); + advancedMenu->addAction(command, Core::Constants::G_EDIT_BLOCKS); m_gotoBlockEndAction = new QAction(tr("Goto Block End"), this); command = am->registerAction(m_gotoBlockEndAction, Constants::GOTO_BLOCK_END, m_contextId); command->setDefaultKeySequence(QKeySequence(tr("Ctrl+]"))); connect(m_gotoBlockEndAction, SIGNAL(triggered()), this, SLOT(gotoBlockEnd())); + advancedMenu->addAction(command, Core::Constants::G_EDIT_BLOCKS); m_gotoBlockStartWithSelectionAction = new QAction(tr("Goto Block Start With Selection"), this); command = am->registerAction(m_gotoBlockStartWithSelectionAction, Constants::GOTO_BLOCK_START_WITH_SELECTION, m_contextId); @@ -252,11 +254,13 @@ void TextEditorActionHandler::createActions() command = am->registerAction(m_selectBlockUpAction, Constants::SELECT_BLOCK_UP, m_contextId); command->setDefaultKeySequence(QKeySequence(tr("Ctrl+U"))); connect(m_selectBlockUpAction, SIGNAL(triggered()), this, SLOT(selectBlockUp())); + advancedMenu->addAction(command, Core::Constants::G_EDIT_BLOCKS); m_selectBlockDownAction= new QAction(tr("Select Block Down"), this); command = am->registerAction(m_selectBlockDownAction, Constants::SELECT_BLOCK_DOWN, m_contextId); command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+U"))); connect(m_selectBlockDownAction, SIGNAL(triggered()), this, SLOT(selectBlockDown())); + advancedMenu->addAction(command, Core::Constants::G_EDIT_BLOCKS); m_moveLineUpAction= new QAction(tr("Move Line Up"), this); command = am->registerAction(m_moveLineUpAction, Constants::MOVE_LINE_UP, m_contextId); -- GitLab