From 454e9ee5ca9d8266ab8e5a654a1d4e7a04b40833 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 22 Mar 2018 09:52:49 +0100 Subject: Add Context Help to text editor context menu For this make the default context menu for the text editor extensible and add the context help item from the help plugin, which now has an optional dependency on the text editor to ensure correct loading order if both are present. Task-number: QTCREATORBUG-55 Change-Id: I378a491ba3700e65fc262bdb10c8ead5ad62cb33 Reviewed-by: David Schulz --- src/plugins/texteditor/texteditorplugin.cpp | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/plugins/texteditor/texteditorplugin.cpp') diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index b0809ad094..5cacd941c4 100644 --- a/src/plugins/texteditor/texteditorplugin.cpp +++ b/src/plugins/texteditor/texteditorplugin.cpp @@ -40,6 +40,7 @@ #include #include +#include #include #include #include @@ -74,6 +75,8 @@ public: void updateSearchResultsTabWidth(const TextEditor::TabSettings &tabSettings); void updateCurrentSelection(const QString &text); + void createStandardContextMenu(); + TextEditorSettings settings; LineNumberFilter lineNumberFilter; // Goto line functionality for quick open OutlineFactory outlineFactory; @@ -148,6 +151,7 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe SnippetProvider::registerGroup(Constants::TEXT_SNIPPET_GROUP_ID, tr("Text", "SnippetProvider")); + d->createStandardContextMenu(); return true; } @@ -262,5 +266,32 @@ void TextEditorPluginPrivate::updateCurrentSelection(const QString &text) } } +void TextEditorPluginPrivate::createStandardContextMenu() +{ + ActionContainer *contextMenu = ActionManager::createMenu(Constants::M_STANDARDCONTEXTMENU); + contextMenu->appendGroup(Constants::G_UNDOREDO); + contextMenu->appendGroup(Constants::G_COPYPASTE); + contextMenu->appendGroup(Constants::G_SELECT); + contextMenu->appendGroup(Constants::G_BOM); + + const auto add = [contextMenu](const Id &id, const Id &group) { + Command *cmd = ActionManager::command(id); + if (cmd) + contextMenu->addAction(cmd, group); + }; + + add(Core::Constants::UNDO, Constants::G_UNDOREDO); + add(Core::Constants::REDO, Constants::G_UNDOREDO); + contextMenu->addSeparator(Constants::G_COPYPASTE); + add(Core::Constants::CUT, Constants::G_COPYPASTE); + add(Core::Constants::COPY, Constants::G_COPYPASTE); + add(Core::Constants::PASTE, Constants::G_COPYPASTE); + add(Constants::CIRCULAR_PASTE, Constants::G_COPYPASTE); + contextMenu->addSeparator(Constants::G_SELECT); + add(Core::Constants::SELECTALL, Constants::G_SELECT); + contextMenu->addSeparator(Constants::G_BOM); + add(Constants::SWITCH_UTF8BOM, Constants::G_BOM); +} + } // namespace Internal } // namespace TextEditor -- cgit v1.2.1