diff options
Diffstat (limited to 'src/plugins')
30 files changed, 924 insertions, 955 deletions
diff --git a/src/plugins/android/androidmanifesteditorfactory.cpp b/src/plugins/android/androidmanifesteditorfactory.cpp index 7a900a687e..41d6af0861 100644 --- a/src/plugins/android/androidmanifesteditorfactory.cpp +++ b/src/plugins/android/androidmanifesteditorfactory.cpp @@ -9,7 +9,6 @@ #include <coreplugin/editormanager/ieditorfactory.h> -#include <texteditor/texteditoractionhandler.h> #include <texteditor/texteditorsettings.h> namespace Android::Internal { @@ -18,10 +17,6 @@ class AndroidManifestEditorFactory final : public Core::IEditorFactory { public: AndroidManifestEditorFactory() - : m_actionHandler(Constants::ANDROID_MANIFEST_EDITOR_ID, - Constants::ANDROID_MANIFEST_EDITOR_CONTEXT, - TextEditor::TextEditorActionHandler::UnCommentSelection, - [](Core::IEditor *editor) { return static_cast<AndroidManifestEditor *>(editor)->textEditor(); }) { setId(Constants::ANDROID_MANIFEST_EDITOR_ID); setDisplayName(Tr::tr("Android Manifest editor")); @@ -31,9 +26,6 @@ public: return androidManifestEditorWidget->editor(); }); } - -private: - TextEditor::TextEditorActionHandler m_actionHandler; }; void setupAndroidManifestEditor() diff --git a/src/plugins/android/androidmanifesteditorwidget.cpp b/src/plugins/android/androidmanifesteditorwidget.cpp index c941f3f43f..608f0b5262 100644 --- a/src/plugins/android/androidmanifesteditorwidget.cpp +++ b/src/plugins/android/androidmanifesteditorwidget.cpp @@ -25,7 +25,6 @@ #include <projectexplorer/projectwindow.h> #include <projectexplorer/target.h> -#include <texteditor/texteditoractionhandler.h> #include <texteditor/texteditor.h> #include <utils/algorithm.h> @@ -114,6 +113,7 @@ private: AndroidManifestEditorWidget::AndroidManifestEditorWidget() { m_textEditorWidget = new AndroidManifestTextEditorWidget(this); + m_textEditorWidget->setOptionalActions(TextEditor::OptionalActions::UnCommentSelection); initializePage(); @@ -1406,7 +1406,7 @@ AndroidManifestTextEditorWidget::AndroidManifestTextEditorWidget(AndroidManifest setupGenericHighlighter(); setMarksVisible(false); - // this context is used by the TextEditorActionHandler registered for the text editor in + // this context is used by the OptionalActions registered for the text editor in // the AndroidManifestEditorFactory m_context = new Core::IContext(this); m_context->setWidget(this); diff --git a/src/plugins/android/javaeditor.cpp b/src/plugins/android/javaeditor.cpp index 27ced1b025..8fa69e6e8b 100644 --- a/src/plugins/android/javaeditor.cpp +++ b/src/plugins/android/javaeditor.cpp @@ -10,7 +10,6 @@ #include <texteditor/codeassist/keywordscompletionassist.h> #include <texteditor/textdocument.h> -#include <texteditor/texteditoractionhandler.h> #include <texteditor/texteditorconstants.h> #include <texteditor/texteditor.h> @@ -48,7 +47,7 @@ public: setDocumentCreator(createJavaDocument); setUseGenericHighlighter(true); setCommentDefinition(Utils::CommentDefinition::CppStyle); - setEditorActionHandlers(TextEditor::TextEditorActionHandler::UnCommentSelection); + setOptionalActionMask(TextEditor::OptionalActions::UnCommentSelection); setCompletionAssistProvider(new TextEditor::KeywordsCompletionAssistProvider(keywords)); } }; diff --git a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp index 968d6260e7..27db33e14d 100644 --- a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp @@ -26,7 +26,6 @@ #include <texteditor/basehoverhandler.h> #include <texteditor/textdocument.h> #include <texteditor/texteditor.h> -#include <texteditor/texteditoractionhandler.h> #include <utils/mimeconstants.h> #include <utils/textutils.h> @@ -533,9 +532,9 @@ public: setCompletionAssistProvider(new CMakeFileCompletionAssistProvider); setAutoCompleterCreator([] { return new CMakeAutoCompleter; }); - setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection - | TextEditorActionHandler::FollowSymbolUnderCursor - | TextEditorActionHandler::Format); + setOptionalActionMask(OptionalActions::UnCommentSelection + | OptionalActions::FollowSymbolUnderCursor + | OptionalActions::Format); addHoverHandler(new CMakeHoverHandler); diff --git a/src/plugins/compilerexplorer/compilerexplorereditor.cpp b/src/plugins/compilerexplorer/compilerexplorereditor.cpp index 651ee59620..107968d970 100644 --- a/src/plugins/compilerexplorer/compilerexplorereditor.cpp +++ b/src/plugins/compilerexplorer/compilerexplorereditor.cpp @@ -18,7 +18,6 @@ #include <texteditor/fontsettings.h> #include <texteditor/textdocument.h> #include <texteditor/texteditor.h> -#include <texteditor/texteditoractionhandler.h> #include <texteditor/texteditorsettings.h> #include <texteditor/textmark.h> @@ -564,12 +563,10 @@ void CompilerWidget::doCompile() EditorWidget::EditorWidget(const std::shared_ptr<JsonSettingsDocument> &document, QUndoStack *undoStack, - TextEditorActionHandler &actionHandler, QWidget *parent) : Utils::FancyMainWindow(parent) , m_document(document) , m_undoStack(undoStack) - , m_actionHandler(actionHandler) { setContextMenuPolicy(Qt::NoContextMenu); setDockNestingEnabled(true); @@ -589,10 +586,6 @@ EditorWidget::EditorWidget(const std::shared_ptr<JsonSettingsDocument> &document this, &EditorWidget::recreateEditors); - connect(this, &EditorWidget::gotFocus, this, [&actionHandler] { - actionHandler.updateCurrentEditor(); - }); - setupHelpWidget(); } @@ -627,10 +620,6 @@ CompilerWidget *EditorWidget::addCompiler(const std::shared_ptr<SourceSettings> sourceSettings->compilers.removeItem(compilerSettings->shared_from_this()); }); - connect(compiler, &CompilerWidget::gotFocus, this, [this] { - m_actionHandler.updateCurrentEditor(); - }); - return compiler; } @@ -669,10 +658,6 @@ void EditorWidget::addSourceEditor(const std::shared_ptr<SourceSettings> &source setupHelpWidget(); }); - connect(sourceEditor, &SourceEditorWidget::gotFocus, this, [this] { - m_actionHandler.updateCurrentEditor(); - }); - dockWidget->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable); addDockWidget(Qt::LeftDockWidgetArea, dockWidget); @@ -842,18 +827,11 @@ TextEditor::TextEditorWidget *EditorWidget::focusedEditorWidget() const return nullptr; } -Editor::Editor(TextEditorActionHandler &actionHandler) +Editor::Editor() : m_document(new JsonSettingsDocument(&m_undoStack)) { setContext(Core::Context(Constants::CE_EDITOR_ID)); - setWidget(new EditorWidget(m_document, &m_undoStack, actionHandler)); - - connect(&m_undoStack, &QUndoStack::canUndoChanged, this, [&actionHandler] { - actionHandler.updateActions(); - }); - connect(&m_undoStack, &QUndoStack::canRedoChanged, this, [&actionHandler] { - actionHandler.updateActions(); - }); + setWidget(new EditorWidget(m_document, &m_undoStack)); } Editor::~Editor() @@ -909,12 +887,6 @@ QWidget *Editor::toolBar() } EditorFactory::EditorFactory() - : m_actionHandler(Constants::CE_EDITOR_ID, - Constants::CE_EDITOR_ID, - TextEditor::TextEditorActionHandler::None, - [](Core::IEditor *editor) -> TextEditorWidget * { - return static_cast<EditorWidget *>(editor->widget())->focusedEditorWidget(); - }) { setId(Constants::CE_EDITOR_ID); setDisplayName(Tr::tr("Compiler Explorer Editor")); @@ -926,48 +898,7 @@ EditorFactory::EditorFactory() return &static_cast<Editor *>(editor)->m_undoStack; }; - m_actionHandler.setCanUndoCallback([undoStackFromEditor](Core::IEditor *editor) { - if (auto undoStack = undoStackFromEditor(editor)) - return undoStack->canUndo(); - return false; - }); - - m_actionHandler.setCanRedoCallback([undoStackFromEditor](Core::IEditor *editor) { - if (auto undoStack = undoStackFromEditor(editor)) - return undoStack->canRedo(); - return false; - }); - - m_actionHandler.setUnhandledCallback( - [undoStackFromEditor](Utils::Id cmdId, Core::IEditor *editor) { - if (cmdId == TextEditor::Constants::INCREASE_FONT_SIZE) { - TextEditor::TextEditorSettings::instance()->increaseFontZoom(); - return true; - } else if (cmdId == TextEditor::Constants::DECREASE_FONT_SIZE) { - TextEditor::TextEditorSettings::instance()->decreaseFontZoom(); - return true; - } - - if (cmdId != Core::Constants::UNDO && cmdId != Core::Constants::REDO) - return false; - - if (!childHasFocus(editor->widget())) - return false; - - QUndoStack *undoStack = undoStackFromEditor(editor); - - if (!undoStack) - return false; - - if (cmdId == Core::Constants::UNDO) - undoStack->undo(); - else - undoStack->redo(); - - return true; - }); - - setEditorCreator([this]() { return new Editor(m_actionHandler); }); + setEditorCreator([this]() { return new Editor; }); } QList<QTextEdit::ExtraSelection> AsmDocument::setCompileResult( diff --git a/src/plugins/compilerexplorer/compilerexplorereditor.h b/src/plugins/compilerexplorer/compilerexplorereditor.h index c9c02e5215..56eef3fd36 100644 --- a/src/plugins/compilerexplorer/compilerexplorereditor.h +++ b/src/plugins/compilerexplorer/compilerexplorereditor.h @@ -11,7 +11,6 @@ #include <solutions/spinner/spinner.h> #include <texteditor/texteditor.h> -#include <texteditor/texteditoractionhandler.h> #include <utils/fancymainwindow.h> @@ -223,7 +222,6 @@ class EditorWidget : public Utils::FancyMainWindow public: EditorWidget(const std::shared_ptr<JsonSettingsDocument> &document, QUndoStack *undoStack, - TextEditor::TextEditorActionHandler &actionHandler, QWidget *parent = nullptr); ~EditorWidget() override; @@ -253,7 +251,6 @@ protected: private: std::shared_ptr<JsonSettingsDocument> m_document; QUndoStack *m_undoStack; - TextEditor::TextEditorActionHandler &m_actionHandler; QList<QDockWidget *> m_compilerWidgets; QList<QDockWidget *> m_sourceWidgets; @@ -262,7 +259,7 @@ private: class Editor : public Core::IEditor { public: - Editor(TextEditor::TextEditorActionHandler &actionHandler); + Editor(); ~Editor(); Core::IDocument *document() const override { return m_document.get(); } @@ -279,8 +276,6 @@ public: EditorFactory(); private: - TextEditor::TextEditorActionHandler m_actionHandler; - QAction m_undoAction; QAction m_redoAction; }; diff --git a/src/plugins/cppeditor/cppeditorplugin.cpp b/src/plugins/cppeditor/cppeditorplugin.cpp index 4328c93970..9a11039876 100644 --- a/src/plugins/cppeditor/cppeditorplugin.cpp +++ b/src/plugins/cppeditor/cppeditorplugin.cpp @@ -75,7 +75,6 @@ #include <texteditor/colorpreviewhoverhandler.h> #include <texteditor/snippets/snippetprovider.h> #include <texteditor/texteditor.h> -#include <texteditor/texteditoractionhandler.h> #include <texteditor/texteditorconstants.h> #include <utils/algorithm.h> @@ -139,14 +138,14 @@ public: setCodeFoldingSupported(true); setParenthesesMatchingEnabled(true); - setEditorActionHandlers(TextEditorActionHandler::Format - | TextEditorActionHandler::UnCommentSelection - | TextEditorActionHandler::UnCollapseAll - | TextEditorActionHandler::FollowSymbolUnderCursor - | TextEditorActionHandler::FollowTypeUnderCursor - | TextEditorActionHandler::RenameSymbol - | TextEditorActionHandler::TypeHierarchy - | TextEditorActionHandler::FindUsage); + setOptionalActionMask(OptionalActions::Format + | OptionalActions::UnCommentSelection + | OptionalActions::UnCollapseAll + | OptionalActions::FollowSymbolUnderCursor + | OptionalActions::FollowTypeUnderCursor + | OptionalActions::RenameSymbol + | OptionalActions::TypeHierarchy + | OptionalActions::FindUsage); } }; diff --git a/src/plugins/diffeditor/diffeditorfactory.cpp b/src/plugins/diffeditor/diffeditorfactory.cpp index 70537dd3f7..a3981ed49b 100644 --- a/src/plugins/diffeditor/diffeditorfactory.cpp +++ b/src/plugins/diffeditor/diffeditorfactory.cpp @@ -7,8 +7,6 @@ #include "diffeditordocument.h" #include "diffeditortr.h" -#include "texteditor/texteditoractionhandler.h" - #include <QCoreApplication> using namespace Core; @@ -17,31 +15,7 @@ using namespace Utils; namespace DiffEditor::Internal { -DiffEditorFactory::DiffEditorFactory() : - descriptionHandler { - Constants::DIFF_EDITOR_ID, - Constants::C_DIFF_EDITOR_DESCRIPTION, - TextEditorActionHandler::None, - [](IEditor *e) { return static_cast<DiffEditor *>(e)->descriptionWidget(); } - }, - unifiedHandler { - Constants::DIFF_EDITOR_ID, - Constants::UNIFIED_VIEW_ID, - TextEditorActionHandler::None, - [](IEditor *e) { return static_cast<DiffEditor *>(e)->unifiedEditorWidget(); } - }, - leftHandler { - Constants::DIFF_EDITOR_ID, - Id(Constants::SIDE_BY_SIDE_VIEW_ID).withSuffix(1), - TextEditorActionHandler::None, - [](IEditor *e) { return static_cast<DiffEditor *>(e)->sideEditorWidget(LeftSide); } - }, - rightHandler { - Constants::DIFF_EDITOR_ID, - Id(Constants::SIDE_BY_SIDE_VIEW_ID).withSuffix(2), - TextEditorActionHandler::None, - [](Core::IEditor *e) { return static_cast<DiffEditor *>(e)->sideEditorWidget(RightSide); } - } +DiffEditorFactory::DiffEditorFactory() { setId(Constants::DIFF_EDITOR_ID); setDisplayName(Tr::tr("Diff Editor")); diff --git a/src/plugins/diffeditor/diffeditorfactory.h b/src/plugins/diffeditor/diffeditorfactory.h index e39f0fc46f..3c05e4af1c 100644 --- a/src/plugins/diffeditor/diffeditorfactory.h +++ b/src/plugins/diffeditor/diffeditorfactory.h @@ -5,20 +5,12 @@ #include <coreplugin/editormanager/ieditorfactory.h> -#include <texteditor/texteditoractionhandler.h> - namespace DiffEditor::Internal { class DiffEditorFactory : public Core::IEditorFactory { public: DiffEditorFactory(); - -private: - TextEditor::TextEditorActionHandler descriptionHandler; - TextEditor::TextEditorActionHandler unifiedHandler; - TextEditor::TextEditorActionHandler leftHandler; - TextEditor::TextEditorActionHandler rightHandler; }; } // namespace DiffEditor::Internal diff --git a/src/plugins/genericprojectmanager/genericprojectfileseditor.cpp b/src/plugins/genericprojectmanager/genericprojectfileseditor.cpp index eef322a151..5070cf67cd 100644 --- a/src/plugins/genericprojectmanager/genericprojectfileseditor.cpp +++ b/src/plugins/genericprojectmanager/genericprojectfileseditor.cpp @@ -9,7 +9,6 @@ #include <texteditor/textdocument.h> #include <texteditor/texteditor.h> -#include <texteditor/texteditoractionhandler.h> using namespace TextEditor; @@ -29,7 +28,7 @@ public: addMimeType("application/vnd.qtcreator.generic.cflags"); setDocumentCreator([]() { return new TextDocument(Constants::FILES_EDITOR_ID); }); - setEditorActionHandlers(TextEditorActionHandler::None); + setOptionalActionMask(OptionalActions::None); } }; diff --git a/src/plugins/glsleditor/glsleditor.cpp b/src/plugins/glsleditor/glsleditor.cpp index 36bba04137..a454057ce2 100644 --- a/src/plugins/glsleditor/glsleditor.cpp +++ b/src/plugins/glsleditor/glsleditor.cpp @@ -31,7 +31,6 @@ #include <texteditor/textdocument.h> #include <texteditor/syntaxhighlighter.h> #include <texteditor/texteditor.h> -#include <texteditor/texteditoractionhandler.h> #include <texteditor/texteditorconstants.h> #include <texteditor/texteditorsettings.h> @@ -466,9 +465,9 @@ public: setParenthesesMatchingEnabled(true); setCodeFoldingSupported(true); - setEditorActionHandlers(TextEditorActionHandler::Format - | TextEditorActionHandler::UnCommentSelection - | TextEditorActionHandler::UnCollapseAll); + setOptionalActionMask(OptionalActions::Format + | OptionalActions::UnCommentSelection + | OptionalActions::UnCollapseAll); } }; diff --git a/src/plugins/haskell/haskelleditorfactory.cpp b/src/plugins/haskell/haskelleditorfactory.cpp index 89bf561b1f..55f077a9f9 100644 --- a/src/plugins/haskell/haskelleditorfactory.cpp +++ b/src/plugins/haskell/haskelleditorfactory.cpp @@ -13,7 +13,6 @@ #include <texteditor/textdocument.h> #include <texteditor/texteditor.h> -#include <texteditor/texteditoractionhandler.h> #include <texteditor/textindenter.h> #include <QAction> @@ -42,8 +41,8 @@ public: setId(Constants::C_HASKELLEDITOR_ID); setDisplayName(::Core::Tr::tr("Haskell Editor")); addMimeType("text/x-haskell"); - setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection - | TextEditorActionHandler::FollowSymbolUnderCursor); + setOptionalActionMask( + OptionalActions::UnCommentSelection | OptionalActions::FollowSymbolUnderCursor); setDocumentCreator([] { return new TextDocument(Constants::C_HASKELLEDITOR_ID); }); setIndenterCreator([](QTextDocument *doc) { return new TextIndenter(doc); }); setEditorWidgetCreator(&createEditorWidget); diff --git a/src/plugins/languageclient/client.cpp b/src/plugins/languageclient/client.cpp index 5e3d240f8c..0d7826307a 100644 --- a/src/plugins/languageclient/client.cpp +++ b/src/plugins/languageclient/client.cpp @@ -49,7 +49,6 @@ #include <texteditor/tabsettings.h> #include <texteditor/textdocument.h> #include <texteditor/texteditor.h> -#include <texteditor/texteditoractionhandler.h> #include <texteditor/texteditorsettings.h> #include <utils/appinfo.h> @@ -1005,17 +1004,17 @@ void Client::activateEditor(Core::IEditor *editor) d->requestDocumentHighlights(widget); uint optionalActions = widget->optionalActions(); if (symbolSupport().supportsFindUsages(widget->textDocument())) - optionalActions |= TextEditor::TextEditorActionHandler::FindUsage; + optionalActions |= TextEditor::OptionalActions::FindUsage; if (symbolSupport().supportsRename(widget->textDocument())) - optionalActions |= TextEditor::TextEditorActionHandler::RenameSymbol; + optionalActions |= TextEditor::OptionalActions::RenameSymbol; if (symbolSupport().supportsFindLink(widget->textDocument(), LinkTarget::SymbolDef)) - optionalActions |= TextEditor::TextEditorActionHandler::FollowSymbolUnderCursor; + optionalActions |= TextEditor::OptionalActions::FollowSymbolUnderCursor; if (symbolSupport().supportsFindLink(widget->textDocument(), LinkTarget::SymbolTypeDef)) - optionalActions |= TextEditor::TextEditorActionHandler::FollowTypeUnderCursor; + optionalActions |= TextEditor::OptionalActions::FollowTypeUnderCursor; if (supportsCallHierarchy(this, textEditor->document())) - optionalActions |= TextEditor::TextEditorActionHandler::CallHierarchy; + optionalActions |= TextEditor::OptionalActions::CallHierarchy; if (supportsTypeHierarchy(this, textEditor->document())) - optionalActions |= TextEditor::TextEditorActionHandler::TypeHierarchy; + optionalActions |= TextEditor::OptionalActions::TypeHierarchy; widget->setOptionalActions(optionalActions); } } diff --git a/src/plugins/nim/editor/nimeditorfactory.cpp b/src/plugins/nim/editor/nimeditorfactory.cpp index ac8aa6c932..edd7bcea06 100644 --- a/src/plugins/nim/editor/nimeditorfactory.cpp +++ b/src/plugins/nim/editor/nimeditorfactory.cpp @@ -11,7 +11,6 @@ #include <coreplugin/coreplugintr.h> #include <texteditor/textdocument.h> -#include <texteditor/texteditoractionhandler.h> #include <texteditor/texteditorconstants.h> using namespace TextEditor; @@ -26,10 +25,10 @@ NimEditorFactory::NimEditorFactory() addMimeType(QLatin1String(Nim::Constants::C_NIM_MIMETYPE)); addMimeType(QLatin1String(Nim::Constants::C_NIM_SCRIPT_MIMETYPE)); - setEditorActionHandlers(TextEditorActionHandler::Format - | TextEditorActionHandler::UnCommentSelection - | TextEditorActionHandler::UnCollapseAll - | TextEditorActionHandler::FollowSymbolUnderCursor); + setOptionalActionMask(OptionalActions::Format + | OptionalActions::UnCommentSelection + | OptionalActions::UnCollapseAll + | OptionalActions::FollowSymbolUnderCursor); setEditorWidgetCreator([]{ return new NimTextEditorWidget(); }); diff --git a/src/plugins/python/pythoneditor.cpp b/src/plugins/python/pythoneditor.cpp index ddd30f2acf..94a8e498eb 100644 --- a/src/plugins/python/pythoneditor.cpp +++ b/src/plugins/python/pythoneditor.cpp @@ -27,7 +27,6 @@ #include <projectexplorer/target.h> #include <texteditor/texteditor.h> -#include <texteditor/texteditoractionhandler.h> #include <utils/stylehelper.h> @@ -317,10 +316,10 @@ public: setDisplayName(::Core::Tr::tr(Constants::C_EDITOR_DISPLAY_NAME)); addMimeType(Constants::C_PY_MIMETYPE); - setEditorActionHandlers(TextEditorActionHandler::Format - | TextEditorActionHandler::UnCommentSelection - | TextEditorActionHandler::UnCollapseAll - | TextEditorActionHandler::FollowSymbolUnderCursor); + setOptionalActionMask(OptionalActions::Format + | OptionalActions::UnCommentSelection + | OptionalActions::UnCollapseAll + | OptionalActions::FollowSymbolUnderCursor); setDocumentCreator([]() { return new PythonDocument; }); setEditorWidgetCreator([]() { return new PythonEditorWidget; }); diff --git a/src/plugins/qmakeprojectmanager/profileeditor.cpp b/src/plugins/qmakeprojectmanager/profileeditor.cpp index c510e13901..8b86a58b4b 100644 --- a/src/plugins/qmakeprojectmanager/profileeditor.cpp +++ b/src/plugins/qmakeprojectmanager/profileeditor.cpp @@ -19,7 +19,6 @@ #include <projectexplorer/target.h> #include <texteditor/textdocument.h> -#include <texteditor/texteditoractionhandler.h> #include <utils/fsengine/fileiconprovider.h> #include <utils/mimeconstants.h> @@ -273,8 +272,8 @@ ProFileEditorFactory::ProFileEditorFactory() setCompletionAssistProvider(completionAssistProvider); setCommentDefinition(CommentDefinition::HashStyle); - setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection - | TextEditorActionHandler::JumpToFileUnderCursor); + setOptionalActionMask(OptionalActions::UnCommentSelection + | OptionalActions::JumpToFileUnderCursor); addHoverHandler(new ProFileHoverHandler); setSyntaxHighlighterCreator([]() { return new ProFileHighlighter; }); diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp index 9dd3fa079b..c2f2d2c6e2 100644 --- a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp @@ -36,7 +36,6 @@ #include <projectexplorer/projectexplorericons.h> #include <texteditor/texteditor.h> -#include <texteditor/texteditoractionhandler.h> #include <texteditor/texteditorconstants.h> #include <utils/action.h> diff --git a/src/plugins/qmldesigner/components/bindingeditor/bindingeditorwidget.cpp b/src/plugins/qmldesigner/components/bindingeditor/bindingeditorwidget.cpp index ff2361aa36..b067dc8d46 100644 --- a/src/plugins/qmldesigner/components/bindingeditor/bindingeditorwidget.cpp +++ b/src/plugins/qmldesigner/components/bindingeditor/bindingeditorwidget.cpp @@ -147,7 +147,6 @@ BindingEditorFactory::BindingEditorFactory() { setId(BINDINGEDITOR_CONTEXT_ID); setDisplayName(::Core::Tr::tr("Binding Editor")); - setEditorActionHandlers(0); addMimeType(BINDINGEDITOR_CONTEXT_ID); addMimeType(Utils::Constants::QML_MIMETYPE); addMimeType(Utils::Constants::QMLTYPES_MIMETYPE); diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 79d24891c7..540e5559de 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -52,7 +52,6 @@ #include <texteditor/codeassist/genericproposalmodel.h> #include <texteditor/colorpreviewhoverhandler.h> #include <texteditor/snippets/snippetprovider.h> -#include <texteditor/texteditoractionhandler.h> #include <texteditor/textmark.h> #include <utils/algorithm.h> @@ -1169,12 +1168,12 @@ QmlJSEditorFactory::QmlJSEditorFactory(Utils::Id _id) addHoverHandler(new ColorPreviewHoverHandler); setCompletionAssistProvider(new QmlJSCompletionAssistProvider); - setEditorActionHandlers(TextEditorActionHandler::Format - | TextEditorActionHandler::UnCommentSelection - | TextEditorActionHandler::UnCollapseAll - | TextEditorActionHandler::FollowSymbolUnderCursor - | TextEditorActionHandler::RenameSymbol - | TextEditorActionHandler::FindUsage); + setOptionalActionMask(OptionalActions::Format + | OptionalActions::UnCommentSelection + | OptionalActions::UnCollapseAll + | OptionalActions::FollowSymbolUnderCursor + | OptionalActions::RenameSymbol + | OptionalActions::FindUsage); } static void decorateEditor(TextEditorWidget *editor) diff --git a/src/plugins/texteditor/CMakeLists.txt b/src/plugins/texteditor/CMakeLists.txt index e766ec06a1..978d0de86a 100644 --- a/src/plugins/texteditor/CMakeLists.txt +++ b/src/plugins/texteditor/CMakeLists.txt @@ -104,7 +104,6 @@ add_qtc_plugin(TextEditor texteditor.qrc texteditor_global.h texteditortr.h - texteditoractionhandler.cpp texteditoractionhandler.h texteditorconstants.cpp texteditorconstants.h texteditoroverlay.cpp texteditoroverlay.h texteditorplugin.cpp diff --git a/src/plugins/texteditor/jsoneditor.cpp b/src/plugins/texteditor/jsoneditor.cpp index d06f215c68..7081394f9b 100644 --- a/src/plugins/texteditor/jsoneditor.cpp +++ b/src/plugins/texteditor/jsoneditor.cpp @@ -6,7 +6,6 @@ #include "autocompleter.h" #include "textdocument.h" #include "texteditor.h" -#include "texteditoractionhandler.h" #include "texteditortr.h" #include "textindenter.h" @@ -164,7 +163,7 @@ public: setDocumentCreator([] { return new TextDocument(JSON_EDITOR_ID); }); setAutoCompleterCreator([] { return new JsonAutoCompleter; }); setIndenterCreator([](QTextDocument *doc) { return new JsonIndenter(doc); }); - setEditorActionHandlers(TextEditorActionHandler::Format); + setOptionalActionMask(OptionalActions::Format); setUseGenericHighlighter(true); } }; diff --git a/src/plugins/texteditor/markdowneditor.cpp b/src/plugins/texteditor/markdowneditor.cpp index dbfdcda2b4..c08fedeb10 100644 --- a/src/plugins/texteditor/markdowneditor.cpp +++ b/src/plugins/texteditor/markdowneditor.cpp @@ -16,8 +16,6 @@ #include <coreplugin/icore.h> #include <coreplugin/minisplitter.h> -#include <texteditor/texteditoractionhandler.h> - #include <utils/action.h> #include <utils/ranges.h> #include <utils/qtcsettings.h> @@ -73,7 +71,7 @@ class MarkdownEditor : public IEditor { Q_OBJECT public: - MarkdownEditor(const TextEditor::TextEditorActionHandler *actionHandler) + MarkdownEditor() : m_document(new TextDocument(MARKDOWNVIEWER_ID)) { m_document->setMimeType(MARKDOWNVIEWER_MIME_TYPE); @@ -108,7 +106,7 @@ public: // editor m_textEditorWidget = new MarkdownEditorWidget; - m_textEditorWidget->setOptionalActions(actionHandler->optionalActions()); + m_textEditorWidget->setOptionalActions(OptionalActions::FollowSymbolUnderCursor); m_textEditorWidget->setTextDocument(m_document); m_textEditorWidget->setupGenericHighlighter(); m_textEditorWidget->setMarksVisible(false); @@ -501,7 +499,6 @@ public: MarkdownEditorFactory(); private: - TextEditorActionHandler m_actionHandler; Action m_emphasisAction; Action m_strongAction; Action m_inlineCodeAction; @@ -512,17 +509,11 @@ private: }; MarkdownEditorFactory::MarkdownEditorFactory() - : m_actionHandler(MARKDOWNVIEWER_ID, - MARKDOWNVIEWER_TEXT_CONTEXT, - TextEditor::TextEditorActionHandler::FollowSymbolUnderCursor, - [](IEditor *editor) { - return static_cast<MarkdownEditor *>(editor)->textEditorWidget(); - }) { setId(MARKDOWNVIEWER_ID); setDisplayName(::Core::Tr::tr("Markdown Editor")); addMimeType(MARKDOWNVIEWER_MIME_TYPE); - setEditorCreator([this] { return new MarkdownEditor{&m_actionHandler}; }); + setEditorCreator([] { return new MarkdownEditor; }); const auto textContext = Context(MARKDOWNVIEWER_TEXT_CONTEXT); const auto context = Context(MARKDOWNVIEWER_ID); diff --git a/src/plugins/texteditor/plaintexteditorfactory.cpp b/src/plugins/texteditor/plaintexteditorfactory.cpp index fbaf430284..ef989ee621 100644 --- a/src/plugins/texteditor/plaintexteditorfactory.cpp +++ b/src/plugins/texteditor/plaintexteditorfactory.cpp @@ -5,7 +5,6 @@ #include "basehoverhandler.h" #include "textdocument.h" #include "texteditor.h" -#include "texteditoractionhandler.h" #include "texteditorconstants.h" #include <coreplugin/coreconstants.h> @@ -40,9 +39,9 @@ public: setEditorWidgetCreator([]() { return new PlainTextEditorWidget; }); setUseGenericHighlighter(true); - setEditorActionHandlers(TextEditorActionHandler::Format | - TextEditorActionHandler::UnCommentSelection | - TextEditorActionHandler::UnCollapseAll); + setOptionalActionMask( + OptionalActions::Format | OptionalActions::UnCommentSelection + | OptionalActions::UnCollapseAll); } }; diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 85bd4732ba..9a7c0a2b26 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -21,6 +21,7 @@ #include "highlighterhelper.h" #include "highlightersettings.h" #include "icodestylepreferences.h" +#include "linenumberfilter.h" #include "marginsettings.h" #include "refactoroverlay.h" #include "snippets/snippetoverlay.h" @@ -28,11 +29,11 @@ #include "tabsettings.h" #include "textdocument.h" #include "textdocumentlayout.h" -#include "texteditoractionhandler.h" #include "texteditorconstants.h" #include "texteditoroverlay.h" #include "texteditorsettings.h" #include "texteditortr.h" +#include "typehierarchy.h" #include "typingsettings.h" #include <aggregation/aggregate.h> @@ -45,7 +46,9 @@ #include <coreplugin/find/basetextfind.h> #include <coreplugin/find/highlightscrollbarcontroller.h> #include <coreplugin/icore.h> +#include <coreplugin/locator/locatormanager.h> #include <coreplugin/manhattanstyle.h> +#include <coreplugin/navigationwidget.h> #include <utils/algorithm.h> #include <utils/async.h> @@ -738,6 +741,14 @@ public: void openTypeUnderCursor(bool openInNextSplit); qreal charWidth() const; + // actions + void registerActions(); + void updateActions(); + void updateOptionalActions(); + void updateRedoAction(bool on); + void updateUndoAction(bool on); + void updateCopyAction(bool on); + public: TextEditorWidget *q; QWidget *m_toolBarWidget = nullptr; @@ -753,7 +764,7 @@ public: QToolButton *m_fileLineEnding = nullptr; QAction *m_fileLineEndingAction = nullptr; - uint m_optionalActionMask = TextEditorActionHandler::None; + uint m_optionalActionMask = OptionalActions::None; bool m_contentsChanged = false; bool m_lastCursorChangeWasInteresting = false; std::shared_ptr<void> m_suggestionBlocker; @@ -927,6 +938,30 @@ public: void updateSuggestion(); void clearCurrentSuggestion(); QTextBlock m_suggestionBlock; + + Context m_editorContext; + QAction *m_undoAction = nullptr; + QAction *m_redoAction = nullptr; + QAction *m_copyAction = nullptr; + QAction *m_copyHtmlAction = nullptr; + QAction *m_cutAction = nullptr; + QAction *m_autoIndentAction = nullptr; + QAction *m_autoFormatAction = nullptr; + QAction *m_visualizeWhitespaceAction = nullptr; + QAction *m_textWrappingAction = nullptr; + QAction *m_unCommentSelectionAction = nullptr; + QAction *m_unfoldAllAction = nullptr; + QAction *m_followSymbolAction = nullptr; + QAction *m_followSymbolInNextSplitAction = nullptr; + QAction *m_followToTypeAction = nullptr; + QAction *m_followToTypeInNextSplitAction = nullptr; + QAction *m_findUsageAction = nullptr; + QAction *m_openCallHierarchyAction = nullptr; + QAction *m_openTypeHierarchyAction = nullptr; + QAction *m_renameSymbolAction = nullptr; + QAction *m_jumpToFileAction = nullptr; + QAction *m_jumpToFileInNextSplitAction = nullptr; + QList<QAction *> m_modifyingActions; }; class TextEditorWidgetFind : public BaseTextFind @@ -1031,6 +1066,8 @@ TextEditorWidgetPrivate::TextEditorWidgetPrivate(TextEditorWidget *parent) , m_codeAssistant(parent) , m_hoverHandlerRunner(parent, m_hoverHandlers) , m_autoCompleter(new AutoCompleter) + , m_editorContext( + Id(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID).withSuffix(QUuid::createUuid().toString())) { m_selectionHighlightOverlay->show(); auto aggregate = new Aggregation::Aggregate; @@ -1095,6 +1132,15 @@ TextEditorWidgetPrivate::TextEditorWidgetPrivate(TextEditorWidget *parent) connect(q, &QPlainTextEdit::selectionChanged, this, &TextEditorWidgetPrivate::slotSelectionChanged); + connect(q, &QPlainTextEdit::undoAvailable, + this, &TextEditorWidgetPrivate::updateUndoAction); + + connect(q, &QPlainTextEdit::redoAvailable, + this, &TextEditorWidgetPrivate::updateRedoAction); + + connect(q, &QPlainTextEdit::copyAvailable, + this, &TextEditorWidgetPrivate::updateCopyAction); + m_parenthesesMatchingTimer.setSingleShot(true); m_parenthesesMatchingTimer.setInterval(50); connect(&m_parenthesesMatchingTimer, &QTimer::timeout, @@ -1141,6 +1187,14 @@ TextEditorWidgetPrivate::TextEditorWidgetPrivate(TextEditorWidget *parent) q, &TextEditorWidget::setCompletionSettings); connect(settings, &TextEditorSettings::extraEncodingSettingsChanged, q, &TextEditorWidget::setExtraEncodingSettings); + + auto context = new Core::IContext(this); + context->setWidget(q); + context->setContext(m_editorContext); + Core::ICore::addContextObject(context); + + registerActions(); + updateActions(); } TextEditorWidgetPrivate::~TextEditorWidgetPrivate() @@ -3810,6 +3864,434 @@ qreal TextEditorWidgetPrivate::charWidth() const return QFontMetricsF(q->font()).horizontalAdvance(QLatin1Char('x')); } +void TextEditorWidgetPrivate::registerActions() +{ + using namespace Core::Constants; + using namespace TextEditor::Constants; + + m_undoAction = ActionBuilder(this, UNDO) + .setContext(m_editorContext) + .addOnTriggered([this] { q->undo(); }) + .contextAction(); + m_redoAction = ActionBuilder(this, REDO) + .setContext(m_editorContext) + .addOnTriggered([this] { q->redo(); }) + .contextAction(); + m_copyAction = ActionBuilder(this, COPY) + .setContext(m_editorContext) + .addOnTriggered([this] { q->copy(); }) + .contextAction(); + m_cutAction = ActionBuilder(this, CUT) + .setContext(m_editorContext) + .addOnTriggered([this] { q->cut(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, PASTE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->paste(); }) + .contextAction(); + ActionBuilder(this, SELECTALL) + .setContext(m_editorContext) + .addOnTriggered([this] { q->selectAll(); }); + ActionBuilder(this, GOTO) + .setContext(m_editorContext) + .addOnTriggered([] { LocatorManager::showFilter(lineNumberFilter()); }); + ActionBuilder(this, PRINT) + .setContext(m_editorContext) + .addOnTriggered([this] { q->print(ICore::printer()); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, DELETE_LINE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->deleteLine(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, DELETE_END_OF_LINE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->deleteEndOfLine(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, DELETE_END_OF_WORD) + .setContext(m_editorContext) + .addOnTriggered([this] { q->deleteEndOfWord(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, DELETE_END_OF_WORD_CAMEL_CASE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->deleteEndOfWordCamelCase(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, DELETE_START_OF_LINE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->deleteStartOfLine(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, DELETE_START_OF_WORD) + .setContext(m_editorContext) + .addOnTriggered([this] { q->deleteStartOfWord(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, DELETE_START_OF_WORD_CAMEL_CASE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->deleteStartOfWordCamelCase(); }) + .contextAction(); + ActionBuilder(this, GOTO_BLOCK_START_WITH_SELECTION) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoBlockStartWithSelection(); }); + ActionBuilder(this, GOTO_BLOCK_END_WITH_SELECTION) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoBlockEndWithSelection(); }); + m_modifyingActions << ActionBuilder(this, MOVE_LINE_UP) + .setContext(m_editorContext) + .addOnTriggered([this] { q->moveLineUp(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, MOVE_LINE_DOWN) + .setContext(m_editorContext) + .addOnTriggered([this] { q->moveLineDown(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, COPY_LINE_UP) + .setContext(m_editorContext) + .addOnTriggered([this] { q->copyLineUp(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, COPY_LINE_DOWN) + .setContext(m_editorContext) + .addOnTriggered([this] { q->copyLineDown(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, JOIN_LINES) + .setContext(m_editorContext) + .addOnTriggered([this] { q->joinLines(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, INSERT_LINE_ABOVE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->insertLineAbove(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, INSERT_LINE_BELOW) + .setContext(m_editorContext) + .addOnTriggered([this] { q->insertLineBelow(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, SWITCH_UTF8BOM) + .setContext(m_editorContext) + .addOnTriggered([this] { q->switchUtf8bom(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, INDENT) + .setContext(m_editorContext) + .addOnTriggered([this] { q->indent(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, UNINDENT) + .setContext(m_editorContext) + .addOnTriggered([this] { q->unindent(); }) + .contextAction(); + m_followSymbolAction = ActionBuilder(this, FOLLOW_SYMBOL_UNDER_CURSOR) + .setContext(m_editorContext) + .addOnTriggered([this] { q->openLinkUnderCursor(); }) + .contextAction(); + m_followSymbolInNextSplitAction = ActionBuilder(this, FOLLOW_SYMBOL_UNDER_CURSOR_IN_NEXT_SPLIT) + .setContext(m_editorContext) + .addOnTriggered([this] { q->openLinkUnderCursorInNextSplit(); }) + .contextAction(); + m_followToTypeAction = ActionBuilder(this, FOLLOW_SYMBOL_TO_TYPE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->openTypeUnderCursor(); }) + .contextAction(); + m_followToTypeInNextSplitAction = ActionBuilder(this, FOLLOW_SYMBOL_TO_TYPE_IN_NEXT_SPLIT) + .setContext(m_editorContext) + .addOnTriggered([this] { q->openTypeUnderCursorInNextSplit(); }) + .contextAction(); + m_findUsageAction = ActionBuilder(this, FIND_USAGES) + .setContext(m_editorContext) + .addOnTriggered([this] { q->findUsages(); }) + .contextAction(); + m_renameSymbolAction = ActionBuilder(this, RENAME_SYMBOL) + .setContext(m_editorContext) + .addOnTriggered([this] { q->renameSymbolUnderCursor(); }) + .contextAction(); + m_jumpToFileAction = ActionBuilder(this, JUMP_TO_FILE_UNDER_CURSOR) + .setContext(m_editorContext) + .addOnTriggered([this] { q->openLinkUnderCursor(); }) + .contextAction(); + m_jumpToFileInNextSplitAction = ActionBuilder(this, JUMP_TO_FILE_UNDER_CURSOR_IN_NEXT_SPLIT) + .setContext(m_editorContext) + .addOnTriggered([this] { q->openLinkUnderCursorInNextSplit(); }) + .contextAction(); + m_openCallHierarchyAction = ActionBuilder(this, OPEN_CALL_HIERARCHY) + .setContext(m_editorContext) + .addOnTriggered([this] { q->openCallHierarchy(); }) + .contextAction(); + m_openTypeHierarchyAction = ActionBuilder(this, OPEN_TYPE_HIERARCHY) + .setContext(m_editorContext) + .addOnTriggered([] { + updateTypeHierarchy(NavigationWidget::activateSubWidget( + Constants::TYPE_HIERARCHY_FACTORY_ID, Side::Left)); + }) + .contextAction(); + ActionBuilder(this, VIEW_PAGE_UP) + .setContext(m_editorContext) + .addOnTriggered([this] { q->viewPageUp(); }); + ActionBuilder(this, VIEW_PAGE_DOWN) + .setContext(m_editorContext) + .addOnTriggered([this] { q->viewPageDown(); }); + ActionBuilder(this, VIEW_LINE_UP) + .setContext(m_editorContext) + .addOnTriggered([this] { q->viewLineUp(); }); + ActionBuilder(this, VIEW_LINE_DOWN) + .setContext(m_editorContext) + .addOnTriggered([this] { q->viewLineDown(); }); + + ActionBuilder(this, SELECT_ENCODING) + .setContext(m_editorContext) + .addOnTriggered([this] { q->selectEncoding(); }); + m_modifyingActions << ActionBuilder(this, CIRCULAR_PASTE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->circularPaste(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, NO_FORMAT_PASTE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->pasteWithoutFormat(); }) + .contextAction(); + + m_autoIndentAction = ActionBuilder(this, AUTO_INDENT_SELECTION) + .setContext(m_editorContext) + .addOnTriggered([this] { q->autoIndent(); }) + .contextAction(); + m_autoFormatAction = ActionBuilder(this, AUTO_FORMAT_SELECTION) + .setContext(m_editorContext) + .addOnTriggered([this] { q->autoFormat(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, REWRAP_PARAGRAPH) + .setContext(m_editorContext) + .addOnTriggered([this] { q->rewrapParagraph(); }) + .contextAction(); + m_visualizeWhitespaceAction = ActionBuilder(this, VISUALIZE_WHITESPACE) + .setContext(m_editorContext) + .addOnToggled( + this, + [this](bool checked) { + DisplaySettings ds = q->displaySettings(); + ds.m_visualizeWhitespace = checked; + q->setDisplaySettings(ds); + }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, CLEAN_WHITESPACE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->cleanWhitespace(); }) + .contextAction(); + m_textWrappingAction = ActionBuilder(this, TEXT_WRAPPING) + .setContext(m_editorContext) + .addOnToggled(this, [this] (bool checked) { + DisplaySettings ds = q->displaySettings(); + ds.m_textWrapping = checked; + q->setDisplaySettings(ds); + }) + .contextAction(); + m_unCommentSelectionAction = ActionBuilder(this, UN_COMMENT_SELECTION) + .setContext(m_editorContext) + .addOnTriggered([this] { q->unCommentSelection(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, CUT_LINE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->cutLine(); }) + .contextAction(); + ActionBuilder(this, COPY_LINE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->copyLine(); }); + m_copyHtmlAction = ActionBuilder(this, COPY_WITH_HTML) + .setContext(m_editorContext) + .addOnTriggered([this] { q->copyWithHtml(); }) + .contextAction(); + ActionBuilder(this, ADD_CURSORS_TO_LINE_ENDS) + .setContext(m_editorContext) + .addOnTriggered([this] { q->addCursorsToLineEnds(); }); + ActionBuilder(this, ADD_SELECT_NEXT_FIND_MATCH) + .setContext(m_editorContext) + .addOnTriggered([this] { q->addSelectionNextFindMatch(); }); + m_modifyingActions << ActionBuilder(this, DUPLICATE_SELECTION) + .setContext(m_editorContext) + .addOnTriggered([this] { q->duplicateSelection(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, DUPLICATE_SELECTION_AND_COMMENT) + .setContext(m_editorContext) + .addOnTriggered([this] { q->duplicateSelectionAndComment(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, UPPERCASE_SELECTION) + .setContext(m_editorContext) + .addOnTriggered([this] { q->uppercaseSelection(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, LOWERCASE_SELECTION) + .setContext(m_editorContext) + .addOnTriggered([this] { q->lowercaseSelection(); }) + .contextAction(); + m_modifyingActions << ActionBuilder(this, SORT_LINES) + .setContext(m_editorContext) + .addOnTriggered([this] { q->sortLines(); }) + .contextAction(); + ActionBuilder(this, FOLD) + .setContext(m_editorContext) + .addOnTriggered([this] { q->foldCurrentBlock(); }); + ActionBuilder(this, UNFOLD) + .setContext(m_editorContext) + .addOnTriggered([this] { q->unfoldCurrentBlock(); }); + m_unfoldAllAction = ActionBuilder(this, UNFOLD_ALL) + .setContext(m_editorContext) + .addOnTriggered([this] { q->unfoldAll(); }) + .contextAction(); + ActionBuilder(this, INCREASE_FONT_SIZE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->increaseFontZoom(); }); + ActionBuilder(this, DECREASE_FONT_SIZE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->decreaseFontZoom(); }); + ActionBuilder(this, RESET_FONT_SIZE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->zoomReset(); }); + ActionBuilder(this, GOTO_BLOCK_START) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoBlockStart(); }); + ActionBuilder(this, GOTO_BLOCK_END) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoBlockEnd(); }); + ActionBuilder(this, SELECT_BLOCK_UP) + .setContext(m_editorContext) + .addOnTriggered([this] { q->selectBlockUp(); }); + ActionBuilder(this, SELECT_BLOCK_DOWN) + .setContext(m_editorContext) + .addOnTriggered([this] { q->selectBlockDown(); }); + ActionBuilder(this, SELECT_WORD_UNDER_CURSOR) + .setContext(m_editorContext) + .addOnTriggered([this] { q->selectWordUnderCursor(); }); + + ActionBuilder(this, GOTO_DOCUMENT_START) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoDocumentStart(); }); + ActionBuilder(this, GOTO_DOCUMENT_END) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoDocumentEnd(); }); + ActionBuilder(this, GOTO_LINE_START) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoLineStart(); }); + ActionBuilder(this, GOTO_LINE_END) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoLineEnd(); }); + ActionBuilder(this, GOTO_NEXT_LINE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoNextLine(); }); + ActionBuilder(this, GOTO_PREVIOUS_LINE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoPreviousLine(); }); + ActionBuilder(this, GOTO_PREVIOUS_CHARACTER) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoPreviousCharacter(); }); + ActionBuilder(this, GOTO_NEXT_CHARACTER) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoNextCharacter(); }); + ActionBuilder(this, GOTO_PREVIOUS_WORD) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoPreviousWord(); }); + ActionBuilder(this, GOTO_NEXT_WORD) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoNextWord(); }); + ActionBuilder(this, GOTO_PREVIOUS_WORD_CAMEL_CASE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoPreviousWordCamelCase(); }); + ActionBuilder(this, GOTO_NEXT_WORD_CAMEL_CASE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoNextWordCamelCase(); }); + + ActionBuilder(this, GOTO_LINE_START_WITH_SELECTION) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoLineStartWithSelection(); }); + ActionBuilder(this, GOTO_LINE_END_WITH_SELECTION) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoLineEndWithSelection(); }); + ActionBuilder(this, GOTO_NEXT_LINE_WITH_SELECTION) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoNextLineWithSelection(); }); + ActionBuilder(this, GOTO_PREVIOUS_LINE_WITH_SELECTION) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoPreviousLineWithSelection(); }); + ActionBuilder(this, GOTO_PREVIOUS_CHARACTER_WITH_SELECTION) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoPreviousCharacterWithSelection(); }); + ActionBuilder(this, GOTO_NEXT_CHARACTER_WITH_SELECTION) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoNextCharacterWithSelection(); }); + ActionBuilder(this, GOTO_PREVIOUS_WORD_WITH_SELECTION) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoPreviousWordWithSelection(); }); + ActionBuilder(this, GOTO_NEXT_WORD_WITH_SELECTION) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoNextWordWithSelection(); }); + ActionBuilder(this, GOTO_PREVIOUS_WORD_CAMEL_CASE_WITH_SELECTION) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoPreviousWordCamelCaseWithSelection(); }); + ActionBuilder(this, GOTO_NEXT_WORD_CAMEL_CASE_WITH_SELECTION) + .setContext(m_editorContext) + .addOnTriggered([this] { q->gotoNextWordCamelCaseWithSelection(); }); + + // Collect additional modifying actions so we can check for them inside a readonly file + // and disable them + m_modifyingActions << m_autoIndentAction; + m_modifyingActions << m_autoFormatAction; + m_modifyingActions << m_unCommentSelectionAction; + + updateOptionalActions(); +} + +void TextEditorWidgetPrivate::updateActions() +{ + bool isWritable = !q->isReadOnly(); + for (QAction *a : std::as_const(m_modifyingActions)) + a->setEnabled(isWritable); + m_unCommentSelectionAction->setEnabled((m_optionalActionMask & OptionalActions::UnCommentSelection) && isWritable); + m_visualizeWhitespaceAction->setEnabled(q); + if (TextEditorSettings::fontSettings().relativeLineSpacing() == 100) { + m_textWrappingAction->setEnabled(q); + } else { + m_textWrappingAction->setEnabled(false); + m_textWrappingAction->setChecked(false); + } + m_visualizeWhitespaceAction->setChecked(m_displaySettings.m_visualizeWhitespace); + m_textWrappingAction->setChecked(m_displaySettings.m_textWrapping); + + updateRedoAction(q->document()->isRedoAvailable()); + updateUndoAction(q->document()->isUndoAvailable()); + updateCopyAction(q->textCursor().hasSelection()); + + updateOptionalActions(); +} + +void TextEditorWidgetPrivate::updateOptionalActions() +{ + using namespace OptionalActions; + m_followSymbolAction->setEnabled(m_optionalActionMask & FollowSymbolUnderCursor); + m_followSymbolInNextSplitAction->setEnabled(m_optionalActionMask & FollowSymbolUnderCursor); + m_followToTypeAction->setEnabled(m_optionalActionMask & FollowTypeUnderCursor); + m_followToTypeInNextSplitAction->setEnabled(m_optionalActionMask & FollowTypeUnderCursor); + m_findUsageAction->setEnabled(m_optionalActionMask & FindUsage); + m_jumpToFileAction->setEnabled(m_optionalActionMask & JumpToFileUnderCursor); + m_jumpToFileInNextSplitAction->setEnabled(m_optionalActionMask & JumpToFileUnderCursor); + m_unfoldAllAction->setEnabled(m_optionalActionMask & UnCollapseAll); + m_renameSymbolAction->setEnabled(m_optionalActionMask & RenameSymbol); + m_openCallHierarchyAction->setEnabled(m_optionalActionMask & CallHierarchy); + m_openTypeHierarchyAction->setEnabled(m_optionalActionMask & TypeHierarchy); + + bool formatEnabled = (m_optionalActionMask & OptionalActions::Format) + && !q->isReadOnly(); + m_autoIndentAction->setEnabled(formatEnabled); + m_autoFormatAction->setEnabled(formatEnabled); +} + +void TextEditorWidgetPrivate::updateRedoAction(bool on) +{ + m_redoAction->setEnabled(on); +} + +void TextEditorWidgetPrivate::updateUndoAction(bool on) +{ + m_undoAction->setEnabled(on); +} + +void TextEditorWidgetPrivate::updateCopyAction(bool hasCopyableText) +{ + if (m_cutAction) + m_cutAction->setEnabled(hasCopyableText && !q->isReadOnly()); + if (m_copyAction) + m_copyAction->setEnabled(hasCopyableText); + if (m_copyHtmlAction) + m_copyHtmlAction->setEnabled(hasCopyableText); +} + bool TextEditorWidget::codeFoldingVisible() const { return d->m_codeFoldingVisible; @@ -8103,6 +8585,7 @@ void TextEditorWidgetPrivate::applyFontSettingsDelayed() m_fontSettingsNeedsApply = true; if (q->isVisible()) q->triggerPendingUpdates(); + updateActions(); } void TextEditorWidgetPrivate::markRemoved(TextMark *mark) @@ -8338,6 +8821,7 @@ void TextEditorWidget::setReadOnly(bool b) emit readOnlyChanged(); if (b) setTextInteractionFlags(textInteractionFlags() | Qt::TextSelectableByKeyboard); + d->updateActions(); } void TextEditorWidget::cut() @@ -8735,32 +9219,32 @@ void TextEditorWidget::setupFallBackEditor(Id id) void TextEditorWidget::appendStandardContextMenuActions(QMenu *menu) { - if (optionalActions() & TextEditorActionHandler::FollowSymbolUnderCursor) { + if (optionalActions() & OptionalActions::FollowSymbolUnderCursor) { const auto action = ActionManager::command(Constants::FOLLOW_SYMBOL_UNDER_CURSOR)->action(); if (!menu->actions().contains(action)) menu->addAction(action); } - if (optionalActions() & TextEditorActionHandler::FollowTypeUnderCursor) { + if (optionalActions() & OptionalActions::FollowTypeUnderCursor) { const auto action = ActionManager::command(Constants::FOLLOW_SYMBOL_TO_TYPE)->action(); if (!menu->actions().contains(action)) menu->addAction(action); } - if (optionalActions() & TextEditorActionHandler::FindUsage) { + if (optionalActions() & OptionalActions::FindUsage) { const auto action = ActionManager::command(Constants::FIND_USAGES)->action(); if (!menu->actions().contains(action)) menu->addAction(action); } - if (optionalActions() & TextEditorActionHandler::RenameSymbol) { + if (optionalActions() & OptionalActions::RenameSymbol) { const auto action = ActionManager::command(Constants::RENAME_SYMBOL)->action(); if (!menu->actions().contains(action)) menu->addAction(action); } - if (optionalActions() & TextEditorActionHandler::CallHierarchy) { + if (optionalActions() & OptionalActions::CallHierarchy) { const auto action = ActionManager::command(Constants::OPEN_CALL_HIERARCHY)->action(); if (!menu->actions().contains(action)) menu->addAction(action); } - if (optionalActions() & TextEditorActionHandler::TypeHierarchy) { + if (optionalActions() & OptionalActions::TypeHierarchy) { const auto action = ActionManager::command(Constants::OPEN_TYPE_HIERARCHY)->action(); if (!menu->actions().contains(action)) menu->addAction(action); @@ -8792,7 +9276,7 @@ void TextEditorWidget::setOptionalActions(uint optionalActionMask) if (d->m_optionalActionMask == optionalActionMask) return; d->m_optionalActionMask = optionalActionMask; - emit optionalActionMaskChanged(); + d->updateOptionalActions(); } void TextEditorWidget::addOptionalActions( uint optionalActionMask) @@ -9492,7 +9976,7 @@ public: CommentDefinition m_commentDefinition; QList<BaseHoverHandler *> m_hoverHandlers; // owned std::unique_ptr<CompletionAssistProvider> m_completionAssistProvider; // owned - std::unique_ptr<TextEditorActionHandler> m_textEditorActionHandler; + int m_optionalActionMask = 0; bool m_useGenericHighlighter = false; bool m_duplicatedSupported = true; bool m_codeFoldingSupported = false; @@ -9565,9 +10049,9 @@ void TextEditorFactory::setAutoCompleterCreator(const AutoCompleterCreator &crea d->m_autoCompleterCreator = creator; } -void TextEditorFactory::setEditorActionHandlers(uint optionalActions) +void TextEditorFactory::setOptionalActionMask(int optionalActions) { - d->m_textEditorActionHandler.reset(new TextEditorActionHandler(id(), id(), optionalActions)); + d->m_optionalActionMask = optionalActions; } void TextEditorFactory::addHoverHandler(BaseHoverHandler *handler) @@ -9613,8 +10097,7 @@ BaseTextEditor *TextEditorFactoryPrivate::createEditorHelper(const TextDocumentP textEditorWidget->setMarksVisible(m_marksVisible); textEditorWidget->setParenthesesMatchingEnabled(m_paranthesesMatchinEnabled); textEditorWidget->setCodeFoldingSupported(m_codeFoldingSupported); - if (m_textEditorActionHandler) - textEditorWidget->setOptionalActions(m_textEditorActionHandler->optionalActions()); + textEditorWidget->setOptionalActions(m_optionalActionMask); BaseTextEditor *editor = m_editorCreator(); editor->setDuplicateSupported(m_duplicatedSupported); diff --git a/src/plugins/texteditor/texteditor.h b/src/plugins/texteditor/texteditor.h index 85344a8dbd..2d54231b1c 100644 --- a/src/plugins/texteditor/texteditor.h +++ b/src/plugins/texteditor/texteditor.h @@ -85,6 +85,22 @@ enum TextMarkRequestKind TaskMarkRequest }; +namespace OptionalActions { +enum Mask { + None = 0, + Format = 1, + UnCommentSelection = 2, + UnCollapseAll = 4, + FollowSymbolUnderCursor = 8, + FollowTypeUnderCursor = 16, + JumpToFileUnderCursor = 32, + RenameSymbol = 64, + FindUsage = 128, + CallHierarchy = 256, + TypeHierarchy = 512, +}; +} // namespace OptionalActions + class TEXTEDITOR_EXPORT BaseTextEditor : public Core::IEditor { Q_OBJECT @@ -511,7 +527,6 @@ signals: void requestUsages(const QTextCursor &cursor); void requestRename(const QTextCursor &cursor); void requestCallHierarchy(const QTextCursor &cursor); - void optionalActionMaskChanged(); void toolbarOutlineChanged(QWidget *newOutline); protected: @@ -689,7 +704,7 @@ public: void setSyntaxHighlighterCreator(const SyntaxHighLighterCreator &creator); void setUseGenericHighlighter(bool enabled); void setAutoCompleterCreator(const AutoCompleterCreator &creator); - void setEditorActionHandlers(uint optionalActions); + void setOptionalActionMask(int optionalActions); void addHoverHandler(BaseHoverHandler *handler); void setCompletionAssistProvider(CompletionAssistProvider *provider); diff --git a/src/plugins/texteditor/texteditor.qbs b/src/plugins/texteditor/texteditor.qbs index 30a4712b73..7c0ee12093 100644 --- a/src/plugins/texteditor/texteditor.qbs +++ b/src/plugins/texteditor/texteditor.qbs @@ -137,8 +137,6 @@ QtcPlugin { "texteditor.qrc", "texteditor_global.h", "texteditortr.h", - "texteditoractionhandler.cpp", - "texteditoractionhandler.h", "texteditorconstants.cpp", "texteditorconstants.h", "texteditoroverlay.cpp", diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp deleted file mode 100644 index 2cf553689c..0000000000 --- a/src/plugins/texteditor/texteditoractionhandler.cpp +++ /dev/null @@ -1,671 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#include "texteditoractionhandler.h" - -#include "texteditor.h" -#include "displaysettings.h" -#include "fontsettings.h" -#include "linenumberfilter.h" -#include "texteditortr.h" -#include "texteditorsettings.h" -#include "typehierarchy.h" - -#include <aggregation/aggregate.h> - -#include <coreplugin/locator/locatormanager.h> -#include <coreplugin/icore.h> -#include <coreplugin/editormanager/editormanager.h> -#include <coreplugin/coreconstants.h> -#include <coreplugin/navigationwidget.h> -#include <coreplugin/actionmanager/actionmanager.h> -#include <coreplugin/actionmanager/actioncontainer.h> -#include <coreplugin/actionmanager/command.h> - -#include <utils/hostosinfo.h> -#include <utils/qtcassert.h> - -#include <QDebug> -#include <QAction> - -#include <functional> - -using namespace Core; - -namespace TextEditor { -namespace Internal { - -class TextEditorActionHandlerPrivate : public QObject -{ -public: - TextEditorActionHandlerPrivate(Utils::Id editorId, Utils::Id contextId, uint optionalActions); - - QAction *registerActionHelper(Utils::Id id, - bool scriptable, - const QString &title, - const QKeySequence &keySequence, - Utils::Id menueGroup, - ActionContainer *container, - std::function<void(bool)> slot) - { - auto result = new QAction(title, this); - Command *command - = ActionManager::registerAction(result, id, Context(m_contextId), scriptable); - if (!keySequence.isEmpty()) - command->setDefaultKeySequence(keySequence); - - if (container && menueGroup.isValid()) - container->addAction(command, menueGroup); - - connect(result, &QAction::triggered, slot); - return result; - } - - QAction *registerAction(Utils::Id id, - std::function<void(TextEditorWidget *)> slot, - bool scriptable = false, - const QString &title = QString(), - const QKeySequence &keySequence = QKeySequence(), - Utils::Id menueGroup = Utils::Id(), - ActionContainer *container = nullptr) - { - return registerActionHelper(id, - scriptable, - title, - keySequence, - menueGroup, - container, - [this, slot, id](bool) { - if (m_currentEditorWidget) - slot(m_currentEditorWidget); - else if (m_unhandledCallback) - m_unhandledCallback(id, m_currentEditor); - }); - } - - QAction *registerBoolAction(Utils::Id id, - std::function<void(TextEditorWidget *, bool)> slot, - bool scriptable = false, - const QString &title = QString(), - const QKeySequence &keySequence = QKeySequence(), - Utils::Id menueGroup = Utils::Id(), - ActionContainer *container = nullptr) - { - return registerActionHelper(id, scriptable, title, keySequence, menueGroup, container, - [this, slot](bool on) { if (m_currentEditorWidget) slot(m_currentEditorWidget, on); }); - } - - QAction *registerIntAction(Utils::Id id, - std::function<void(TextEditorWidget *, int)> slot, - bool scriptable = false, - const QString &title = QString(), - const QKeySequence &keySequence = QKeySequence(), - Utils::Id menueGroup = Utils::Id(), - ActionContainer *container = nullptr) - { - return registerActionHelper(id, scriptable, title, keySequence, menueGroup, container, - [this, slot](bool on) { if (m_currentEditorWidget) slot(m_currentEditorWidget, on); }); - } - - void createActions(); - - void updateActions(); - void updateOptionalActions(); - void updateRedoAction(bool on); - void updateUndoAction(bool on); - void updateCopyAction(bool on); - - void updateCurrentEditor(IEditor *editor); - - void setCanUndoCallback(const TextEditorActionHandler::Predicate &callback); - void setCanRedoCallback(const TextEditorActionHandler::Predicate &callback); - -public: - TextEditorActionHandler::TextEditorWidgetResolver m_findTextWidget; - QAction *m_undoAction = nullptr; - QAction *m_redoAction = nullptr; - QAction *m_copyAction = nullptr; - QAction *m_copyHtmlAction = nullptr; - QAction *m_cutAction = nullptr; - QAction *m_autoIndentAction = nullptr; - QAction *m_autoFormatAction = nullptr; - QAction *m_visualizeWhitespaceAction = nullptr; - QAction *m_textWrappingAction = nullptr; - QAction *m_unCommentSelectionAction = nullptr; - QAction *m_unfoldAllAction = nullptr; - QAction *m_followSymbolAction = nullptr; - QAction *m_followSymbolInNextSplitAction = nullptr; - QAction *m_followToTypeAction = nullptr; - QAction *m_followToTypeInNextSplitAction = nullptr; - QAction *m_findUsageAction = nullptr; - QAction *m_openCallHierarchyAction = nullptr; - QAction *m_openTypeHierarchyAction = nullptr; - QAction *m_renameSymbolAction = nullptr; - QAction *m_jumpToFileAction = nullptr; - QAction *m_jumpToFileInNextSplitAction = nullptr; - QList<QAction *> m_modifyingActions; - - uint m_optionalActions = TextEditorActionHandler::None; - QPointer<TextEditorWidget> m_currentEditorWidget; - QPointer<IEditor> m_currentEditor; - Utils::Id m_editorId; - Utils::Id m_contextId; - - TextEditorActionHandler::Predicate m_canUndoCallback; - TextEditorActionHandler::Predicate m_canRedoCallback; - - TextEditorActionHandler::UnhandledCallback m_unhandledCallback; -}; - -TextEditorActionHandlerPrivate::TextEditorActionHandlerPrivate - (Utils::Id editorId, Utils::Id contextId, uint optionalActions) - : m_optionalActions(optionalActions) - , m_editorId(editorId) - , m_contextId(contextId) -{ - createActions(); - connect(EditorManager::instance(), - &EditorManager::currentEditorChanged, - this, - &TextEditorActionHandlerPrivate::updateCurrentEditor); - connect(TextEditorSettings::instance(), &TextEditorSettings::fontSettingsChanged, - this, &TextEditorActionHandlerPrivate::updateActions); -} - -void TextEditorActionHandlerPrivate::createActions() -{ - using namespace Core::Constants; - using namespace TextEditor::Constants; - - m_undoAction = registerAction(UNDO, - [] (TextEditorWidget *w) { w->undo(); }, true, Tr::tr("&Undo")); - m_redoAction = registerAction(REDO, - [] (TextEditorWidget *w) { w->redo(); }, true, Tr::tr("&Redo")); - m_copyAction = registerAction(COPY, - [] (TextEditorWidget *w) { w->copy(); }, true); - m_cutAction = registerAction(CUT, - [] (TextEditorWidget *w) { w->cut(); }, true); - m_modifyingActions << registerAction(PASTE, - [] (TextEditorWidget *w) { w->paste(); }, true); - registerAction(SELECTALL, - [] (TextEditorWidget *w) { w->selectAll(); }, true); - registerAction(GOTO, [](TextEditorWidget *) { - LocatorManager::showFilter(lineNumberFilter()); - }); - m_modifyingActions << registerAction(PRINT, [](TextEditorWidget *widget) { - widget->print(ICore::printer()); - }); - m_modifyingActions << registerAction(DELETE_LINE, - [] (TextEditorWidget *w) { w->deleteLine(); }, true, Tr::tr("Delete &Line")); - m_modifyingActions << registerAction(DELETE_END_OF_LINE, - [] (TextEditorWidget *w) { w->deleteEndOfLine(); }, true, Tr::tr("Delete Line from Cursor On")); - m_modifyingActions << registerAction(DELETE_END_OF_WORD, - [] (TextEditorWidget *w) { w->deleteEndOfWord(); }, true, Tr::tr("Delete Word from Cursor On")); - m_modifyingActions << registerAction(DELETE_END_OF_WORD_CAMEL_CASE, - [] (TextEditorWidget *w) { w->deleteEndOfWordCamelCase(); }, true, Tr::tr("Delete Word Camel Case from Cursor On")); - m_modifyingActions << registerAction( - DELETE_START_OF_LINE, - [](TextEditorWidget *w) { w->deleteStartOfLine(); }, - true, - Tr::tr("Delete Line up to Cursor"), - Core::useMacShortcuts ? QKeySequence(Tr::tr("Ctrl+Backspace")) : QKeySequence()); - m_modifyingActions << registerAction(DELETE_START_OF_WORD, - [] (TextEditorWidget *w) { w->deleteStartOfWord(); }, true, Tr::tr("Delete Word up to Cursor")); - m_modifyingActions << registerAction(DELETE_START_OF_WORD_CAMEL_CASE, - [] (TextEditorWidget *w) { w->deleteStartOfWordCamelCase(); }, true, Tr::tr("Delete Word Camel Case up to Cursor")); - registerAction(GOTO_BLOCK_START_WITH_SELECTION, - [] (TextEditorWidget *w) { w->gotoBlockStartWithSelection(); }, true, Tr::tr("Go to Block Start with Selection"), - QKeySequence(Tr::tr("Ctrl+{"))); - registerAction(GOTO_BLOCK_END_WITH_SELECTION, - [] (TextEditorWidget *w) { w->gotoBlockEndWithSelection(); }, true, Tr::tr("Go to Block End with Selection"), - QKeySequence(Tr::tr("Ctrl+}"))); - m_modifyingActions << registerAction(MOVE_LINE_UP, - [] (TextEditorWidget *w) { w->moveLineUp(); }, true, Tr::tr("Move Line Up"), - QKeySequence(Tr::tr("Ctrl+Shift+Up"))); - m_modifyingActions << registerAction(MOVE_LINE_DOWN, - [] (TextEditorWidget *w) { w->moveLineDown(); }, true, Tr::tr("Move Line Down"), - QKeySequence(Tr::tr("Ctrl+Shift+Down"))); - m_modifyingActions << registerAction(COPY_LINE_UP, - [] (TextEditorWidget *w) { w->copyLineUp(); }, true, Tr::tr("Copy Line Up"), - QKeySequence(Tr::tr("Ctrl+Alt+Up"))); - m_modifyingActions << registerAction(COPY_LINE_DOWN, - [] (TextEditorWidget *w) { w->copyLineDown(); }, true, Tr::tr("Copy Line Down"), - QKeySequence(Tr::tr("Ctrl+Alt+Down"))); - m_modifyingActions << registerAction(JOIN_LINES, - [] (TextEditorWidget *w) { w->joinLines(); }, true, Tr::tr("Join Lines"), - QKeySequence(Tr::tr("Ctrl+J"))); - m_modifyingActions << registerAction(INSERT_LINE_ABOVE, - [] (TextEditorWidget *w) { w->insertLineAbove(); }, true, Tr::tr("Insert Line Above Current Line"), - QKeySequence(Tr::tr("Ctrl+Shift+Return"))); - m_modifyingActions << registerAction(INSERT_LINE_BELOW, - [] (TextEditorWidget *w) { w->insertLineBelow(); }, true, Tr::tr("Insert Line Below Current Line"), - QKeySequence(Tr::tr("Ctrl+Return"))); - m_modifyingActions << registerAction(SWITCH_UTF8BOM, - [] (TextEditorWidget *w) { w->switchUtf8bom(); }, true, Tr::tr("Toggle UTF-8 BOM")); - m_modifyingActions << registerAction(INDENT, - [] (TextEditorWidget *w) { w->indent(); }, true, Tr::tr("Indent")); - m_modifyingActions << registerAction(UNINDENT, - [] (TextEditorWidget *w) { w->unindent(); }, true, Tr::tr("Unindent")); - m_followSymbolAction = registerAction(FOLLOW_SYMBOL_UNDER_CURSOR, - [] (TextEditorWidget *w) { w->openLinkUnderCursor(); }, true, Tr::tr("Follow Symbol Under Cursor"), - QKeySequence(Qt::Key_F2)); - m_followSymbolInNextSplitAction = registerAction(FOLLOW_SYMBOL_UNDER_CURSOR_IN_NEXT_SPLIT, - [] (TextEditorWidget *w) { w->openLinkUnderCursorInNextSplit(); }, true, Tr::tr("Follow Symbol Under Cursor in Next Split"), - QKeySequence(Utils::HostOsInfo::isMacHost() ? Tr::tr("Meta+E, F2") : Tr::tr("Ctrl+E, F2"))); - m_followToTypeAction = registerAction(FOLLOW_SYMBOL_TO_TYPE, - [] (TextEditorWidget *w) { w->openTypeUnderCursor(); }, true, Tr::tr("Follow Type Under Cursor"), - QKeySequence(Tr::tr("Ctrl+Shift+F2"))); - m_followToTypeInNextSplitAction = registerAction(FOLLOW_SYMBOL_TO_TYPE_IN_NEXT_SPLIT, - [] (TextEditorWidget *w) { w->openTypeUnderCursorInNextSplit(); }, true, Tr::tr("Follow Type Under Cursor in Next Split"), - QKeySequence(Utils::HostOsInfo::isMacHost() ? Tr::tr("Meta+E, Shift+F2") : Tr::tr("Ctrl+E, Ctrl+Shift+F2"))); - m_findUsageAction = registerAction(FIND_USAGES, - [] (TextEditorWidget *w) { w->findUsages(); }, true, Tr::tr("Find References to Symbol Under Cursor"), - QKeySequence(Tr::tr("Ctrl+Shift+U"))); - m_renameSymbolAction = registerAction(RENAME_SYMBOL, - [] (TextEditorWidget *w) { w->renameSymbolUnderCursor(); }, true, Tr::tr("Rename Symbol Under Cursor"), - QKeySequence(Tr::tr("Ctrl+Shift+R"))); - m_jumpToFileAction = registerAction(JUMP_TO_FILE_UNDER_CURSOR, - [] (TextEditorWidget *w) { w->openLinkUnderCursor(); }, true, Tr::tr("Jump to File Under Cursor"), - QKeySequence(Qt::Key_F2)); - m_jumpToFileInNextSplitAction = registerAction(JUMP_TO_FILE_UNDER_CURSOR_IN_NEXT_SPLIT, - [] (TextEditorWidget *w) { w->openLinkUnderCursorInNextSplit(); }, true, Tr::tr("Jump to File Under Cursor in Next Split"), - QKeySequence(Utils::HostOsInfo::isMacHost() ? Tr::tr("Meta+E, F2") : Tr::tr("Ctrl+E, F2")).toString()); - m_openCallHierarchyAction = registerAction(OPEN_CALL_HIERARCHY, - [] (TextEditorWidget *w) { w->openCallHierarchy(); }, true, Tr::tr("Open Call Hierarchy")); - m_openTypeHierarchyAction = registerAction( - OPEN_TYPE_HIERARCHY, - [](TextEditorWidget *) { - updateTypeHierarchy( - NavigationWidget::activateSubWidget(Constants::TYPE_HIERARCHY_FACTORY_ID, - Side::Left)); - }, - true, - Tr::tr("Open Type Hierarchy"), - QKeySequence(Utils::HostOsInfo::isMacHost() ? Tr::tr("Meta+Shift+T") - : Tr::tr("Ctrl+Shift+T"))); - registerAction(VIEW_PAGE_UP, - [] (TextEditorWidget *w) { w->viewPageUp(); }, true, Tr::tr("Move the View a Page Up and Keep the Cursor Position"), - QKeySequence(Tr::tr("Ctrl+PgUp"))); - registerAction(VIEW_PAGE_DOWN, - [] (TextEditorWidget *w) { w->viewPageDown(); }, true, Tr::tr("Move the View a Page Down and Keep the Cursor Position"), - QKeySequence(Tr::tr("Ctrl+PgDown"))); - registerAction(VIEW_LINE_UP, - [] (TextEditorWidget *w) { w->viewLineUp(); }, true, Tr::tr("Move the View a Line Up and Keep the Cursor Position"), - QKeySequence(Tr::tr("Ctrl+Up"))); - registerAction(VIEW_LINE_DOWN, - [] (TextEditorWidget *w) { w->viewLineDown(); }, true, Tr::tr("Move the View a Line Down and Keep the Cursor Position"), - QKeySequence(Tr::tr("Ctrl+Down"))); - - // register "Edit" Menu Actions - ActionContainer *editMenu = ActionManager::actionContainer(M_EDIT); - registerAction(SELECT_ENCODING, - [] (TextEditorWidget *w) { w->selectEncoding(); }, false, Tr::tr("Select Encoding..."), - QKeySequence(), G_EDIT_OTHER, editMenu); - m_modifyingActions << registerAction(CIRCULAR_PASTE, - [] (TextEditorWidget *w) { w->circularPaste(); }, false, Tr::tr("Paste from Clipboard History"), - QKeySequence(Tr::tr("Ctrl+Shift+V")), G_EDIT_COPYPASTE, editMenu); - m_modifyingActions << registerAction(NO_FORMAT_PASTE, - [] (TextEditorWidget *w) { w->pasteWithoutFormat(); }, false, Tr::tr("Paste Without Formatting"), - QKeySequence(Core::useMacShortcuts ? Tr::tr("Ctrl+Alt+Shift+V") : QString()), G_EDIT_COPYPASTE, editMenu); - - // register "Edit -> Advanced" Menu Actions - ActionContainer *advancedEditMenu = ActionManager::actionContainer(M_EDIT_ADVANCED); - m_autoIndentAction = registerAction(AUTO_INDENT_SELECTION, - [] (TextEditorWidget *w) { w->autoIndent(); }, true, Tr::tr("Auto-&indent Selection"), - QKeySequence(Tr::tr("Ctrl+I")), - G_EDIT_FORMAT, advancedEditMenu); - m_autoFormatAction = registerAction(AUTO_FORMAT_SELECTION, - [] (TextEditorWidget *w) { w->autoFormat(); }, true, Tr::tr("Auto-&format Selection"), - QKeySequence(Tr::tr("Ctrl+;")), - G_EDIT_FORMAT, advancedEditMenu); - m_modifyingActions << registerAction(REWRAP_PARAGRAPH, - [] (TextEditorWidget *w) { w->rewrapParagraph(); }, true, Tr::tr("&Rewrap Paragraph"), - QKeySequence(Core::useMacShortcuts ? Tr::tr("Meta+E, R") : Tr::tr("Ctrl+E, R")), - G_EDIT_FORMAT, advancedEditMenu); - m_visualizeWhitespaceAction = registerBoolAction(VISUALIZE_WHITESPACE, - [] (TextEditorWidget *widget, bool checked) { - if (widget) { - DisplaySettings ds = widget->displaySettings(); - ds.m_visualizeWhitespace = checked; - widget->setDisplaySettings(ds); - } - }, - false, Tr::tr("&Visualize Whitespace"), - QKeySequence(Core::useMacShortcuts ? Tr::tr("Meta+E, Meta+V") : Tr::tr("Ctrl+E, Ctrl+V")), - G_EDIT_FORMAT, advancedEditMenu); - m_visualizeWhitespaceAction->setCheckable(true); - m_modifyingActions << registerAction(CLEAN_WHITESPACE, - [] (TextEditorWidget *w) { w->cleanWhitespace(); }, true, Tr::tr("Clean Whitespace"), - QKeySequence(), - G_EDIT_FORMAT, advancedEditMenu); - m_textWrappingAction = registerBoolAction(TEXT_WRAPPING, - [] (TextEditorWidget *widget, bool checked) { - if (widget) { - DisplaySettings ds = widget->displaySettings(); - ds.m_textWrapping = checked; - widget->setDisplaySettings(ds); - } - }, - false, Tr::tr("Enable Text &Wrapping"), - QKeySequence(Core::useMacShortcuts ? Tr::tr("Meta+E, Meta+W") : Tr::tr("Ctrl+E, Ctrl+W")), - G_EDIT_FORMAT, advancedEditMenu); - m_textWrappingAction->setCheckable(true); - m_unCommentSelectionAction = registerAction(UN_COMMENT_SELECTION, - [] (TextEditorWidget *w) { w->unCommentSelection(); }, true, Tr::tr("Toggle Comment &Selection"), - QKeySequence(Tr::tr("Ctrl+/")), - G_EDIT_FORMAT, advancedEditMenu); - m_modifyingActions << registerAction(CUT_LINE, - [] (TextEditorWidget *w) { w->cutLine(); }, true, Tr::tr("Cut &Line"), - QKeySequence(Tr::tr("Shift+Del")), - G_EDIT_TEXT, advancedEditMenu); - registerAction(COPY_LINE, - [] (TextEditorWidget *w) { w->copyLine(); }, false, Tr::tr("Copy &Line"), - QKeySequence(Tr::tr("Ctrl+Ins")), - G_EDIT_TEXT, advancedEditMenu); - m_copyHtmlAction = registerAction(COPY_WITH_HTML, - [] (TextEditorWidget *w) { w->copyWithHtml(); }, true, Tr::tr("Copy With Highlighting"), - QKeySequence(), G_EDIT_TEXT, advancedEditMenu); - - registerAction(ADD_CURSORS_TO_LINE_ENDS, - [] (TextEditorWidget *w) { w->addCursorsToLineEnds(); }, false, Tr::tr("Create Cursors at Selected Line Ends"), - QKeySequence(Tr::tr("Alt+Shift+I")), - G_EDIT_TEXT, advancedEditMenu); - registerAction(ADD_SELECT_NEXT_FIND_MATCH, - [] (TextEditorWidget *w) { w->addSelectionNextFindMatch(); }, false, Tr::tr("Add Next Occurrence to Selection"), - QKeySequence(Tr::tr("Ctrl+D")), - G_EDIT_TEXT, advancedEditMenu); - m_modifyingActions << registerAction(DUPLICATE_SELECTION, - [] (TextEditorWidget *w) { w->duplicateSelection(); }, false, Tr::tr("&Duplicate Selection"), - QKeySequence(), - G_EDIT_TEXT, advancedEditMenu); - m_modifyingActions << registerAction(DUPLICATE_SELECTION_AND_COMMENT, - [] (TextEditorWidget *w) { w->duplicateSelectionAndComment(); }, false, Tr::tr("&Duplicate Selection and Comment"), - QKeySequence(), - G_EDIT_TEXT, advancedEditMenu); - m_modifyingActions << registerAction(UPPERCASE_SELECTION, - [] (TextEditorWidget *w) { w->uppercaseSelection(); }, true, Tr::tr("Uppercase Selection"), - QKeySequence(Core::useMacShortcuts ? Tr::tr("Meta+Shift+U") : Tr::tr("Alt+Shift+U")), - G_EDIT_TEXT, advancedEditMenu); - m_modifyingActions << registerAction(LOWERCASE_SELECTION, - [] (TextEditorWidget *w) { w->lowercaseSelection(); }, true, Tr::tr("Lowercase Selection"), - QKeySequence(Core::useMacShortcuts ? Tr::tr("Meta+U") : Tr::tr("Alt+U")), - G_EDIT_TEXT, advancedEditMenu); - m_modifyingActions << registerAction(SORT_LINES, - [] (TextEditorWidget *w) { w->sortLines(); }, false, Tr::tr("&Sort Lines"), - QKeySequence(Core::useMacShortcuts ? Tr::tr("Meta+Shift+S") : Tr::tr("Alt+Shift+S")), - G_EDIT_TEXT, advancedEditMenu); - registerAction(FOLD, - [] (TextEditorWidget *w) { w->foldCurrentBlock(); }, true, Tr::tr("Fold"), - QKeySequence(Tr::tr("Ctrl+<")), - G_EDIT_COLLAPSING, advancedEditMenu); - registerAction(UNFOLD, - [] (TextEditorWidget *w) { w->unfoldCurrentBlock(); }, true, Tr::tr("Unfold"), - QKeySequence(Tr::tr("Ctrl+>")), - G_EDIT_COLLAPSING, advancedEditMenu); - m_unfoldAllAction = registerAction(UNFOLD_ALL, - [] (TextEditorWidget *w) { w->unfoldAll(); }, true, Tr::tr("Toggle &Fold All"), - QKeySequence(), - G_EDIT_COLLAPSING, advancedEditMenu); - registerAction(INCREASE_FONT_SIZE, - [] (TextEditorWidget *w) { w->increaseFontZoom(); }, false, Tr::tr("Increase Font Size"), - QKeySequence(Tr::tr("Ctrl++")), - G_EDIT_FONT, advancedEditMenu); - registerAction(DECREASE_FONT_SIZE, - [] (TextEditorWidget *w) { w->decreaseFontZoom(); }, false, Tr::tr("Decrease Font Size"), - QKeySequence(Tr::tr("Ctrl+-")), - G_EDIT_FONT, advancedEditMenu); - registerAction(RESET_FONT_SIZE, - [] (TextEditorWidget *w) { w->zoomReset(); }, false, Tr::tr("Reset Font Size"), - QKeySequence(Core::useMacShortcuts ? Tr::tr("Meta+0") : Tr::tr("Ctrl+0")), - G_EDIT_FONT, advancedEditMenu); - registerAction(GOTO_BLOCK_START, - [] (TextEditorWidget *w) { w->gotoBlockStart(); }, true, Tr::tr("Go to Block Start"), - QKeySequence(Tr::tr("Ctrl+[")), - G_EDIT_BLOCKS, advancedEditMenu); - registerAction(GOTO_BLOCK_END, - [] (TextEditorWidget *w) { w->gotoBlockEnd(); }, true, Tr::tr("Go to Block End"), - QKeySequence(Tr::tr("Ctrl+]")), - G_EDIT_BLOCKS, advancedEditMenu); - registerAction(SELECT_BLOCK_UP, - [] (TextEditorWidget *w) { w->selectBlockUp(); }, true, Tr::tr("Select Block Up"), - QKeySequence(Tr::tr("Ctrl+U")), - G_EDIT_BLOCKS, advancedEditMenu); - registerAction(SELECT_BLOCK_DOWN, - [] (TextEditorWidget *w) { w->selectBlockDown(); }, true, Tr::tr("Select Block Down"), - QKeySequence(Tr::tr("Ctrl+Shift+Alt+U")), - G_EDIT_BLOCKS, advancedEditMenu); - registerAction(SELECT_WORD_UNDER_CURSOR, - [] (TextEditorWidget *w) { w->selectWordUnderCursor(); }, true, - Tr::tr("Select Word Under Cursor")); - - // register GOTO Actions - registerAction(GOTO_DOCUMENT_START, - [] (TextEditorWidget *w) { w->gotoDocumentStart(); }, true, Tr::tr("Go to Document Start")); - registerAction(GOTO_DOCUMENT_END, - [] (TextEditorWidget *w) { w->gotoDocumentEnd(); }, true, Tr::tr("Go to Document End")); - registerAction(GOTO_LINE_START, - [] (TextEditorWidget *w) { w->gotoLineStart(); }, true, Tr::tr("Go to Line Start")); - registerAction(GOTO_LINE_END, - [] (TextEditorWidget *w) { w->gotoLineEnd(); }, true, Tr::tr("Go to Line End")); - registerAction(GOTO_NEXT_LINE, - [] (TextEditorWidget *w) { w->gotoNextLine(); }, true, Tr::tr("Go to Next Line")); - registerAction(GOTO_PREVIOUS_LINE, - [] (TextEditorWidget *w) { w->gotoPreviousLine(); }, true, Tr::tr("Go to Previous Line")); - registerAction(GOTO_PREVIOUS_CHARACTER, - [] (TextEditorWidget *w) { w->gotoPreviousCharacter(); }, true, Tr::tr("Go to Previous Character")); - registerAction(GOTO_NEXT_CHARACTER, - [] (TextEditorWidget *w) { w->gotoNextCharacter(); }, true, Tr::tr("Go to Next Character")); - registerAction(GOTO_PREVIOUS_WORD, - [] (TextEditorWidget *w) { w->gotoPreviousWord(); }, true, Tr::tr("Go to Previous Word")); - registerAction(GOTO_NEXT_WORD, - [] (TextEditorWidget *w) { w->gotoNextWord(); }, true, Tr::tr("Go to Next Word")); - registerAction(GOTO_PREVIOUS_WORD_CAMEL_CASE, - [] (TextEditorWidget *w) { w->gotoPreviousWordCamelCase(); }, false, Tr::tr("Go to Previous Word Camel Case")); - registerAction(GOTO_NEXT_WORD_CAMEL_CASE, - [] (TextEditorWidget *w) { w->gotoNextWordCamelCase(); }, false, Tr::tr("Go to Next Word Camel Case")); - - // register GOTO actions with selection - registerAction(GOTO_LINE_START_WITH_SELECTION, - [] (TextEditorWidget *w) { w->gotoLineStartWithSelection(); }, true, Tr::tr("Go to Line Start with Selection")); - registerAction(GOTO_LINE_END_WITH_SELECTION, - [] (TextEditorWidget *w) { w->gotoLineEndWithSelection(); }, true, Tr::tr("Go to Line End with Selection")); - registerAction(GOTO_NEXT_LINE_WITH_SELECTION, - [] (TextEditorWidget *w) { w->gotoNextLineWithSelection(); }, true, Tr::tr("Go to Next Line with Selection")); - registerAction(GOTO_PREVIOUS_LINE_WITH_SELECTION, - [] (TextEditorWidget *w) { w->gotoPreviousLineWithSelection(); }, true, Tr::tr("Go to Previous Line with Selection")); - registerAction(GOTO_PREVIOUS_CHARACTER_WITH_SELECTION, - [] (TextEditorWidget *w) { w->gotoPreviousCharacterWithSelection(); }, true, Tr::tr("Go to Previous Character with Selection")); - registerAction(GOTO_NEXT_CHARACTER_WITH_SELECTION, - [] (TextEditorWidget *w) { w->gotoNextCharacterWithSelection(); }, true, Tr::tr("Go to Next Character with Selection")); - registerAction(GOTO_PREVIOUS_WORD_WITH_SELECTION, - [] (TextEditorWidget *w) { w->gotoPreviousWordWithSelection(); }, true, Tr::tr("Go to Previous Word with Selection")); - registerAction(GOTO_NEXT_WORD_WITH_SELECTION, - [] (TextEditorWidget *w) { w->gotoNextWordWithSelection(); }, true, Tr::tr("Go to Next Word with Selection")); - registerAction(GOTO_PREVIOUS_WORD_CAMEL_CASE_WITH_SELECTION, - [] (TextEditorWidget *w) { w->gotoPreviousWordCamelCaseWithSelection(); }, false, Tr::tr("Go to Previous Word Camel Case with Selection")); - registerAction(GOTO_NEXT_WORD_CAMEL_CASE_WITH_SELECTION, - [] (TextEditorWidget *w) { w->gotoNextWordCamelCaseWithSelection(); }, false, Tr::tr("Go to Next Word Camel Case with Selection")); - - // Collect additional modifying actions so we can check for them inside a readonly file - // and disable them - m_modifyingActions << m_autoIndentAction; - m_modifyingActions << m_autoFormatAction; - m_modifyingActions << m_unCommentSelectionAction; - - updateOptionalActions(); -} - -void TextEditorActionHandlerPrivate::updateActions() -{ - bool isWritable = m_currentEditorWidget && !m_currentEditorWidget->isReadOnly(); - for (QAction *a : std::as_const(m_modifyingActions)) - a->setEnabled(isWritable); - m_unCommentSelectionAction->setEnabled((m_optionalActions & TextEditorActionHandler::UnCommentSelection) && isWritable); - m_visualizeWhitespaceAction->setEnabled(m_currentEditorWidget); - if (TextEditorSettings::fontSettings().relativeLineSpacing() == 100) { - m_textWrappingAction->setEnabled(m_currentEditorWidget); - } else { - m_textWrappingAction->setEnabled(false); - m_textWrappingAction->setChecked(false); - } - if (m_currentEditorWidget) { - m_visualizeWhitespaceAction->setChecked( - m_currentEditorWidget->displaySettings().m_visualizeWhitespace); - m_textWrappingAction->setChecked(m_currentEditorWidget->displaySettings().m_textWrapping); - } - - bool canRedo = false; - bool canUndo = false; - bool canCopy = false; - - if (m_currentEditor && m_currentEditor->document() - && m_currentEditor->document()->id() == m_editorId) { - canRedo = m_canRedoCallback ? m_canRedoCallback(m_currentEditor) : false; - canUndo = m_canUndoCallback ? m_canUndoCallback(m_currentEditor) : false; - - if (m_currentEditorWidget) { - canRedo = m_canRedoCallback ? canRedo - : m_currentEditorWidget->document()->isRedoAvailable(); - canUndo = m_canUndoCallback ? canUndo - : m_currentEditorWidget->document()->isUndoAvailable(); - canCopy = m_currentEditorWidget->textCursor().hasSelection(); - } - } - - updateRedoAction(canRedo); - updateUndoAction(canUndo); - updateCopyAction(canCopy); - - updateOptionalActions(); -} - -void TextEditorActionHandlerPrivate::updateOptionalActions() -{ - const uint optionalActions = m_currentEditorWidget ? m_currentEditorWidget->optionalActions() - : m_optionalActions; - m_followSymbolAction->setEnabled( - optionalActions & TextEditorActionHandler::FollowSymbolUnderCursor); - m_followSymbolInNextSplitAction->setEnabled( - optionalActions & TextEditorActionHandler::FollowSymbolUnderCursor); - m_followToTypeAction->setEnabled( - optionalActions & TextEditorActionHandler::FollowTypeUnderCursor); - m_followToTypeInNextSplitAction->setEnabled( - optionalActions & TextEditorActionHandler::FollowTypeUnderCursor); - m_findUsageAction->setEnabled( - optionalActions & TextEditorActionHandler::FindUsage); - m_jumpToFileAction->setEnabled( - optionalActions & TextEditorActionHandler::JumpToFileUnderCursor); - m_jumpToFileInNextSplitAction->setEnabled( - optionalActions & TextEditorActionHandler::JumpToFileUnderCursor); - m_unfoldAllAction->setEnabled( - optionalActions & TextEditorActionHandler::UnCollapseAll); - m_renameSymbolAction->setEnabled( - optionalActions & TextEditorActionHandler::RenameSymbol); - m_openCallHierarchyAction->setEnabled( - optionalActions & TextEditorActionHandler::CallHierarchy); - m_openTypeHierarchyAction->setEnabled( - optionalActions & TextEditorActionHandler::TypeHierarchy); - - bool formatEnabled = (optionalActions & TextEditorActionHandler::Format) - && m_currentEditorWidget && !m_currentEditorWidget->isReadOnly(); - m_autoIndentAction->setEnabled(formatEnabled); - m_autoFormatAction->setEnabled(formatEnabled); -} - -void TextEditorActionHandlerPrivate::updateRedoAction(bool on) -{ - m_redoAction->setEnabled(on); -} - -void TextEditorActionHandlerPrivate::updateUndoAction(bool on) -{ - m_undoAction->setEnabled(on); -} - -void TextEditorActionHandlerPrivate::updateCopyAction(bool hasCopyableText) -{ - if (m_cutAction) - m_cutAction->setEnabled(hasCopyableText && m_currentEditorWidget - && !m_currentEditorWidget->isReadOnly()); - if (m_copyAction) - m_copyAction->setEnabled(hasCopyableText); - if (m_copyHtmlAction) - m_copyHtmlAction->setEnabled(hasCopyableText); -} - -void TextEditorActionHandlerPrivate::updateCurrentEditor(IEditor *editor) -{ - if (m_currentEditorWidget) - m_currentEditorWidget->disconnect(this); - m_currentEditorWidget = nullptr; - - m_currentEditor = editor; - - if (editor && editor->document()->id() == m_editorId) { - m_currentEditorWidget = m_findTextWidget(editor); - if (m_currentEditorWidget) { - connect(m_currentEditorWidget, &QPlainTextEdit::undoAvailable, - this, &TextEditorActionHandlerPrivate::updateUndoAction); - connect(m_currentEditorWidget, &QPlainTextEdit::redoAvailable, - this, &TextEditorActionHandlerPrivate::updateRedoAction); - connect(m_currentEditorWidget, &QPlainTextEdit::copyAvailable, - this, &TextEditorActionHandlerPrivate::updateCopyAction); - connect(m_currentEditorWidget, &TextEditorWidget::readOnlyChanged, - this, &TextEditorActionHandlerPrivate::updateActions); - connect(m_currentEditorWidget, &TextEditorWidget::optionalActionMaskChanged, - this, &TextEditorActionHandlerPrivate::updateOptionalActions); - } - } - updateActions(); -} - -} // namespace Internal - -TextEditorActionHandler::TextEditorActionHandler(Utils::Id editorId, - Utils::Id contextId, - uint optionalActions, - const TextEditorWidgetResolver &resolver) - : d(new Internal::TextEditorActionHandlerPrivate(editorId, contextId, optionalActions)) -{ - if (resolver) - d->m_findTextWidget = resolver; - else - d->m_findTextWidget = TextEditorWidget::fromEditor; -} - -uint TextEditorActionHandler::optionalActions() const -{ - return d->m_optionalActions; -} - -TextEditorActionHandler::~TextEditorActionHandler() -{ - delete d; -} - -void TextEditorActionHandler::updateCurrentEditor() -{ - d->updateCurrentEditor(EditorManager::currentEditor()); -} - -void TextEditorActionHandler::updateActions() -{ - d->updateActions(); -} - -void TextEditorActionHandler::setCanUndoCallback(const Predicate &callback) -{ - d->m_canUndoCallback = callback; -} - -void TextEditorActionHandler::setCanRedoCallback(const Predicate &callback) -{ - d->m_canRedoCallback = callback; -} - -void TextEditorActionHandler::setUnhandledCallback(const UnhandledCallback &callback) -{ - d->m_unhandledCallback = callback; -} - -} // namespace TextEditor diff --git a/src/plugins/texteditor/texteditoractionhandler.h b/src/plugins/texteditor/texteditoractionhandler.h deleted file mode 100644 index ce969b7b6f..0000000000 --- a/src/plugins/texteditor/texteditoractionhandler.h +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#pragma once - -#include "texteditor_global.h" - -#include <utils/id.h> - -#include <QObject> - -#include <functional> - -namespace Core { -class IEditor; -} - -namespace TextEditor { -class TextEditorWidget; - -namespace Internal { class TextEditorActionHandlerPrivate; } - -// Redirects slots from global actions to the respective editor. - -class TEXTEDITOR_EXPORT TextEditorActionHandler final -{ - TextEditorActionHandler(const TextEditorActionHandler &) = delete; - TextEditorActionHandler &operator=(const TextEditorActionHandler &) = delete; - -public: - enum OptionalActionsMask { - None = 0, - Format = 1, - UnCommentSelection = 2, - UnCollapseAll = 4, - FollowSymbolUnderCursor = 8, - FollowTypeUnderCursor = 16, - JumpToFileUnderCursor = 32, - RenameSymbol = 64, - FindUsage = 128, - CallHierarchy = 256, - TypeHierarchy = 512, - }; - using TextEditorWidgetResolver = std::function<TextEditorWidget *(Core::IEditor *)>; - - TextEditorActionHandler(Utils::Id editorId, - Utils::Id contextId, - uint optionalActions = None, - const TextEditorWidgetResolver &resolver = {}); - - uint optionalActions() const; - ~TextEditorActionHandler(); - - void updateCurrentEditor(); - void updateActions(); - - using Predicate = std::function<bool(Core::IEditor *editor)>; - - void setCanUndoCallback(const Predicate &callback); - void setCanRedoCallback(const Predicate &callback); - - using UnhandledCallback = std::function<void(Utils::Id commandId, Core::IEditor *editor)>; - void setUnhandledCallback(const UnhandledCallback &callback); - -private: - Internal::TextEditorActionHandlerPrivate *d; -}; - -} // namespace TextEditor diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index d279b6254f..0852da2ca8 100644 --- a/src/plugins/texteditor/texteditorplugin.cpp +++ b/src/plugins/texteditor/texteditorplugin.cpp @@ -85,6 +85,7 @@ public: void updateCurrentSelection(const QString &text); void createStandardContextMenu(); + void createEditorCommands(); }; void TextEditorPlugin::initialize() @@ -174,6 +175,7 @@ void TextEditorPlugin::initialize() Tr::tr("Text", "SnippetProvider")); createStandardContextMenu(); + createEditorCommands(); #ifdef WITH_TESTS addTestCreator(createCodeAssistTests); @@ -349,6 +351,359 @@ void TextEditorPlugin::createStandardContextMenu() add(Constants::SWITCH_UTF8BOM, Constants::G_BOM); } +void TextEditorPlugin::createEditorCommands() +{ + using namespace Core::Constants; + ActionBuilder(this, UNDO).setText(Tr::tr("&Undo")).setScriptable(true); + ActionBuilder(this, REDO).setText(Tr::tr("&Redo")).setScriptable(true); + ActionBuilder(this, COPY).setScriptable(true); + ActionBuilder(this, CUT).setScriptable(true); + ActionBuilder(this, PASTE).setScriptable(true); + ActionBuilder(this, SELECTALL).setScriptable(true); + ActionBuilder(this, GOTO); + ActionBuilder(this, PRINT); + ActionBuilder(this, DELETE_LINE).setText(Tr::tr("Delete &Line")).setScriptable(true); + ActionBuilder(this, DELETE_END_OF_LINE) + .setText(Tr::tr("Delete Line from Cursor On")) + .setScriptable(true); + ActionBuilder(this, DELETE_END_OF_WORD) + .setText(Tr::tr("Delete Word from Cursor On")) + .setScriptable(true); + ActionBuilder(this, DELETE_END_OF_WORD_CAMEL_CASE) + .setText(Tr::tr("Delete Word Camel Case from Cursor On")) + .setScriptable(true); + ActionBuilder(this, DELETE_START_OF_LINE) + .setText(Tr::tr("Delete Line up to Cursor")) + .setScriptable(true) + .setDefaultKeySequence(Tr::tr("Ctrl+Backspace"), {}); + ActionBuilder(this, DELETE_START_OF_WORD) + .setText(Tr::tr("Delete Word up to Cursor")) + .setScriptable(true); + ActionBuilder(this, DELETE_START_OF_WORD_CAMEL_CASE) + .setText(Tr::tr("Delete Word Camel Case up to Cursor")) + .setScriptable(true); + ActionBuilder(this, GOTO_BLOCK_START_WITH_SELECTION) + .setText(Tr::tr("Go to Block Start with Selection")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+{"))); + ActionBuilder(this, GOTO_BLOCK_END_WITH_SELECTION) + .setText(Tr::tr("Go to Block End with Selection")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+}"))); + ActionBuilder(this, MOVE_LINE_UP) + .setText(Tr::tr("Move Line Up")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Shift+Up"))); + ActionBuilder(this, MOVE_LINE_DOWN) + .setText(Tr::tr("Move Line Down")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Shift+Down"))); + ActionBuilder(this, COPY_LINE_UP) + .setText(Tr::tr("Copy Line Up")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Alt+Up"))); + ActionBuilder(this, COPY_LINE_DOWN) + .setText(Tr::tr("Copy Line Down")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Alt+Down"))); + ActionBuilder(this, JOIN_LINES) + .setText(Tr::tr("Join Lines")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+J"))); + ActionBuilder(this, INSERT_LINE_ABOVE) + .setText(Tr::tr("Insert Line Above Current Line")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Shift+Return"))); + ActionBuilder(this, INSERT_LINE_BELOW) + .setText(Tr::tr("Insert Line Below Current Line")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Return"))); + ActionBuilder(this, SWITCH_UTF8BOM) + .setText(Tr::tr("Delete Word up to Cursor")) + .setScriptable(true); + ActionBuilder(this, INDENT) + .setText(Tr::tr("Indent")) + .setScriptable(true); + ActionBuilder(this, UNINDENT) + .setText(Tr::tr("Unindent")) + .setScriptable(true); + ActionBuilder(this, FOLLOW_SYMBOL_UNDER_CURSOR) + .setText(Tr::tr("Follow Symbol Under Cursor")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Qt::Key_F2)); + ActionBuilder(this, FOLLOW_SYMBOL_UNDER_CURSOR_IN_NEXT_SPLIT) + .setText(Tr::tr("Follow Symbol Under Cursor in Next Split")) + .setScriptable(true) + .setDefaultKeySequence(Tr::tr("Meta+E, F2"), Tr::tr("Ctrl+E, F2")); + ActionBuilder(this, FOLLOW_SYMBOL_TO_TYPE) + .setText(Tr::tr("Follow Type Under Cursor")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Shift+F2"))); + ActionBuilder(this, FOLLOW_SYMBOL_TO_TYPE_IN_NEXT_SPLIT) + .setText(Tr::tr("Follow Type Under Cursor in Next Split")) + .setScriptable(true) + .setDefaultKeySequence(Tr::tr("Meta+E, Shift+F2"), Tr::tr("Ctrl+E, Ctrl+Shift+F2")); + ActionBuilder(this, FIND_USAGES) + .setText(Tr::tr("Find References to Symbol Under Cursor")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Shift+U"))); + ActionBuilder(this, RENAME_SYMBOL) + .setText(Tr::tr("Rename Symbol Under Cursor")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Shift+R"))); + ActionBuilder(this, JUMP_TO_FILE_UNDER_CURSOR) + .setText(Tr::tr("Jump to File Under Cursor")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Qt::Key_F2)); + ActionBuilder(this, JUMP_TO_FILE_UNDER_CURSOR_IN_NEXT_SPLIT) + .setText(Tr::tr("Jump to File Under Cursor in Next Split")) + .setScriptable(true) + .setDefaultKeySequence(Tr::tr("Meta+E, F2"), Tr::tr("Ctrl+E, F2")); + ActionBuilder(this, OPEN_CALL_HIERARCHY) + .setText(Tr::tr("Open Call Hierarchy")) + .setScriptable(true); + ActionBuilder(this, OPEN_TYPE_HIERARCHY) + .setText(Tr::tr("Open Type Hierarchy")) + .setScriptable(true) + .setDefaultKeySequence(Tr::tr("Meta+Shift+T"), Tr::tr("Ctrl+Shift+T")); + ActionBuilder(this, VIEW_PAGE_UP) + .setText(Tr::tr("Move the View a Page Up and Keep the Cursor Position")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+PgUp"))); + ActionBuilder(this, VIEW_PAGE_DOWN) + .setText(Tr::tr("Move the View a Page Down and Keep the Cursor Position")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+PgDown"))); + ActionBuilder(this, VIEW_LINE_UP) + .setText(Tr::tr("Move the View a Line Up and Keep the Cursor Position")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Up"))); + ActionBuilder(this, VIEW_LINE_DOWN) + .setText(Tr::tr("Move the View a Line Down and Keep the Cursor Position")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Down"))); + + ActionManager::actionContainer(M_EDIT); + ActionBuilder(this, SELECT_ENCODING) + .setText(Tr::tr("Select Encoding...")) + .setScriptable(false) + .addToContainer(M_EDIT, G_EDIT_OTHER); + ActionBuilder(this, CIRCULAR_PASTE) + .setText(Tr::tr("Paste from Clipboard History")) + .setScriptable(false) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Shift+V"))) + .addToContainer(M_EDIT, G_EDIT_COPYPASTE); + ActionBuilder(this, NO_FORMAT_PASTE) + .setText(Tr::tr("Paste Without Formatting")) + .setScriptable(false) + .setDefaultKeySequence(Tr::tr("Ctrl+Alt+Shift+V"), QString()) + .addToContainer(M_EDIT, G_EDIT_COPYPASTE); + + ActionManager::actionContainer(M_EDIT_ADVANCED); + ActionBuilder(this, AUTO_INDENT_SELECTION) + .setText(Tr::tr("Auto-&indent Selection")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+I"))) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_FORMAT); + ActionBuilder(this, AUTO_FORMAT_SELECTION) + .setText(Tr::tr("Auto-&format Selection")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+;"))) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_FORMAT); + ActionBuilder(this, REWRAP_PARAGRAPH) + .setText(Tr::tr("&Rewrap Paragraph")) + .setScriptable(true) + .setDefaultKeySequence(Tr::tr("Meta+E, R"), Tr::tr("Ctrl+E, R")) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_FORMAT); + ActionBuilder(this, VISUALIZE_WHITESPACE) + .setText(Tr::tr("&Visualize Whitespace")) + .setScriptable(false) + .setDefaultKeySequence(Tr::tr("Meta+E, Meta+V"), Tr::tr("Ctrl+E, Ctrl+V")) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_FORMAT); + ActionBuilder(this, CLEAN_WHITESPACE) + .setText(Tr::tr("Clean Whitespace")) + .setScriptable(true) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_FORMAT); + ActionBuilder(this, TEXT_WRAPPING) + .setText(Tr::tr("Enable Text &Wrapping")) + .setScriptable(true) + .setDefaultKeySequence(Tr::tr("Meta+E, Meta+W"), Tr::tr("Ctrl+E, Ctrl+W")) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_FORMAT) + .setCheckable(true); + ActionBuilder(this, UN_COMMENT_SELECTION) + .setText(Tr::tr("Toggle Comment &Selection")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+/"))) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_FORMAT); + ActionBuilder(this, CUT_LINE) + .setText(Tr::tr("Cut &Line")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Shift+Del"))) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_TEXT); + ActionBuilder(this, COPY_LINE) + .setText(Tr::tr("Copy &Line")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Ins"))) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_TEXT); + ActionBuilder(this, COPY_WITH_HTML) + .setText(Tr::tr("Copy With Highlighting")) + .setScriptable(true) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_TEXT); + ActionBuilder(this, ADD_CURSORS_TO_LINE_ENDS) + .setText(Tr::tr("Create Cursors at Selected Line Ends")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Alt+Shift+I"))) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_TEXT); + ActionBuilder(this, ADD_SELECT_NEXT_FIND_MATCH) + .setText(Tr::tr("Add Next Occurrence to Selection")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+D"))) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_TEXT); + ActionBuilder(this, DUPLICATE_SELECTION) + .setText(Tr::tr("&Duplicate Selection")) + .setScriptable(true) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_TEXT); + ActionBuilder(this, DUPLICATE_SELECTION_AND_COMMENT) + .setText(Tr::tr("&Duplicate Selection and Comment")) + .setScriptable(true) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_TEXT); + ActionBuilder(this, UPPERCASE_SELECTION) + .setText(Tr::tr("Uppercase Selection")) + .setScriptable(true) + .setDefaultKeySequence(Tr::tr("Meta+Shift+U"), Tr::tr("Alt+Shift+U")) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_TEXT); + ActionBuilder(this, LOWERCASE_SELECTION) + .setText(Tr::tr("Lowercase Selection")) + .setScriptable(true) + .setDefaultKeySequence(Tr::tr("Meta+U"), Tr::tr("Alt+U")) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_TEXT); + ActionBuilder(this, SORT_LINES) + .setText(Tr::tr("Sort Lines")) + .setScriptable(true) + .setDefaultKeySequence(Tr::tr("Meta+Shift+S"), Tr::tr("Alt+Shift+S")) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_TEXT); + ActionBuilder(this, FOLD) + .setText(Tr::tr("Fold")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+<"))) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_COLLAPSING); + ActionBuilder(this, UNFOLD) + .setText(Tr::tr("Unfold")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+>"))) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_COLLAPSING); + ActionBuilder(this, UNFOLD_ALL) + .setText(Tr::tr("Toggle &Fold All")) + .setScriptable(true) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_COLLAPSING); + ActionBuilder(this, INCREASE_FONT_SIZE) + .setText(Tr::tr("Increase Font Size")) + .setScriptable(false) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl++"))) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_FONT); + ActionBuilder(this, DECREASE_FONT_SIZE) + .setText(Tr::tr("Decrease Font Size")) + .setScriptable(false) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+-"))) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_FONT); + ActionBuilder(this, RESET_FONT_SIZE) + .setText(Tr::tr("Reset Font Size")) + .setScriptable(false) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+0"))) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_FONT); + ActionBuilder(this, GOTO_BLOCK_START) + .setText(Tr::tr("Go to Block Start")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+["))) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_BLOCKS); + ActionBuilder(this, GOTO_BLOCK_END) + .setText(Tr::tr("Go to Block End")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+]"))) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_BLOCKS); + ActionBuilder(this, SELECT_BLOCK_UP) + .setText(Tr::tr("Select Block Up")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+U"))) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_BLOCKS); + ActionBuilder(this, SELECT_BLOCK_DOWN) + .setText(Tr::tr("Select Block Down")) + .setScriptable(true) + .setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Shift+Alt+U"))) + .addToContainer(M_EDIT_ADVANCED, G_EDIT_BLOCKS); + ActionBuilder(this, SELECT_WORD_UNDER_CURSOR) + .setText(Tr::tr("Select Word Under Cursor")) + .setScriptable(true); + + ActionBuilder(this, GOTO_DOCUMENT_START) + .setText(Tr::tr("Go to Document Start")) + .setScriptable(true); + ActionBuilder(this, GOTO_DOCUMENT_END) + .setText(Tr::tr("Go to Document End")) + .setScriptable(true); + ActionBuilder(this, GOTO_LINE_START) + .setText(Tr::tr("Go to Line Start")) + .setScriptable(true); + ActionBuilder(this, GOTO_LINE_END) + .setText(Tr::tr("Go to Line End")) + .setScriptable(true); + ActionBuilder(this, GOTO_NEXT_LINE) + .setText(Tr::tr("Go to Next Line")) + .setScriptable(true); + ActionBuilder(this, GOTO_PREVIOUS_LINE) + .setText(Tr::tr("Go to Previous Line")) + .setScriptable(true); + ActionBuilder(this, GOTO_PREVIOUS_CHARACTER) + .setText(Tr::tr("Go to Previous Character")) + .setScriptable(true); + ActionBuilder(this, GOTO_NEXT_CHARACTER) + .setText(Tr::tr("Go to Next Character")) + .setScriptable(true); + ActionBuilder(this, GOTO_PREVIOUS_WORD) + .setText(Tr::tr("Go to Previous Word")) + .setScriptable(true); + ActionBuilder(this, GOTO_NEXT_WORD) + .setText(Tr::tr("Go to Next Word")) + .setScriptable(true); + ActionBuilder(this, GOTO_PREVIOUS_WORD_CAMEL_CASE) + .setText(Tr::tr("Go to Previous Word (Camel Case)")) + .setScriptable(true); + ActionBuilder(this, GOTO_NEXT_WORD_CAMEL_CASE) + .setText(Tr::tr("Go to Next Word (Camel Case)")) + .setScriptable(true); + + ActionBuilder(this, GOTO_LINE_START_WITH_SELECTION) + .setText(Tr::tr("Go to Line Start with Selection")) + .setScriptable(true); + ActionBuilder(this, GOTO_LINE_END_WITH_SELECTION) + .setText(Tr::tr("Go to Line End with Selection")) + .setScriptable(true); + ActionBuilder(this, GOTO_NEXT_LINE_WITH_SELECTION) + .setText(Tr::tr("Go to Next Line with Selection")) + .setScriptable(true); + ActionBuilder(this, GOTO_PREVIOUS_LINE_WITH_SELECTION) + .setText(Tr::tr("Go to Previous Line with Selection")) + .setScriptable(true); + ActionBuilder(this, GOTO_PREVIOUS_CHARACTER_WITH_SELECTION) + .setText(Tr::tr("Go to Previous Character with Selection")) + .setScriptable(true); + ActionBuilder(this, GOTO_NEXT_CHARACTER_WITH_SELECTION) + .setText(Tr::tr("Go to Next Character with Selection")) + .setScriptable(true); + ActionBuilder(this, GOTO_PREVIOUS_WORD_WITH_SELECTION) + .setText(Tr::tr("Go to Previous Word with Selection")) + .setScriptable(true); + ActionBuilder(this, GOTO_NEXT_WORD_WITH_SELECTION) + .setText(Tr::tr("Go to Next Word with Selection")) + .setScriptable(true); + ActionBuilder(this, GOTO_PREVIOUS_WORD_CAMEL_CASE_WITH_SELECTION) + .setText(Tr::tr("Go to Previous Word (Camel Case) with Selection")) + .setScriptable(true); + ActionBuilder(this, GOTO_NEXT_WORD_CAMEL_CASE_WITH_SELECTION) + .setText(Tr::tr("Go to Next Word (Camel Case) with Selection")) + .setScriptable(true); +} + } // namespace TextEditor::Internal #include "texteditorplugin.moc" diff --git a/src/plugins/vcsbase/vcsbaseeditor.cpp b/src/plugins/vcsbase/vcsbaseeditor.cpp index 13338584bf..462412df06 100644 --- a/src/plugins/vcsbase/vcsbaseeditor.cpp +++ b/src/plugins/vcsbase/vcsbaseeditor.cpp @@ -27,7 +27,6 @@ #include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectmanager.h> -#include <texteditor/texteditoractionhandler.h> #include <texteditor/textdocument.h> #include <texteditor/textdocumentlayout.h> #include <texteditor/syntaxhighlighter.h> @@ -1661,7 +1660,7 @@ VcsEditorFactory::VcsEditorFactory(const VcsBaseEditorParameters ¶meters) if (parameters.mimeType != DiffEditor::Constants::DIFF_EDITOR_MIMETYPE) addMimeType(parameters.mimeType); - setEditorActionHandlers(TextEditorActionHandler::None); + setOptionalActionMask(OptionalActions::None); setDuplicatedSupported(false); setDocumentCreator([parameters] { |