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 <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2018-03-22 09:52:49 +01:00
parent 26bfa469db
commit 454e9ee5ca
5 changed files with 55 additions and 22 deletions

View File

@@ -40,6 +40,7 @@
#include <coreplugin/icore.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/externaltoolmanager.h>
#include <extensionsystem/pluginmanager.h>
@@ -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