17#include "clipboardhistorydialog.h"
18#include "export/exporter.h"
19#include "inlinenotedata.h"
20#include "kateabstractinputmode.h"
21#include "kateautoindent.h"
22#include "katebookmarks.h"
23#include "katebuffer.h"
24#include "katecompletionwidget.h"
25#include "kateconfig.h"
26#include "katedialogs.h"
27#include "katedocument.h"
28#include "kateglobal.h"
29#include "katehighlight.h"
30#include "katehighlightmenu.h"
31#include "katekeywordcompletion.h"
32#include "katelayoutcache.h"
33#include "katemessagewidget.h"
34#include "katemodemenu.h"
35#include "katepartdebug.h"
36#include "katerenderer.h"
37#include "katestatusbar.h"
38#include "katetemplatehandler.h"
39#include "katetextline.h"
40#include "kateundomanager.h"
41#include "kateviewhelpers.h"
42#include "kateviewinternal.h"
43#include "katewordcompletion.h"
44#include "printing/kateprinter.h"
45#include "screenshotdialog.h"
46#include "script/katescriptaction.h"
47#include "script/katescriptmanager.h"
48#include "spellcheck/spellcheck.h"
49#include "spellcheck/spellcheckdialog.h"
50#include "spellcheck/spellingmenu.h"
52#include <KTextEditor/Message>
53#include <ktexteditor/annotationinterface.h>
54#include <ktexteditor/inlinenoteprovider.h>
55#include <ktexteditor/texthintinterface.h>
57#include <KActionCollection>
59#include <KConfigGroup>
62#include <KSelectAction>
63#include <KStandardActions>
64#include <KStandardShortcut>
65#include <KToggleAction>
66#include <KXMLGUIFactory>
68#include <QActionGroup>
69#include <QApplication>
74#include <QInputDialog>
79#include <QRegularExpression>
80#include <QTextToSpeech>
92 return doc->isComment(0, line.
firstChar());
106KTextEditor::ViewPrivate::ViewPrivate(KTextEditor::DocumentPrivate *doc, QWidget *parent, KTextEditor::MainWindow *mainWindow)
107 : KTextEditor::
View(this, parent)
108 , m_completionWidget(nullptr)
109 , m_annotationModel(nullptr)
110 , m_markedSelection(false)
113 , m_textFolding(doc->buffer())
114 , m_config(new KateViewConfig(this))
115 , m_renderer(new KateRenderer(doc, m_textFolding, this))
116 , m_viewInternal(new KateViewInternal(this))
117 , m_spell(new KateSpellCheckDialog(this))
118 , m_bookmarks(new KateBookmarks(this))
119 , m_topSpacer(new QSpacerItem(0, 0))
120 , m_leftSpacer(new QSpacerItem(0, 0))
121 , m_rightSpacer(new QSpacerItem(0, 0))
122 , m_bottomSpacer(new QSpacerItem(0, 0))
124 , m_updatingDocumentConfig(false)
125 , m_selection(&m_doc->buffer(), KTextEditor::
Range::invalid(), Kate::TextRange::ExpandLeft, Kate::TextRange::AllowEmpty)
127 , m_bottomViewBar(nullptr)
129 , m_dictionaryBar(nullptr)
130 , m_spellingMenu(new KateSpellingMenu(this))
131 , m_userContextMenuSet(false)
132 , m_lineToUpdateRange(KTextEditor::
LineRange::invalid())
133 , m_mainWindow(mainWindow ? mainWindow : KTextEditor::
EditorPrivate::self()->dummyMainWindow())
134 , m_statusBar(nullptr)
135 , m_temporaryAutomaticInvocationDisabled(false)
136 , m_autoFoldedFirstLine(false)
139 connect(
this, &KTextEditor::ViewPrivate::delayedUpdateOfView,
this, &KTextEditor::ViewPrivate::slotDelayedUpdateOfView,
Qt::QueuedConnection);
141 m_delayedUpdateTimer.setSingleShot(
true);
142 m_delayedUpdateTimer.setInterval(0);
143 connect(&m_delayedUpdateTimer, &
QTimer::timeout,
this, &KTextEditor::ViewPrivate::delayedUpdateOfView);
149 m_selection.setView(
this);
152 m_selection.setZDepth(-100000.0);
157 QWidget *bottomBarParent = m_mainWindow->createViewBar(
this);
159 m_bottomViewBar =
new KateViewBar(bottomBarParent !=
nullptr, bottomBarParent ? bottomBarParent :
this,
this);
167 m_bottomViewBar->installEventFilter(m_viewInternal);
180 if (bottomBarParent) {
181 m_mainWindow->addWidgetToViewBar(
this, m_bottomViewBar);
186 m_notificationLayout->setContentsMargins(20, 20, 20, 20);
187 m_viewInternal->setLayout(m_notificationLayout);
190 m_viewInternal->updateView();
194 setFocusProxy(m_viewInternal);
197 setXMLFile(QStringLiteral(
"katepart5ui.rc"));
203 new KateWordCompletionView(
this, actionCollection());
212 m_startingUp =
false;
218 for (
auto messageWidget : m_messageWidgets) {
245KTextEditor::ViewPrivate::~ViewPrivate()
252 doc()->removeView(
this);
255 delete m_completionWidget;
263 delete m_viewInternal;
266 m_mainWindow->deleteViewBar(
this);
267 m_bottomViewBar =
nullptr;
274void KTextEditor::ViewPrivate::toggleStatusBar()
278 bottomViewBar()->removePermanentBarWidget(m_statusBar);
280 m_statusBar =
nullptr;
281 Q_EMIT statusBarEnabledChanged(
this,
false);
286 m_statusBar =
new KateStatusBar(
this);
287 bottomViewBar()->addPermanentBarWidget(m_statusBar);
288 Q_EMIT statusBarEnabledChanged(
this,
true);
291void KTextEditor::ViewPrivate::setupLayout()
299 m_topSpacer =
new QSpacerItem(0, 0);
300 m_leftSpacer =
new QSpacerItem(0, 0);
301 m_rightSpacer =
new QSpacerItem(0, 0);
302 m_bottomSpacer =
new QSpacerItem(0, 0);
306 QStyleOptionFrame opt;
317 QGridLayout *layout =
new QGridLayout(
this);
322 if (frameAroundContents) {
327 layout->
addItem(m_topSpacer, 1, 0, 1, 4);
330 layout->
addItem(m_leftSpacer, 2, 0, 1, 1);
333 layout->
addWidget(m_viewInternal->m_leftBorder, 2, 1, 1, 1);
336 layout->
addWidget(m_viewInternal, 2, 2, 1, 1);
339 layout->
addItem(m_rightSpacer, 2, 3, 1, 1);
342 layout->
addItem(m_bottomSpacer, 3, 0, 1, 4);
345 layout->
addWidget(m_viewInternal->m_lineScroll, 1, 4, 3, 1);
348 layout->
addWidget(m_viewInternal->m_columnScroll, 4, 0, 1, 4);
351 layout->
addWidget(m_viewInternal->m_dummy, 4, 4, 1, 1);
357 if (m_bottomViewBar->parentWidget() ==
this) {
358 layout->
addWidget(m_bottomViewBar, 6, 0, 1, 5);
367 m_viewInternal->m_lineScroll->setAutoFillBackground(
false);
370 m_viewInternal->m_columnScroll->setAutoFillBackground(
false);
377 layout->
addItem(m_topSpacer, 1, 0, 1, 5);
380 layout->
addItem(m_leftSpacer, 2, 0, 1, 1);
383 layout->
addWidget(m_viewInternal->m_leftBorder, 2, 1, 1, 1);
386 layout->
addWidget(m_viewInternal, 2, 2, 1, 1);
389 layout->
addWidget(m_viewInternal->m_lineScroll, 2, 3, 1, 1);
392 layout->
addItem(m_rightSpacer, 2, 4, 1, 1);
395 layout->
addWidget(m_viewInternal->m_columnScroll, 3, 1, 1, 2);
398 layout->
addWidget(m_viewInternal->m_dummy, 3, 3, 1, 1);
401 layout->
addItem(m_bottomSpacer, 4, 0, 1, 5);
407 if (m_bottomViewBar->parentWidget() ==
this) {
408 layout->
addWidget(m_bottomViewBar, 6, 0, 1, 5);
417 m_viewInternal->m_lineScroll->setAutoFillBackground(
true);
419 m_viewInternal->m_columnScroll->setBackgroundRole(
QPalette::Base);
420 m_viewInternal->m_columnScroll->setAutoFillBackground(
true);
424void KTextEditor::ViewPrivate::setupConnections()
426 connect(m_doc->undoManager(), &KateUndoManager::undoChanged,
this, &KTextEditor::ViewPrivate::slotUpdateUndo);
429 connect(m_viewInternal, &KateViewInternal::dropEventPass,
this, &KTextEditor::ViewPrivate::dropEventPass);
431 connect(m_doc, &KTextEditor::DocumentPrivate::annotationModelChanged, m_viewInternal->m_leftBorder, &KateIconBorder::annotationModelChanged);
434void KTextEditor::ViewPrivate::goToPreviousEditingPosition()
436 auto c = doc()->
lastEditingPosition(KTextEditor::DocumentPrivate::Previous, cursorPosition());
438 setCursorPosition(c);
442void KTextEditor::ViewPrivate::goToNextEditingPosition()
446 setCursorPosition(c);
449void KTextEditor::ViewPrivate::setupActions()
451 KActionCollection *ac = actionCollection();
454 m_toggleWriteLock =
nullptr;
457 a->
setWhatsThis(
i18n(
"Cut the selected text and move it to the clipboard"));
465 a->
setWhatsThis(
i18n(
"Use this command to copy the currently selected text to the system clipboard."));
467 m_clipboardHistory = a = ac->
addAction(QStringLiteral(
"clipboard_history_paste"),
this, [
this] {
468 ClipboardHistoryDialog chd(mainWindow()->
window(),
this);
475 m_pasteSelection = a = ac->
addAction(QStringLiteral(
"edit_paste_selection"),
this, &KTextEditor::ViewPrivate::pasteSelection);
481 a = ac->
addAction(QStringLiteral(
"edit_paste_from_file"),
this, &KTextEditor::ViewPrivate::pasteFromFile);
484 a = ac->
addAction(QStringLiteral(
"edit_copy_file_location"),
this, &KTextEditor::ViewPrivate::copyFileLocation);
489 m_swapWithClipboard = a = ac->
addAction(QStringLiteral(
"edit_swap_with_clipboard"),
this, &KTextEditor::ViewPrivate::swapWithClipboard);
491 a->
setWhatsThis(
i18n(
"Swap the selected text with the clipboard contents"));
493 m_screenshotSelection = a = ac->
addAction(QStringLiteral(
"text_screenshot_selection"),
this, &KTextEditor::ViewPrivate::screenshot);
496 if (!doc()->readOnly()) {
508 m_scriptActionMenu.reset(
new KateScriptActionMenu(
this,
i18n(
"&Scripts")));
509 ac->
addAction(QStringLiteral(
"tools_scripts"), m_scriptActionMenu.get());
511 a = ac->
addAction(QStringLiteral(
"tools_apply_wordwrap"));
514 i18n(
"Use this to wrap the current line, or to reformat the selected lines as paragraph, "
515 "to fit the 'Wrap words at' setting in the configuration dialog.<br /><br />"
516 "This is a static word wrap, meaning the document is changed."));
519 a = ac->
addAction(QStringLiteral(
"tools_cleanIndent"));
522 i18n(
"Use this to clean the indentation of a selected block of text (only tabs/only spaces).<br /><br />"
523 "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog."));
526 a = ac->
addAction(QStringLiteral(
"tools_convertTabsSpaces"));
529 doc()->
config()->setReplaceTabsDyn(
true);
530 doc()->indent(doc()->documentRange(), 0);
533 a = ac->
addAction(QStringLiteral(
"tools_convertSpacesTabs"));
536 auto config = doc()->
config();
537 if (config->replaceTabsDyn()) {
538 config->configStart();
539 config->setReplaceTabsDyn(
false);
540 config->setTabWidth(config->indentationWidth());
543 config->setTabWidth(config->indentationWidth());
545 doc()->indent(doc()->documentRange(), 0);
548 a = ac->
addAction(QStringLiteral(
"tools_formatIndent"));
550 a->setWhatsThis(
i18n(
"Use this to auto indent the current line or block of text to its proper indent level."));
553 a = ac->
addAction(QStringLiteral(
"tools_alignOn"));
556 i18n(
"This command aligns lines in the selected block or whole document on the column given by a regular expression "
557 "that you will be prompted for.<br /><br />"
558 "If you give an empty pattern it will align on the first non-blank character by default.<br />"
559 "If the pattern has a capture it will indent on the captured match.<br /><br />"
560 "<i>Examples</i>:<br />"
561 "With '-' it will insert spaces before the first '-' of each lines to align them all on the same column.<br />"
562 "With ':\\s+(.)' it will insert spaces before the first non-blank character that occurs after a colon to align "
563 "them all on the same column."));
566 a = ac->
addAction(QStringLiteral(
"tools_comment"));
570 i18n(
"This command comments out the current line or a selected block of text.<br /><br />"
571 "The characters for single/multiple line comments are defined within the language's highlighting."));
574 a = ac->
addAction(QStringLiteral(
"Previous Editing Line"));
575 a->
setText(
i18n(
"Go to Previous Editing Location"));
580 a = ac->
addAction(QStringLiteral(
"Next Editing Line"));
586 a = ac->
addAction(QStringLiteral(
"tools_uncomment"));
590 i18n(
"This command removes comments from the current line or a selected block of text.<br /><br />"
591 "The characters for single/multiple line comments are defined within the language's highlighting."));
594 a = ac->
addAction(QStringLiteral(
"tools_toggle_comment"));
599 a = m_toggleWriteLock =
new KToggleAction(
i18n(
"&Read Only Mode"),
this);
600 a->setWhatsThis(
i18n(
"Lock/unlock the document for writing"));
601 a->setChecked(!doc()->isReadWrite());
603 ac->
addAction(QStringLiteral(
"tools_toggle_write_lock"), a);
605 a = m_forceRTLDirection =
new KToggleAction(
i18n(
"&Force RTL Direction"),
this);
606 a->setWhatsThis(
i18n(
"Force RTL Text Direction"));
608 m_forceRTL = checked;
612 ac->
addAction(QStringLiteral(
"force_rtl_direction"), a);
614 a = ac->
addAction(QStringLiteral(
"tools_uppercase"));
616 a->setText(
i18n(
"Uppercase"));
619 i18n(
"Convert the selection to uppercase, or the character to the "
620 "right of the cursor if no text is selected."));
623 a = ac->
addAction(QStringLiteral(
"tools_lowercase"));
625 a->setText(
i18n(
"Lowercase"));
628 i18n(
"Convert the selection to lowercase, or the character to the "
629 "right of the cursor if no text is selected."));
632 a = ac->
addAction(QStringLiteral(
"tools_capitalize"));
634 a->setText(
i18n(
"Capitalize"));
637 i18n(
"Capitalize the selection, or the word under the "
638 "cursor if no text is selected."));
641 a = ac->
addAction(QStringLiteral(
"tools_join_lines"));
646 a = ac->
addAction(QStringLiteral(
"tools_invoke_code_completion"));
648 a->setWhatsThis(
i18n(
"Manually invoke command completion, usually by using a shortcut bound to this action."));
652 a = ac->
addAction(QStringLiteral(
"remove_trailing_spaces"));
658 for (
auto *action : {m_cut, m_paste, m_clipboardHistory, m_swapWithClipboard}) {
659 action->setEnabled(
false);
662 if (m_pasteSelection) {
663 m_pasteSelection->setEnabled(
false);
666 m_editUndo =
nullptr;
667 m_editRedo =
nullptr;
676 a = ac->
addAction(QStringLiteral(
"file_reload"));
678 a->setText(
i18n(
"Reloa&d"));
680 a->setWhatsThis(
i18n(
"Reload the current document from disk."));
684 a->
setWhatsThis(
i18n(
"Save the current document to disk, with a name of your choice."));
686 a =
new KateViewEncodingAction(m_doc,
this,
i18nc(
"@action",
"Save As with Encodin&g…"),
this,
true );
688 ac->
addAction(QStringLiteral(
"file_save_as_with_encoding"), a);
690 a = ac->
addAction(QStringLiteral(
"file_save_copy_as"));
692 a->setText(
i18nc(
"@action",
"Save Cop&y As…"));
693 a->setWhatsThis(
i18n(
"Save a copy of the current document to disk."));
697 a->
setWhatsThis(
i18n(
"This command opens a dialog and lets you choose a line that you want the cursor to move to."));
699 a = ac->
addAction(QStringLiteral(
"modified_line_up"));
701 a->setText(
i18n(
"Go to Previous Modified Line"));
702 a->setWhatsThis(
i18n(
"Move upwards to the previous modified line."));
705 a = ac->
addAction(QStringLiteral(
"modified_line_down"));
707 a->setText(
i18n(
"Go to Next Modified Line"));
708 a->setWhatsThis(
i18n(
"Move downwards to the next modified line."));
711 a = ac->
addAction(QStringLiteral(
"set_confdlg"));
714 a->setWhatsThis(
i18n(
"Configure various aspects of this editor."));
717 m_modeAction =
new KateModeMenu(
i18n(
"&Mode"),
this);
718 ac->
addAction(QStringLiteral(
"tools_mode"), m_modeAction);
720 "Here you can choose which mode should be used for the current document. This will influence the highlighting and folding being used, for example."));
721 m_modeAction->updateMenu(m_doc);
723 KateHighlightingMenu *menu =
new KateHighlightingMenu(
i18n(
"&Highlighting"),
this);
724 ac->
addAction(QStringLiteral(
"tools_highlighting"), menu);
725 menu->
setWhatsThis(
i18n(
"Here you can choose how the current document should be highlighted."));
726 menu->updateMenu(m_doc);
728 KateViewSchemaAction *schemaMenu =
new KateViewSchemaAction(
i18n(
"&Editor Color Theme"),
this);
730 ac->
addAction(QStringLiteral(
"view_schemas"), schemaMenu);
731 schemaMenu->updateMenu(
this);
734 KateViewIndentationAction *indentMenu =
new KateViewIndentationAction(m_doc,
i18n(
"&Indentation"),
this);
735 ac->
addAction(QStringLiteral(
"tools_indentation"), indentMenu);
744 a->
setWhatsThis(
i18n(
"If you have selected something within the current document, this will no longer be selected."));
746 a = ac->
addAction(QStringLiteral(
"view_inc_font_sizes"));
748 a->setText(
i18n(
"Enlarge Font"));
750 a->setWhatsThis(
i18n(
"This increases the display font size."));
752 m_viewInternal->slotIncFontSizes();
755 a = ac->
addAction(QStringLiteral(
"view_dec_font_sizes"));
757 a->setText(
i18n(
"Shrink Font"));
759 a->setWhatsThis(
i18n(
"This decreases the display font size."));
761 m_viewInternal->slotDecFontSizes();
764 a = ac->
addAction(QStringLiteral(
"view_reset_font_sizes"));
766 a->setText(
i18n(
"Reset Font Size"));
768 a->setWhatsThis(
i18n(
"This resets the display font size."));
771 a = m_toggleBlockSelection =
new KToggleAction(
i18n(
"Bl&ock Selection Mode"),
this);
772 ac->
addAction(QStringLiteral(
"set_verticalSelect"), a);
774 a->setWhatsThis(
i18n(
"This command allows switching between the normal (line based) selection mode and the block selection mode."));
777 a = ac->
addAction(QStringLiteral(
"switch_next_input_mode"));
780 a->setWhatsThis(
i18n(
"Switch to the next input mode."));
783 a = m_toggleInsert =
new KToggleAction(
i18n(
"Overwr&ite Mode"),
this);
784 ac->
addAction(QStringLiteral(
"set_insert"), a);
786 a->setWhatsThis(
i18n(
"Choose whether you want the text you type to be inserted or to overwrite existing text."));
789 KToggleAction *toggleAction;
790 a = m_toggleShowSpace = toggleAction =
new KToggleAction(
i18n(
"Show Whitespace"),
this);
791 ac->
addAction(QStringLiteral(
"view_show_whitespaces"), a);
793 i18n(
"If this option is checked, whitespaces in this document will be visible.<br /><br />"
794 "This is only a view option, meaning the document will not be changed."));
797 a = m_toggleDynWrap = toggleAction =
new KToggleAction(
i18n(
"&Dynamic Word Wrap"),
this);
799 ac->
addAction(QStringLiteral(
"view_dynamic_word_wrap"), a);
801 i18n(
"If this option is checked, the text lines will be wrapped at the view border on the screen.<br /><br />"
802 "This is only a view option, meaning the document will not be changed."));
805 a = m_setDynWrapIndicators =
new KSelectAction(
i18n(
"Dynamic Word Wrap Indicators"),
this);
806 ac->
addAction(QStringLiteral(
"dynamic_word_wrap_indicators"), a);
807 a->
setWhatsThis(
i18n(
"Choose when the Dynamic Word Wrap Indicators should be displayed"));
809 const QStringList list2{
i18n(
"&Off"),
i18n(
"Follow &Line Numbers"),
i18n(
"&Always On")};
810 m_setDynWrapIndicators->setItems(list2);
811 m_setDynWrapIndicators->setEnabled(m_toggleDynWrap->isChecked());
813 a = toggleAction =
new KToggleAction(
i18n(
"Static Word Wrap"),
this);
814 ac->
addAction(QStringLiteral(
"view_static_word_wrap"), a);
815 a->
setWhatsThis(
i18n(
"If this option is checked, the text lines will be wrapped at the column defined in the editing properties."));
818 m_doc->setWordWrap(!m_doc->wordWrap());
822 a = toggleAction = m_toggleWWMarker =
new KToggleAction(
i18n(
"Show Static &Word Wrap Marker"),
this);
823 ac->
addAction(QStringLiteral(
"view_word_wrap_marker"), a);
825 i18n(
"Show/hide the Word Wrap Marker, a vertical line drawn at the word "
826 "wrap column as defined in the editing properties"));
829 a = toggleAction = m_toggleFoldingMarkers =
new KToggleAction(
i18n(
"Show Folding &Markers"),
this);
830 ac->
addAction(QStringLiteral(
"view_folding_markers"), a);
831 a->
setWhatsThis(
i18n(
"You can choose if the codefolding marks should be shown, if codefolding is possible."));
834 a = m_toggleIconBar = toggleAction =
new KToggleAction(
i18n(
"Show &Icon Border"),
this);
835 ac->
addAction(QStringLiteral(
"view_border"), a);
836 a->
setWhatsThis(
i18n(
"Show/hide the icon border.<br /><br />The icon border shows bookmark symbols, for instance."));
839 a = toggleAction = m_toggleLineNumbers =
new KToggleAction(
i18n(
"Show &Line Numbers"),
this);
840 ac->
addAction(QStringLiteral(
"view_line_numbers"), a);
841 a->
setWhatsThis(
i18n(
"Show/hide the line numbers on the left hand side of the view."));
844 a = m_toggleScrollBarMarks = toggleAction =
new KToggleAction(
i18n(
"Show Scroll&bar Marks"),
this);
845 ac->
addAction(QStringLiteral(
"view_scrollbar_marks"), a);
846 a->
setWhatsThis(
i18n(
"Show/hide the marks on the vertical scrollbar.<br /><br />The marks show bookmarks, for instance."));
849 a = m_toggleScrollBarMiniMap = toggleAction =
new KToggleAction(
i18n(
"Show Scrollbar Mini-Map"),
this);
850 ac->
addAction(QStringLiteral(
"view_scrollbar_minimap"), a);
851 a->
setWhatsThis(
i18n(
"Show/hide the mini-map on the vertical scrollbar.<br /><br />The mini-map shows an overview of the whole document."));
854 a = m_doc->autoReloadToggleAction();
855 ac->
addAction(QStringLiteral(
"view_auto_reload"), a);
863 a = m_toggleNPSpaces =
new KToggleAction(
i18n(
"Show Non-Printable Spaces"),
this);
864 ac->
addAction(QStringLiteral(
"view_non_printable_spaces"), a);
865 a->
setWhatsThis(
i18n(
"Show/hide bounding box around non-printable spaces"));
868 a = m_switchCmdLine = ac->
addAction(QStringLiteral(
"switch_to_cmd_line"));
871 a->setWhatsThis(
i18n(
"Show/hide the command line on the bottom of the view."));
874 KActionMenu *am =
new KActionMenu(
i18n(
"Input Modes"),
this);
875 m_inputModeActions =
new QActionGroup(am);
876 ac->
addAction(QStringLiteral(
"view_input_modes"), am);
877 auto switchInputModeAction = ac->
action(QStringLiteral(
"switch_next_input_mode"));
880 for (
const auto &mode : m_viewInternal->m_inputModes) {
881 a =
new QAction(mode->viewInputModeHuman(), m_inputModeActions);
883 a->setWhatsThis(
i18n(
"Activate/deactivate %1", mode->viewInputModeHuman()));
884 const InputMode im = mode->viewInputMode();
885 a->setData(
static_cast<int>(im));
886 a->setCheckable(
true);
887 if (im == m_config->inputMode()) {
893 a = m_setEndOfLine =
new KSelectAction(
i18n(
"&End of Line"),
this);
894 ac->
addAction(QStringLiteral(
"set_eol"), a);
895 a->
setWhatsThis(
i18n(
"Choose which line endings should be used, when you save the document"));
896 const QStringList
list{
i18nc(
"@item:inmenu End of Line",
"&UNIX"),
897 i18nc(
"@item:inmenu End of Line",
"&Windows/DOS"),
898 i18nc(
"@item:inmenu End of Line",
"&Macintosh")};
899 m_setEndOfLine->setItems(list);
900 m_setEndOfLine->setCurrentItem(doc()->config()->eol());
903 a = m_addBom =
new KToggleAction(
i18n(
"Add &Byte Order Mark (BOM)"),
this);
904 m_addBom->setChecked(doc()->config()->
bom());
905 ac->
addAction(QStringLiteral(
"add_bom"), a);
906 a->
setWhatsThis(
i18n(
"Enable/disable adding of byte order marks for UTF-8/UTF-16 encoded files while saving"));
910 m_encodingAction =
new KateViewEncodingAction(m_doc,
this,
i18n(
"E&ncoding"),
this);
911 ac->
addAction(QStringLiteral(
"set_encoding"), m_encodingAction);
914 a->
setWhatsThis(
i18n(
"Look up the first occurrence of a piece of text or regular expression."));
917 a = ac->
addAction(QStringLiteral(
"edit_find_selected"));
920 a->setWhatsThis(
i18n(
"Finds next occurrence of selected text."));
923 a = ac->
addAction(QStringLiteral(
"edit_find_selected_backwards"));
926 a->setWhatsThis(
i18n(
"Finds previous occurrence of selected text."));
929 a = ac->
addAction(QStringLiteral(
"edit_find_multicursor_next_occurrence"));
930 a->
setText(
i18n(
"Find and Select Next Occurrence"));
932 a->setWhatsThis(
i18n(
"Finds next occurrence of the word under cursor and add it to selection."));
935 a = ac->
addAction(QStringLiteral(
"edit_skip_multicursor_current_occurrence"));
936 a->
setText(
i18n(
"Mark Currently Selected Occurrence as Skipped"));
938 a->setWhatsThis(
i18n(
"Marks the currently selected word as skipped."));
941 a = ac->
addAction(QStringLiteral(
"edit_find_multicursor_all_occurrences"));
942 a->
setText(
i18n(
"Find and Select All Occurrences"));
944 a->setWhatsThis(
i18n(
"Finds all occurrences of the word under cursor and selects them."));
952 a->
setWhatsThis(
i18n(
"Look up the previous occurrence of the search phrase."));
956 a->
setWhatsThis(
i18n(
"Look up a piece of text or regular expression and replace the result with some given text."));
958 a = ac->
addAction(QStringLiteral(
"edit_create_multi_cursor_from_sel"));
961 a->setWhatsThis(
i18n(
"Creates a cursor at the end of every line in selection."));
964 a = ac->
addAction(QStringLiteral(
"edit_create_multi_cursor_down"));
967 a->setWhatsThis(
i18n(
"Adds a caret in the line below the current caret."));
970 a = ac->
addAction(QStringLiteral(
"edit_create_multi_cursor_up"));
973 a->setWhatsThis(
i18n(
"Adds a caret in the line above the current caret."));
976 a = ac->
addAction(QStringLiteral(
"edit_toggle_camel_case_cursor"));
977 a->
setText(
i18n(
"Toggle Camel Case Cursor Movement"));
978 a->setWhatsThis(
i18n(
"Toggle between normal word movement and camel case cursor movement."));
981 a = ac->
addAction(QStringLiteral(
"edit_remove_cursors_from_empty_lines"));
982 a->
setText(
i18n(
"Remove Cursors from Empty Lines"));
983 a->setWhatsThis(
i18n(
"Remove cursors from empty lines"));
986 m_spell->createActions(ac);
987 m_toggleOnTheFlySpellCheck =
new KToggleAction(
i18n(
"Automatic Spell Checking"),
this);
988 m_toggleOnTheFlySpellCheck->setWhatsThis(
i18n(
"Enable/disable automatic spell checking"));
990 ac->
addAction(QStringLiteral(
"tools_toggle_automatic_spell_checking"), m_toggleOnTheFlySpellCheck);
993 a = ac->
addAction(QStringLiteral(
"tools_change_dictionary"));
995 a->setWhatsThis(
i18n(
"Change the dictionary that is used for spell checking."));
998 a = ac->
addAction(QStringLiteral(
"tools_clear_dictionary_ranges"));
1000 a->setEnabled(
false);
1001 a->setWhatsThis(
i18n(
"Remove all the separate dictionary ranges that were set for spell checking."));
1005 m_copyHtmlAction = ac->
addAction(QStringLiteral(
"edit_copy_html"),
this, SLOT(exportHtmlToClipboard()));
1007 m_copyHtmlAction->setText(
i18n(
"Copy as &HTML"));
1008 m_copyHtmlAction->setWhatsThis(
i18n(
"Copy the selection as HTML, formatted using the current syntax highlighting and color scheme settings."));
1010 a = ac->
addAction(QStringLiteral(
"file_export_html"),
this, SLOT(exportHtmlToFile()));
1012 a->setText(
i18nc(
"@action",
"E&xport as HTML…"));
1014 i18n(
"This command allows you to export the current document"
1015 " with all highlighting information into a HTML document."));
1017 m_spellingMenu->createActions(ac);
1019 m_bookmarks->createActions(ac);
1021 slotSelectionChanged();
1027 setupSpeechActions();
1031 const auto actions = ac->
actions();
1032 for (QAction *action : actions) {
1039void KTextEditor::ViewPrivate::slotConfigDialog()
1045void KTextEditor::ViewPrivate::setupEditActions()
1050 KActionCollection *ac = actionCollection();
1052 QAction *a = ac->
addAction(QStringLiteral(
"word_left"));
1056 m_editActions.push_back(a);
1058 a = ac->
addAction(QStringLiteral(
"select_char_left"));
1062 m_editActions.push_back(a);
1064 a = ac->
addAction(QStringLiteral(
"select_word_left"));
1072 m_editActions.push_back(a);
1074 a = ac->
addAction(QStringLiteral(
"word_right"));
1078 m_editActions.push_back(a);
1080 a = ac->
addAction(QStringLiteral(
"select_char_right"));
1084 m_editActions.push_back(a);
1086 a = ac->
addAction(QStringLiteral(
"select_word_right"));
1094 m_editActions.push_back(a);
1096 a = ac->
addAction(QStringLiteral(
"mark_selection"));
1098 a->
setWhatsThis(
i18n(
"Emulate the Emacs-like selection mode, where the beginning is marked and then the selection is continuously updated."));
1100 m_editActions.push_back(a);
1102 a = ac->
addAction(QStringLiteral(
"beginning_of_line"));
1106 m_editActions.push_back(a);
1108 a = ac->
addAction(QStringLiteral(
"beginning_of_document"));
1109 a->
setText(
i18n(
"Move to Beginning of Document"));
1112 m_editActions.push_back(a);
1114 a = ac->
addAction(QStringLiteral(
"select_beginning_of_line"));
1122 m_editActions.push_back(a);
1124 a = ac->
addAction(QStringLiteral(
"select_beginning_of_document"));
1125 a->
setText(
i18n(
"Select to Beginning of Document"));
1132 m_editActions.push_back(a);
1134 a = ac->
addAction(QStringLiteral(
"end_of_line"));
1138 m_editActions.push_back(a);
1140 a = ac->
addAction(QStringLiteral(
"end_of_document"));
1144 m_editActions.push_back(a);
1146 a = ac->
addAction(QStringLiteral(
"select_end_of_line"));
1154 m_editActions.push_back(a);
1156 a = ac->
addAction(QStringLiteral(
"select_end_of_document"));
1164 m_editActions.push_back(a);
1166 a = ac->
addAction(QStringLiteral(
"select_line_up"));
1170 m_editActions.push_back(a);
1172 a = ac->
addAction(QStringLiteral(
"scroll_line_up"));
1179 m_editActions.push_back(a);
1181 a = ac->
addAction(QStringLiteral(
"move_line_down"));
1185 m_editActions.push_back(a);
1187 a = ac->
addAction(QStringLiteral(
"move_line_up"));
1191 m_editActions.push_back(a);
1193 a = ac->
addAction(QStringLiteral(
"move_cursor_right"));
1197 m_editActions.push_back(a);
1199 a = ac->
addAction(QStringLiteral(
"move_cursor_left"));
1203 m_editActions.push_back(a);
1205 a = ac->
addAction(QStringLiteral(
"select_line_down"));
1209 m_editActions.push_back(a);
1211 a = ac->
addAction(QStringLiteral(
"scroll_line_down"));
1218 m_editActions.push_back(a);
1220 a = ac->
addAction(QStringLiteral(
"scroll_page_up"));
1224 m_editActions.push_back(a);
1226 a = ac->
addAction(QStringLiteral(
"select_page_up"));
1230 m_editActions.push_back(a);
1232 a = ac->
addAction(QStringLiteral(
"move_top_of_view"));
1236 m_editActions.push_back(a);
1238 a = ac->
addAction(QStringLiteral(
"select_top_of_view"));
1242 m_editActions.push_back(a);
1244 a = ac->
addAction(QStringLiteral(
"scroll_page_down"));
1248 m_editActions.push_back(a);
1250 a = ac->
addAction(QStringLiteral(
"select_page_down"));
1254 m_editActions.push_back(a);
1256 a = ac->
addAction(QStringLiteral(
"move_bottom_of_view"));
1260 m_editActions.push_back(a);
1262 a = ac->
addAction(QStringLiteral(
"select_bottom_of_view"));
1266 m_editActions.push_back(a);
1268 a = ac->
addAction(QStringLiteral(
"to_matching_bracket"));
1274 a = ac->
addAction(QStringLiteral(
"select_matching_bracket"));
1281 a = ac->
addAction(QStringLiteral(
"subword_right"));
1286 m_editActions.push_back(a);
1288 a = ac->
addAction(QStringLiteral(
"select_subword_right"));
1291 shiftWordRight(
true);
1293 m_editActions.push_back(a);
1295 a = ac->
addAction(QStringLiteral(
"subword_left"));
1300 m_editActions.push_back(a);
1302 a = ac->
addAction(QStringLiteral(
"select_subword_left"));
1305 shiftWordLeft(
true);
1307 m_editActions.push_back(a);
1311 if (!doc()->readOnly()) {
1312 a = ac->
addAction(QStringLiteral(
"transpose_char"));
1315 m_editActions.push_back(a);
1317 a = ac->
addAction(QStringLiteral(
"transpose_word"));
1320 m_editActions.push_back(a);
1322 a = ac->
addAction(QStringLiteral(
"delete_line"));
1326 m_editActions.push_back(a);
1328 a = ac->
addAction(QStringLiteral(
"delete_word_left"));
1332 m_editActions.push_back(a);
1334 a = ac->
addAction(QStringLiteral(
"delete_word_right"));
1338 m_editActions.push_back(a);
1340 a = ac->
addAction(QStringLiteral(
"delete_next_character"));
1344 m_editActions.push_back(a);
1346 a = ac->
addAction(QStringLiteral(
"backspace"));
1348 QList<QKeySequence> scuts;
1352 m_editActions.push_back(a);
1354 a = ac->
addAction(QStringLiteral(
"insert_tabulator"));
1357 m_editActions.push_back(a);
1359 a = ac->
addAction(QStringLiteral(
"smart_newline"));
1361 a->
setWhatsThis(
i18n(
"Insert newline including leading characters of the current line which are not letters or numbers."));
1366 m_editActions.push_back(a);
1368 a = ac->
addAction(QStringLiteral(
"no_indent_newline"));
1369 a->
setText(
i18n(
"Insert a Non-Indented Newline"));
1370 a->
setWhatsThis(
i18n(
"Insert a new line without indentation, regardless of indentation settings."));
1375 m_editActions.push_back(a);
1377 a = ac->
addAction(QStringLiteral(
"newline_above"));
1378 a->
setText(
i18n(
"Insert a Newline Above Current Line"));
1379 a->
setWhatsThis(
i18n(
"Insert a new line above current line without modifying the current line."));
1384 m_editActions.push_back(a);
1386 a = ac->
addAction(QStringLiteral(
"newline_below"));
1387 a->
setText(
i18n(
"Insert a Newline Below Current Line"));
1388 a->
setWhatsThis(
i18n(
"Insert a new line below current line without modifying the current line."));
1393 m_editActions.push_back(a);
1395 a = ac->
addAction(QStringLiteral(
"tools_indent"));
1399 i18n(
"Use this to indent a selected block of text.<br /><br />"
1400 "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog."));
1404 a = ac->
addAction(QStringLiteral(
"tools_unindent"));
1412 a = ac->
addAction(QStringLiteral(
"delete_subword_left"));
1415 deleteWordLeft(
true);
1417 m_editActions.push_back(a);
1419 a = ac->
addAction(QStringLiteral(
"delete_subword_right"));
1422 deleteWordRight(
true);
1424 m_editActions.push_back(a);
1435void KTextEditor::ViewPrivate::setupCodeFolding()
1437 KActionCollection *ac = this->actionCollection();
1440 a = ac->
addAction(QStringLiteral(
"folding_toplevel"));
1444 a = ac->
addAction(QStringLiteral(
"folding_expandtoplevel"));
1448 a = ac->
addAction(QStringLiteral(
"folding_toggle_current"));
1452 a = ac->
addAction(QStringLiteral(
"folding_toggle_in_current"));
1457void KTextEditor::ViewPrivate::setupSpeechActions()
1459 KActionCollection *ac = actionCollection();
1461 QAction *a = ac->
addAction(QStringLiteral(
"tools_speech_say"));
1462 a->
setText(
i18n(
"Say current selection or document"));
1471 a = ac->
addAction(QStringLiteral(
"tools_speech_stop"));
1477 a = ac->
addAction(QStringLiteral(
"tools_speech_pause"));
1483 a = ac->
addAction(QStringLiteral(
"tools_speech_resume"));
1490void KTextEditor::ViewPrivate::slotFoldToplevelNodes()
1492 for (
int line = 0; line < doc()->
lines(); ++line) {
1493 if (textFolding().isLineVisible(line)) {
1499void KTextEditor::ViewPrivate::slotExpandToplevelNodes()
1501 const auto topLevelRanges(textFolding().foldingRangesForParentRange());
1502 for (
const auto &range : topLevelRanges) {
1503 textFolding().unfoldRange(range.first);
1507void KTextEditor::ViewPrivate::slotToggleFolding()
1509 int line = cursorPosition().line();
1510 bool actionDone =
false;
1511 while (!actionDone && (line > -1)) {
1512 actionDone = unfoldLine(line);
1514 actionDone = foldLine(line--).isValid();
1519void KTextEditor::ViewPrivate::slotToggleFoldingsInRange()
1521 int line = cursorPosition().line();
1522 while (!toggleFoldingsInRange(line) && (line > -1)) {
1527KTextEditor::Range KTextEditor::ViewPrivate::foldLine(
int line)
1530 if (!foldingRange.
isValid()) {
1531 return foldingRange;
1536 if (!m_doc->buffer().isFoldingStartingOnLine(line).second && !foldingRange.
onSingleLine()) {
1537 const int adjustedLine = foldingRange.
end().
line() - 1;
1538 foldingRange.
setEnd(KTextEditor::Cursor(adjustedLine, doc()->buffer().plainLine(adjustedLine).length()));
1545 auto folds = textFolding().foldingRangesStartingOnLine(line);
1546 for (
int i = 0; i < folds.size(); ++i) {
1547 KTextEditor::Range fold = textFolding().foldingRange(folds[i].first);
1548 if (fold == foldingRange) {
1549 return foldingRange;
1559 return foldingRange;
1562bool KTextEditor::ViewPrivate::unfoldLine(
int line)
1564 bool actionDone =
false;
1565 const KTextEditor::Cursor currentCursor = cursorPosition();
1569 auto startingRanges = textFolding().foldingRangesStartingOnLine(line);
1570 for (
int i = 0; i < startingRanges.size() && !actionDone; ++i) {
1572 setCursorPosition(textFolding().foldingRange(startingRanges[i].first).
start());
1574 actionDone |= textFolding().unfoldRange(startingRanges[i].first);
1579 setCursorPosition(currentCursor);
1585bool KTextEditor::ViewPrivate::toggleFoldingOfLine(
int line)
1587 bool actionDone = unfoldLine(line);
1589 actionDone = foldLine(line).isValid();
1595bool KTextEditor::ViewPrivate::toggleFoldingsInRange(
int line)
1598 if (!foldingRange.
isValid()) {
1603 bool actionDone =
false;
1604 const KTextEditor::Cursor currentCursor = cursorPosition();
1608 actionDone |= unfoldLine(line);
1612 for (
int ln = foldingRange.
start().
line() + 1; ln < foldingRange.
end().
line(); ++ln) {
1613 actionDone |= unfoldLine(ln);
1618 setCursorPosition(currentCursor);
1624 for (
int ln = foldingRange.
start().
line() + 1; ln < foldingRange.
end().
line(); ++ln) {
1625 KTextEditor::Range fr = foldLine(ln);
1628 ln = qMax(ln, fr.
end().
line() - 1);
1637 actionDone |= foldLine(line).isValid();
1646 return currentInputMode()->viewMode();
1649QString KTextEditor::ViewPrivate::viewModeHuman()
const
1651 QString currentMode = currentInputMode()->viewModeHuman();
1654 if (!doc()->isReadWrite()) {
1655 currentMode =
i18n(
"(R/O) %1", currentMode);
1664 return currentInputMode()->viewInputMode();
1667QString KTextEditor::ViewPrivate::viewInputModeHuman()
const
1669 return currentInputMode()->viewInputModeHuman();
1674 if (currentInputMode()->viewInputMode() == mode) {
1680 clearSecondaryCursors();
1683 m_viewInternal->m_currentInputMode->deactivate();
1684 m_viewInternal->m_currentInputMode = m_viewInternal->m_inputModes[mode].get();
1685 m_viewInternal->m_currentInputMode->activate();
1688 if (rememberInConfig) {
1689 config()->setValue(KateViewConfig::InputMode, mode);
1693 const auto inputModeActions = m_inputModeActions->actions();
1694 for (QAction *action : inputModeActions) {
1695 if (
static_cast<InputMode
>(action->data().toInt()) == mode) {
1696 action->setChecked(
true);
1702 Q_EMIT viewInputModeChanged(
this, mode);
1703 Q_EMIT viewModeChanged(
this, viewMode());
1706void KTextEditor::ViewPrivate::slotDocumentAboutToReload()
1708 if (doc()->isAutoReload()) {
1709 const int lastVisibleLine = m_viewInternal->endLine();
1710 const int currentLine = cursorPosition().line();
1711 m_gotoBottomAfterReload = (lastVisibleLine == currentLine) && (currentLine == doc()->lastLine());
1712 if (!m_gotoBottomAfterReload) {
1714 const int firstVisibleLine = 1 + lastVisibleLine - m_viewInternal->linesDisplayed();
1715 const int newLine = qBound(firstVisibleLine, currentLine, lastVisibleLine);
1716 setCursorPositionVisual(KTextEditor::Cursor(newLine, cursorPosition().column()));
1719 m_gotoBottomAfterReload =
false;
1723void KTextEditor::ViewPrivate::slotDocumentReloaded()
1725 if (m_gotoBottomAfterReload) {
1730void KTextEditor::ViewPrivate::slotGotFocus()
1733 currentInputMode()->gotFocus();
1739 if (m_viewInternal->m_lineScroll->isVisible()) {
1740 m_viewInternal->m_lineScroll->update();
1743 if (m_viewInternal->m_columnScroll->isVisible()) {
1744 m_viewInternal->m_columnScroll->update();
1750void KTextEditor::ViewPrivate::slotLostFocus()
1753 currentInputMode()->lostFocus();
1759 if (m_viewInternal->m_lineScroll->isVisible()) {
1760 m_viewInternal->m_lineScroll->update();
1763 if (m_viewInternal->m_columnScroll->isVisible()) {
1764 m_viewInternal->m_columnScroll->update();
1767 if (doc()->config()->autoSave() && doc()->config()->autoSaveOnFocusOut() && doc()->isModified() && doc()->url().isLocalFile()) {
1768 doc()->documentSave();
1774void KTextEditor::ViewPrivate::setDynWrapIndicators(
int mode)
1776 config()->setValue(KateViewConfig::DynWordWrapIndicators, mode);
1779bool KTextEditor::ViewPrivate::isOverwriteMode()
const
1781 return doc()->
config()->ovr();
1784void KTextEditor::ViewPrivate::reloadFile()
1790void KTextEditor::ViewPrivate::slotReadWriteChanged()
1792 if (m_toggleWriteLock) {
1793 m_toggleWriteLock->setChecked(!doc()->isReadWrite());
1796 m_cut->setEnabled(doc()->isReadWrite() && (selection() || m_config->smartCopyCut()));
1797 m_paste->setEnabled(doc()->isReadWrite());
1798 if (m_pasteSelection) {
1799 m_pasteSelection->setEnabled(doc()->isReadWrite());
1801 m_swapWithClipboard->setEnabled(doc()->isReadWrite());
1802 m_setEndOfLine->setEnabled(doc()->isReadWrite());
1804 static const auto l = {QStringLiteral(
"edit_replace"),
1805 QStringLiteral(
"tools_spelling"),
1806 QStringLiteral(
"tools_indent"),
1807 QStringLiteral(
"tools_unindent"),
1808 QStringLiteral(
"tools_cleanIndent"),
1809 QStringLiteral(
"tools_formatIndet"),
1810 QStringLiteral(
"tools_alignOn"),
1811 QStringLiteral(
"tools_comment"),
1812 QStringLiteral(
"tools_uncomment"),
1813 QStringLiteral(
"tools_toggle_comment"),
1814 QStringLiteral(
"tools_uppercase"),
1815 QStringLiteral(
"tools_lowercase"),
1816 QStringLiteral(
"tools_capitalize"),
1817 QStringLiteral(
"tools_join_lines"),
1818 QStringLiteral(
"tools_apply_wordwrap"),
1819 QStringLiteral(
"tools_spelling_from_cursor"),
1820 QStringLiteral(
"tools_spelling_selection")};
1822 for (
const auto &action : l) {
1823 QAction *a = actionCollection()->action(action);
1830 currentInputMode()->readWriteChanged(doc()->isReadWrite());
1833 Q_EMIT viewModeChanged(
this, viewMode());
1834 Q_EMIT viewInputModeChanged(
this, viewInputMode());
1837void KTextEditor::ViewPrivate::toggleCamelCaseCursor()
1839 const auto enabled = doc()->
config()->camelCursor();
1840 doc()->
config()->setCamelCursor(!enabled);
1841 KTextEditor::Message *m;
1843 m =
new KTextEditor::Message(
i18n(
"Camel case movement disabled"));
1845 m =
new KTextEditor::Message(
i18n(
"Camel case movement enabled"));
1853void KTextEditor::ViewPrivate::slotUpdateUndo()
1855 if (doc()->readOnly()) {
1859 m_editUndo->setEnabled(doc()->isReadWrite() && doc()->undoCount() > 0);
1860 m_editRedo->setEnabled(doc()->isReadWrite() && doc()->redoCount() > 0);
1863bool KTextEditor::ViewPrivate::setCursorPositionInternal(
const KTextEditor::Cursor position, uint tabwidth,
bool calledExternally)
1865 if (position.
line() < 0 || position.
line() >= doc()->lines()) {
1870 const QString line_str = l.
text();
1874 for (; z < line_str.
length() && z < position.
column(); z++) {
1875 if (line_str[z] == QLatin1Char(
'\t')) {
1876 x += tabwidth - (x % tabwidth);
1882 if (blockSelection()) {
1883 if (z < position.
column()) {
1884 x += position.
column() - z;
1888 m_viewInternal->updateCursor(KTextEditor::Cursor(position.
line(), x),
1896void KTextEditor::ViewPrivate::toggleInsert()
1898 doc()->
config()->setOvr(!doc()->config()->ovr());
1899 m_toggleInsert->setChecked(isOverwriteMode());
1902 if (isOverwriteMode()) {
1903 clearSecondaryCursors();
1906 Q_EMIT viewModeChanged(
this, viewMode());
1907 Q_EMIT viewInputModeChanged(
this, viewInputMode());
1910void KTextEditor::ViewPrivate::slotSaveCanceled(
const QString &error)
1912 if (!
error.isEmpty()) {
1917void KTextEditor::ViewPrivate::gotoLine()
1919 gotoBar()->updateData();
1920 bottomViewBar()->showBarWidget(gotoBar());
1923void KTextEditor::ViewPrivate::changeDictionary()
1925 dictionaryBar()->updateData();
1926 bottomViewBar()->showBarWidget(dictionaryBar());
1929void KTextEditor::ViewPrivate::joinLines()
1931 int first = selectionRange().start().line();
1932 int last = selectionRange().end().line();
1934 if (first == last) {
1935 first = cursorPosition().line();
1941void KTextEditor::ViewPrivate::readSessionConfig(
const KConfigGroup &config,
const QSet<QString> &flags)
1946 KTextEditor::Cursor savedPosition(config.
readEntry(
"CursorLine", 0), config.
readEntry(
"CursorColumn", 0));
1947 setCursorPositionInternal(savedPosition);
1950 const int scroll = config.
readEntry(
"ScrollLine", -1);
1951 if (scroll >= 0 && scroll < doc()->lines() && savedPosition.
line() < doc()->lines()) {
1952 setScrollPositionInternal(KTextEditor::Cursor(scroll, 0));
1956 if (config.
hasKey(
"Dynamic Word Wrap")) {
1958 m_config->setDynWordWrap(config.
readEntry(
"Dynamic Word Wrap", m_config->global()->dynWordWrap()));
1963 applyFoldingState();
1965 m_forceRTL = config.
readEntry(
"Force RTL Direction",
false);
1966 m_forceRTLDirection->setChecked(m_forceRTL);
1968 for (
const auto &mode : m_viewInternal->m_inputModes) {
1969 mode->readSessionConfig(config);
1973void KTextEditor::ViewPrivate::writeSessionConfig(KConfigGroup &config,
const QSet<QString> &)
1979 const auto cursor = cursorPosition();
1980 if (cursor.isValid() && cursor != KTextEditor::Cursor(0, 0)) {
1981 config.
writeEntry(
"CursorLine", cursor.line());
1982 config.
writeEntry(
"CursorColumn", cursor.column());
1986 const int scrollLine = firstDisplayedLineInternal(LineType::RealLine);
1987 if (scrollLine > 0 && scrollLine != cursor.line()) {
1992 if (m_config->isSet(KateViewConfig::DynamicWordWrap)) {
1993 config.
writeEntry(
"Dynamic Word Wrap", m_config->dynWordWrap());
1998 if (!m_savedFoldingState.object().value(QLatin1String(
"ranges")).toArray().isEmpty()) {
2000 m_savedFoldingState = QJsonDocument();
2004 config.
writeEntry(
"Force RTL Direction", m_forceRTL);
2007 for (
const auto &mode : m_viewInternal->m_inputModes) {
2008 mode->writeSessionConfig(config);
2012int KTextEditor::ViewPrivate::getEol()
const
2014 return doc()->
config()->eol();
2017QMenu *KTextEditor::ViewPrivate::getEolMenu()
2019 return m_setEndOfLine->menu();
2022void KTextEditor::ViewPrivate::setEol(
int eol)
2024 if (!doc()->isReadWrite()) {
2028 if (m_updatingDocumentConfig) {
2032 if (eol != doc()->config()->eol()) {
2033 doc()->setModified(
true);
2034 doc()->
config()->setEol(eol);
2038void KTextEditor::ViewPrivate::setAddBom(
bool enabled)
2040 if (!doc()->isReadWrite()) {
2044 if (m_updatingDocumentConfig) {
2048 doc()->
config()->setBom(enabled);
2052void KTextEditor::ViewPrivate::setIconBorder(
bool enable)
2054 config()->setValue(KateViewConfig::ShowIconBar, enable);
2057void KTextEditor::ViewPrivate::toggleIconBorder()
2059 config()->setValue(KateViewConfig::ShowIconBar, !config()->iconBar());
2062void KTextEditor::ViewPrivate::setLineNumbersOn(
bool enable)
2064 config()->setValue(KateViewConfig::ShowLineNumbers, enable);
2067void KTextEditor::ViewPrivate::toggleLineNumbersOn()
2069 config()->setValue(KateViewConfig::ShowLineNumbers, !config()->lineNumbers());
2072void KTextEditor::ViewPrivate::setScrollBarMarks(
bool enable)
2074 config()->setValue(KateViewConfig::ShowScrollBarMarks, enable);
2077void KTextEditor::ViewPrivate::toggleScrollBarMarks()
2079 config()->setValue(KateViewConfig::ShowScrollBarMarks, !config()->scrollBarMarks());
2082void KTextEditor::ViewPrivate::setScrollBarMiniMap(
bool enable)
2084 config()->setValue(KateViewConfig::ShowScrollBarMiniMap, enable);
2087void KTextEditor::ViewPrivate::toggleScrollBarMiniMap()
2089 config()->setValue(KateViewConfig::ShowScrollBarMiniMap, !config()->scrollBarMiniMap());
2092void KTextEditor::ViewPrivate::setScrollBarMiniMapAll(
bool enable)
2094 config()->setValue(KateViewConfig::ShowScrollBarMiniMapAll, enable);
2097void KTextEditor::ViewPrivate::toggleScrollBarMiniMapAll()
2099 config()->setValue(KateViewConfig::ShowScrollBarMiniMapAll, !config()->scrollBarMiniMapAll());
2102void KTextEditor::ViewPrivate::setScrollBarMiniMapWidth(
int width)
2104 config()->setValue(KateViewConfig::ScrollBarMiniMapWidth, width);
2107void KTextEditor::ViewPrivate::toggleShowSpaces()
2109 if (m_updatingDocumentConfig) {
2113 using WhitespaceRendering = KateDocumentConfig::WhitespaceRendering;
2114 doc()->
config()->setShowSpaces(doc()->config()->showSpaces() != WhitespaceRendering::None ? WhitespaceRendering::None : WhitespaceRendering::All);
2117void KTextEditor::ViewPrivate::toggleDynWordWrap()
2119 config()->setDynWordWrap(!config()->dynWordWrap());
2122void KTextEditor::ViewPrivate::toggleWWMarker()
2124 m_renderer->config()->setWordWrapMarker(!m_renderer->config()->wordWrapMarker());
2127void KTextEditor::ViewPrivate::toggleNPSpaces()
2129 m_renderer->setShowNonPrintableSpaces(!m_renderer->showNonPrintableSpaces());
2130 m_viewInternal->update();
2133void KTextEditor::ViewPrivate::toggleWordCount(
bool on)
2135 config()->setShowWordCount(on);
2138void KTextEditor::ViewPrivate::setFoldingMarkersOn(
bool enable)
2140 config()->setValue(KateViewConfig::ShowFoldingBar, enable);
2143void KTextEditor::ViewPrivate::toggleFoldingMarkers()
2145 config()->setValue(KateViewConfig::ShowFoldingBar, !config()->foldingBar());
2148bool KTextEditor::ViewPrivate::iconBorder()
2150 return m_viewInternal->m_leftBorder->iconBorderOn();
2153bool KTextEditor::ViewPrivate::lineNumbersOn()
2155 return m_viewInternal->m_leftBorder->lineNumbersOn();
2158bool KTextEditor::ViewPrivate::scrollBarMarks()
2160 return m_viewInternal->m_lineScroll->showMarks();
2163bool KTextEditor::ViewPrivate::scrollBarMiniMap()
2165 return m_viewInternal->m_lineScroll->showMiniMap();
2168int KTextEditor::ViewPrivate::dynWrapIndicators()
2170 return m_viewInternal->m_leftBorder->dynWrapIndicators();
2173bool KTextEditor::ViewPrivate::foldingMarkersOn()
2175 return m_viewInternal->m_leftBorder->foldingMarkersOn();
2178bool KTextEditor::ViewPrivate::forceRTLDirection()
const
2183void KTextEditor::ViewPrivate::toggleWriteLock()
2185 doc()->setReadWrite(!doc()->isReadWrite());
2188void KTextEditor::ViewPrivate::registerTextHintProvider(KTextEditor::TextHintProvider *provider)
2190 m_viewInternal->registerTextHintProvider(provider);
2193void KTextEditor::ViewPrivate::unregisterTextHintProvider(KTextEditor::TextHintProvider *provider)
2195 m_viewInternal->unregisterTextHintProvider(provider);
2198void KTextEditor::ViewPrivate::setTextHintDelay(
int delay)
2200 m_viewInternal->setTextHintDelay(delay);
2203int KTextEditor::ViewPrivate::textHintDelay()
const
2205 return m_viewInternal->textHintDelay();
2209void KTextEditor::ViewPrivate::find()
2211 currentInputMode()->find();
2215void KTextEditor::ViewPrivate::findSelectedForwards()
2217 currentInputMode()->findSelectedForwards();
2221void KTextEditor::ViewPrivate::findSelectedBackwards()
2223 currentInputMode()->findSelectedBackwards();
2226void KTextEditor::ViewPrivate::skipCurrentOccurunceSelection()
2228 if (isMulticursorNotAllowed()) {
2231 m_skipCurrentSelection =
true;
2234void KTextEditor::ViewPrivate::findNextOccurunceAndSelect()
2236 if (isMulticursorNotAllowed()) {
2240 const auto text = selection() ? doc()->
text(selectionRange()) : QString();
2241 if (text.isEmpty()) {
2242 const auto selection = doc()->
wordRangeAt(cursorPosition());
2244 setSelection(selection);
2245 setCursorPosition(selection.end());
2248 for (
auto &c : m_secondaryCursors) {
2249 const auto range = doc()->
wordRangeAt(c.cursor());
2250 if (!c.range && !c.anchor.isValid()) {
2251 c.anchor = range.
start();
2252 c.range.reset(newSecondarySelectionRange(range));
2258 }
else if (!m_rangesForHighlights.empty()) {
2263 const auto lastSelectionRange = selectionRange();
2265 KTextEditor::Range searchRange(lastSelectionRange.end(), doc()->documentRange().
end());
2266 QList<KTextEditor::Range> matches = doc()->searchText(searchRange, text,
KTextEditor::Default);
2268 searchRange.setRange(doc()->documentRange().
start(), lastSelectionRange.end());
2277 auto it = std::find_if(m_secondaryCursors.begin(), m_secondaryCursors.end(), [&](
const SecondaryCursor &c) {
2278 return c.range && c.range->toRange() == matches.constFirst();
2281 if (it != m_secondaryCursors.end()) {
2282 m_secondaryCursors.erase(it);
2288 setCursorPosition(matches.
constFirst().end());
2292 if (!m_skipCurrentSelection) {
2293 PlainSecondaryCursor c;
2294 c.pos = lastSelectionRange.end();
2295 c.range = lastSelectionRange;
2297 addSecondaryCursorsWithSelection({c});
2300 m_skipCurrentSelection =
false;
2303void KTextEditor::ViewPrivate::findAllOccuruncesAndSelect()
2305 if (isMulticursorNotAllowed()) {
2309 QString text = selection() ? doc()->
text(selectionRange()) : QString();
2311 const auto selection = doc()->
wordRangeAt(cursorPosition());
2312 setSelection(selection);
2313 setCursorPosition(selection.end());
2315 text = doc()->
text(selection);
2317 for (
auto &c : m_secondaryCursors) {
2318 const auto range = doc()->
wordRangeAt(c.cursor());
2319 if (!c.range && !c.anchor.isValid()) {
2320 c.anchor = range.
start();
2321 c.range.reset(newSecondarySelectionRange(range));
2328 KTextEditor::Range searchRange(doc()->documentRange());
2329 QList<KTextEditor::Range> matches;
2330 QList<PlainSecondaryCursor> resultRanges;
2336 if (matches.
constFirst() != selectionRange()) {
2337 PlainSecondaryCursor c;
2342 searchRange.setStart(matches.
constFirst().end());
2344 }
while (matches.
first().isValid());
2347 if (!resultRanges.
empty()) {
2351 clearSecondaryCursors();
2352 addSecondaryCursorsWithSelection(resultRanges);
2356void KTextEditor::ViewPrivate::replace()
2358 currentInputMode()->findReplace();
2362void KTextEditor::ViewPrivate::findNext()
2364 currentInputMode()->findNext();
2368void KTextEditor::ViewPrivate::findPrevious()
2370 currentInputMode()->findPrevious();
2373void KTextEditor::ViewPrivate::showSearchWrappedHint(
bool isReverseSearch)
2376 const QIcon icon = isReverseSearch ?
QIcon::fromTheme(QStringLiteral(
"go-up-search")) : QIcon::fromTheme(QStringLiteral(
"go-down-search"));
2378 if (!m_wrappedMessage || m_isLastSearchReversed != isReverseSearch) {
2379 m_isLastSearchReversed = isReverseSearch;
2381 m_wrappedMessage->setIcon(icon);
2383 m_wrappedMessage->setAutoHide(2000);
2385 m_wrappedMessage->setView(
this);
2390void KTextEditor::ViewPrivate::createMultiCursorsFromSelection()
2392 if (!selection() || selectionRange().isEmpty()) {
2397 clearSecondaryCursors();
2399 const auto range = selectionRange();
2400 QList<KTextEditor::Cursor> cursorsToAdd;
2403 const auto currentLine = cursorPosition().line();
2404 setCursorPosition({currentLine, doc()->
lineLength(currentLine)});
2405 for (
int line =
start; line <=
end; ++line) {
2406 if (line != currentLine) {
2412 setSecondaryCursors(cursorsToAdd);
2415void KTextEditor::ViewPrivate::removeCursorsFromEmptyLines()
2417 if (!m_secondaryCursors.empty()) {
2418 std::vector<KTextEditor::Cursor> cursorsToRemove;
2419 for (
const auto &c : m_secondaryCursors) {
2420 auto cursor = c.cursor();
2421 if (doc()->lineLength(cursor.line()) == 0) {
2422 cursorsToRemove.push_back(cursor);
2425 removeSecondaryCursors(cursorsToRemove);
2429void KTextEditor::ViewPrivate::slotSelectionChanged()
2431 m_copy->setEnabled(selection() || m_config->smartCopyCut());
2432 m_deSelect->setEnabled(selection());
2433 m_copyHtmlAction->setEnabled(selection());
2436 selectionChangedForHighlights();
2438 if (doc()->readOnly()) {
2442 m_cut->setEnabled(selection() || m_config->smartCopyCut());
2443 m_screenshotSelection->setVisible(selection());
2444 m_screenshotSelection->setEnabled(selection());
2448void KTextEditor::ViewPrivate::switchToCmdLine()
2450 currentInputMode()->activateCommandLine();
2453KateRenderer *KTextEditor::ViewPrivate::renderer()
2458KateRendererConfig *KTextEditor::ViewPrivate::rendererConfig()
2460 return m_renderer->config();
2463void KTextEditor::ViewPrivate::updateConfig()
2469 m_toggleShowSpace->setChecked(doc()->config()->showSpaces() != KateDocumentConfig::WhitespaceRendering::None);
2472 if (m_hasWrap != config()->dynWordWrap()) {
2473 m_hasWrap = config()->dynWordWrap();
2475 m_viewInternal->dynWrapChanged();
2477 m_setDynWrapIndicators->setEnabled(config()->dynWordWrap());
2478 m_toggleDynWrap->setChecked(config()->dynWordWrap());
2481 m_viewInternal->m_leftBorder->setDynWrapIndicators(config()->dynWordWrapIndicators());
2482 m_setDynWrapIndicators->setCurrentItem(config()->dynWordWrapIndicators());
2485 m_viewInternal->m_leftBorder->setLineNumbersOn(config()->lineNumbers());
2486 m_toggleLineNumbers->setChecked(config()->lineNumbers());
2489 m_viewInternal->m_leftBorder->setIconBorderOn(config()->iconBar());
2490 m_toggleIconBar->setChecked(config()->iconBar());
2493 m_viewInternal->m_lineScroll->setShowMarks(config()->scrollBarMarks());
2494 m_toggleScrollBarMarks->setChecked(config()->scrollBarMarks());
2497 m_viewInternal->m_lineScroll->setShowMiniMap(config()->scrollBarMiniMap());
2498 m_toggleScrollBarMiniMap->setChecked(config()->scrollBarMiniMap());
2501 m_viewInternal->m_lineScroll->setMiniMapAll(config()->scrollBarMiniMapAll());
2505 m_viewInternal->m_lineScroll->setMiniMapWidth(config()->scrollBarMiniMapWidth());
2508 m_toggleBlockSelection->setChecked(blockSelection());
2509 m_toggleInsert->setChecked(isOverwriteMode());
2511 updateFoldingConfig();
2514 m_bookmarks->setSorting((KateBookmarks::Sorting)config()->bookmarkSort());
2516 m_viewInternal->setAutoCenterLines(config()->autoCenterLines());
2518 for (
const auto &input : m_viewInternal->m_inputModes) {
2519 input->updateConfig();
2522 setInputMode(config()->inputMode(),
false );
2524 reflectOnTheFlySpellCheckStatus(doc()->isOnTheFlySpellCheckingEnabled());
2527 bool wc = config()->wordCompletion();
2536 bool kc = config()->keywordCompletion();
2545 m_cut->setEnabled(doc()->isReadWrite() && (selection() || m_config->smartCopyCut()));
2546 m_copy->setEnabled(selection() || m_config->smartCopyCut());
2548 m_accessibilityEnabled = m_config->value(KateViewConfig::EnableAccessibility).toBool();
2549 m_bookmarks->setCycleThroughBookmarks(m_config->value(KateViewConfig::CycleThroughBookmarks).toBool());
2553 m_statusBar->updateStatus();
2557 m_viewInternal->cache()->clear();
2561 Q_EMIT configChanged(
this);
2564void KTextEditor::ViewPrivate::updateDocumentConfig()
2570 m_updatingDocumentConfig =
true;
2572 m_setEndOfLine->setCurrentItem(doc()->config()->eol());
2574 m_addBom->setChecked(doc()->config()->
bom());
2576 m_updatingDocumentConfig =
false;
2579 ensureCursorColumnValid();
2582 m_renderer->setTabWidth(doc()->config()->tabWidth());
2583 m_renderer->setIndentWidth(doc()->config()->indentationWidth());
2586 m_viewInternal->cache()->clear();
2591void KTextEditor::ViewPrivate::updateRendererConfig()
2597 m_toggleWWMarker->setChecked(m_renderer->config()->wordWrapMarker());
2599 m_viewInternal->updateBracketMarkAttributes();
2600 m_viewInternal->updateBracketMarks();
2603 m_viewInternal->cache()->clear();
2605 m_viewInternal->updateView(
true);
2608 m_viewInternal->m_leftBorder->updateFont();
2609 m_viewInternal->m_leftBorder->repaint();
2611 m_viewInternal->m_lineScroll->queuePixmapUpdate();
2613 currentInputMode()->updateRendererConfig();
2617 Q_EMIT configChanged(
this);
2620void KTextEditor::ViewPrivate::updateFoldingConfig()
2623 m_viewInternal->m_leftBorder->setFoldingMarkersOn(config()->foldingBar());
2624 m_toggleFoldingMarkers->setChecked(config()->foldingBar());
2626 if (hasCommentInFirstLine(m_doc)) {
2627 if (config()->foldFirstLine() && !m_autoFoldedFirstLine) {
2629 m_autoFoldedFirstLine =
true;
2630 }
else if (!config()->foldFirstLine() && m_autoFoldedFirstLine) {
2632 m_autoFoldedFirstLine =
false;
2635 m_autoFoldedFirstLine =
false;
2640 const QStringList l = {
2641 QStringLiteral(
"folding_toplevel")
2642 , QStringLiteral(
"folding_expandtoplevel")
2643 , QStringLiteral(
"folding_toggle_current")
2644 , QStringLiteral(
"folding_toggle_in_current")
2648 for (
int z = 0; z < l.
size(); z++)
2649 if ((a = actionCollection()->action(l[z].toAscii().constData()))) {
2650 a->
setEnabled(doc()->highlight() && doc()->highlight()->allowsFolding());
2655void KTextEditor::ViewPrivate::ensureCursorColumnValid()
2657 KTextEditor::Cursor c = m_viewInternal->cursorPosition();
2662 if (!blockSelection() && wrapCursor() && (!c.
isValid() || c.
column() > doc()->lineLength(c.
line()))) {
2663 c.
setColumn(doc()->lineLength(cursorPosition().line()));
2664 setCursorPosition(c);
2669void KTextEditor::ViewPrivate::editStart()
2671 m_viewInternal->editStart();
2674void KTextEditor::ViewPrivate::editEnd(
int editTagLineStart,
int editTagLineEnd,
bool tagFrom)
2676 m_viewInternal->editEnd(editTagLineStart, editTagLineEnd, tagFrom);
2677 textFolding().editEnd(editTagLineStart, editTagLineEnd, [
this](
int line) {
2678 return m_doc->buffer().isFoldingStartingOnLine(line).first;
2682void KTextEditor::ViewPrivate::editSetCursor(
const KTextEditor::Cursor cursor)
2684 m_viewInternal->editSetCursor(cursor);
2689bool KTextEditor::ViewPrivate::tagLine(
const KTextEditor::Cursor virtualCursor)
2691 return m_viewInternal->tagLine(virtualCursor);
2694bool KTextEditor::ViewPrivate::tagRange(KTextEditor::Range range,
bool realLines)
2696 return m_viewInternal->tagRange(range, realLines);
2699bool KTextEditor::ViewPrivate::tagLines(KTextEditor::LineRange lineRange,
bool realLines)
2701 return m_viewInternal->tagLines(lineRange.
start(), lineRange.
end(), realLines);
2704bool KTextEditor::ViewPrivate::tagLines(KTextEditor::Cursor
start, KTextEditor::Cursor end,
bool realCursors)
2706 return m_viewInternal->tagLines(
start, end, realCursors);
2709void KTextEditor::ViewPrivate::tagAll()
2711 m_viewInternal->tagAll();
2714void KTextEditor::ViewPrivate::clear()
2716 m_viewInternal->clear();
2719void KTextEditor::ViewPrivate::repaintText(
bool paintOnlyDirty)
2721 if (paintOnlyDirty) {
2722 m_viewInternal->updateDirty();
2724 m_viewInternal->update();
2728void KTextEditor::ViewPrivate::updateView(
bool changed)
2731 m_viewInternal->updateView(changed);
2732 m_viewInternal->m_leftBorder->update();
2737void KTextEditor::ViewPrivate::slotHlChanged()
2739 KateHighlighting *hl = doc()->highlight();
2740 bool ok(!hl->getCommentStart(0).
isEmpty() || !hl->getCommentSingleLineStart(0).
isEmpty());
2742 if (actionCollection()->action(QStringLiteral(
"tools_comment"))) {
2743 actionCollection()->action(QStringLiteral(
"tools_comment"))->setEnabled(ok);
2746 if (actionCollection()->action(QStringLiteral(
"tools_uncomment"))) {
2747 actionCollection()->action(QStringLiteral(
"tools_uncomment"))->setEnabled(ok);
2750 if (actionCollection()->action(QStringLiteral(
"tools_toggle_comment"))) {
2751 actionCollection()->action(QStringLiteral(
"tools_toggle_comment"))->setEnabled(ok);
2755 updateFoldingConfig();
2758int KTextEditor::ViewPrivate::virtualCursorColumn()
const
2760 return doc()->toVirtualColumn(m_viewInternal->cursorPosition());
2763void KTextEditor::ViewPrivate::notifyMousePositionChanged(
const KTextEditor::Cursor newPosition)
2765 Q_EMIT mousePositionChanged(
this, newPosition);
2770bool KTextEditor::ViewPrivate::setSelection(KTextEditor::Range selection)
2773 if (selection == m_selection) {
2778 KTextEditor::Range oldSelection = m_selection;
2784 tagSelection(oldSelection);
2788 Q_EMIT selectionChanged(
this);
2794bool KTextEditor::ViewPrivate::clearSelection()
2796 return clearSelection(
true);
2799bool KTextEditor::ViewPrivate::clearSelection(
bool redraw,
bool finishedChangingSelection)
2807 KTextEditor::Range oldSelection = m_selection;
2813 tagSelection(oldSelection);
2819 if (finishedChangingSelection) {
2820 Q_EMIT selectionChanged(
this);
2823 m_viewInternal->m_selChangedByUser =
false;
2828bool KTextEditor::ViewPrivate::selection()
const
2830 if (!wrapCursor()) {
2833 return m_selection.toRange().isValid();
2837QString KTextEditor::ViewPrivate::selectionText()
const
2840 return doc()->
text(m_selection, blockSelect);
2843 QVarLengthArray<KTextEditor::Range, 16> ranges;
2844 for (
const auto &c : m_secondaryCursors) {
2849 ranges.
push_back(m_selection.toRange());
2850 std::sort(ranges.
begin(), ranges.
end());
2853 text.
reserve(ranges.
size() * m_selection.toRange().columnWidth());
2854 for (
int i = 0; i < ranges.
size() - 1; ++i) {
2855 text += doc()->
text(ranges[i]) + QStringLiteral(
"\n");
2857 text += doc()->
text(ranges.
last());
2862bool KTextEditor::ViewPrivate::removeSelectedText()
2864 if (!hasSelections()) {
2868 KTextEditor::Document::EditingTransaction t(doc());
2870 bool removed =
false;
2873 completionWidget()->setIgnoreBufferSignals(
true);
2874 for (
auto &c : m_secondaryCursors) {
2877 doc()->removeText(c.range->toRange());
2881 completionWidget()->setIgnoreBufferSignals(
false);
2885 KTextEditor::Range selection = m_selection;
2889 doc()->removeText(selection, blockSelect);
2894 int selectionColumn = qMin(doc()->toVirtualColumn(selection.
start()), doc()->toVirtualColumn(selection.
end()));
2895 KTextEditor::Range newSelection = selection;
2896 newSelection.
setStart(KTextEditor::Cursor(newSelection.
start().
line(), doc()->fromVirtualColumn(newSelection.
start().
line(), selectionColumn)));
2897 newSelection.
setEnd(KTextEditor::Cursor(newSelection.
end().
line(), doc()->fromVirtualColumn(newSelection.
end().
line(), selectionColumn)));
2898 setSelection(newSelection);
2899 setCursorPositionInternal(newSelection.
start());
2901 clearSecondarySelections();
2902 clearSelection(
false);
2908bool KTextEditor::ViewPrivate::selectAll()
2910 clearSecondaryCursors();
2911 setBlockSelection(
false);
2918 setSelection(doc()->documentRange());
2919 m_viewInternal->moveCursorToSelectionEdge(
false);
2920 m_viewInternal->updateMicroFocus();
2924bool KTextEditor::ViewPrivate::cursorSelected(
const KTextEditor::Cursor cursor)
2926 KTextEditor::Cursor ret = cursor;
2927 if ((!blockSelect) && (ret.
column() < 0)) {
2932 return cursor.
line() >= m_selection.start().line() && ret.
line() <= m_selection.end().line() && ret.
column() >= m_selection.start().column()
2933 && ret.
column() <= m_selection.end().column();
2935 return m_selection.toRange().contains(cursor) || m_selection.end() == cursor;
2939bool KTextEditor::ViewPrivate::lineSelected(
int line)
2941 return !blockSelect && m_selection.toRange().containsLine(line);
2944bool KTextEditor::ViewPrivate::lineEndSelected(
const KTextEditor::Cursor lineEndPos)
2946 return (!blockSelect)
2947 && (lineEndPos.
line() > m_selection.start().line()
2948 || (lineEndPos.
line() == m_selection.start().line() && (m_selection.start().column() < lineEndPos.
column() || lineEndPos.
column() == -1)))
2949 && (lineEndPos.
line() < m_selection.end().line()
2950 || (lineEndPos.
line() == m_selection.end().line() && (lineEndPos.
column() <= m_selection.end().column() && lineEndPos.
column() != -1)));
2953bool KTextEditor::ViewPrivate::lineHasSelected(
int line)
2955 return selection() && m_selection.toRange().
containsLine(line);
2958bool KTextEditor::ViewPrivate::lineIsSelection(
int line)
2960 return (line == m_selection.start().line() && line == m_selection.end().line());
2963void KTextEditor::ViewPrivate::tagSelection(KTextEditor::Range oldSelection)
2966 if (oldSelection.
start().
line() == -1) {
2970 tagLines(m_selection,
true);
2972 }
else if (blockSelection()
2973 && (oldSelection.
start().
column() != m_selection.start().column() || oldSelection.
end().
column() != m_selection.end().column())) {
2975 tagLines(m_selection,
true);
2976 tagLines(oldSelection,
true);
2979 if (oldSelection.
start() != m_selection.
start()) {
2980 tagLines(KTextEditor::LineRange(oldSelection.
start().
line(), m_selection.start().line()),
true);
2983 if (oldSelection.
end() != m_selection.end()) {
2984 tagLines(KTextEditor::LineRange(oldSelection.
end().
line(), m_selection.end().line()),
true);
2990 tagLines(oldSelection,
true);
2994void KTextEditor::ViewPrivate::selectWord(
const KTextEditor::Cursor cursor)
2996 setSelection(doc()->wordRangeAt(cursor));
2999void KTextEditor::ViewPrivate::selectLine(
const KTextEditor::Cursor cursor)
3001 int line = cursor.
line();
3002 if (line + 1 >= doc()->lines()) {
3003 setSelection(KTextEditor::Range(line, 0, line, doc()->lineLength(line)));
3005 setSelection(KTextEditor::Range(line, 0, line + 1, 0));
3009void KTextEditor::ViewPrivate::cut()
3011 if (!selection() && !m_config->smartCopyCut()) {
3017 m_markedSelection =
false;
3021 selectLine(cursorPosition());
3023 removeSelectedText();
3026void KTextEditor::ViewPrivate::copy()
3030 if (!m_config->smartCopyCut()) {
3033 text = doc()->
line(cursorPosition().line()) + QLatin1Char(
'\n');
3034 m_viewInternal->moveEdge(KateViewInternal::left,
false);
3036 text = selectionText();
3038 if (m_markedSelection) {
3040 m_markedSelection =
false;
3048void KTextEditor::ViewPrivate::screenshot()
3054 ScreenshotDialog d(selectionRange(),
this);
3055 d.renderScreenshot(m_renderer);
3059void KTextEditor::ViewPrivate::pasteSelection()
3061 m_temporaryAutomaticInvocationDisabled =
true;
3063 m_temporaryAutomaticInvocationDisabled =
false;
3066void KTextEditor::ViewPrivate::pasteFromFile()
3071 KTextEditor::DocumentPrivate insertDocument;
3072 insertDocument.openUrl(insertFromUrl);
3075 document()->insertText(cursorPosition(), insertDocument.
text());
3078void KTextEditor::ViewPrivate::swapWithClipboard()
3080 m_temporaryAutomaticInvocationDisabled =
true;
3089 doc()->paste(
this, text);
3091 m_temporaryAutomaticInvocationDisabled =
false;
3094void KTextEditor::ViewPrivate::applyWordWrap()
3096 int first = selectionRange().start().line();
3097 int last = selectionRange().end().line();
3099 if (first == last) {
3101 first = cursorPosition().line();
3112bool KTextEditor::ViewPrivate::blockSelection()
const
3117bool KTextEditor::ViewPrivate::setBlockSelection(
bool on)
3119 if (on != blockSelect) {
3122 KTextEditor::Range oldSelection = m_selection;
3124 const bool hadSelection = clearSelection(
false,
false);
3126 setSelection(oldSelection);
3128 m_toggleBlockSelection->setChecked(blockSelection());
3132 ensureCursorColumnValid();
3134 if (!hadSelection) {
3139 Q_EMIT selectionChanged(
this);
3146bool KTextEditor::ViewPrivate::toggleBlockSelection()
3149 clearSecondaryCursors();
3151 m_toggleBlockSelection->setChecked(!blockSelect);
3152 return setBlockSelection(!blockSelect);
3155bool KTextEditor::ViewPrivate::wrapCursor()
const
3157 return !blockSelection();
3162void KTextEditor::ViewPrivate::slotTextInserted(KTextEditor::View *view,
const KTextEditor::Cursor position,
const QString &text)
3164 Q_EMIT textInserted(view, position, text);
3167bool KTextEditor::ViewPrivate::insertTemplateInternal(
const KTextEditor::Cursor c,
const QString &templateString,
const QString &script)
3170 if (templateString.
isEmpty()) {
3175 if (!doc()->isReadWrite()) {
3181 doc()->setActiveTemplateHandler(
nullptr);
3182 doc()->setActiveTemplateHandler(
new KateTemplateHandler(
this, c, templateString, script, doc()->undoManager()));
3186bool KTextEditor::ViewPrivate::tagLines(KTextEditor::Range range,
bool realRange)
3188 return tagLines(range.
start(), range.
end(), realRange);
3191void KTextEditor::ViewPrivate::deactivateEditActions()
3193 for (QAction *action : std::as_const(m_editActions)) {
3194 action->setEnabled(
false);
3198void KTextEditor::ViewPrivate::activateEditActions()
3200 for (QAction *action : std::as_const(m_editActions)) {
3201 action->setEnabled(
true);
3205bool KTextEditor::ViewPrivate::mouseTrackingEnabled()
const
3211bool KTextEditor::ViewPrivate::setMouseTrackingEnabled(
bool)
3217bool KTextEditor::ViewPrivate::isMulticursorNotAllowed()
const
3222void KTextEditor::ViewPrivate::addSecondaryCursor(KTextEditor::Cursor pos)
3224 auto primaryCursor = cursorPosition();
3225 const bool overlapsOrOnPrimary = pos == primaryCursor || (selection() && selectionRange().
contains(pos));
3226 if (overlapsOrOnPrimary && m_secondaryCursors.empty()) {
3230 }
else if (overlapsOrOnPrimary) {
3234 auto &last = m_secondaryCursors.back();
3235 setCursorPosition(last.cursor());
3237 setSelection(last.range->toRange());
3238 Q_ASSERT(last.anchor.isValid());
3239 m_viewInternal->m_selectAnchor = last.anchor;
3241 m_secondaryCursors.pop_back();
3248 if (removeSecondaryCursors({pos},
true)) {
3256 setCursorPosition(pos);
3257 KTextEditor::ViewPrivate::PlainSecondaryCursor p;
3258 p.pos = primaryCursor;
3259 p.range = selection() ? selectionRange() : KTextEditor::
Range::invalid();
3261 addSecondaryCursorsWithSelection({p});
3264void KTextEditor::ViewPrivate::setSecondaryCursors(
const QList<KTextEditor::Cursor> &positions)
3266 clearSecondaryCursors();
3268 if (positions.
isEmpty() || isMulticursorNotAllowed()) {
3272 const auto totalLines = doc()->
lines();
3273 for (
auto p : positions) {
3274 if (p != cursorPosition() && p.line() < totalLines) {
3276 c.pos.reset(
static_cast<Kate::TextCursor *
>(doc()->newMovingCursor(p)));
3277 m_secondaryCursors.push_back(std::move(c));
3285void KTextEditor::ViewPrivate::clearSecondarySelections()
3287 for (
auto &c : m_secondaryCursors) {
3292void KTextEditor::ViewPrivate::clearSecondaryCursors()
3294 if (m_secondaryCursors.empty()) {
3297 for (
const auto &c : m_secondaryCursors) {
3298 tagLine(c.cursor());
3300 m_secondaryCursors.clear();
3301 m_viewInternal->updateDirty();
3304const std::vector<KTextEditor::ViewPrivate::SecondaryCursor> &KTextEditor::ViewPrivate::secondaryCursors()
const
3306 return m_secondaryCursors;
3309QList<KTextEditor::ViewPrivate::PlainSecondaryCursor> KTextEditor::ViewPrivate::plainSecondaryCursors()
const
3311 QList<PlainSecondaryCursor> cursors;
3312 cursors.
reserve(m_secondaryCursors.size());
3313 std::transform(m_secondaryCursors.begin(), m_secondaryCursors.end(), std::back_inserter(cursors), [](
const SecondaryCursor &c) {
3315 return PlainSecondaryCursor{.pos = c.cursor(), .range = c.range->toRange()};
3317 return PlainSecondaryCursor{.pos = c.cursor(), .range = KTextEditor::Range::invalid()};
3322bool KTextEditor::ViewPrivate::removeSecondaryCursors(
const std::vector<KTextEditor::Cursor> &cursorsToRemove,
bool removeIfOverlapsSelection)
3324 Q_ASSERT(std::is_sorted(cursorsToRemove.begin(), cursorsToRemove.end()));
3326 QVarLengthArray<KTextEditor::Cursor, 8> linesToTag;
3328 if (removeIfOverlapsSelection) {
3329 m_secondaryCursors.erase(std::remove_if(m_secondaryCursors.begin(),
3330 m_secondaryCursors.end(),
3331 [&](
const SecondaryCursor &c) {
3332 auto it = std::find_if(cursorsToRemove.begin(), cursorsToRemove.end(), [&c](KTextEditor::Cursor pos) {
3333 return c.cursor() == pos || (c.range && c.range->contains(pos));
3335 const bool match = it != cursorsToRemove.end();
3341 m_secondaryCursors.end());
3343 m_secondaryCursors.erase(std::remove_if(m_secondaryCursors.begin(),
3344 m_secondaryCursors.end(),
3345 [&](
const SecondaryCursor &c) {
3346 auto it = std::find_if(cursorsToRemove.begin(), cursorsToRemove.end(), [&c](KTextEditor::Cursor pos) {
3347 return c.cursor() == pos;
3349 const bool match = it != cursorsToRemove.end();
3355 m_secondaryCursors.end());
3358 for (
const auto &c : linesToTag) {
3359 tagLine(m_viewInternal->toVirtualCursor(c));
3361 return !linesToTag.
empty();
3363 for (
auto cur : cursorsToRemove) {
3364 auto &sec = m_secondaryCursors;
3365 auto it = std::find_if(sec.begin(), sec.end(), [cur](
const SecondaryCursor &c) {
3366 return c.cursor() == cur;
3368 if (it != sec.end()) {
3370 m_secondaryCursors.erase(it);
3371 tagLine(m_viewInternal->toVirtualCursor(cur));
3376 m_viewInternal->updateDirty();
3377 if (cursorPosition() == KTextEditor::Cursor(0, 0)) {
3378 m_viewInternal->paintCursor();
3380 return !linesToTag.
empty();
3385void KTextEditor::ViewPrivate::ensureUniqueCursors(
bool matchLine)
3387 if (m_secondaryCursors.empty()) {
3391 std::vector<SecondaryCursor>::iterator it;
3393 auto matchLine = [](
const SecondaryCursor &l,
const SecondaryCursor &r) {
3394 return l.cursor().line() == r.cursor().line();
3396 it = std::unique(m_secondaryCursors.begin(), m_secondaryCursors.end(), matchLine);
3398 it = std::unique(m_secondaryCursors.begin(), m_secondaryCursors.end());
3400 if (it != m_secondaryCursors.end()) {
3401 m_secondaryCursors.erase(it, m_secondaryCursors.end());
3405 const int ln = cursorPosition().line();
3406 m_secondaryCursors.erase(std::remove_if(m_secondaryCursors.begin(),
3407 m_secondaryCursors.end(),
3408 [ln](
const SecondaryCursor &c) {
3409 return c.cursor().line() == ln;
3411 m_secondaryCursors.end());
3413 const auto cp = cursorPosition();
3414 const auto sel = selectionRange();
3415 m_secondaryCursors.erase(std::remove_if(m_secondaryCursors.begin(),
3416 m_secondaryCursors.end(),
3417 [cp, sel](
const SecondaryCursor &c) {
3418 return c.cursor() == cp && c.selectionRange() == sel;
3420 m_secondaryCursors.end());
3424void KTextEditor::ViewPrivate::addSecondaryCursorsWithSelection(
const QList<PlainSecondaryCursor> &cursorsWithSelection)
3426 if (isMulticursorNotAllowed() || cursorsWithSelection.
isEmpty()) {
3430 for (
const auto &c : cursorsWithSelection) {
3432 if (c.pos == cursorPosition()) {
3436 n.pos.reset(
static_cast<Kate::TextCursor *
>(doc()->newMovingCursor(c.pos)));
3437 if (c.range.isValid()) {
3438 n.range.reset(newSecondarySelectionRange(c.range));
3439 n.anchor = c.range.start() == c.pos ? c.range.end() : c.range.start();
3441 m_secondaryCursors.push_back(std::move(n));
3447Kate::TextRange *KTextEditor::ViewPrivate::newSecondarySelectionRange(KTextEditor::Range selRange)
3450 auto range =
new Kate::TextRange(&doc()->buffer(), selRange, expandBehaviour);
3453 selAttr =
new KTextEditor::Attribute;
3455 selAttr->setBackground(color);
3457 range->setZDepth(-999999.);
3458 range->setAttribute(selAttr);
3462bool KTextEditor::ViewPrivate::hasSelections()
const
3466 return std::any_of(m_secondaryCursors.cbegin(), m_secondaryCursors.cend(), [](
const SecondaryCursor &c) {
3467 return c.range && !c.range->isEmpty();
3471void KTextEditor::ViewPrivate::addSecondaryCursorDown()
3473 KTextEditor::Cursor last = cursorPosition();
3474 const auto &secondary = secondaryCursors();
3475 if (!secondary.empty()) {
3476 last = secondary.back().cursor();
3477 last = std::max(cursorPosition(), last);
3479 if (last.
line() >= doc()->lastLine()) {
3483 auto nextRange = m_viewInternal->nextLayout(last);
3484 if (!nextRange.isValid()) {
3487 auto primaryCursorLineLayout = m_viewInternal->currentLayout(cursorPosition());
3488 if (!primaryCursorLineLayout.isValid()) {
3492 int x = renderer()->cursorToX(primaryCursorLineLayout, cursorPosition().column(), !wrapCursor());
3493 auto next = renderer()->xToCursor(nextRange, x, !wrapCursor());
3494 addSecondaryCursor(next);
3497void KTextEditor::ViewPrivate::addSecondaryCursorUp()
3499 KTextEditor::Cursor last = cursorPosition();
3500 const auto &secondary = secondaryCursors();
3501 if (!secondary.empty()) {
3502 last = secondary.front().cursor();
3503 last = std::min(cursorPosition(), last);
3505 if (last.
line() == 0) {
3508 auto nextRange = m_viewInternal->previousLayout(last);
3509 if (!nextRange.isValid()) {
3513 auto primaryCursorLineLayout = m_viewInternal->currentLayout(cursorPosition());
3514 if (!primaryCursorLineLayout.isValid()) {
3518 int x = renderer()->cursorToX(primaryCursorLineLayout, cursorPosition().column(), !wrapCursor());
3519 auto next = renderer()->xToCursor(nextRange, x, !wrapCursor());
3520 addSecondaryCursor(next);
3523QList<KTextEditor::Cursor> KTextEditor::ViewPrivate::cursors()
const
3525 QList<KTextEditor::Cursor> ret;
3526 ret.
reserve(m_secondaryCursors.size() + 1);
3527 ret << cursorPosition();
3528 std::transform(m_secondaryCursors.begin(), m_secondaryCursors.end(), std::back_inserter(ret), [](
const SecondaryCursor &c) {
3534QList<KTextEditor::Range> KTextEditor::ViewPrivate::selectionRanges()
const
3540 QList<KTextEditor::Range> ret;
3541 ret.
reserve(m_secondaryCursors.size() + 1);
3542 ret << selectionRange();
3543 std::transform(m_secondaryCursors.begin(), m_secondaryCursors.end(), std::back_inserter(ret), [](
const SecondaryCursor &c) {
3545 qWarning() <<
"selectionRanges(): Unexpected null selection range, please fix";
3546 return KTextEditor::Range::invalid();
3548 return c.range->toRange();
3553void KTextEditor::ViewPrivate::setCursors(
const QList<KTextEditor::Cursor> &cursorPositions)
3555 if (isMulticursorNotAllowed()) {
3556 qWarning() <<
"setCursors failed: Multicursors not allowed because one of the following is true"
3557 <<
", blockSelection: " << blockSelection() <<
", overwriteMode: " << isOverwriteMode()
3562 clearSecondaryCursors();
3563 if (cursorPositions.
empty()) {
3567 const auto primary = cursorPositions.
front();
3571 setCursorPosition(primary);
3573 setSecondaryCursors(cursorPositions);
3576void KTextEditor::ViewPrivate::setSelections(
const QList<KTextEditor::Range> &selectionRanges)
3578 if (isMulticursorNotAllowed()) {
3579 qWarning() <<
"setSelections failed: Multicursors not allowed because one of the following is true"
3580 <<
", blockSelection: " << blockSelection() <<
", overwriteMode: " << isOverwriteMode()
3585 clearSecondaryCursors();
3587 if (selectionRanges.
isEmpty()) {
3591 auto first = selectionRanges.
front();
3592 setCursorPosition(first.end());
3593 setSelection(first);
3595 if (selectionRanges.
size() == 1) {
3600 for (
auto it = selectionRanges.
begin() + 1; it != selectionRanges.
end(); ++it) {
3601 KTextEditor::Range r = *it;
3602 KTextEditor::Cursor c = r.
end();
3603 if (c == cursorPosition() || !r.
isValid() || r.
isEmpty() || !docRange.contains(r)) {
3608 n.pos.reset(
static_cast<Kate::TextCursor *
>(doc()->newMovingCursor(c)));
3609 n.range.reset(newSecondarySelectionRange(r));
3610 n.anchor = r.
start();
3611 m_secondaryCursors.push_back(std::move(n));
3613 m_viewInternal->mergeSelections();
3619void KTextEditor::ViewPrivate::sortCursors()
3621 std::sort(m_secondaryCursors.begin(), m_secondaryCursors.end());
3622 ensureUniqueCursors();
3625void KTextEditor::ViewPrivate::paintCursors()
3627 if (m_viewInternal->m_cursorTimer.isActive()) {
3631 renderer()->setDrawCaret(
true);
3633 m_viewInternal->paintCursor();
3636bool KTextEditor::ViewPrivate::isCompletionActive()
const
3638 return completionWidget()->isCompletionActive();
3641KateCompletionWidget *KTextEditor::ViewPrivate::completionWidget()
const
3643 if (!m_completionWidget) {
3644 m_completionWidget =
new KateCompletionWidget(
const_cast<KTextEditor::ViewPrivate *
>(
this));
3647 return m_completionWidget;
3650void KTextEditor::ViewPrivate::startCompletion(KTextEditor::Range word, KTextEditor::CodeCompletionModel *model)
3652 completionWidget()->startCompletion(word, model);
3655void KTextEditor::ViewPrivate::startCompletion(
const Range &word,
3656 const QList<KTextEditor::CodeCompletionModel *> &models,
3657 KTextEditor::CodeCompletionModel::InvocationType invocationType)
3659 completionWidget()->startCompletion(word, models, invocationType);
3662void KTextEditor::ViewPrivate::abortCompletion()
3664 completionWidget()->abortCompletion();
3667void KTextEditor::ViewPrivate::forceCompletion()
3669 completionWidget()->execute();
3672void KTextEditor::ViewPrivate::registerCompletionModel(KTextEditor::CodeCompletionModel *model)
3674 completionWidget()->registerCompletionModel(model);
3677void KTextEditor::ViewPrivate::unregisterCompletionModel(KTextEditor::CodeCompletionModel *model)
3679 completionWidget()->unregisterCompletionModel(model);
3682bool KTextEditor::ViewPrivate::isCompletionModelRegistered(KTextEditor::CodeCompletionModel *model)
const
3684 return completionWidget()->isCompletionModelRegistered(model);
3687QList<KTextEditor::CodeCompletionModel *> KTextEditor::ViewPrivate::codeCompletionModels()
const
3689 return completionWidget()->codeCompletionModels();
3692bool KTextEditor::ViewPrivate::isAutomaticInvocationEnabled()
const
3694 return !m_temporaryAutomaticInvocationDisabled && m_config->automaticCompletionInvocation();
3697void KTextEditor::ViewPrivate::setAutomaticInvocationEnabled(
bool enabled)
3699 config()->setValue(KateViewConfig::AutomaticCompletionInvocation, enabled);
3702void KTextEditor::ViewPrivate::sendCompletionExecuted(
const KTextEditor::Cursor position, KTextEditor::CodeCompletionModel *model,
const QModelIndex &index)
3704 Q_EMIT completionExecuted(
this, position, model, index);
3707void KTextEditor::ViewPrivate::sendCompletionAborted()
3709 Q_EMIT completionAborted(
this);
3712void KTextEditor::ViewPrivate::paste(
const QString *textToPaste)
3714 const int cursorCount = m_secondaryCursors.size() + 1;
3715 if (!textToPaste && cursorCount > 1) {
3719 static const QRegularExpression lineEndings(QStringLiteral(
"\r\n?"));
3720 clipboard.
replace(lineEndings, QStringLiteral(
"\n"));
3725 if (texts.
size() != cursorCount) {
3728 for (
int i = 0; i < cursorCount; ++i) {
3734 if (doc()->multiPaste(
this, texts)) {
3739 m_temporaryAutomaticInvocationDisabled =
true;
3741 m_temporaryAutomaticInvocationDisabled =
false;
3744bool KTextEditor::ViewPrivate::setCursorPosition(KTextEditor::Cursor position)
3746 return setCursorPositionInternal(position, 1,
true);
3749KTextEditor::Cursor KTextEditor::ViewPrivate::cursorPosition()
const
3751 return m_viewInternal->cursorPosition();
3754KTextEditor::Cursor KTextEditor::ViewPrivate::cursorPositionVirtual()
const
3756 return KTextEditor::Cursor(m_viewInternal->cursorPosition().line(), virtualCursorColumn());
3759QPoint KTextEditor::ViewPrivate::cursorToCoordinate(KTextEditor::Cursor cursor)
const
3762 const QPoint pt = m_viewInternal->cursorToCoordinate(cursor,
true,
false);
3763 return pt == QPoint(-1, -1) ? pt : m_viewInternal->mapToParent(pt);
3766KTextEditor::Cursor KTextEditor::ViewPrivate::coordinatesToCursor(
const QPoint &coords)
const
3769 return m_viewInternal->coordinatesToCursor(m_viewInternal->mapFromParent(coords),
false);
3772QPoint KTextEditor::ViewPrivate::cursorPositionCoordinates()
const
3775 const QPoint pt = m_viewInternal->cursorCoordinates(
false);
3776 return pt == QPoint(-1, -1) ? pt : m_viewInternal->mapToParent(pt);
3779void KTextEditor::ViewPrivate::setScrollPositionInternal(KTextEditor::Cursor cursor)
3781 m_viewInternal->scrollPos(cursor,
false,
true,
false);
3784void KTextEditor::ViewPrivate::setHorizontalScrollPositionInternal(
int x)
3786 m_viewInternal->scrollColumns(x);
3789KTextEditor::Cursor KTextEditor::ViewPrivate::maxScrollPositionInternal()
const
3791 return m_viewInternal->maxStartPos(
true);
3794int KTextEditor::ViewPrivate::firstDisplayedLineInternal(LineType lineType)
const
3796 if (lineType == RealLine) {
3797 return m_textFolding.visibleLineToLine(m_viewInternal->startLine());
3799 return m_viewInternal->startLine();
3803int KTextEditor::ViewPrivate::lastDisplayedLineInternal(LineType lineType)
const
3805 if (lineType == RealLine) {
3806 return m_textFolding.visibleLineToLine(m_viewInternal->endLine());
3808 return m_viewInternal->endLine();
3812QRect KTextEditor::ViewPrivate::textAreaRectInternal()
const
3814 const auto sourceRect = m_viewInternal->rect();
3815 const auto topLeft = m_viewInternal->mapTo(
this, sourceRect.topLeft());
3816 const auto bottomRight = m_viewInternal->mapTo(
this, sourceRect.bottomRight());
3817 return {topLeft, bottomRight};
3820bool KTextEditor::ViewPrivate::setCursorPositionVisual(
const KTextEditor::Cursor position)
3822 return setCursorPositionInternal(position, doc()->config()->tabWidth(),
true);
3825QScrollBar *KTextEditor::ViewPrivate::verticalScrollBar()
const
3827 return m_viewInternal->m_lineScroll;
3830QScrollBar *KTextEditor::ViewPrivate::horizontalScrollBar()
const
3832 return m_viewInternal->m_columnScroll;
3835bool KTextEditor::ViewPrivate::isLineRTL(
int line)
const
3837 const QString s = doc()->
line(line);
3839 int line = cursorPosition().line();
3841 const int count = doc()->
lines();
3842 for (
int i = 1; i < count; ++i) {
3843 const QString ln = doc()->
line(i);
3850 int line = cursorPosition().line();
3851 for (; line >= 0; --line) {
3852 const QString s = doc()->
line(line);
3865const QTextLayout *KTextEditor::ViewPrivate::textLayout(
const KTextEditor::Cursor pos)
const
3867 KateLineLayout *thisLine = m_viewInternal->cache()->line(pos.
line());
3868 return thisLine && thisLine->isValid() ? &thisLine->layout() :
nullptr;
3871void KTextEditor::ViewPrivate::indent()
3873 if (blockSelect && selection()) {
3874 for (
int line = selectionRange().
start().line(); line <= selectionRange().end().line(); line++) {
3875 KTextEditor::Cursor c(line, 0);
3876 KTextEditor::Range r = KTextEditor::Range(c, c);
3877 doc()->indent(r, 1);
3880 KTextEditor::Cursor c(cursorPosition().line(), 0);
3881 QSet<int> indentedLines = {c.
line()};
3882 KTextEditor::Range r = selection() ? selectionRange() : KTextEditor::
Range(c, c);
3883 doc()->indent(r, 1);
3885 for (
const auto &cursor : secondaryCursors()) {
3886 int line = cursor.cursor().
line();
3887 if (indentedLines.
contains(line)) {
3890 indentedLines.
insert(line);
3891 KTextEditor::Cursor c(line, 0);
3892 KTextEditor::Range r = cursor.range ? cursor.range->toRange() : KTextEditor::Range(c, c);
3893 doc()->indent(r, 1);
3898void KTextEditor::ViewPrivate::unIndent()
3900 if (blockSelect && selection()) {
3901 for (
int line = selectionRange().
start().line(); line <= selectionRange().end().line(); line++) {
3902 KTextEditor::Cursor c(line, 0);
3903 KTextEditor::Range r = KTextEditor::Range(c, c);
3904 doc()->indent(r, -1);
3907 KTextEditor::Cursor c(cursorPosition().line(), 0);
3908 QSet<int> indentedLines = {c.
line()};
3909 KTextEditor::Range r = selection() ? selectionRange() : KTextEditor::
Range(c, c);
3910 doc()->indent(r, -1);
3912 for (
const auto &cursor : secondaryCursors()) {
3913 int line = cursor.cursor().
line();
3914 if (indentedLines.
contains(line)) {
3917 indentedLines.
insert(line);
3918 KTextEditor::Cursor c(line, 0);
3919 KTextEditor::Range r = cursor.range ? cursor.range->toRange() : KTextEditor::Range(c, c);
3920 doc()->indent(r, -1);
3925void KTextEditor::ViewPrivate::cleanIndent()
3927 KTextEditor::Cursor c(cursorPosition().line(), 0);
3928 KTextEditor::Range r = selection() ? selectionRange() : KTextEditor::
Range(c, c);
3929 doc()->indent(r, 0);
3932void KTextEditor::ViewPrivate::formatIndent()
3935 const int line = cursorPosition().line();
3936 KTextEditor::Range formatRange(KTextEditor::Cursor(line, 0), KTextEditor::Cursor(line, 0));
3938 formatRange = selectionRange();
3941 doc()->align(
this, formatRange);
3945void KTextEditor::ViewPrivate::align()
3950void KTextEditor::ViewPrivate::alignOn()
3952 static QString pattern;
3953 KTextEditor::Range range;
3957 range = selectionRange();
3964 doc()->alignOn(range, pattern, this->blockSelection());
3967void KTextEditor::ViewPrivate::comment()
3970 doc()->comment(
this, cursorPosition().line(), cursorPosition().column(), DocumentPrivate::Comment);
3974void KTextEditor::ViewPrivate::uncomment()
3976 doc()->comment(
this, cursorPosition().line(), cursorPosition().column(), DocumentPrivate::UnComment);
3979void KTextEditor::ViewPrivate::toggleComment()
3982 doc()->comment(
this, cursorPosition().line(), cursorPosition().column(), DocumentPrivate::ToggleComment);
3986void KTextEditor::ViewPrivate::uppercase()
3988 doc()->
transform(
this, cursorPosition(), KTextEditor::DocumentPrivate::Uppercase);
3991void KTextEditor::ViewPrivate::killLine()
3993 std::vector<int> linesToRemove;
3994 if (m_selection.isEmpty()) {
3996 linesToRemove.reserve(m_secondaryCursors.size() + 1);
3997 for (
const auto &c : m_secondaryCursors) {
3998 linesToRemove.push_back(c.pos->
line());
4001 linesToRemove.push_back(cursorPosition().line());
4003 linesToRemove.reserve(m_secondaryCursors.size() + 1);
4004 for (
const auto &c : m_secondaryCursors) {
4005 const auto &range = c.range;
4009 for (
int line = range->
end().
line(); line >= range->
start().
line(); line--) {
4010 linesToRemove.push_back(line);
4015 for (
int line = m_selection.end().line(), endLine = m_selection.start().line(); line >= endLine; line--) {
4016 linesToRemove.push_back(line);
4020 std::sort(linesToRemove.begin(), linesToRemove.end(), std::greater{});
4021 linesToRemove.erase(std::unique(linesToRemove.begin(), linesToRemove.end()), linesToRemove.end());
4026 clearSecondarySelections();
4027 int removeCount = 0;
4028 for (
int line : linesToRemove) {
4029 doc()->removeLine(line);
4032 if (removeCount++ > 1000) {
4033 ensureUniqueCursors();
4039 ensureUniqueCursors();
4042void KTextEditor::ViewPrivate::lowercase()
4044 doc()->
transform(
this, cursorPosition(), KTextEditor::DocumentPrivate::Lowercase);
4047void KTextEditor::ViewPrivate::capitalize()
4050 doc()->
transform(
this, cursorPosition(), KTextEditor::DocumentPrivate::Lowercase);
4051 doc()->
transform(
this, cursorPosition(), KTextEditor::DocumentPrivate::Capitalize);
4055void KTextEditor::ViewPrivate::keyReturn()
4057 doc()->newLine(
this);
4058 m_viewInternal->iconBorder()->updateForCursorLineChange();
4059 m_viewInternal->updateView();
4062void KTextEditor::ViewPrivate::smartNewline()
4064 const KTextEditor::Cursor cursor = cursorPosition();
4065 const int ln = cursor.
line();
4077 doc()->insertText(KTextEditor::Cursor(ln + 1, 0), line.
string(0, col));
4080 m_viewInternal->updateView();
4083void KTextEditor::ViewPrivate::noIndentNewline()
4085 doc()->newLine(
this, KTextEditor::DocumentPrivate::NoIndent);
4086 m_viewInternal->iconBorder()->updateForCursorLineChange();
4087 m_viewInternal->updateView();
4090void KTextEditor::ViewPrivate::newLineAbove()
4092 doc()->newLine(
this, KTextEditor::DocumentPrivate::Indent, KTextEditor::DocumentPrivate::Above);
4093 m_viewInternal->iconBorder()->updateForCursorLineChange();
4094 m_viewInternal->updateView();
4097void KTextEditor::ViewPrivate::newLineBelow()
4099 doc()->newLine(
this, KTextEditor::DocumentPrivate::Indent, KTextEditor::DocumentPrivate::Below);
4100 m_viewInternal->iconBorder()->updateForCursorLineChange();
4101 m_viewInternal->updateView();
4104void KTextEditor::ViewPrivate::backspace()
4107 doc()->backspace(
this);
4110void KTextEditor::ViewPrivate::insertTab()
4112 doc()->insertTab(
this, cursorPosition());
4115void KTextEditor::ViewPrivate::deleteWordLeft(
bool subword)
4118 m_viewInternal->wordPrev(
true, subword);
4119 KTextEditor::Range selection = selectionRange();
4120 removeSelectedText();
4123 ensureUniqueCursors();
4125 m_viewInternal->tagRange(selection,
true);
4126 m_viewInternal->updateDirty();
4129void KTextEditor::ViewPrivate::keyDelete()
4131 KTextEditor::Document::EditingTransaction t(doc());
4134 KTextEditor::Range selection = m_selection;
4137 selection = {selection.
start(),
end};
4138 doc()->removeText(selection, blockSelect);
4145 if (removeSelectedText()) {
4149 for (
const auto &c : m_secondaryCursors) {
4151 doc()->removeText(c.range->toRange());
4153 doc()->del(
this, c.cursor());
4158 doc()->del(
this, cursorPosition());
4160 ensureUniqueCursors();
4163void KTextEditor::ViewPrivate::deleteWordRight(
bool subword)
4166 m_viewInternal->wordNext(
true, subword);
4167 KTextEditor::Range selection = selectionRange();
4168 removeSelectedText();
4171 ensureUniqueCursors();
4173 m_viewInternal->tagRange(selection,
true);
4174 m_viewInternal->updateDirty();
4177void KTextEditor::ViewPrivate::transpose()
4180 for (
const auto &c : m_secondaryCursors) {
4181 doc()->transpose(c.cursor());
4183 doc()->transpose(cursorPosition());
4187void KTextEditor::ViewPrivate::transposeWord()
4189 const KTextEditor::Cursor originalCurPos = cursorPosition();
4190 const KTextEditor::Range firstWord = doc()->
wordRangeAt(originalCurPos);
4195 auto wordIsInvalid = [](QStringView word) {
4196 for (
const QChar &character : word) {
4197 if (character.isLetterOrNumber()) {
4204 if (wordIsInvalid(doc()->text(firstWord))) {
4208 setCursorPosition(firstWord.
end());
4210 KTextEditor::Cursor curPos = cursorPosition();
4213 setCursorPosition(firstWord.
start());
4215 curPos = cursorPosition();
4218 setCursorPosition(originalCurPos);
4223 if (wordIsInvalid(doc()->wordAt(curPos))) {
4224 setCursorPosition(originalCurPos);
4228 const KTextEditor::Range secondWord = doc()->
wordRangeAt(curPos);
4229 doc()->swapTextRanges(firstWord, secondWord);
4233 const int offsetFromWordEnd = firstWord.
end().
column() - originalCurPos.
column();
4234 setCursorPosition(cursorPosition() - KTextEditor::Cursor(0, offsetFromWordEnd));
4237void KTextEditor::ViewPrivate::cursorLeft()
4239 if (selection() && !config()->persistentSelection() && !m_markedSelection) {
4240 if (isLineRTL(cursorPosition().line())) {
4241 m_viewInternal->updateCursor(selectionRange().
end());
4244 m_viewInternal->updateCursor(selectionRange().
start());
4248 for (
const auto &c : m_secondaryCursors) {
4252 const bool rtl = isLineRTL(c.cursor().
line());
4255 clearSecondarySelections();
4257 if (isLineRTL(cursorPosition().line())) {
4258 m_viewInternal->cursorNextChar(m_markedSelection);
4260 m_viewInternal->cursorPrevChar(m_markedSelection);
4265void KTextEditor::ViewPrivate::shiftCursorLeft()
4267 if (isLineRTL(cursorPosition().line())) {
4268 m_viewInternal->cursorNextChar(
true);
4270 m_viewInternal->cursorPrevChar(
true);
4274void KTextEditor::ViewPrivate::cursorRight()
4276 if (selection() && !config()->persistentSelection() && !m_markedSelection) {
4277 if (isLineRTL(cursorPosition().line())) {
4278 m_viewInternal->updateCursor(selectionRange().
start());
4281 m_viewInternal->updateCursor(selectionRange().
end());
4285 for (
const auto &c : m_secondaryCursors) {
4292 clearSecondarySelections();
4294 if (isLineRTL(cursorPosition().line())) {
4295 m_viewInternal->cursorPrevChar(m_markedSelection);
4297 m_viewInternal->cursorNextChar(m_markedSelection);
4302void KTextEditor::ViewPrivate::shiftCursorRight()
4304 if (isLineRTL(cursorPosition().line())) {
4305 m_viewInternal->cursorPrevChar(
true);
4307 m_viewInternal->cursorNextChar(
true);
4311void KTextEditor::ViewPrivate::wordLeft(
bool subword)
4313 if (isLineRTL(cursorPosition().line())) {
4314 m_viewInternal->wordNext(m_markedSelection, subword);
4316 m_viewInternal->wordPrev(m_markedSelection, subword);
4320void KTextEditor::ViewPrivate::shiftWordLeft(
bool subword)
4322 if (isLineRTL(cursorPosition().line())) {
4323 m_viewInternal->wordNext(
true, subword);
4325 m_viewInternal->wordPrev(
true, subword);
4329void KTextEditor::ViewPrivate::wordRight(
bool subword)
4331 if (isLineRTL(cursorPosition().line())) {
4332 m_viewInternal->wordPrev(m_markedSelection, subword);
4334 m_viewInternal->wordNext(m_markedSelection, subword);
4338void KTextEditor::ViewPrivate::shiftWordRight(
bool subword)
4340 if (isLineRTL(cursorPosition().line())) {
4341 m_viewInternal->wordPrev(
true, subword);
4343 m_viewInternal->wordNext(
true, subword);
4347void KTextEditor::ViewPrivate::markSelection()
4349 if (m_markedSelection && selection()) {
4351 clearSecondarySelections();
4353 m_markedSelection = !m_markedSelection;
4357void KTextEditor::ViewPrivate::home()
4359 m_viewInternal->home(m_markedSelection);
4362void KTextEditor::ViewPrivate::shiftHome()
4364 m_viewInternal->home(
true);
4367void KTextEditor::ViewPrivate::end()
4369 m_viewInternal->end(m_markedSelection);
4372void KTextEditor::ViewPrivate::shiftEnd()
4374 m_viewInternal->end(
true);
4377void KTextEditor::ViewPrivate::up()
4379 m_viewInternal->cursorUp(m_markedSelection);
4382void KTextEditor::ViewPrivate::shiftUp()
4384 m_viewInternal->cursorUp(
true);
4387void KTextEditor::ViewPrivate::down()
4389 m_viewInternal->cursorDown(m_markedSelection);
4392void KTextEditor::ViewPrivate::shiftDown()
4394 m_viewInternal->cursorDown(
true);
4397void KTextEditor::ViewPrivate::scrollUp()
4399 m_viewInternal->scrollUp();
4402void KTextEditor::ViewPrivate::scrollDown()
4404 m_viewInternal->scrollDown();
4407void KTextEditor::ViewPrivate::topOfView()
4409 m_viewInternal->topOfView();
4412void KTextEditor::ViewPrivate::shiftTopOfView()
4414 m_viewInternal->topOfView(
true);
4417void KTextEditor::ViewPrivate::bottomOfView()
4419 m_viewInternal->bottomOfView();
4422void KTextEditor::ViewPrivate::shiftBottomOfView()
4424 m_viewInternal->bottomOfView(
true);
4427void KTextEditor::ViewPrivate::pageUp()
4429 m_viewInternal->pageUp(m_markedSelection);
4432void KTextEditor::ViewPrivate::shiftPageUp()
4434 m_viewInternal->pageUp(
true);
4437void KTextEditor::ViewPrivate::pageDown()
4439 m_viewInternal->pageDown(m_markedSelection);
4442void KTextEditor::ViewPrivate::shiftPageDown()
4444 m_viewInternal->pageDown(
true);
4447void KTextEditor::ViewPrivate::top()
4449 m_viewInternal->top_home(m_markedSelection);
4452void KTextEditor::ViewPrivate::shiftTop()
4454 m_viewInternal->top_home(
true);
4457void KTextEditor::ViewPrivate::bottom()
4459 m_viewInternal->bottom_end(m_markedSelection);
4462void KTextEditor::ViewPrivate::shiftBottom()
4464 m_viewInternal->bottom_end(
true);
4467void KTextEditor::ViewPrivate::toMatchingBracket()
4469 m_viewInternal->cursorToMatchingBracket();
4472void KTextEditor::ViewPrivate::shiftToMatchingBracket()
4474 m_viewInternal->cursorToMatchingBracket(
true);
4477void KTextEditor::ViewPrivate::toPrevModifiedLine()
4479 const int startLine = cursorPosition().line() - 1;
4482 KTextEditor::Cursor c(line, 0);
4483 m_viewInternal->updateSelection(c,
false);
4484 m_viewInternal->updateCursor(c);
4488void KTextEditor::ViewPrivate::toNextModifiedLine()
4490 const int startLine = cursorPosition().line() + 1;
4493 KTextEditor::Cursor c(line, 0);
4494 m_viewInternal->updateSelection(c,
false);
4495 m_viewInternal->updateCursor(c);
4499KTextEditor::Range KTextEditor::ViewPrivate::selectionRange()
const
4504KTextEditor::Document *KTextEditor::ViewPrivate::document()
const
4509void KTextEditor::ViewPrivate::setContextMenu(QMenu *menu)
4511 if (m_contextMenu) {
4512 disconnect(m_contextMenu.data(), &
QMenu::aboutToShow,
this, &KTextEditor::ViewPrivate::aboutToShowContextMenu);
4513 disconnect(m_contextMenu.data(), &
QMenu::aboutToHide,
this, &KTextEditor::ViewPrivate::aboutToHideContextMenu);
4515 m_contextMenu = menu;
4516 m_userContextMenuSet =
true;
4518 if (m_contextMenu) {
4524QMenu *KTextEditor::ViewPrivate::contextMenu()
const
4526 if (m_userContextMenuSet) {
4527 return m_contextMenu;
4529 KXMLGUIClient *client =
const_cast<KTextEditor::ViewPrivate *
>(
this);
4536 const QList<QWidget *> menuContainers = client->
factory()->containers(QStringLiteral(
"menu"));
4537 for (QWidget *w : menuContainers) {
4538 if (w->objectName() == QLatin1String(
"ktexteditor_popup")) {
4540 QMenu *menu = (QMenu *)w;
4558QMenu *KTextEditor::ViewPrivate::defaultContextMenu(QMenu *menu)
const
4561 menu =
new QMenu(
const_cast<KTextEditor::ViewPrivate *
>(
this));
4575 if (m_pasteSelection) {
4584 QAction *editing = actionCollection()->action(QStringLiteral(
"tools_scripts_Editing"));
4588 if (QAction *spellingSuggestions = actionCollection()->action(QStringLiteral(
"spelling_suggestions"))) {
4592 if (QAction *bookmark = actionCollection()->action(QStringLiteral(
"bookmarks"))) {
4600void KTextEditor::ViewPrivate::aboutToShowContextMenu()
4602 QMenu *menu = qobject_cast<QMenu *>(sender());
4605 Q_EMIT contextMenuAboutToShow(
this, menu);
4609void KTextEditor::ViewPrivate::aboutToHideContextMenu()
4611 m_spellingMenu->cleanUpAfterShown();
4615QStringList KTextEditor::ViewPrivate::configKeys()
const
4617 static const QStringList keys = {QStringLiteral(
"icon-bar"),
4618 QStringLiteral(
"line-numbers"),
4619 QStringLiteral(
"dynamic-word-wrap"),
4620 QStringLiteral(
"background-color"),
4621 QStringLiteral(
"selection-color"),
4622 QStringLiteral(
"search-highlight-color"),
4623 QStringLiteral(
"replace-highlight-color"),
4624 QStringLiteral(
"default-mark-type"),
4625 QStringLiteral(
"allow-mark-menu"),
4626 QStringLiteral(
"folding-bar"),
4627 QStringLiteral(
"folding-preview"),
4628 QStringLiteral(
"icon-border-color"),
4629 QStringLiteral(
"folding-marker-color"),
4630 QStringLiteral(
"line-number-color"),
4631 QStringLiteral(
"current-line-number-color"),
4632 QStringLiteral(
"modification-markers"),
4633 QStringLiteral(
"keyword-completion"),
4634 QStringLiteral(
"word-count"),
4635 QStringLiteral(
"line-count"),
4636 QStringLiteral(
"scrollbar-minimap"),
4637 QStringLiteral(
"scrollbar-preview"),
4638 QStringLiteral(
"font"),
4639 QStringLiteral(
"theme")};
4643QVariant KTextEditor::ViewPrivate::configValue(
const QString &key)
4645 if (key == QLatin1String(
"icon-bar")) {
4646 return config()->iconBar();
4647 }
else if (key == QLatin1String(
"line-numbers")) {
4648 return config()->lineNumbers();
4649 }
else if (key == QLatin1String(
"dynamic-word-wrap")) {
4650 return config()->dynWordWrap();
4651 }
else if (key == QLatin1String(
"background-color")) {
4652 return rendererConfig()->backgroundColor();
4653 }
else if (key == QLatin1String(
"selection-color")) {
4654 return rendererConfig()->selectionColor();
4655 }
else if (key == QLatin1String(
"search-highlight-color")) {
4656 return rendererConfig()->searchHighlightColor();
4657 }
else if (key == QLatin1String(
"replace-highlight-color")) {
4658 return rendererConfig()->replaceHighlightColor();
4659 }
else if (key == QLatin1String(
"default-mark-type")) {
4660 return config()->defaultMarkType();
4661 }
else if (key == QLatin1String(
"allow-mark-menu")) {
4662 return config()->allowMarkMenu();
4663 }
else if (key == QLatin1String(
"folding-bar")) {
4664 return config()->foldingBar();
4665 }
else if (key == QLatin1String(
"folding-preview")) {
4666 return config()->foldingPreview();
4667 }
else if (key == QLatin1String(
"icon-border-color")) {
4668 return rendererConfig()->iconBarColor();
4669 }
else if (key == QLatin1String(
"folding-marker-color")) {
4670 return rendererConfig()->foldingColor();
4671 }
else if (key == QLatin1String(
"line-number-color")) {
4672 return rendererConfig()->lineNumberColor();
4673 }
else if (key == QLatin1String(
"current-line-number-color")) {
4674 return rendererConfig()->currentLineNumberColor();
4675 }
else if (key == QLatin1String(
"modification-markers")) {
4676 return config()->lineModification();
4677 }
else if (key == QLatin1String(
"keyword-completion")) {
4678 return config()->keywordCompletion();
4679 }
else if (key == QLatin1String(
"word-count")) {
4680 return config()->showWordCount();
4681 }
else if (key == QLatin1String(
"line-count")) {
4682 return config()->showLineCount();
4683 }
else if (key == QLatin1String(
"scrollbar-minimap")) {
4684 return config()->scrollBarMiniMap();
4685 }
else if (key == QLatin1String(
"scrollbar-preview")) {
4686 return config()->scrollBarPreview();
4687 }
else if (key == QLatin1String(
"font")) {
4688 return rendererConfig()->baseFont();
4689 }
else if (key == QLatin1String(
"theme")) {
4690 return rendererConfig()->schema();
4697void KTextEditor::ViewPrivate::setConfigValue(
const QString &key,
const QVariant &value)
4700 if (config()->setValue(key, value)) {
4703 }
else if (rendererConfig()->setValue(key, value)) {
4709 if (key == QLatin1String(
"background-color")) {
4710 rendererConfig()->setBackgroundColor(value.
value<QColor>());
4711 }
else if (key == QLatin1String(
"selection-color")) {
4712 rendererConfig()->setSelectionColor(value.
value<QColor>());
4713 }
else if (key == QLatin1String(
"search-highlight-color")) {
4714 rendererConfig()->setSearchHighlightColor(value.
value<QColor>());
4715 }
else if (key == QLatin1String(
"replace-highlight-color")) {
4716 rendererConfig()->setReplaceHighlightColor(value.
value<QColor>());
4717 }
else if (key == QLatin1String(
"icon-border-color")) {
4718 rendererConfig()->setIconBarColor(value.
value<QColor>());
4719 }
else if (key == QLatin1String(
"folding-marker-color")) {
4720 rendererConfig()->setFoldingColor(value.
value<QColor>());
4721 }
else if (key == QLatin1String(
"line-number-color")) {
4722 rendererConfig()->setLineNumberColor(value.
value<QColor>());
4723 }
else if (key == QLatin1String(
"current-line-number-color")) {
4724 rendererConfig()->setCurrentLineNumberColor(value.
value<QColor>());
4730 if (key == QLatin1String(
"dynamic-word-wrap")) {
4731 config()->setDynWordWrap(value.
toBool());
4732 }
else if (key == QLatin1String(
"word-count")) {
4733 config()->setShowWordCount(value.
toBool());
4734 }
else if (key == QLatin1String(
"line-count")) {
4735 config()->setShowLineCount(value.
toBool());
4737 }
else if (key == QLatin1String(
"font") && value.
canConvert<QFont>()) {
4738 rendererConfig()->setFont(value.
value<QFont>());
4740 rendererConfig()->setSchema(value.
toString());
4747void KTextEditor::ViewPrivate::userInvokedCompletion()
4749 completionWidget()->userInvokedCompletion();
4752KateViewBar *KTextEditor::ViewPrivate::bottomViewBar()
const
4754 return m_bottomViewBar;
4757KateGotoBar *KTextEditor::ViewPrivate::gotoBar()
4760 m_gotoBar =
new KateGotoBar(
this);
4761 bottomViewBar()->addBarWidget(m_gotoBar);
4767KateDictionaryBar *KTextEditor::ViewPrivate::dictionaryBar()
4769 if (!m_dictionaryBar) {
4770 m_dictionaryBar =
new KateDictionaryBar(
this);
4771 bottomViewBar()->addBarWidget(m_dictionaryBar);
4774 return m_dictionaryBar;
4777void KTextEditor::ViewPrivate::setAnnotationModel(KTextEditor::AnnotationModel *model)
4779 KTextEditor::AnnotationModel *oldmodel = m_annotationModel;
4780 m_annotationModel = model;
4781 m_viewInternal->m_leftBorder->annotationModelChanged(oldmodel, m_annotationModel);
4784KTextEditor::AnnotationModel *KTextEditor::ViewPrivate::annotationModel()
const
4786 return m_annotationModel;
4789void KTextEditor::ViewPrivate::setAnnotationBorderVisible(
bool visible)
4791 m_viewInternal->m_leftBorder->setAnnotationBorderOn(visible);
4794bool KTextEditor::ViewPrivate::isAnnotationBorderVisible()
const
4796 return m_viewInternal->m_leftBorder->annotationBorderOn();
4799KTextEditor::AbstractAnnotationItemDelegate *KTextEditor::ViewPrivate::annotationItemDelegate()
const
4801 return m_viewInternal->m_leftBorder->annotationItemDelegate();
4804void KTextEditor::ViewPrivate::setAnnotationItemDelegate(KTextEditor::AbstractAnnotationItemDelegate *delegate)
4806 m_viewInternal->m_leftBorder->setAnnotationItemDelegate(delegate);
4809bool KTextEditor::ViewPrivate::uniformAnnotationItemSizes()
const
4811 return m_viewInternal->m_leftBorder->uniformAnnotationItemSizes();
4814void KTextEditor::ViewPrivate::setAnnotationUniformItemSizes(
bool enable)
4816 m_viewInternal->m_leftBorder->setAnnotationUniformItemSizes(enable);
4819KTextEditor::Range KTextEditor::ViewPrivate::visibleRange()
4822 if (!m_viewInternal->endPos().isValid()) {
4823 m_viewInternal->updateView();
4825 return KTextEditor::Range(m_viewInternal->toRealCursor(m_viewInternal->startPos()), m_viewInternal->toRealCursor(m_viewInternal->endPos()));
4828bool KTextEditor::ViewPrivate::event(QEvent *e)
4830 switch (e->
type()) {
4839void KTextEditor::ViewPrivate::toggleOnTheFlySpellCheck(
bool b)
4841 doc()->onTheFlySpellCheckingEnabled(b);
4844void KTextEditor::ViewPrivate::reflectOnTheFlySpellCheckStatus(
bool enabled)
4846 m_spellingMenu->setVisible(enabled);
4847 m_toggleOnTheFlySpellCheck->setChecked(enabled);
4850KateSpellingMenu *KTextEditor::ViewPrivate::spellingMenu()
4852 return m_spellingMenu;
4855void KTextEditor::ViewPrivate::notifyAboutRangeChange(KTextEditor::LineRange lineRange,
bool needsRepaint, Kate::TextRange *deleteRange)
4857#ifdef VIEW_RANGE_DEBUG
4859 qCDebug(LOG_KTE) <<
"trigger attribute changed in line range " << lineRange <<
"needsRepaint" << needsRepaint;
4863 m_rangesCaretIn.remove(deleteRange);
4864 m_rangesMouseIn.remove(deleteRange);
4868 if (needsRepaint && lineRange.
isValid()) {
4869 if (m_lineToUpdateRange.isValid()) {
4870 m_lineToUpdateRange.expandToRange(lineRange);
4872 m_lineToUpdateRange = lineRange;
4877 if (!m_delayedUpdateTimer.isActive()) {
4878 m_delayedUpdateTimer.start();
4882void KTextEditor::ViewPrivate::slotDelayedUpdateOfView()
4884#ifdef VIEW_RANGE_DEBUG
4886 qCDebug(LOG_KTE) <<
"delayed attribute changed in line range" << m_lineToUpdateRange;
4893 if (m_lineToUpdateRange.isValid()) {
4894 tagLines(m_lineToUpdateRange,
true);
4905 QSet<Kate::TextRange *> newRangesIn;
4911 KTextEditor::Cursor currentCursor =
4915 QSet<Kate::TextRange *> validRanges = oldSet;
4918 if (currentCursor.
isValid() && currentCursor.
line() < doc()->buffer().lines()) {
4920 const QList<Kate::TextRange *> rangesForCurrentCursor = doc()->
buffer().
rangesForLine(currentCursor.
line(),
this,
false);
4923 for (Kate::TextRange *range : rangesForCurrentCursor) {
4925 auto attribute = range->attribute();
4926 if ((!attribute || !attribute->dynamicAttribute(activationType)) && !range->feedback()) {
4932 : (currentCursor <= range->toRange().
start())) {
4937 : (range->toRange().
end() < currentCursor)) {
4942 auto it = validRanges.
find(range);
4943 if (it != validRanges.
end()) {
4945 newRangesIn.
insert(range);
4946 validRanges.
erase(it);
4951 newRangesIn.
insert(range);
4953 if (attribute && attribute->dynamicAttribute(activationType)) {
4954 notifyAboutRangeChange(range->
toLineRange(),
true,
nullptr);
4958 if (range->feedback()) {
4960 range->feedback()->mouseEnteredRange(range,
this);
4962 range->feedback()->caretEnteredRange(range,
this);
4963 Q_EMIT caretChangedRange(
this);
4967#ifdef VIEW_RANGE_DEBUG
4969 qCDebug(LOG_KTE) <<
"activated new range" << range <<
"by" << activationType;
4975 for (Kate::TextRange *range : std::as_const(validRanges)) {
4977 if (range->toRange().
isValid() && range->attribute() && range->attribute()->dynamicAttribute(activationType)) {
4978 notifyAboutRangeChange(range->
toLineRange(),
true,
nullptr);
4982 if (range->feedback()) {
4984 range->feedback()->mouseExitedRange(range,
this);
4986 range->feedback()->caretExitedRange(range,
this);
4987 Q_EMIT caretChangedRange(
this);
4993 oldSet = newRangesIn;
4996void KTextEditor::ViewPrivate::postMessage(KTextEditor::Message *message, QList<std::shared_ptr<QAction>> actions)
4999 auto messageWidget = m_messageWidgets[message->
position()];
5000 if (!messageWidget) {
5002 messageWidget =
new KateMessageWidget(m_viewInternal,
true);
5003 m_messageWidgets[message->
position()] = messageWidget;
5004 m_notificationLayout->addWidget(messageWidget, message->
position());
5008 messageWidget->postMessage(message, std::move(actions));
5011KateMessageWidget *KTextEditor::ViewPrivate::messageWidget()
5016void KTextEditor::ViewPrivate::saveFoldingState()
5018 m_savedFoldingState = m_textFolding.exportFoldingRanges();
5021void KTextEditor::ViewPrivate::clearFoldingState()
5023 m_savedFoldingState = {};
5026void KTextEditor::ViewPrivate::applyFoldingState()
5028 m_textFolding.importFoldingRanges(m_savedFoldingState);
5029 m_savedFoldingState = QJsonDocument();
5032void KTextEditor::ViewPrivate::exportHtmlToFile(
const QString &file)
5034 KateExporter(
this).exportToFile(file);
5037void KTextEditor::ViewPrivate::exportHtmlToClipboard()
5039 KateExporter(
this).exportToClipboard();
5042void KTextEditor::ViewPrivate::exportHtmlToFile()
5046 KateExporter(
this).exportToFile(file);
5050void KTextEditor::ViewPrivate::clearHighlights()
5052 m_rangesForHighlights.clear();
5053 m_currentTextForHighlights.clear();
5056void KTextEditor::ViewPrivate::selectionChangedForHighlights()
5060 if (!m_secondaryCursors.empty()) {
5061 for (
const auto &cursor : m_secondaryCursors) {
5069 if (selection() && selectionRange().onSingleLine()) {
5070 text = selectionText();
5071 if (text == m_currentTextForHighlights) {
5078 m_rangesForHighlights.
clear();
5086 m_currentTextForHighlights = text;
5090void KTextEditor::ViewPrivate::createHighlights()
5093 if (m_currentTextForHighlights.isEmpty()) {
5098 m_rangesForHighlights.clear();
5104 QColor fgColor = defaultStyleAttribute(KSyntaxHighlighting::Theme::TextStyle::Normal)->foreground().color();
5105 QColor bgColor = rendererConfig()->searchHighlightColor();
5106 attr->setForeground(fgColor);
5107 attr->setBackground(bgColor);
5109 KTextEditor::Cursor
start(visibleRange().
start());
5110 KTextEditor::Range searchRange;
5116 pattern.
prepend(QLatin1String(
"\\b"));
5120 pattern += QLatin1String(
"\\b");
5123 QList<KTextEditor::Range> matches;
5129 if (matches.
first().isValid()) {
5130 if (matches.
first() != selectionRange()) {
5131 std::unique_ptr<KTextEditor::MovingRange> mr(doc()->newMovingRange(matches.
first()));
5132 mr->setZDepth(-90000.0);
5133 mr->setAttribute(attr);
5135 mr->setAttributeOnlyForViews(
true);
5136 m_rangesForHighlights.push_back(std::move(mr));
5140 }
while (matches.
first().isValid());
5143KateAbstractInputMode *KTextEditor::ViewPrivate::currentInputMode()
const
5145 return m_viewInternal->m_currentInputMode;
5148void KTextEditor::ViewPrivate::toggleInputMode()
5150 if (QAction *a = qobject_cast<QAction *>(sender())) {
5155void KTextEditor::ViewPrivate::cycleInputMode()
5157 InputMode current = currentInputMode()->viewInputMode();
5163bool KTextEditor::ViewPrivate::print()
5165 return KatePrinter::print(
this);
5168void KTextEditor::ViewPrivate::printPreview()
5170 KatePrinter::printPreview(
this);
5176void KTextEditor::ViewPrivate::registerInlineNoteProvider(KTextEditor::InlineNoteProvider *provider)
5178 if (std::find(m_inlineNoteProviders.cbegin(), m_inlineNoteProviders.cend(), provider) == m_inlineNoteProviders.cend()) {
5179 m_inlineNoteProviders.push_back(provider);
5188void KTextEditor::ViewPrivate::unregisterInlineNoteProvider(KTextEditor::InlineNoteProvider *provider)
5190 auto it = std::find(m_inlineNoteProviders.cbegin(), m_inlineNoteProviders.cend(), provider);
5191 if (it != m_inlineNoteProviders.cend()) {
5192 m_inlineNoteProviders.erase(it);
5199QVarLengthArray<KateInlineNoteData, 8> KTextEditor::ViewPrivate::inlineNotes(
int line)
const
5201 QVarLengthArray<KateInlineNoteData, 8> allInlineNotes;
5202 for (KTextEditor::InlineNoteProvider *provider : m_inlineNoteProviders) {
5205 for (
int column : columns) {
5206 const bool underMouse =
Cursor(line, column) == m_viewInternal->m_activeInlineNote.m_position;
5207 KateInlineNoteData note =
5208 {provider,
this, {line, column}, index, underMouse, m_viewInternal->renderer()->currentFont(), m_viewInternal->renderer()->lineHeight()};
5209 allInlineNotes.
append(note);
5213 return allInlineNotes;
5216QRect KTextEditor::ViewPrivate::inlineNoteRect(
const KateInlineNoteData ¬e)
const
5218 return m_viewInternal->inlineNoteRect(note);
5221void KTextEditor::ViewPrivate::inlineNotesReset()
5223 m_viewInternal->m_activeInlineNote = {};
5224 tagLines(KTextEditor::LineRange(0, doc()->lastLine()),
true);
5227void KTextEditor::ViewPrivate::inlineNotesLineChanged(
int line)
5229 if (line == m_viewInternal->m_activeInlineNote.m_position.line()) {
5230 m_viewInternal->m_activeInlineNote = {};
5232 tagLines({line, line},
true);
5239 KateRendererConfig *renderConfig =
const_cast<KTextEditor::ViewPrivate *
>(
this)->rendererConfig();
5244 style =
new KTextEditor::Attribute(*style);
5245 style->setBackground(QBrush(renderConfig->backgroundColor()));
5250QList<KTextEditor::AttributeBlock> KTextEditor::ViewPrivate::lineAttributes(
int line)
5252 QList<KTextEditor::AttributeBlock> attribs;
5254 if (line < 0 || line >= doc()->lines()) {
5258 const Kate::TextLine kateLine = doc()->
kateTextLine(line);
5260 for (qsizetype i = 0; i < intAttrs.size(); ++i) {
5261 if (intAttrs[i].length > 0 && intAttrs[i].attributeValue > 0) {
5262 attribs << KTextEditor::AttributeBlock(intAttrs.at(i).offset, intAttrs.at(i).length, renderer()->attribute(intAttrs.at(i).attributeValue));
5269void KTextEditor::ViewPrivate::copyFileLocation()
const
5275#include "moc_kateview.cpp"
Q_INVOKABLE QAction * action(const QString &name) const
void addAssociatedWidget(QWidget *widget)
QAction * addAction(const QString &name, const QObject *receiver=nullptr, const char *member=nullptr)
static void setDefaultShortcut(QAction *action, const QKeySequence &shortcut)
static Q_INVOKABLE void setDefaultShortcuts(QAction *action, const QList< QKeySequence > &shortcuts)
QList< QAction * > actions() const
bool hasKey(const char *key) const
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
void deleteGroup(const QString &group, WriteConfigFlags flags=Normal)
QString readEntry(const char *key, const char *aDefault=nullptr) const
static void setAutoHideCursor(QWidget *w, bool enable, bool customEventFilter=false)
void canceled(const QString &errMsg)
void indexTriggered(int index)
ActivationType
Several automatic activation mechanisms exist for associated attributes.
@ ActivateMouseIn
Activate attribute on mouse in.
@ ActivateCaretIn
Activate attribute on caret in.
QExplicitlySharedDataPointer< Attribute > Ptr
Shared data pointer for Attribute.
The Cursor represents a position in a Document.
constexpr int column() const noexcept
Retrieve the column on which this cursor is situated.
void setColumn(int column) noexcept
Set the cursor column to column.
void setPosition(Cursor position) noexcept
Set the current cursor position to position.
constexpr bool isValid() const noexcept
Returns whether the current position of this cursor is a valid position (line + column must both be >...
static constexpr Cursor start() noexcept
Returns a cursor representing the start of any document - i.e., line 0, column 0.
constexpr int line() const noexcept
Retrieve the line on which this cursor is situated.
Backend of KTextEditor::Document related public KTextEditor interfaces.
bool documentReload() override
Reloads the current document from disk if possible.
bool postMessage(KTextEditor::Message *message) override
Post message to the Document and its Views.
void joinLines(uint first, uint last)
Unwrap a range of lines.
QString text(KTextEditor::Range range, bool blockwise=false) const override
Get the document content within the given range.
void transform(KTextEditor::ViewPrivate *view, KTextEditor::Cursor, TextTransform)
Handling uppercase, lowercase and capitalize for the view.
QString line(int line) const override
Get a single text line.
KateBuffer & buffer()
Get access to buffer of this document.
int lines() const override
Get the count of lines of the document.
void bomSetByUser()
Set that the BOM marker is forced via the tool menu.
bool editStart()
Enclose editor actions with editStart() and editEnd() to group them.
KTextEditor::Cursor lastEditingPosition(EditingPositionKind nextOrPrevious, KTextEditor::Cursor)
Returns the next or previous position cursor in this document from the stack depending on the argumen...
KateDocumentConfig * config()
Configuration.
bool editWrapLine(int line, int col, bool newLine=true, bool *newLineAdded=nullptr, bool notify=true)
Wrap line.
void removeAllTrailingSpaces()
This function doesn't check for config and is available for use all the time via an action.
Kate::TextLine kateTextLine(int i)
Same as plainKateTextLine(), except that it is made sure the line is highlighted.
bool editEnd()
End a editor operation.
int findTouchedLine(int startLine, bool down)
Find the next modified/saved line, starting at startLine.
int lineLength(int line) const override
Get the length of a given line in characters.
KTextEditor::Range wordRangeAt(KTextEditor::Cursor cursor) const override
Get the text range for the word located under the text position cursor.
bool wrapParagraph(int first, int last)
Wrap lines touched by the selection with respect of existing paragraphs.
void reloaded(KTextEditor::Document *document)
Emitted after the current document was reloaded.
Range documentRange() const
A Range which encompasses the whole document.
void highlightingModeChanged(KTextEditor::Document *document)
Warn anyone listening that the current document's highlighting mode has changed.
void aboutToReload(KTextEditor::Document *document)
Warn anyone listening that the current document is about to reload.
KTextEditor::EditorPrivate One instance of this class is hold alive during a kate part session,...
void copyToClipboard(const QString &text, const QString &fileName)
Copy text to clipboard an remember it in the history.
void deregisterView(KTextEditor::ViewPrivate *view)
unregister view at the factory
QTextToSpeech * speechEngine(KTextEditor::ViewPrivate *view)
text to speech engine to be use by the view actions, constructed on demand.
void configDialog(QWidget *parent) override
Configuration management.
void registerView(KTextEditor::ViewPrivate *view)
register view at the factory this allows us to loop over all views for example on config changes
static KTextEditor::EditorPrivate * self()
Kate Part Internal stuff ;)
void inlineNotesReset()
The provider should emit the signal inlineNotesReset() when almost all inline notes changed.
void inlineNotesChanged(int line)
The provider should emit the signal inlineNotesChanged() whenever one or more InlineNotes on the line...
virtual QList< int > inlineNotes(int line) const =0
Get list of inline notes for given line.
An object representing lines from a start line to an end line.
constexpr int start() const noexcept
Get the start line of this line range.
static constexpr LineRange invalid() noexcept
Returns an invalid line range.
constexpr bool isValid() const noexcept
Validity check.
constexpr int end() const noexcept
Get the end line of this line range.
@ BelowView
show message below view.
@ AboveView
show message above view.
@ TopInView
show message as view overlay in the top right corner.
@ BottomInView
show message as view overlay in the bottom right corner.
void setAutoHide(int delay=0)
Set the auto hide time to delay milliseconds.
void setAutoHideMode(KTextEditor::Message::AutoHideMode mode)
Sets the auto hide mode to mode.
MessagePosition position() const
Returns the message position of this message.
@ Information
information message type
@ Immediate
auto-hide is triggered as soon as the message is shown
void setPosition(MessagePosition position)
Sets the position of the message to position.
@ StayOnInsert
stay on insert
@ ExpandRight
Expand to encapsulate new characters to the right of the range.
@ ExpandLeft
Expand to encapsulate new characters to the left of the range.
An object representing a section of text, from one Cursor to another.
constexpr LineRange toLineRange() const noexcept
Convert this Range to a LineRange.
constexpr Cursor end() const noexcept
Get the end position of this range.
constexpr Cursor start() const noexcept
Get the start position of this range.
void setEnd(Cursor end) noexcept
Set the end cursor to end.
constexpr bool isEmpty() const noexcept
Returns true if this range contains no characters, ie.
void setRange(Range range) noexcept
Set the start and end cursors to range.start() and range.end() respectively.
constexpr bool onSingleLine() const noexcept
Check whether this range is wholly contained within one line, ie.
static constexpr Range invalid() noexcept
Returns an invalid range.
constexpr bool isValid() const noexcept
Validity check.
constexpr bool containsLine(int line) const noexcept
Returns true if this range wholly encompasses line.
constexpr bool contains(Range range) const noexcept
Check whether the this range wholly encompasses range.
void setStart(Cursor start) noexcept
Set the start cursor to start.
A text widget with KXMLGUIClient that represents a Document.
void displayRangeChanged(KTextEditor::View *view)
This signal is emitted whenever the displayed range changes.
ViewMode
Possible view modes These correspond to various modes the text editor might be in.
InputMode
Possible input modes.
@ NormalInputMode
Normal Mode.
void cursorPositionChanged(KTextEditor::View *view, KTextEditor::Cursor newPosition)
This signal is emitted whenever the view's cursor position changed.
void selectionChanged(KTextEditor::View *view)
This signal is emitted whenever the view's selection changes.
KXMLGUIClient * parentClient() const
KXMLGUIFactory * factory() const
virtual void setComponentName(const QString &componentName, const QString &componentDisplayName)
void removeClient(KXMLGUIClient *client)
KTextEditor::Range computeFoldingRangeForStartLine(int startLine)
For a given line, compute the folding range that starts there to be used to fold e....
Class to layout KTextEditor::Messages in KateView.
QList< TextRange * > rangesForLine(int line, KTextEditor::View *view, bool rangesWithAttributeOnly) const
Return the ranges which affect the given line.
@ Folded
Range is folded away.
Class representing a single text line.
const QString & text() const
Accessor to the text contained in this line.
const QList< Attribute > & attributesList() const
Accessor to attributes.
QString string(int column, int length) const
Returns the substring with length beginning at the given column.
int length() const
Returns the line's length.
QChar at(int column) const
Returns the character at the given column.
int firstChar() const
Returns the position of the first non-whitespace character.
Q_SCRIPTABLE bool focusOut(int ms=-1, int speedFactor=1)
Q_SCRIPTABLE bool focusIn(int ms=-1, int speedFactor=1)
Q_SCRIPTABLE Q_NOREPLY void start()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
AKONADI_CALENDAR_EXPORT QString displayName(Akonadi::ETMCalendar *calendar, const Akonadi::Collection &collection)
void update(Part *part, const QByteArray &data, qint64 dataSize)
KCOREADDONS_EXPORT Result match(QStringView pattern, QStringView str)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QAction * paste(const QObject *recvr, const char *slot, QObject *parent)
QAction * copy(const QObject *recvr, const char *slot, QObject *parent)
QAction * selectAll(const QObject *recvr, const char *slot, QObject *parent)
QAction * next(const QObject *recvr, const char *slot, QObject *parent)
const QList< QKeySequence > & beginningOfLine()
const QList< QKeySequence > & begin()
const QList< QKeySequence > & reload()
const QList< QKeySequence > & zoomIn()
const QList< QKeySequence > & zoomOut()
const QList< QKeySequence > & next()
const QList< QKeySequence > & deleteWordBack()
const QList< QKeySequence > & end()
const QList< QKeySequence > & backwardWord()
const QList< QKeySequence > & endOfLine()
const QList< QKeySequence > & forwardWord()
const QList< QKeySequence > & shortcut(StandardShortcut id)
const QList< QKeySequence > & deleteWordForward()
const QList< QKeySequence > & prior()
const QList< QKeySequence > & pasteSelection()
@ Default
Default settings.
@ Regex
Treats the pattern as a regular expression.
QVariant data() const const
void setIcon(const QIcon &icon)
void setText(const QString &text)
void triggered(bool checked)
void setWhatsThis(const QString &what)
bool isLetterOrNumber(char32_t ucs4)
bool isSpace(char32_t ucs4)
void setText(const QString &text, Mode mode)
QString text(Mode mode) const const
QColor fromRgba(QRgb rgba)
QUrl getOpenFileUrl(QWidget *parent, const QString &caption, const QUrl &dir, const QString &filter, QString *selectedFilter, Options options, const QStringList &supportedSchemes)
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, Options options)
virtual void addItem(QLayoutItem *item) override
void setColumnStretch(int column, int stretch)
void setRowStretch(int row, int stretch)
virtual void setSpacing(int spacing) override
QIcon fromTheme(const QString &name)
QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, bool *ok, Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
void setContentsMargins(const QMargins &margins)
const_reference at(qsizetype i) const const
const T & constFirst() const const
bool isEmpty() const const
void push_back(parameter_type value)
void reserve(qsizetype size)
qsizetype size() const const
bool disconnect(const QMetaObject::Connection &connection)
virtual bool event(QEvent *e)
UseUnicodePropertiesOption
QString escape(QStringView str)
bool contains(const QSet< T > &other) const const
iterator erase(const_iterator pos)
iterator find(const T &value)
iterator insert(const T &value)
const QChar at(qsizetype position) const const
bool isEmpty() const const
bool isRightToLeft() const const
qsizetype length() const const
QString number(double n, char format, int precision)
QString & prepend(QChar ch)
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
void reserve(qsizetype size)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
SH_ScrollView_FrameOnlyAroundContents
void initFrom(const QWidget *widget)
WidgetWithChildrenShortcut
QTextStream & bom(QTextStream &stream)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool canConvert() const const
bool toBool() const const
int toInt(bool *ok) const const
QString toString() const const
int userType() const const
qsizetype size() const const