forked from qt-creator/qt-creator
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:
@@ -6,3 +6,5 @@ QTC_LIB_DEPENDS += \
|
||||
QTC_PLUGIN_DEPENDS += \
|
||||
coreplugin \
|
||||
projectexplorer
|
||||
QTC_PLUGIN_RECOMMENDS += \
|
||||
texteditor
|
||||
|
||||
@@ -254,6 +254,14 @@ HelpPluginPrivate::HelpPluginPrivate()
|
||||
ActionManager::actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP);
|
||||
cmd->setDefaultKeySequence(QKeySequence(Qt::Key_F1));
|
||||
connect(action, &QAction::triggered, this, &HelpPluginPrivate::requestContextHelp);
|
||||
ActionContainer *textEditorContextMenu = ActionManager::actionContainer(
|
||||
TextEditor::Constants::M_STANDARDCONTEXTMENU);
|
||||
if (textEditorContextMenu) {
|
||||
textEditorContextMenu->insertGroup(TextEditor::Constants::G_BOM,
|
||||
Core::Constants::G_HELP);
|
||||
textEditorContextMenu->addSeparator(Core::Constants::G_HELP);
|
||||
textEditorContextMenu->addAction(cmd, Core::Constants::G_HELP);
|
||||
}
|
||||
|
||||
action = new QAction(HelpPlugin::tr("Technical Support"), this);
|
||||
cmd = ActionManager::registerAction(action, "Help.TechSupport");
|
||||
|
||||
@@ -7762,30 +7762,17 @@ void TextEditorWidget::setupFallBackEditor(Id id)
|
||||
void TextEditorWidget::appendStandardContextMenuActions(QMenu *menu)
|
||||
{
|
||||
menu->addSeparator();
|
||||
const auto add = [menu](const Id &id) {
|
||||
QAction *a = ActionManager::command(id)->action();
|
||||
if (a)
|
||||
menu->addAction(a);
|
||||
};
|
||||
|
||||
add(Core::Constants::UNDO);
|
||||
add(Core::Constants::REDO);
|
||||
menu->addSeparator();
|
||||
add(Core::Constants::CUT);
|
||||
add(Core::Constants::COPY);
|
||||
add(Core::Constants::PASTE);
|
||||
add(Constants::CIRCULAR_PASTE);
|
||||
menu->addSeparator();
|
||||
add(Core::Constants::SELECTALL);
|
||||
|
||||
TextDocument *doc = textDocument();
|
||||
if (doc->codec()->name() == QByteArray("UTF-8") && doc->supportsUtf8Bom()) {
|
||||
QAction *a = ActionManager::command(Constants::SWITCH_UTF8BOM)->action();
|
||||
if (a) {
|
||||
appendMenuActionsFromContext(menu, Constants::M_STANDARDCONTEXTMENU);
|
||||
Command *bomCmd = ActionManager::command(Constants::SWITCH_UTF8BOM);
|
||||
if (bomCmd) {
|
||||
QAction *a = bomCmd->action();
|
||||
TextDocument *doc = textDocument();
|
||||
if (doc->codec()->name() == QByteArray("UTF-8") && doc->supportsUtf8Bom()) {
|
||||
a->setVisible(true);
|
||||
a->setText(doc->format().hasUtf8Bom ? tr("Delete UTF-8 BOM on Save")
|
||||
: tr("Add UTF-8 BOM on Save"));
|
||||
menu->addSeparator();
|
||||
menu->addAction(a);
|
||||
} else {
|
||||
a->setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +109,11 @@ enum TextStyle : quint8 {
|
||||
namespace Constants {
|
||||
|
||||
const char C_TEXTEDITOR[] = "Text Editor";
|
||||
const char M_STANDARDCONTEXTMENU[] = "TextEditor.StandardContextMenu";
|
||||
const char G_UNDOREDO[] = "TextEditor.UndoRedoGroup";
|
||||
const char G_COPYPASTE[] = "TextEditor.CopyPasteGroup";
|
||||
const char G_SELECT[] = "TextEditor.SelectGroup";
|
||||
const char G_BOM[] = "TextEditor.BomGroup";
|
||||
const char COMPLETE_THIS[] = "TextEditor.CompleteThis";
|
||||
const char QUICKFIX_THIS[] = "TextEditor.QuickFix";
|
||||
const char SHOWCONTEXTMENU[] = "TextEditor.ShowContextMenu";
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user