2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2023-09-22 18:05:03 +02:00
|
|
|
#include "bookmarkfilter.h"
|
|
|
|
|
#include "bookmarkmanager.h"
|
2009-05-29 14:14:08 +02:00
|
|
|
#include "findincurrentfile.h"
|
2014-09-02 12:54:28 +02:00
|
|
|
#include "findinfiles.h"
|
2012-01-23 11:49:14 +01:00
|
|
|
#include "findinopenfiles.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "fontsettings.h"
|
2023-11-01 10:08:31 +01:00
|
|
|
#include "highlighterhelper.h"
|
2023-01-17 18:02:43 +01:00
|
|
|
#include "icodestylepreferences.h"
|
2023-08-23 15:38:01 +02:00
|
|
|
#include "jsoneditor.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "linenumberfilter.h"
|
2023-02-20 08:56:33 +01:00
|
|
|
#include "markdowneditor.h"
|
2010-07-08 11:15:26 +02:00
|
|
|
#include "outlinefactory.h"
|
2014-09-02 12:54:28 +02:00
|
|
|
#include "plaintexteditorfactory.h"
|
2017-04-24 15:52:04 +02:00
|
|
|
#include "snippets/snippetprovider.h"
|
2023-01-17 18:02:43 +01:00
|
|
|
#include "tabsettings.h"
|
2021-10-21 15:39:28 +02:00
|
|
|
#include "textdocument.h"
|
2018-11-08 11:39:48 +01:00
|
|
|
#include "texteditor.h"
|
2024-01-17 08:45:47 +01:00
|
|
|
#include "texteditor_test.h"
|
2023-09-22 18:05:03 +02:00
|
|
|
#include "texteditorconstants.h"
|
2014-09-02 12:54:28 +02:00
|
|
|
#include "texteditorsettings.h"
|
2023-01-17 18:02:43 +01:00
|
|
|
#include "texteditortr.h"
|
2024-01-17 10:08:06 +01:00
|
|
|
#include "textmark.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2022-11-14 12:54:05 +01:00
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
#include "codeassist/codeassist_test.h"
|
2023-05-25 11:00:13 +02:00
|
|
|
#include "highlighter_test.h"
|
2022-11-14 12:54:05 +01:00
|
|
|
#endif
|
|
|
|
|
|
2018-03-22 09:52:49 +01:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
2021-10-21 15:39:28 +02:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2015-02-26 13:38:54 +01:00
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2023-09-22 18:05:03 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2021-10-21 15:39:28 +02:00
|
|
|
#include <coreplugin/diffservice.h>
|
2023-09-22 18:05:03 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
2011-08-17 12:54:58 +02:00
|
|
|
#include <coreplugin/externaltoolmanager.h>
|
2021-10-21 15:39:28 +02:00
|
|
|
#include <coreplugin/foldernavigationwidget.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
2013-07-03 18:23:03 +02:00
|
|
|
|
2023-01-17 18:02:43 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2024-01-17 09:56:06 +01:00
|
|
|
#include <extensionsystem/iplugin.h>
|
2013-07-03 18:23:03 +02:00
|
|
|
|
2019-08-27 14:16:24 +02:00
|
|
|
#include <utils/fancylineedit.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2014-10-13 18:49:44 +02:00
|
|
|
#include <utils/macroexpander.h>
|
2023-09-22 18:05:03 +02:00
|
|
|
#include <utils/utilsicons.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2023-09-01 17:19:37 +02:00
|
|
|
#include <QMenu>
|
|
|
|
|
|
2014-09-02 12:54:28 +02:00
|
|
|
using namespace Core;
|
2020-06-26 13:59:38 +02:00
|
|
|
using namespace Utils;
|
2023-09-22 18:05:03 +02:00
|
|
|
using namespace TextEditor::Constants;
|
2014-09-02 12:54:28 +02:00
|
|
|
|
2023-09-22 18:05:03 +02:00
|
|
|
namespace TextEditor::Internal {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2023-01-17 18:02:43 +01:00
|
|
|
const char kCurrentDocumentSelection[] = "CurrentDocument:Selection";
|
|
|
|
|
const char kCurrentDocumentRow[] = "CurrentDocument:Row";
|
|
|
|
|
const char kCurrentDocumentColumn[] = "CurrentDocument:Column";
|
|
|
|
|
const char kCurrentDocumentRowCount[] = "CurrentDocument:RowCount";
|
|
|
|
|
const char kCurrentDocumentColumnCount[] = "CurrentDocument:ColumnCount";
|
|
|
|
|
const char kCurrentDocumentFontSize[] = "CurrentDocument:FontSize";
|
|
|
|
|
const char kCurrentDocumentWordUnderCursor[] = "CurrentDocument:WordUnderCursor";
|
2011-02-10 20:58:17 +01:00
|
|
|
|
2018-02-06 14:00:12 +01:00
|
|
|
class TextEditorPluginPrivate : public QObject
|
|
|
|
|
{
|
|
|
|
|
public:
|
2023-09-22 18:05:03 +02:00
|
|
|
TextEditorPluginPrivate();
|
|
|
|
|
|
|
|
|
|
void updateActions(bool enableToggle, int stateMask);
|
|
|
|
|
void editorOpened(Core::IEditor *editor);
|
|
|
|
|
void editorAboutToClose(Core::IEditor *editor);
|
|
|
|
|
|
|
|
|
|
void requestContextMenu(TextEditorWidget *widget, int lineNumber, QMenu *menu);
|
|
|
|
|
|
2018-02-06 14:00:12 +01:00
|
|
|
void extensionsInitialized();
|
2023-09-22 18:05:03 +02:00
|
|
|
void updateSearchResultsFont(const FontSettings &);
|
|
|
|
|
void updateSearchResultsTabWidth(const TabSettings &tabSettings);
|
2018-02-06 14:00:12 +01:00
|
|
|
void updateCurrentSelection(const QString &text);
|
|
|
|
|
|
2018-03-22 09:52:49 +01:00
|
|
|
void createStandardContextMenu();
|
|
|
|
|
|
2024-01-17 15:14:37 +01:00
|
|
|
BookmarkFilter m_bookmarkFilter;
|
|
|
|
|
BookmarkViewFactory m_bookmarkViewFactory;
|
2023-09-22 18:05:03 +02:00
|
|
|
|
2018-02-06 14:00:12 +01:00
|
|
|
TextEditorSettings settings;
|
|
|
|
|
|
|
|
|
|
FindInFiles findInFilesFilter;
|
|
|
|
|
FindInCurrentFile findInCurrentFileFilter;
|
|
|
|
|
FindInOpenFiles findInOpenFilesFilter;
|
|
|
|
|
|
|
|
|
|
PlainTextEditorFactory plainTextEditorFactory;
|
2023-02-20 08:56:33 +01:00
|
|
|
MarkdownEditorFactory markdownEditorFactory;
|
2023-08-23 15:38:01 +02:00
|
|
|
JsonEditorFactory jsonEditorFactory;
|
2018-02-06 14:00:12 +01:00
|
|
|
};
|
|
|
|
|
|
2023-09-22 18:05:03 +02:00
|
|
|
TextEditorPluginPrivate::TextEditorPluginPrivate()
|
|
|
|
|
{
|
|
|
|
|
// EditorManager
|
|
|
|
|
connect(EditorManager::instance(), &EditorManager::editorAboutToClose,
|
2023-07-05 14:16:10 +02:00
|
|
|
this, &TextEditorPluginPrivate::editorAboutToClose);
|
2023-09-22 18:05:03 +02:00
|
|
|
connect(EditorManager::instance(), &EditorManager::editorOpened,
|
2023-07-05 14:16:10 +02:00
|
|
|
this, &TextEditorPluginPrivate::editorOpened);
|
2023-09-22 18:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TextEditorPluginPrivate::editorOpened(IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
if (auto widget = TextEditorWidget::fromEditor(editor)) {
|
|
|
|
|
connect(widget, &TextEditorWidget::markRequested,
|
2024-01-17 15:14:37 +01:00
|
|
|
this, [editor](TextEditorWidget *, int line, TextMarkRequestKind kind) {
|
2023-09-22 18:05:03 +02:00
|
|
|
if (kind == BookmarkRequest && !editor->document()->isTemporary())
|
2024-01-17 15:14:37 +01:00
|
|
|
bookmarkManager().toggleBookmark(editor->document()->filePath(), line);
|
2023-09-22 18:05:03 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(widget, &TextEditorWidget::markContextMenuRequested,
|
|
|
|
|
this, &TextEditorPluginPrivate::requestContextMenu);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TextEditorPluginPrivate::editorAboutToClose(IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
if (auto widget = TextEditorWidget::fromEditor(editor)) {
|
|
|
|
|
disconnect(widget, &TextEditorWidget::markContextMenuRequested,
|
|
|
|
|
this, &TextEditorPluginPrivate::requestContextMenu);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TextEditorPluginPrivate::requestContextMenu(TextEditorWidget *widget,
|
|
|
|
|
int lineNumber, QMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
if (widget->textDocument()->isTemporary())
|
|
|
|
|
return;
|
|
|
|
|
|
2024-01-17 15:14:37 +01:00
|
|
|
bookmarkManager().requestContextMenu(widget->textDocument()->filePath(), lineNumber, menu);
|
2023-09-22 18:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-17 09:56:06 +01:00
|
|
|
static class TextEditorPlugin *m_instance = nullptr;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2024-01-17 09:56:06 +01:00
|
|
|
class TextEditorPlugin final : public ExtensionSystem::IPlugin
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2024-01-17 09:56:06 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "TextEditor.json")
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2024-01-17 09:56:06 +01:00
|
|
|
public:
|
|
|
|
|
TextEditorPlugin()
|
|
|
|
|
{
|
|
|
|
|
m_instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~TextEditorPlugin() final
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
d = nullptr;
|
|
|
|
|
m_instance = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ShutdownFlag aboutToShutdown() final;
|
|
|
|
|
|
|
|
|
|
void initialize() final;
|
|
|
|
|
void extensionsInitialized() final;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2024-01-17 09:56:06 +01:00
|
|
|
TextEditorPluginPrivate *d = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-20 12:28:36 +01:00
|
|
|
void TextEditorPlugin::initialize()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2024-01-17 08:45:47 +01:00
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
addTestCreator(createFormatTextTest);
|
|
|
|
|
addTestCreator(createTextDocumentTest);
|
|
|
|
|
addTestCreator(createTextEditorTest);
|
|
|
|
|
addTestCreator(createSnippetParserTest);
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-01-17 10:08:06 +01:00
|
|
|
setupTextMarkRegistry(this);
|
2024-01-09 17:11:25 +01:00
|
|
|
setupOutlineFactory();
|
2024-01-17 10:27:33 +01:00
|
|
|
setupLineNumberFilter(); // Goto line functionality for quick open
|
2024-01-09 17:11:25 +01:00
|
|
|
|
2024-01-17 15:14:37 +01:00
|
|
|
setupBookmarkManager(this);
|
|
|
|
|
|
2018-02-07 10:14:23 +01:00
|
|
|
d = new TextEditorPluginPrivate;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-09-02 12:54:28 +02:00
|
|
|
Context context(TextEditor::Constants::C_TEXTEDITOR);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Add shortcut for invoking automatic completion
|
2023-01-17 18:02:43 +01:00
|
|
|
QAction *completionAction = new QAction(Tr::tr("Trigger Completion"), this);
|
2014-09-02 12:54:28 +02:00
|
|
|
Command *command = ActionManager::registerAction(completionAction, Constants::COMPLETE_THIS, context);
|
2023-01-17 18:02:43 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+Space") : Tr::tr("Ctrl+Space")));
|
2022-12-08 00:29:41 +01:00
|
|
|
connect(completionAction, &QAction::triggered, this, [] {
|
2014-09-02 12:54:28 +02:00
|
|
|
if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor())
|
|
|
|
|
editor->editorWidget()->invokeAssist(Completion);
|
|
|
|
|
});
|
2019-08-27 14:16:24 +02:00
|
|
|
connect(command, &Command::keySequenceChanged, [command] {
|
2023-09-22 18:05:03 +02:00
|
|
|
FancyLineEdit::setCompletionShortcut(command->keySequence());
|
2019-08-27 14:16:24 +02:00
|
|
|
});
|
2023-09-22 18:05:03 +02:00
|
|
|
FancyLineEdit::setCompletionShortcut(command->keySequence());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-07-31 16:50:03 +02:00
|
|
|
// Add shortcut for invoking function hint completion
|
2023-01-17 18:02:43 +01:00
|
|
|
QAction *functionHintAction = new QAction(Tr::tr("Display Function Hint"), this);
|
2020-07-31 16:50:03 +02:00
|
|
|
command = ActionManager::registerAction(functionHintAction, Constants::FUNCTION_HINT, context);
|
2023-01-17 18:02:43 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+Shift+D")
|
|
|
|
|
: Tr::tr("Ctrl+Shift+D")));
|
2022-12-08 00:29:41 +01:00
|
|
|
connect(functionHintAction, &QAction::triggered, this, [] {
|
2020-07-31 16:50:03 +02:00
|
|
|
if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor())
|
|
|
|
|
editor->editorWidget()->invokeAssist(FunctionHint);
|
|
|
|
|
});
|
|
|
|
|
|
2009-07-15 12:27:02 +02:00
|
|
|
// Add shortcut for invoking quick fix options
|
2023-01-17 18:02:43 +01:00
|
|
|
QAction *quickFixAction = new QAction(Tr::tr("Trigger Refactoring Action"), this);
|
2014-09-02 12:54:28 +02:00
|
|
|
Command *quickFixCommand = ActionManager::registerAction(quickFixAction, Constants::QUICKFIX_THIS, context);
|
2023-01-17 18:02:43 +01:00
|
|
|
quickFixCommand->setDefaultKeySequence(QKeySequence(Tr::tr("Alt+Return")));
|
2022-12-08 00:29:41 +01:00
|
|
|
connect(quickFixAction, &QAction::triggered, this, [] {
|
2014-09-02 12:54:28 +02:00
|
|
|
if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor())
|
|
|
|
|
editor->editorWidget()->invokeAssist(QuickFix);
|
|
|
|
|
});
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2023-01-17 18:02:43 +01:00
|
|
|
QAction *showContextMenuAction = new QAction(Tr::tr("Show Context Menu"), this);
|
2017-06-01 17:15:35 +02:00
|
|
|
ActionManager::registerAction(showContextMenuAction,
|
|
|
|
|
Constants::SHOWCONTEXTMENU,
|
|
|
|
|
context);
|
2022-12-08 00:29:41 +01:00
|
|
|
connect(showContextMenuAction, &QAction::triggered, this, [] {
|
2017-06-01 17:15:35 +02:00
|
|
|
if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor())
|
|
|
|
|
editor->editorWidget()->showContextMenu();
|
|
|
|
|
});
|
|
|
|
|
|
2010-12-02 17:02:23 +01:00
|
|
|
// Add text snippet provider.
|
2017-04-24 15:52:04 +02:00
|
|
|
SnippetProvider::registerGroup(Constants::TEXT_SNIPPET_GROUP_ID,
|
2023-01-17 18:02:43 +01:00
|
|
|
Tr::tr("Text", "SnippetProvider"));
|
2010-12-02 17:02:23 +01:00
|
|
|
|
2018-03-22 09:52:49 +01:00
|
|
|
d->createStandardContextMenu();
|
2022-11-14 12:54:05 +01:00
|
|
|
|
|
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
addTest<CodeAssistTests>();
|
2023-05-25 11:00:13 +02:00
|
|
|
addTest<GenerigHighlighterTests>();
|
2022-11-14 12:54:05 +01:00
|
|
|
#endif
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2018-02-06 14:00:12 +01:00
|
|
|
void TextEditorPluginPrivate::extensionsInitialized()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2021-10-21 15:39:28 +02:00
|
|
|
connect(FolderNavigationWidgetFactory::instance(),
|
|
|
|
|
&FolderNavigationWidgetFactory::aboutToShowContextMenu,
|
2022-12-08 00:29:41 +01:00
|
|
|
this, [](QMenu *menu, const FilePath &filePath, bool isDir) {
|
2021-10-21 15:39:28 +02:00
|
|
|
if (!isDir && Core::DiffService::instance()) {
|
2023-09-22 18:05:03 +02:00
|
|
|
menu->addAction(TextDocument::createDiffAgainstCurrentFileAction(
|
2022-12-08 00:29:41 +01:00
|
|
|
menu, [filePath] { return filePath; }));
|
2021-10-21 15:39:28 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(&settings,
|
|
|
|
|
&TextEditorSettings::fontSettingsChanged,
|
|
|
|
|
this,
|
|
|
|
|
&TextEditorPluginPrivate::updateSearchResultsFont);
|
2009-04-08 14:32:31 +02:00
|
|
|
|
2020-11-18 22:42:51 +01:00
|
|
|
updateSearchResultsFont(TextEditorSettings::fontSettings());
|
2009-05-28 16:42:29 +02:00
|
|
|
|
2020-11-18 22:42:51 +01:00
|
|
|
connect(TextEditorSettings::codeStyle(), &ICodeStylePreferences::currentTabSettingsChanged,
|
2018-02-06 14:00:12 +01:00
|
|
|
this, &TextEditorPluginPrivate::updateSearchResultsTabWidth);
|
2013-07-03 18:23:03 +02:00
|
|
|
|
2020-11-18 22:42:51 +01:00
|
|
|
updateSearchResultsTabWidth(TextEditorSettings::codeStyle()->currentTabSettings());
|
2018-02-06 14:00:12 +01:00
|
|
|
|
|
|
|
|
connect(ExternalToolManager::instance(), &ExternalToolManager::replaceSelectionRequested,
|
|
|
|
|
this, &TextEditorPluginPrivate::updateCurrentSelection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TextEditorPlugin::extensionsInitialized()
|
|
|
|
|
{
|
2018-02-07 10:14:23 +01:00
|
|
|
d->extensionsInitialized();
|
2013-07-03 18:23:03 +02:00
|
|
|
|
2023-09-22 18:05:03 +02:00
|
|
|
MacroExpander *expander = Utils::globalMacroExpander();
|
2014-10-13 12:49:05 +02:00
|
|
|
|
|
|
|
|
expander->registerVariable(kCurrentDocumentSelection,
|
2023-01-17 18:02:43 +01:00
|
|
|
Tr::tr("Selected text within the current document."),
|
2014-06-23 16:57:56 +02:00
|
|
|
[]() -> QString {
|
|
|
|
|
QString value;
|
2014-07-23 19:10:38 +02:00
|
|
|
if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) {
|
2014-06-23 16:57:56 +02:00
|
|
|
value = editor->selectedText();
|
|
|
|
|
value.replace(QChar::ParagraphSeparator, QLatin1String("\n"));
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
});
|
|
|
|
|
|
2014-10-13 12:49:05 +02:00
|
|
|
expander->registerIntVariable(kCurrentDocumentRow,
|
2023-01-17 18:02:43 +01:00
|
|
|
Tr::tr("Line number of the text cursor position in current document (starts with 1)."),
|
2014-06-23 16:57:56 +02:00
|
|
|
[]() -> int {
|
2014-07-23 19:10:38 +02:00
|
|
|
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
|
2014-06-23 16:57:56 +02:00
|
|
|
return editor ? editor->currentLine() : 0;
|
|
|
|
|
});
|
|
|
|
|
|
2014-10-13 12:49:05 +02:00
|
|
|
expander->registerIntVariable(kCurrentDocumentColumn,
|
2023-01-17 18:02:43 +01:00
|
|
|
Tr::tr("Column number of the text cursor position in current document (starts with 0)."),
|
2014-06-23 16:57:56 +02:00
|
|
|
[]() -> int {
|
2014-07-23 19:10:38 +02:00
|
|
|
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
|
2014-06-23 16:57:56 +02:00
|
|
|
return editor ? editor->currentColumn() : 0;
|
|
|
|
|
});
|
|
|
|
|
|
2014-10-13 12:49:05 +02:00
|
|
|
expander->registerIntVariable(kCurrentDocumentRowCount,
|
2023-01-17 18:02:43 +01:00
|
|
|
Tr::tr("Number of lines visible in current document."),
|
2014-06-23 16:57:56 +02:00
|
|
|
[]() -> int {
|
2014-07-23 19:10:38 +02:00
|
|
|
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
|
2014-06-23 16:57:56 +02:00
|
|
|
return editor ? editor->rowCount() : 0;
|
|
|
|
|
});
|
|
|
|
|
|
2014-10-13 12:49:05 +02:00
|
|
|
expander->registerIntVariable(kCurrentDocumentColumnCount,
|
2023-01-17 18:02:43 +01:00
|
|
|
Tr::tr("Number of columns visible in current document."),
|
2014-06-23 16:57:56 +02:00
|
|
|
[]() -> int {
|
2014-07-23 19:10:38 +02:00
|
|
|
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
|
2014-06-23 16:57:56 +02:00
|
|
|
return editor ? editor->columnCount() : 0;
|
|
|
|
|
});
|
|
|
|
|
|
2014-10-13 12:49:05 +02:00
|
|
|
expander->registerIntVariable(kCurrentDocumentFontSize,
|
2023-01-17 18:02:43 +01:00
|
|
|
Tr::tr("Current document's font size in points."),
|
2014-06-23 16:57:56 +02:00
|
|
|
[]() -> int {
|
2014-07-23 19:10:38 +02:00
|
|
|
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
|
2014-06-23 16:57:56 +02:00
|
|
|
return editor ? editor->widget()->font().pointSize() : 0;
|
|
|
|
|
});
|
2020-10-26 12:06:59 +01:00
|
|
|
|
|
|
|
|
expander->registerVariable(kCurrentDocumentWordUnderCursor,
|
2023-01-17 18:02:43 +01:00
|
|
|
Tr::tr("Word under the current document's text cursor."), [] {
|
2020-10-26 12:06:59 +01:00
|
|
|
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
|
|
|
|
|
if (!editor)
|
|
|
|
|
return QString();
|
|
|
|
|
return Text::wordUnderCursor(editor->editorWidget()->textCursor());
|
|
|
|
|
});
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2018-11-08 11:39:48 +01:00
|
|
|
ExtensionSystem::IPlugin::ShutdownFlag TextEditorPlugin::aboutToShutdown()
|
|
|
|
|
{
|
2023-11-01 10:08:31 +01:00
|
|
|
HighlighterHelper::handleShutdown();
|
2018-11-08 11:39:48 +01:00
|
|
|
return SynchronousShutdown;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-06 14:00:12 +01:00
|
|
|
void TextEditorPluginPrivate::updateSearchResultsFont(const FontSettings &settings)
|
2009-04-08 14:32:31 +02:00
|
|
|
{
|
2014-09-02 12:54:28 +02:00
|
|
|
if (auto window = SearchResultWindow::instance()) {
|
2020-09-10 14:33:14 +02:00
|
|
|
const Format textFormat = settings.formatFor(C_TEXT);
|
|
|
|
|
const Format defaultResultFormat = settings.formatFor(C_SEARCH_RESULT);
|
|
|
|
|
const Format alt1ResultFormat = settings.formatFor(C_SEARCH_RESULT_ALT1);
|
|
|
|
|
const Format alt2ResultFormat = settings.formatFor(C_SEARCH_RESULT_ALT2);
|
2022-05-07 00:44:03 +03:00
|
|
|
const Format containingFunctionResultFormat =
|
|
|
|
|
settings.formatFor(C_SEARCH_RESULT_CONTAINING_FUNCTION);
|
2014-09-02 12:54:28 +02:00
|
|
|
window->setTextEditorFont(QFont(settings.family(), settings.fontSize() * settings.fontZoom() / 100),
|
2022-09-30 10:35:15 +02:00
|
|
|
{{SearchResultColor::Style::Default,
|
|
|
|
|
{textFormat.background(), textFormat.foreground(),
|
|
|
|
|
defaultResultFormat.background(), defaultResultFormat.foreground(),
|
|
|
|
|
containingFunctionResultFormat.background(),
|
|
|
|
|
containingFunctionResultFormat.foreground()}},
|
|
|
|
|
{SearchResultColor::Style::Alt1,
|
|
|
|
|
{textFormat.background(), textFormat.foreground(),
|
|
|
|
|
alt1ResultFormat.background(), alt1ResultFormat.foreground(),
|
|
|
|
|
containingFunctionResultFormat.background(),
|
|
|
|
|
containingFunctionResultFormat.foreground()}},
|
|
|
|
|
{SearchResultColor::Style::Alt2,
|
|
|
|
|
{textFormat.background(), textFormat.foreground(),
|
|
|
|
|
alt2ResultFormat.background(), alt2ResultFormat.foreground(),
|
|
|
|
|
containingFunctionResultFormat.background(),
|
|
|
|
|
containingFunctionResultFormat.foreground()}}});
|
2012-10-18 08:02:25 +02:00
|
|
|
}
|
2009-04-08 14:32:31 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2018-02-06 14:00:12 +01:00
|
|
|
void TextEditorPluginPrivate::updateSearchResultsTabWidth(const TabSettings &tabSettings)
|
2013-07-03 18:23:03 +02:00
|
|
|
{
|
|
|
|
|
if (auto window = SearchResultWindow::instance())
|
|
|
|
|
window->setTabWidth(tabSettings.m_tabSize);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-06 14:00:12 +01:00
|
|
|
void TextEditorPluginPrivate::updateCurrentSelection(const QString &text)
|
2010-12-09 15:53:43 +01:00
|
|
|
{
|
2014-09-30 17:45:48 +02:00
|
|
|
if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) {
|
2013-08-08 08:43:04 +02:00
|
|
|
const int pos = editor->position();
|
2014-09-30 17:45:48 +02:00
|
|
|
int anchor = editor->position(AnchorPosition);
|
2011-02-28 14:48:42 +01:00
|
|
|
if (anchor < 0) // no selection
|
|
|
|
|
anchor = pos;
|
2013-08-08 08:43:04 +02:00
|
|
|
int selectionLength = pos - anchor;
|
|
|
|
|
const bool selectionInTextDirection = selectionLength >= 0;
|
|
|
|
|
if (!selectionInTextDirection)
|
2010-12-09 15:53:43 +01:00
|
|
|
selectionLength = -selectionLength;
|
2013-08-08 08:43:04 +02:00
|
|
|
const int start = qMin(pos, anchor);
|
2011-02-21 16:02:26 +01:00
|
|
|
editor->setCursorPosition(start);
|
2010-12-09 15:53:43 +01:00
|
|
|
editor->replace(selectionLength, text);
|
2013-08-08 08:43:04 +02:00
|
|
|
const int replacementEnd = editor->position();
|
|
|
|
|
editor->setCursorPosition(selectionInTextDirection ? start : replacementEnd);
|
|
|
|
|
editor->select(selectionInTextDirection ? replacementEnd : start);
|
2010-12-09 15:53:43 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-22 09:52:49 +01:00
|
|
|
void TextEditorPluginPrivate::createStandardContextMenu()
|
|
|
|
|
{
|
|
|
|
|
ActionContainer *contextMenu = ActionManager::createMenu(Constants::M_STANDARDCONTEXTMENU);
|
|
|
|
|
contextMenu->appendGroup(Constants::G_UNDOREDO);
|
|
|
|
|
contextMenu->appendGroup(Constants::G_COPYPASTE);
|
|
|
|
|
contextMenu->appendGroup(Constants::G_SELECT);
|
|
|
|
|
contextMenu->appendGroup(Constants::G_BOM);
|
|
|
|
|
|
|
|
|
|
const auto add = [contextMenu](const Id &id, const Id &group) {
|
|
|
|
|
Command *cmd = ActionManager::command(id);
|
|
|
|
|
if (cmd)
|
|
|
|
|
contextMenu->addAction(cmd, group);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
add(Core::Constants::UNDO, Constants::G_UNDOREDO);
|
|
|
|
|
add(Core::Constants::REDO, Constants::G_UNDOREDO);
|
|
|
|
|
contextMenu->addSeparator(Constants::G_COPYPASTE);
|
|
|
|
|
add(Core::Constants::CUT, Constants::G_COPYPASTE);
|
|
|
|
|
add(Core::Constants::COPY, Constants::G_COPYPASTE);
|
|
|
|
|
add(Core::Constants::PASTE, Constants::G_COPYPASTE);
|
|
|
|
|
add(Constants::CIRCULAR_PASTE, Constants::G_COPYPASTE);
|
|
|
|
|
contextMenu->addSeparator(Constants::G_SELECT);
|
|
|
|
|
add(Core::Constants::SELECTALL, Constants::G_SELECT);
|
|
|
|
|
contextMenu->addSeparator(Constants::G_BOM);
|
|
|
|
|
add(Constants::SWITCH_UTF8BOM, Constants::G_BOM);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 18:05:03 +02:00
|
|
|
} // namespace TextEditor::Internal
|
2024-01-17 09:56:06 +01:00
|
|
|
|
|
|
|
|
#include "texteditorplugin.moc"
|