diff options
author | Eike Ziller <eike.ziller@qt.io> | 2018-03-22 09:52:49 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2018-03-29 08:26:24 +0000 |
commit | 454e9ee5ca9d8266ab8e5a654a1d4e7a04b40833 (patch) | |
tree | ac89a641f5969cfa47f2d403d99cdda0a8bf70f0 /src/plugins | |
parent | 26bfa469db1fbfb0f5f231c0ac9c780926e5d522 (diff) | |
download | qt-creator-454e9ee5ca9d8266ab8e5a654a1d4e7a04b40833.tar.gz |
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>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/help/help_dependencies.pri | 2 | ||||
-rw-r--r-- | src/plugins/help/helpplugin.cpp | 8 | ||||
-rw-r--r-- | src/plugins/texteditor/texteditor.cpp | 31 | ||||
-rw-r--r-- | src/plugins/texteditor/texteditorconstants.h | 5 | ||||
-rw-r--r-- | src/plugins/texteditor/texteditorplugin.cpp | 31 |
5 files changed, 55 insertions, 22 deletions
diff --git a/src/plugins/help/help_dependencies.pri b/src/plugins/help/help_dependencies.pri index 2094a72dd3..cf2e37d3c3 100644 --- a/src/plugins/help/help_dependencies.pri +++ b/src/plugins/help/help_dependencies.pri @@ -6,3 +6,5 @@ QTC_LIB_DEPENDS += \ QTC_PLUGIN_DEPENDS += \ coreplugin \ projectexplorer +QTC_PLUGIN_RECOMMENDS += \ + texteditor diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index 263f0aac15..091a845686 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -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"); diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index f93d8109e6..a01d8a6e6b 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -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); } } } diff --git a/src/plugins/texteditor/texteditorconstants.h b/src/plugins/texteditor/texteditorconstants.h index e7024614e5..8007c76617 100644 --- a/src/plugins/texteditor/texteditorconstants.h +++ b/src/plugins/texteditor/texteditorconstants.h @@ -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"; 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 <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 |