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(
"Use this command to copy the currently selected text as HTML to the system clipboard."));
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 if (!doc()->readOnly()) {
1282 a = ac->
addAction(QStringLiteral(
"transpose_char"));
1285 m_editActions.push_back(a);
1287 a = ac->
addAction(QStringLiteral(
"transpose_word"));
1290 m_editActions.push_back(a);
1292 a = ac->
addAction(QStringLiteral(
"delete_line"));
1296 m_editActions.push_back(a);
1298 a = ac->
addAction(QStringLiteral(
"delete_word_left"));
1302 m_editActions.push_back(a);
1304 a = ac->
addAction(QStringLiteral(
"delete_word_right"));
1308 m_editActions.push_back(a);
1310 a = ac->
addAction(QStringLiteral(
"delete_next_character"));
1314 m_editActions.push_back(a);
1316 a = ac->
addAction(QStringLiteral(
"backspace"));
1318 QList<QKeySequence> scuts;
1322 m_editActions.push_back(a);
1324 a = ac->
addAction(QStringLiteral(
"insert_tabulator"));
1327 m_editActions.push_back(a);
1329 a = ac->
addAction(QStringLiteral(
"smart_newline"));
1331 a->
setWhatsThis(
i18n(
"Insert newline including leading characters of the current line which are not letters or numbers."));
1336 m_editActions.push_back(a);
1338 a = ac->
addAction(QStringLiteral(
"no_indent_newline"));
1339 a->
setText(
i18n(
"Insert a Non-Indented Newline"));
1340 a->
setWhatsThis(
i18n(
"Insert a new line without indentation, regardless of indentation settings."));
1345 m_editActions.push_back(a);
1347 a = ac->
addAction(QStringLiteral(
"newline_above"));
1348 a->
setText(
i18n(
"Insert a Newline Above Current Line"));
1349 a->
setWhatsThis(
i18n(
"Insert a new line above current line without modifying the current line."));
1354 m_editActions.push_back(a);
1356 a = ac->
addAction(QStringLiteral(
"newline_below"));
1357 a->
setText(
i18n(
"Insert a Newline Below Current Line"));
1358 a->
setWhatsThis(
i18n(
"Insert a new line below current line without modifying the current line."));
1363 m_editActions.push_back(a);
1365 a = ac->
addAction(QStringLiteral(
"tools_indent"));
1369 i18n(
"Use this to indent a selected block of text.<br /><br />"
1370 "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog."));
1374 a = ac->
addAction(QStringLiteral(
"tools_unindent"));
1389void KTextEditor::ViewPrivate::setupCodeFolding()
1391 KActionCollection *ac = this->actionCollection();
1394 a = ac->
addAction(QStringLiteral(
"folding_toplevel"));
1398 a = ac->
addAction(QStringLiteral(
"folding_expandtoplevel"));
1402 a = ac->
addAction(QStringLiteral(
"folding_toggle_current"));
1406 a = ac->
addAction(QStringLiteral(
"folding_toggle_in_current"));
1411void KTextEditor::ViewPrivate::setupSpeechActions()
1413 KActionCollection *ac = actionCollection();
1415 QAction *a = ac->
addAction(QStringLiteral(
"tools_speech_say"));
1416 a->
setText(
i18n(
"Say current selection or document"));
1425 a = ac->
addAction(QStringLiteral(
"tools_speech_stop"));
1431 a = ac->
addAction(QStringLiteral(
"tools_speech_pause"));
1437 a = ac->
addAction(QStringLiteral(
"tools_speech_resume"));
1444void KTextEditor::ViewPrivate::slotFoldToplevelNodes()
1446 for (
int line = 0; line < doc()->
lines(); ++line) {
1447 if (textFolding().isLineVisible(line)) {
1453void KTextEditor::ViewPrivate::slotExpandToplevelNodes()
1455 const auto topLevelRanges(textFolding().foldingRangesForParentRange());
1456 for (
const auto &range : topLevelRanges) {
1457 textFolding().unfoldRange(range.first);
1461void KTextEditor::ViewPrivate::slotToggleFolding()
1463 int line = cursorPosition().line();
1464 bool actionDone =
false;
1465 while (!actionDone && (line > -1)) {
1466 actionDone = unfoldLine(line);
1468 actionDone = foldLine(line--).isValid();
1473void KTextEditor::ViewPrivate::slotToggleFoldingsInRange()
1475 int line = cursorPosition().line();
1476 while (!toggleFoldingsInRange(line) && (line > -1)) {
1481KTextEditor::Range KTextEditor::ViewPrivate::foldLine(
int line)
1484 if (!foldingRange.
isValid()) {
1485 return foldingRange;
1490 if (!m_doc->buffer().isFoldingStartingOnLine(line).second && !foldingRange.
onSingleLine()) {
1491 const int adjustedLine = foldingRange.
end().
line() - 1;
1492 foldingRange.
setEnd(KTextEditor::Cursor(adjustedLine, doc()->buffer().plainLine(adjustedLine).length()));
1499 auto folds = textFolding().foldingRangesStartingOnLine(line);
1500 for (
int i = 0; i < folds.size(); ++i) {
1501 KTextEditor::Range fold = textFolding().foldingRange(folds[i].first);
1502 if (fold == foldingRange) {
1503 return foldingRange;
1513 return foldingRange;
1516bool KTextEditor::ViewPrivate::unfoldLine(
int line)
1518 bool actionDone =
false;
1519 const KTextEditor::Cursor currentCursor = cursorPosition();
1523 auto startingRanges = textFolding().foldingRangesStartingOnLine(line);
1524 for (
int i = 0; i < startingRanges.size() && !actionDone; ++i) {
1526 setCursorPosition(textFolding().foldingRange(startingRanges[i].first).
start());
1528 actionDone |= textFolding().unfoldRange(startingRanges[i].first);
1533 setCursorPosition(currentCursor);
1539bool KTextEditor::ViewPrivate::toggleFoldingOfLine(
int line)
1541 bool actionDone = unfoldLine(line);
1543 actionDone = foldLine(line).isValid();
1549bool KTextEditor::ViewPrivate::toggleFoldingsInRange(
int line)
1552 if (!foldingRange.
isValid()) {
1557 bool actionDone =
false;
1558 const KTextEditor::Cursor currentCursor = cursorPosition();
1562 actionDone |= unfoldLine(line);
1566 for (
int ln = foldingRange.
start().
line() + 1; ln < foldingRange.
end().
line(); ++ln) {
1567 actionDone |= unfoldLine(ln);
1572 setCursorPosition(currentCursor);
1578 for (
int ln = foldingRange.
start().
line() + 1; ln < foldingRange.
end().
line(); ++ln) {
1579 KTextEditor::Range fr = foldLine(ln);
1582 ln = qMax(ln, fr.
end().
line() - 1);
1591 actionDone |= foldLine(line).isValid();
1600 return currentInputMode()->viewMode();
1603QString KTextEditor::ViewPrivate::viewModeHuman()
const
1605 QString currentMode = currentInputMode()->viewModeHuman();
1608 if (!doc()->isReadWrite()) {
1609 currentMode =
i18n(
"(R/O) %1", currentMode);
1618 return currentInputMode()->viewInputMode();
1621QString KTextEditor::ViewPrivate::viewInputModeHuman()
const
1623 return currentInputMode()->viewInputModeHuman();
1628 if (currentInputMode()->viewInputMode() == mode) {
1634 clearSecondaryCursors();
1637 m_viewInternal->m_currentInputMode->deactivate();
1638 m_viewInternal->m_currentInputMode = m_viewInternal->m_inputModes[mode].get();
1639 m_viewInternal->m_currentInputMode->activate();
1642 if (rememberInConfig) {
1643 config()->setValue(KateViewConfig::InputMode, mode);
1647 const auto inputModeActions = m_inputModeActions->actions();
1648 for (QAction *action : inputModeActions) {
1649 if (
static_cast<InputMode
>(action->data().toInt()) == mode) {
1650 action->setChecked(
true);
1656 Q_EMIT viewInputModeChanged(
this, mode);
1657 Q_EMIT viewModeChanged(
this, viewMode());
1660void KTextEditor::ViewPrivate::slotDocumentAboutToReload()
1662 if (doc()->isAutoReload()) {
1663 const int lastVisibleLine = m_viewInternal->endLine();
1664 const int currentLine = cursorPosition().line();
1665 m_gotoBottomAfterReload = (lastVisibleLine == currentLine) && (currentLine == doc()->lastLine());
1666 if (!m_gotoBottomAfterReload) {
1668 const int firstVisibleLine = 1 + lastVisibleLine - m_viewInternal->linesDisplayed();
1669 const int newLine = qBound(firstVisibleLine, currentLine, lastVisibleLine);
1670 setCursorPositionVisual(KTextEditor::Cursor(newLine, cursorPosition().column()));
1673 m_gotoBottomAfterReload =
false;
1677void KTextEditor::ViewPrivate::slotDocumentReloaded()
1679 if (m_gotoBottomAfterReload) {
1684void KTextEditor::ViewPrivate::slotGotFocus()
1687 currentInputMode()->gotFocus();
1693 if (m_viewInternal->m_lineScroll->isVisible()) {
1694 m_viewInternal->m_lineScroll->update();
1697 if (m_viewInternal->m_columnScroll->isVisible()) {
1698 m_viewInternal->m_columnScroll->update();
1704void KTextEditor::ViewPrivate::slotLostFocus()
1707 currentInputMode()->lostFocus();
1713 if (m_viewInternal->m_lineScroll->isVisible()) {
1714 m_viewInternal->m_lineScroll->update();
1717 if (m_viewInternal->m_columnScroll->isVisible()) {
1718 m_viewInternal->m_columnScroll->update();
1721 if (doc()->config()->autoSave() && doc()->config()->autoSaveOnFocusOut() && doc()->isModified() && doc()->url().isLocalFile()) {
1722 doc()->documentSave();
1728void KTextEditor::ViewPrivate::setDynWrapIndicators(
int mode)
1730 config()->setValue(KateViewConfig::DynWordWrapIndicators, mode);
1733bool KTextEditor::ViewPrivate::isOverwriteMode()
const
1735 return doc()->
config()->ovr();
1738void KTextEditor::ViewPrivate::reloadFile()
1744void KTextEditor::ViewPrivate::slotReadWriteChanged()
1746 if (m_toggleWriteLock) {
1747 m_toggleWriteLock->setChecked(!doc()->isReadWrite());
1750 m_cut->setEnabled(doc()->isReadWrite() && (selection() || m_config->smartCopyCut()));
1751 m_paste->setEnabled(doc()->isReadWrite());
1752 if (m_pasteSelection) {
1753 m_pasteSelection->setEnabled(doc()->isReadWrite());
1755 m_swapWithClipboard->setEnabled(doc()->isReadWrite());
1756 m_setEndOfLine->setEnabled(doc()->isReadWrite());
1758 static const auto l = {QStringLiteral(
"edit_replace"),
1759 QStringLiteral(
"tools_spelling"),
1760 QStringLiteral(
"tools_indent"),
1761 QStringLiteral(
"tools_unindent"),
1762 QStringLiteral(
"tools_cleanIndent"),
1763 QStringLiteral(
"tools_formatIndet"),
1764 QStringLiteral(
"tools_alignOn"),
1765 QStringLiteral(
"tools_comment"),
1766 QStringLiteral(
"tools_uncomment"),
1767 QStringLiteral(
"tools_toggle_comment"),
1768 QStringLiteral(
"tools_uppercase"),
1769 QStringLiteral(
"tools_lowercase"),
1770 QStringLiteral(
"tools_capitalize"),
1771 QStringLiteral(
"tools_join_lines"),
1772 QStringLiteral(
"tools_apply_wordwrap"),
1773 QStringLiteral(
"tools_spelling_from_cursor"),
1774 QStringLiteral(
"tools_spelling_selection")};
1776 for (
const auto &action : l) {
1777 QAction *a = actionCollection()->action(action);
1784 currentInputMode()->readWriteChanged(doc()->isReadWrite());
1787 Q_EMIT viewModeChanged(
this, viewMode());
1788 Q_EMIT viewInputModeChanged(
this, viewInputMode());
1791void KTextEditor::ViewPrivate::toggleCamelCaseCursor()
1793 const auto enabled = doc()->
config()->camelCursor();
1794 doc()->
config()->setCamelCursor(!enabled);
1795 KTextEditor::Message *m;
1797 m =
new KTextEditor::Message(
i18n(
"Camel case movement disabled"));
1799 m =
new KTextEditor::Message(
i18n(
"Camel case movement enabled"));
1807void KTextEditor::ViewPrivate::slotUpdateUndo()
1809 if (doc()->readOnly()) {
1813 m_editUndo->setEnabled(doc()->isReadWrite() && doc()->undoCount() > 0);
1814 m_editRedo->setEnabled(doc()->isReadWrite() && doc()->redoCount() > 0);
1817bool KTextEditor::ViewPrivate::setCursorPositionInternal(
const KTextEditor::Cursor position, uint tabwidth,
bool calledExternally)
1819 if (position.
line() < 0 || position.
line() >= doc()->lines()) {
1824 const QString line_str = l.
text();
1828 for (; z < line_str.
length() && z < position.
column(); z++) {
1829 if (line_str[z] == QLatin1Char(
'\t')) {
1830 x += tabwidth - (x % tabwidth);
1836 if (blockSelection()) {
1837 if (z < position.
column()) {
1838 x += position.
column() - z;
1842 m_viewInternal->updateCursor(KTextEditor::Cursor(position.
line(), x),
1850void KTextEditor::ViewPrivate::toggleInsert()
1852 doc()->
config()->setOvr(!doc()->config()->ovr());
1853 m_toggleInsert->setChecked(isOverwriteMode());
1856 if (isOverwriteMode()) {
1857 clearSecondaryCursors();
1860 Q_EMIT viewModeChanged(
this, viewMode());
1861 Q_EMIT viewInputModeChanged(
this, viewInputMode());
1864void KTextEditor::ViewPrivate::slotSaveCanceled(
const QString &error)
1866 if (!
error.isEmpty()) {
1871void KTextEditor::ViewPrivate::gotoLine()
1873 gotoBar()->updateData();
1874 bottomViewBar()->showBarWidget(gotoBar());
1877void KTextEditor::ViewPrivate::changeDictionary()
1879 dictionaryBar()->updateData();
1880 bottomViewBar()->showBarWidget(dictionaryBar());
1883void KTextEditor::ViewPrivate::joinLines()
1885 int first = selectionRange().start().line();
1886 int last = selectionRange().end().line();
1888 if (first == last) {
1889 first = cursorPosition().line();
1895void KTextEditor::ViewPrivate::readSessionConfig(
const KConfigGroup &config,
const QSet<QString> &flags)
1900 KTextEditor::Cursor savedPosition(config.
readEntry(
"CursorLine", 0), config.
readEntry(
"CursorColumn", 0));
1901 setCursorPositionInternal(savedPosition);
1904 const int scroll = config.
readEntry(
"ScrollLine", -1);
1905 if (scroll >= 0 && scroll < doc()->lines() && savedPosition.
line() < doc()->lines()) {
1906 setScrollPositionInternal(KTextEditor::Cursor(scroll, 0));
1910 if (config.
hasKey(
"Dynamic Word Wrap")) {
1912 m_config->setDynWordWrap(config.
readEntry(
"Dynamic Word Wrap", m_config->global()->dynWordWrap()));
1917 applyFoldingState();
1919 m_forceRTL = config.
readEntry(
"Force RTL Direction",
false);
1920 m_forceRTLDirection->setChecked(m_forceRTL);
1922 for (
const auto &mode : m_viewInternal->m_inputModes) {
1923 mode->readSessionConfig(config);
1927void KTextEditor::ViewPrivate::writeSessionConfig(KConfigGroup &config,
const QSet<QString> &)
1933 const auto cursor = cursorPosition();
1934 if (cursor.isValid() && cursor != KTextEditor::Cursor(0, 0)) {
1935 config.
writeEntry(
"CursorLine", cursor.line());
1936 config.
writeEntry(
"CursorColumn", cursor.column());
1940 const int scrollLine = firstDisplayedLineInternal(LineType::RealLine);
1941 if (scrollLine > 0 && scrollLine != cursor.line()) {
1946 if (m_config->isSet(KateViewConfig::DynamicWordWrap)) {
1947 config.
writeEntry(
"Dynamic Word Wrap", m_config->dynWordWrap());
1952 if (!m_savedFoldingState.object().value(QLatin1String(
"ranges")).toArray().isEmpty()) {
1954 m_savedFoldingState = QJsonDocument();
1958 config.
writeEntry(
"Force RTL Direction", m_forceRTL);
1961 for (
const auto &mode : m_viewInternal->m_inputModes) {
1962 mode->writeSessionConfig(config);
1966int KTextEditor::ViewPrivate::getEol()
const
1968 return doc()->
config()->eol();
1971QMenu *KTextEditor::ViewPrivate::getEolMenu()
1973 return m_setEndOfLine->menu();
1976void KTextEditor::ViewPrivate::setEol(
int eol)
1978 if (!doc()->isReadWrite()) {
1982 if (m_updatingDocumentConfig) {
1986 if (eol != doc()->config()->eol()) {
1987 doc()->setModified(
true);
1988 doc()->
config()->setEol(eol);
1992void KTextEditor::ViewPrivate::setAddBom(
bool enabled)
1994 if (!doc()->isReadWrite()) {
1998 if (m_updatingDocumentConfig) {
2002 doc()->
config()->setBom(enabled);
2006void KTextEditor::ViewPrivate::setIconBorder(
bool enable)
2008 config()->setValue(KateViewConfig::ShowIconBar, enable);
2011void KTextEditor::ViewPrivate::toggleIconBorder()
2013 config()->setValue(KateViewConfig::ShowIconBar, !config()->iconBar());
2016void KTextEditor::ViewPrivate::setLineNumbersOn(
bool enable)
2018 config()->setValue(KateViewConfig::ShowLineNumbers, enable);
2021void KTextEditor::ViewPrivate::toggleLineNumbersOn()
2023 config()->setValue(KateViewConfig::ShowLineNumbers, !config()->lineNumbers());
2026void KTextEditor::ViewPrivate::setScrollBarMarks(
bool enable)
2028 config()->setValue(KateViewConfig::ShowScrollBarMarks, enable);
2031void KTextEditor::ViewPrivate::toggleScrollBarMarks()
2033 config()->setValue(KateViewConfig::ShowScrollBarMarks, !config()->scrollBarMarks());
2036void KTextEditor::ViewPrivate::setScrollBarMiniMap(
bool enable)
2038 config()->setValue(KateViewConfig::ShowScrollBarMiniMap, enable);
2041void KTextEditor::ViewPrivate::toggleScrollBarMiniMap()
2043 config()->setValue(KateViewConfig::ShowScrollBarMiniMap, !config()->scrollBarMiniMap());
2046void KTextEditor::ViewPrivate::setScrollBarMiniMapAll(
bool enable)
2048 config()->setValue(KateViewConfig::ShowScrollBarMiniMapAll, enable);
2051void KTextEditor::ViewPrivate::toggleScrollBarMiniMapAll()
2053 config()->setValue(KateViewConfig::ShowScrollBarMiniMapAll, !config()->scrollBarMiniMapAll());
2056void KTextEditor::ViewPrivate::setScrollBarMiniMapWidth(
int width)
2058 config()->setValue(KateViewConfig::ScrollBarMiniMapWidth, width);
2061void KTextEditor::ViewPrivate::toggleShowSpaces()
2063 if (m_updatingDocumentConfig) {
2067 using WhitespaceRendering = KateDocumentConfig::WhitespaceRendering;
2068 doc()->
config()->setShowSpaces(doc()->config()->showSpaces() != WhitespaceRendering::None ? WhitespaceRendering::None : WhitespaceRendering::All);
2071void KTextEditor::ViewPrivate::toggleDynWordWrap()
2073 config()->setDynWordWrap(!config()->dynWordWrap());
2076void KTextEditor::ViewPrivate::toggleWWMarker()
2078 m_renderer->config()->setWordWrapMarker(!m_renderer->config()->wordWrapMarker());
2081void KTextEditor::ViewPrivate::toggleNPSpaces()
2083 m_renderer->setShowNonPrintableSpaces(!m_renderer->showNonPrintableSpaces());
2084 m_viewInternal->update();
2087void KTextEditor::ViewPrivate::toggleWordCount(
bool on)
2089 config()->setShowWordCount(on);
2092void KTextEditor::ViewPrivate::setFoldingMarkersOn(
bool enable)
2094 config()->setValue(KateViewConfig::ShowFoldingBar, enable);
2097void KTextEditor::ViewPrivate::toggleFoldingMarkers()
2099 config()->setValue(KateViewConfig::ShowFoldingBar, !config()->foldingBar());
2102bool KTextEditor::ViewPrivate::iconBorder()
2104 return m_viewInternal->m_leftBorder->iconBorderOn();
2107bool KTextEditor::ViewPrivate::lineNumbersOn()
2109 return m_viewInternal->m_leftBorder->lineNumbersOn();
2112bool KTextEditor::ViewPrivate::scrollBarMarks()
2114 return m_viewInternal->m_lineScroll->showMarks();
2117bool KTextEditor::ViewPrivate::scrollBarMiniMap()
2119 return m_viewInternal->m_lineScroll->showMiniMap();
2122int KTextEditor::ViewPrivate::dynWrapIndicators()
2124 return m_viewInternal->m_leftBorder->dynWrapIndicators();
2127bool KTextEditor::ViewPrivate::foldingMarkersOn()
2129 return m_viewInternal->m_leftBorder->foldingMarkersOn();
2132bool KTextEditor::ViewPrivate::forceRTLDirection()
const
2137void KTextEditor::ViewPrivate::toggleWriteLock()
2139 doc()->setReadWrite(!doc()->isReadWrite());
2142void KTextEditor::ViewPrivate::registerTextHintProvider(KTextEditor::TextHintProvider *provider)
2144 m_viewInternal->registerTextHintProvider(provider);
2147void KTextEditor::ViewPrivate::unregisterTextHintProvider(KTextEditor::TextHintProvider *provider)
2149 m_viewInternal->unregisterTextHintProvider(provider);
2152void KTextEditor::ViewPrivate::setTextHintDelay(
int delay)
2154 m_viewInternal->setTextHintDelay(delay);
2157int KTextEditor::ViewPrivate::textHintDelay()
const
2159 return m_viewInternal->textHintDelay();
2163void KTextEditor::ViewPrivate::find()
2165 currentInputMode()->find();
2169void KTextEditor::ViewPrivate::findSelectedForwards()
2171 currentInputMode()->findSelectedForwards();
2175void KTextEditor::ViewPrivate::findSelectedBackwards()
2177 currentInputMode()->findSelectedBackwards();
2180void KTextEditor::ViewPrivate::skipCurrentOccurunceSelection()
2182 if (isMulticursorNotAllowed()) {
2185 m_skipCurrentSelection =
true;
2188void KTextEditor::ViewPrivate::findNextOccurunceAndSelect()
2190 if (isMulticursorNotAllowed()) {
2194 const auto text = selection() ? doc()->
text(selectionRange()) : QString();
2195 if (text.isEmpty()) {
2196 const auto selection = doc()->
wordRangeAt(cursorPosition());
2198 setSelection(selection);
2199 setCursorPosition(selection.end());
2202 for (
auto &c : m_secondaryCursors) {
2203 const auto range = doc()->
wordRangeAt(c.cursor());
2204 if (!c.range && !c.anchor.isValid()) {
2205 c.anchor = range.
start();
2206 c.range.reset(newSecondarySelectionRange(range));
2212 }
else if (!m_rangesForHighlights.empty()) {
2217 const auto lastSelectionRange = selectionRange();
2219 KTextEditor::Range searchRange(lastSelectionRange.end(), doc()->documentRange().
end());
2220 QList<KTextEditor::Range> matches = doc()->searchText(searchRange, text,
KTextEditor::Default);
2222 searchRange.setRange(doc()->documentRange().
start(), lastSelectionRange.end());
2231 auto it = std::find_if(m_secondaryCursors.begin(), m_secondaryCursors.end(), [&](
const SecondaryCursor &c) {
2232 return c.range && c.range->toRange() == matches.constFirst();
2235 if (it != m_secondaryCursors.end()) {
2236 m_secondaryCursors.erase(it);
2242 setCursorPosition(matches.
constFirst().end());
2246 if (!m_skipCurrentSelection) {
2247 PlainSecondaryCursor c;
2248 c.pos = lastSelectionRange.end();
2249 c.range = lastSelectionRange;
2251 addSecondaryCursorsWithSelection({c});
2254 m_skipCurrentSelection =
false;
2257void KTextEditor::ViewPrivate::findAllOccuruncesAndSelect()
2259 if (isMulticursorNotAllowed()) {
2263 QString text = selection() ? doc()->
text(selectionRange()) : QString();
2265 const auto selection = doc()->
wordRangeAt(cursorPosition());
2266 setSelection(selection);
2267 setCursorPosition(selection.end());
2269 text = doc()->
text(selection);
2271 for (
auto &c : m_secondaryCursors) {
2272 const auto range = doc()->
wordRangeAt(c.cursor());
2273 if (!c.range && !c.anchor.isValid()) {
2274 c.anchor = range.
start();
2275 c.range.reset(newSecondarySelectionRange(range));
2282 KTextEditor::Range searchRange(doc()->documentRange());
2283 QList<KTextEditor::Range> matches;
2284 QList<PlainSecondaryCursor> resultRanges;
2290 if (matches.
constFirst() != selectionRange()) {
2291 PlainSecondaryCursor c;
2296 searchRange.setStart(matches.
constFirst().end());
2298 }
while (matches.
first().isValid());
2301 if (!resultRanges.
empty()) {
2305 clearSecondaryCursors();
2306 addSecondaryCursorsWithSelection(resultRanges);
2310void KTextEditor::ViewPrivate::replace()
2312 currentInputMode()->findReplace();
2316void KTextEditor::ViewPrivate::findNext()
2318 currentInputMode()->findNext();
2322void KTextEditor::ViewPrivate::findPrevious()
2324 currentInputMode()->findPrevious();
2327void KTextEditor::ViewPrivate::showSearchWrappedHint(
bool isReverseSearch)
2330 const QIcon icon = isReverseSearch ?
QIcon::fromTheme(QStringLiteral(
"go-up-search")) : QIcon::fromTheme(QStringLiteral(
"go-down-search"));
2332 if (!m_wrappedMessage || m_isLastSearchReversed != isReverseSearch) {
2333 m_isLastSearchReversed = isReverseSearch;
2335 m_wrappedMessage->setIcon(icon);
2337 m_wrappedMessage->setAutoHide(2000);
2339 m_wrappedMessage->setView(
this);
2344void KTextEditor::ViewPrivate::createMultiCursorsFromSelection()
2346 if (!selection() || selectionRange().isEmpty()) {
2351 clearSecondaryCursors();
2353 const auto range = selectionRange();
2354 QList<KTextEditor::Cursor> cursorsToAdd;
2357 const auto currentLine = cursorPosition().line();
2358 setCursorPosition({currentLine, doc()->
lineLength(currentLine)});
2359 for (
int line =
start; line <=
end; ++line) {
2360 if (line != currentLine) {
2366 setSecondaryCursors(cursorsToAdd);
2369void KTextEditor::ViewPrivate::removeCursorsFromEmptyLines()
2371 if (!m_secondaryCursors.empty()) {
2372 std::vector<KTextEditor::Cursor> cursorsToRemove;
2373 for (
const auto &c : m_secondaryCursors) {
2374 auto cursor = c.cursor();
2375 if (doc()->lineLength(cursor.line()) == 0) {
2376 cursorsToRemove.push_back(cursor);
2379 removeSecondaryCursors(cursorsToRemove);
2383void KTextEditor::ViewPrivate::slotSelectionChanged()
2385 m_copy->setEnabled(selection() || m_config->smartCopyCut());
2386 m_deSelect->setEnabled(selection());
2387 m_copyHtmlAction->setEnabled(selection());
2390 selectionChangedForHighlights();
2392 if (doc()->readOnly()) {
2396 m_cut->setEnabled(selection() || m_config->smartCopyCut());
2397 m_screenshotSelection->setVisible(selection());
2398 m_screenshotSelection->setEnabled(selection());
2402void KTextEditor::ViewPrivate::switchToCmdLine()
2404 currentInputMode()->activateCommandLine();
2407KateRenderer *KTextEditor::ViewPrivate::renderer()
2412KateRendererConfig *KTextEditor::ViewPrivate::rendererConfig()
2414 return m_renderer->config();
2417void KTextEditor::ViewPrivate::updateConfig()
2423 m_toggleShowSpace->setChecked(doc()->config()->showSpaces() != KateDocumentConfig::WhitespaceRendering::None);
2426 if (m_hasWrap != config()->dynWordWrap()) {
2427 m_hasWrap = config()->dynWordWrap();
2429 m_viewInternal->dynWrapChanged();
2431 m_setDynWrapIndicators->setEnabled(config()->dynWordWrap());
2432 m_toggleDynWrap->setChecked(config()->dynWordWrap());
2435 m_viewInternal->m_leftBorder->setDynWrapIndicators(config()->dynWordWrapIndicators());
2436 m_setDynWrapIndicators->setCurrentItem(config()->dynWordWrapIndicators());
2439 m_viewInternal->m_leftBorder->setLineNumbersOn(config()->lineNumbers());
2440 m_toggleLineNumbers->setChecked(config()->lineNumbers());
2443 m_viewInternal->m_leftBorder->setIconBorderOn(config()->iconBar());
2444 m_toggleIconBar->setChecked(config()->iconBar());
2447 m_viewInternal->m_lineScroll->setShowMarks(config()->scrollBarMarks());
2448 m_toggleScrollBarMarks->setChecked(config()->scrollBarMarks());
2451 m_viewInternal->m_lineScroll->setShowMiniMap(config()->scrollBarMiniMap());
2452 m_toggleScrollBarMiniMap->setChecked(config()->scrollBarMiniMap());
2455 m_viewInternal->m_lineScroll->setMiniMapAll(config()->scrollBarMiniMapAll());
2459 m_viewInternal->m_lineScroll->setMiniMapWidth(config()->scrollBarMiniMapWidth());
2462 m_toggleBlockSelection->setChecked(blockSelection());
2463 m_toggleInsert->setChecked(isOverwriteMode());
2465 updateFoldingConfig();
2468 m_bookmarks->setSorting((KateBookmarks::Sorting)config()->bookmarkSort());
2470 m_viewInternal->setAutoCenterLines(config()->autoCenterLines());
2472 for (
const auto &input : m_viewInternal->m_inputModes) {
2473 input->updateConfig();
2476 setInputMode(config()->inputMode(),
false );
2478 reflectOnTheFlySpellCheckStatus(doc()->isOnTheFlySpellCheckingEnabled());
2481 bool wc = config()->wordCompletion();
2490 bool kc = config()->keywordCompletion();
2499 m_cut->setEnabled(doc()->isReadWrite() && (selection() || m_config->smartCopyCut()));
2500 m_copy->setEnabled(selection() || m_config->smartCopyCut());
2502 m_accessibilityEnabled = m_config->value(KateViewConfig::EnableAccessibility).toBool();
2506 m_statusBar->updateStatus();
2510 m_viewInternal->cache()->clear();
2514 Q_EMIT configChanged(
this);
2517void KTextEditor::ViewPrivate::updateDocumentConfig()
2523 m_updatingDocumentConfig =
true;
2525 m_setEndOfLine->setCurrentItem(doc()->config()->eol());
2527 m_addBom->setChecked(doc()->config()->
bom());
2529 m_updatingDocumentConfig =
false;
2532 ensureCursorColumnValid();
2535 m_renderer->setTabWidth(doc()->config()->tabWidth());
2536 m_renderer->setIndentWidth(doc()->config()->indentationWidth());
2539 m_viewInternal->cache()->clear();
2544void KTextEditor::ViewPrivate::updateRendererConfig()
2550 m_toggleWWMarker->setChecked(m_renderer->config()->wordWrapMarker());
2552 m_viewInternal->updateBracketMarkAttributes();
2553 m_viewInternal->updateBracketMarks();
2556 m_viewInternal->cache()->clear();
2558 m_viewInternal->updateView(
true);
2561 m_viewInternal->m_leftBorder->updateFont();
2562 m_viewInternal->m_leftBorder->repaint();
2564 m_viewInternal->m_lineScroll->queuePixmapUpdate();
2566 currentInputMode()->updateRendererConfig();
2570 Q_EMIT configChanged(
this);
2573void KTextEditor::ViewPrivate::updateFoldingConfig()
2576 m_viewInternal->m_leftBorder->setFoldingMarkersOn(config()->foldingBar());
2577 m_toggleFoldingMarkers->setChecked(config()->foldingBar());
2579 if (hasCommentInFirstLine(m_doc)) {
2580 if (config()->foldFirstLine() && !m_autoFoldedFirstLine) {
2582 m_autoFoldedFirstLine =
true;
2583 }
else if (!config()->foldFirstLine() && m_autoFoldedFirstLine) {
2585 m_autoFoldedFirstLine =
false;
2588 m_autoFoldedFirstLine =
false;
2593 const QStringList l = {
2594 QStringLiteral(
"folding_toplevel")
2595 , QStringLiteral(
"folding_expandtoplevel")
2596 , QStringLiteral(
"folding_toggle_current")
2597 , QStringLiteral(
"folding_toggle_in_current")
2601 for (
int z = 0; z < l.
size(); z++)
2602 if ((a = actionCollection()->action(l[z].toAscii().constData()))) {
2603 a->
setEnabled(doc()->highlight() && doc()->highlight()->allowsFolding());
2608void KTextEditor::ViewPrivate::ensureCursorColumnValid()
2610 KTextEditor::Cursor c = m_viewInternal->cursorPosition();
2615 if (!blockSelection() && wrapCursor() && (!c.
isValid() || c.
column() > doc()->lineLength(c.
line()))) {
2616 c.
setColumn(doc()->lineLength(cursorPosition().line()));
2617 setCursorPosition(c);
2622void KTextEditor::ViewPrivate::editStart()
2624 m_viewInternal->editStart();
2627void KTextEditor::ViewPrivate::editEnd(
int editTagLineStart,
int editTagLineEnd,
bool tagFrom)
2629 m_viewInternal->editEnd(editTagLineStart, editTagLineEnd, tagFrom);
2630 textFolding().editEnd(editTagLineStart, editTagLineEnd, [
this](
int line) {
2631 return m_doc->buffer().isFoldingStartingOnLine(line).first;
2635void KTextEditor::ViewPrivate::editSetCursor(
const KTextEditor::Cursor cursor)
2637 m_viewInternal->editSetCursor(cursor);
2642bool KTextEditor::ViewPrivate::tagLine(
const KTextEditor::Cursor virtualCursor)
2644 return m_viewInternal->tagLine(virtualCursor);
2647bool KTextEditor::ViewPrivate::tagRange(KTextEditor::Range range,
bool realLines)
2649 return m_viewInternal->tagRange(range, realLines);
2652bool KTextEditor::ViewPrivate::tagLines(KTextEditor::LineRange lineRange,
bool realLines)
2654 return m_viewInternal->tagLines(lineRange.
start(), lineRange.
end(), realLines);
2657bool KTextEditor::ViewPrivate::tagLines(KTextEditor::Cursor
start, KTextEditor::Cursor end,
bool realCursors)
2659 return m_viewInternal->tagLines(
start, end, realCursors);
2662void KTextEditor::ViewPrivate::tagAll()
2664 m_viewInternal->tagAll();
2667void KTextEditor::ViewPrivate::clear()
2669 m_viewInternal->clear();
2672void KTextEditor::ViewPrivate::repaintText(
bool paintOnlyDirty)
2674 if (paintOnlyDirty) {
2675 m_viewInternal->updateDirty();
2677 m_viewInternal->update();
2681void KTextEditor::ViewPrivate::updateView(
bool changed)
2684 m_viewInternal->updateView(changed);
2685 m_viewInternal->m_leftBorder->update();
2690void KTextEditor::ViewPrivate::slotHlChanged()
2692 KateHighlighting *hl = doc()->highlight();
2693 bool ok(!hl->getCommentStart(0).
isEmpty() || !hl->getCommentSingleLineStart(0).
isEmpty());
2695 if (actionCollection()->action(QStringLiteral(
"tools_comment"))) {
2696 actionCollection()->action(QStringLiteral(
"tools_comment"))->setEnabled(ok);
2699 if (actionCollection()->action(QStringLiteral(
"tools_uncomment"))) {
2700 actionCollection()->action(QStringLiteral(
"tools_uncomment"))->setEnabled(ok);
2703 if (actionCollection()->action(QStringLiteral(
"tools_toggle_comment"))) {
2704 actionCollection()->action(QStringLiteral(
"tools_toggle_comment"))->setEnabled(ok);
2708 updateFoldingConfig();
2711int KTextEditor::ViewPrivate::virtualCursorColumn()
const
2713 return doc()->toVirtualColumn(m_viewInternal->cursorPosition());
2716void KTextEditor::ViewPrivate::notifyMousePositionChanged(
const KTextEditor::Cursor newPosition)
2718 Q_EMIT mousePositionChanged(
this, newPosition);
2723bool KTextEditor::ViewPrivate::setSelection(KTextEditor::Range selection)
2726 if (selection == m_selection) {
2731 KTextEditor::Range oldSelection = m_selection;
2737 tagSelection(oldSelection);
2741 Q_EMIT selectionChanged(
this);
2747bool KTextEditor::ViewPrivate::clearSelection()
2749 return clearSelection(
true);
2752bool KTextEditor::ViewPrivate::clearSelection(
bool redraw,
bool finishedChangingSelection)
2760 KTextEditor::Range oldSelection = m_selection;
2766 tagSelection(oldSelection);
2772 if (finishedChangingSelection) {
2773 Q_EMIT selectionChanged(
this);
2776 m_viewInternal->m_selChangedByUser =
false;
2781bool KTextEditor::ViewPrivate::selection()
const
2783 if (!wrapCursor()) {
2786 return m_selection.toRange().isValid();
2790QString KTextEditor::ViewPrivate::selectionText()
const
2793 return doc()->
text(m_selection, blockSelect);
2796 QVarLengthArray<KTextEditor::Range, 16> ranges;
2797 for (
const auto &c : m_secondaryCursors) {
2802 ranges.
push_back(m_selection.toRange());
2803 std::sort(ranges.
begin(), ranges.
end());
2806 text.
reserve(ranges.
size() * m_selection.toRange().columnWidth());
2807 for (
int i = 0; i < ranges.
size() - 1; ++i) {
2808 text += doc()->
text(ranges[i]) + QStringLiteral(
"\n");
2810 text += doc()->
text(ranges.
last());
2815bool KTextEditor::ViewPrivate::removeSelectedText()
2817 if (!hasSelections()) {
2821 KTextEditor::Document::EditingTransaction t(doc());
2823 bool removed =
false;
2826 completionWidget()->setIgnoreBufferSignals(
true);
2827 for (
auto &c : m_secondaryCursors) {
2830 doc()->removeText(c.range->toRange());
2834 completionWidget()->setIgnoreBufferSignals(
false);
2838 KTextEditor::Range selection = m_selection;
2842 doc()->removeText(selection, blockSelect);
2847 int selectionColumn = qMin(doc()->toVirtualColumn(selection.
start()), doc()->toVirtualColumn(selection.
end()));
2848 KTextEditor::Range newSelection = selection;
2849 newSelection.
setStart(KTextEditor::Cursor(newSelection.
start().
line(), doc()->fromVirtualColumn(newSelection.
start().
line(), selectionColumn)));
2850 newSelection.
setEnd(KTextEditor::Cursor(newSelection.
end().
line(), doc()->fromVirtualColumn(newSelection.
end().
line(), selectionColumn)));
2851 setSelection(newSelection);
2852 setCursorPositionInternal(newSelection.
start());
2854 clearSecondarySelections();
2855 clearSelection(
false);
2861bool KTextEditor::ViewPrivate::selectAll()
2863 clearSecondaryCursors();
2864 setBlockSelection(
false);
2871 setSelection(doc()->documentRange());
2872 m_viewInternal->moveCursorToSelectionEdge(
false);
2873 m_viewInternal->updateMicroFocus();
2877bool KTextEditor::ViewPrivate::cursorSelected(
const KTextEditor::Cursor cursor)
2879 KTextEditor::Cursor ret = cursor;
2880 if ((!blockSelect) && (ret.
column() < 0)) {
2885 return cursor.
line() >= m_selection.start().line() && ret.
line() <= m_selection.end().line() && ret.
column() >= m_selection.start().column()
2886 && ret.
column() <= m_selection.end().column();
2888 return m_selection.toRange().contains(cursor) || m_selection.end() == cursor;
2892bool KTextEditor::ViewPrivate::lineSelected(
int line)
2894 return !blockSelect && m_selection.toRange().containsLine(line);
2897bool KTextEditor::ViewPrivate::lineEndSelected(
const KTextEditor::Cursor lineEndPos)
2899 return (!blockSelect)
2900 && (lineEndPos.
line() > m_selection.start().line()
2901 || (lineEndPos.
line() == m_selection.start().line() && (m_selection.start().column() < lineEndPos.
column() || lineEndPos.
column() == -1)))
2902 && (lineEndPos.
line() < m_selection.end().line()
2903 || (lineEndPos.
line() == m_selection.end().line() && (lineEndPos.
column() <= m_selection.end().column() && lineEndPos.
column() != -1)));
2906bool KTextEditor::ViewPrivate::lineHasSelected(
int line)
2908 return selection() && m_selection.toRange().
containsLine(line);
2911bool KTextEditor::ViewPrivate::lineIsSelection(
int line)
2913 return (line == m_selection.start().line() && line == m_selection.end().line());
2916void KTextEditor::ViewPrivate::tagSelection(KTextEditor::Range oldSelection)
2919 if (oldSelection.
start().
line() == -1) {
2923 tagLines(m_selection,
true);
2925 }
else if (blockSelection()
2926 && (oldSelection.
start().
column() != m_selection.start().column() || oldSelection.
end().
column() != m_selection.end().column())) {
2928 tagLines(m_selection,
true);
2929 tagLines(oldSelection,
true);
2932 if (oldSelection.
start() != m_selection.
start()) {
2933 tagLines(KTextEditor::LineRange(oldSelection.
start().
line(), m_selection.start().line()),
true);
2936 if (oldSelection.
end() != m_selection.end()) {
2937 tagLines(KTextEditor::LineRange(oldSelection.
end().
line(), m_selection.end().line()),
true);
2943 tagLines(oldSelection,
true);
2947void KTextEditor::ViewPrivate::selectWord(
const KTextEditor::Cursor cursor)
2949 setSelection(doc()->wordRangeAt(cursor));
2952void KTextEditor::ViewPrivate::selectLine(
const KTextEditor::Cursor cursor)
2954 int line = cursor.
line();
2955 if (line + 1 >= doc()->lines()) {
2956 setSelection(KTextEditor::Range(line, 0, line, doc()->lineLength(line)));
2958 setSelection(KTextEditor::Range(line, 0, line + 1, 0));
2962void KTextEditor::ViewPrivate::cut()
2964 if (!selection() && !m_config->smartCopyCut()) {
2970 m_markedSelection =
false;
2974 selectLine(cursorPosition());
2976 removeSelectedText();
2979void KTextEditor::ViewPrivate::copy()
2983 if (!m_config->smartCopyCut()) {
2986 text = doc()->
line(cursorPosition().line()) + QLatin1Char(
'\n');
2987 m_viewInternal->moveEdge(KateViewInternal::left,
false);
2989 text = selectionText();
2991 if (m_markedSelection) {
2993 m_markedSelection =
false;
3001void KTextEditor::ViewPrivate::screenshot()
3007 ScreenshotDialog d(selectionRange(),
this);
3008 d.renderScreenshot(m_renderer);
3012void KTextEditor::ViewPrivate::pasteSelection()
3014 m_temporaryAutomaticInvocationDisabled =
true;
3016 m_temporaryAutomaticInvocationDisabled =
false;
3019void KTextEditor::ViewPrivate::pasteFromFile()
3024 KTextEditor::DocumentPrivate insertDocument;
3025 insertDocument.openUrl(insertFromUrl);
3028 document()->insertText(cursorPosition(), insertDocument.
text());
3031void KTextEditor::ViewPrivate::swapWithClipboard()
3033 m_temporaryAutomaticInvocationDisabled =
true;
3042 doc()->paste(
this, text);
3044 m_temporaryAutomaticInvocationDisabled =
false;
3047void KTextEditor::ViewPrivate::applyWordWrap()
3049 int first = selectionRange().start().line();
3050 int last = selectionRange().end().line();
3052 if (first == last) {
3054 first = cursorPosition().line();
3065bool KTextEditor::ViewPrivate::blockSelection()
const
3070bool KTextEditor::ViewPrivate::setBlockSelection(
bool on)
3072 if (on != blockSelect) {
3075 KTextEditor::Range oldSelection = m_selection;
3077 const bool hadSelection = clearSelection(
false,
false);
3079 setSelection(oldSelection);
3081 m_toggleBlockSelection->setChecked(blockSelection());
3085 ensureCursorColumnValid();
3087 if (!hadSelection) {
3092 Q_EMIT selectionChanged(
this);
3099bool KTextEditor::ViewPrivate::toggleBlockSelection()
3102 clearSecondaryCursors();
3104 m_toggleBlockSelection->setChecked(!blockSelect);
3105 return setBlockSelection(!blockSelect);
3108bool KTextEditor::ViewPrivate::wrapCursor()
const
3110 return !blockSelection();
3115void KTextEditor::ViewPrivate::slotTextInserted(KTextEditor::View *view,
const KTextEditor::Cursor position,
const QString &text)
3117 Q_EMIT textInserted(view, position, text);
3120bool KTextEditor::ViewPrivate::insertTemplateInternal(
const KTextEditor::Cursor c,
const QString &templateString,
const QString &script)
3123 if (templateString.
isEmpty()) {
3128 if (!doc()->isReadWrite()) {
3134 doc()->setActiveTemplateHandler(
nullptr);
3135 doc()->setActiveTemplateHandler(
new KateTemplateHandler(
this, c, templateString, script, doc()->undoManager()));
3139bool KTextEditor::ViewPrivate::tagLines(KTextEditor::Range range,
bool realRange)
3141 return tagLines(range.
start(), range.
end(), realRange);
3144void KTextEditor::ViewPrivate::deactivateEditActions()
3146 for (QAction *action : std::as_const(m_editActions)) {
3147 action->setEnabled(
false);
3151void KTextEditor::ViewPrivate::activateEditActions()
3153 for (QAction *action : std::as_const(m_editActions)) {
3154 action->setEnabled(
true);
3158bool KTextEditor::ViewPrivate::mouseTrackingEnabled()
const
3164bool KTextEditor::ViewPrivate::setMouseTrackingEnabled(
bool)
3170bool KTextEditor::ViewPrivate::isMulticursorNotAllowed()
const
3175void KTextEditor::ViewPrivate::addSecondaryCursor(KTextEditor::Cursor pos)
3177 auto primaryCursor = cursorPosition();
3178 const bool overlapsOrOnPrimary = pos == primaryCursor || (selection() && selectionRange().
contains(pos));
3179 if (overlapsOrOnPrimary && m_secondaryCursors.empty()) {
3183 }
else if (overlapsOrOnPrimary) {
3187 auto &last = m_secondaryCursors.back();
3188 setCursorPosition(last.cursor());
3190 setSelection(last.range->toRange());
3191 Q_ASSERT(last.anchor.isValid());
3192 m_viewInternal->m_selectAnchor = last.anchor;
3194 m_secondaryCursors.pop_back();
3201 if (removeSecondaryCursors({pos},
true)) {
3209 setCursorPosition(pos);
3210 KTextEditor::ViewPrivate::PlainSecondaryCursor p;
3211 p.pos = primaryCursor;
3212 p.range = selection() ? selectionRange() : KTextEditor::
Range::invalid();
3214 addSecondaryCursorsWithSelection({p});
3217void KTextEditor::ViewPrivate::setSecondaryCursors(
const QList<KTextEditor::Cursor> &positions)
3219 clearSecondaryCursors();
3221 if (positions.
isEmpty() || isMulticursorNotAllowed()) {
3225 const auto totalLines = doc()->
lines();
3226 for (
auto p : positions) {
3227 if (p != cursorPosition() && p.line() < totalLines) {
3229 c.pos.reset(
static_cast<Kate::TextCursor *
>(doc()->newMovingCursor(p)));
3230 m_secondaryCursors.push_back(std::move(c));
3238void KTextEditor::ViewPrivate::clearSecondarySelections()
3240 for (
auto &c : m_secondaryCursors) {
3245void KTextEditor::ViewPrivate::clearSecondaryCursors()
3247 if (m_secondaryCursors.empty()) {
3250 for (
const auto &c : m_secondaryCursors) {
3251 tagLine(c.cursor());
3253 m_secondaryCursors.clear();
3254 m_viewInternal->updateDirty();
3257const std::vector<KTextEditor::ViewPrivate::SecondaryCursor> &KTextEditor::ViewPrivate::secondaryCursors()
const
3259 return m_secondaryCursors;
3262QList<KTextEditor::ViewPrivate::PlainSecondaryCursor> KTextEditor::ViewPrivate::plainSecondaryCursors()
const
3264 QList<PlainSecondaryCursor> cursors;
3265 cursors.
reserve(m_secondaryCursors.size());
3266 std::transform(m_secondaryCursors.begin(), m_secondaryCursors.end(), std::back_inserter(cursors), [](
const SecondaryCursor &c) {
3268 return PlainSecondaryCursor{.pos = c.cursor(), .range = c.range->toRange()};
3270 return PlainSecondaryCursor{.pos = c.cursor(), .range = KTextEditor::Range::invalid()};
3275bool KTextEditor::ViewPrivate::removeSecondaryCursors(
const std::vector<KTextEditor::Cursor> &cursorsToRemove,
bool removeIfOverlapsSelection)
3277 Q_ASSERT(std::is_sorted(cursorsToRemove.begin(), cursorsToRemove.end()));
3279 QVarLengthArray<KTextEditor::Cursor, 8> linesToTag;
3281 if (removeIfOverlapsSelection) {
3282 m_secondaryCursors.erase(std::remove_if(m_secondaryCursors.begin(),
3283 m_secondaryCursors.end(),
3284 [&](
const SecondaryCursor &c) {
3285 auto it = std::find_if(cursorsToRemove.begin(), cursorsToRemove.end(), [&c](KTextEditor::Cursor pos) {
3286 return c.cursor() == pos || (c.range && c.range->contains(pos));
3288 const bool match = it != cursorsToRemove.end();
3294 m_secondaryCursors.end());
3296 m_secondaryCursors.erase(std::remove_if(m_secondaryCursors.begin(),
3297 m_secondaryCursors.end(),
3298 [&](
const SecondaryCursor &c) {
3299 auto it = std::find_if(cursorsToRemove.begin(), cursorsToRemove.end(), [&c](KTextEditor::Cursor pos) {
3300 return c.cursor() == pos;
3302 const bool match = it != cursorsToRemove.end();
3308 m_secondaryCursors.end());
3311 for (
const auto &c : linesToTag) {
3312 tagLine(m_viewInternal->toVirtualCursor(c));
3314 return !linesToTag.
empty();
3316 for (
auto cur : cursorsToRemove) {
3317 auto &sec = m_secondaryCursors;
3318 auto it = std::find_if(sec.begin(), sec.end(), [cur](
const SecondaryCursor &c) {
3319 return c.cursor() == cur;
3321 if (it != sec.end()) {
3323 m_secondaryCursors.erase(it);
3324 tagLine(m_viewInternal->toVirtualCursor(cur));
3329 m_viewInternal->updateDirty();
3330 if (cursorPosition() == KTextEditor::Cursor(0, 0)) {
3331 m_viewInternal->paintCursor();
3333 return !linesToTag.
empty();
3338void KTextEditor::ViewPrivate::ensureUniqueCursors(
bool matchLine)
3340 if (m_secondaryCursors.empty()) {
3344 std::vector<SecondaryCursor>::iterator it;
3346 auto matchLine = [](
const SecondaryCursor &l,
const SecondaryCursor &r) {
3347 return l.cursor().line() == r.cursor().line();
3349 it = std::unique(m_secondaryCursors.begin(), m_secondaryCursors.end(), matchLine);
3351 it = std::unique(m_secondaryCursors.begin(), m_secondaryCursors.end());
3353 if (it != m_secondaryCursors.end()) {
3354 m_secondaryCursors.erase(it, m_secondaryCursors.end());
3358 const int ln = cursorPosition().line();
3359 m_secondaryCursors.erase(std::remove_if(m_secondaryCursors.begin(),
3360 m_secondaryCursors.end(),
3361 [ln](
const SecondaryCursor &c) {
3362 return c.cursor().line() == ln;
3364 m_secondaryCursors.end());
3366 const auto cp = cursorPosition();
3367 const auto sel = selectionRange();
3368 m_secondaryCursors.erase(std::remove_if(m_secondaryCursors.begin(),
3369 m_secondaryCursors.end(),
3370 [cp, sel](
const SecondaryCursor &c) {
3371 return c.cursor() == cp && c.selectionRange() == sel;
3373 m_secondaryCursors.end());
3377void KTextEditor::ViewPrivate::addSecondaryCursorsWithSelection(
const QList<PlainSecondaryCursor> &cursorsWithSelection)
3379 if (isMulticursorNotAllowed() || cursorsWithSelection.
isEmpty()) {
3383 for (
const auto &c : cursorsWithSelection) {
3385 if (c.pos == cursorPosition()) {
3389 n.pos.reset(
static_cast<Kate::TextCursor *
>(doc()->newMovingCursor(c.pos)));
3390 if (c.range.isValid()) {
3391 n.range.reset(newSecondarySelectionRange(c.range));
3392 n.anchor = c.range.start() == c.pos ? c.range.end() : c.range.start();
3394 m_secondaryCursors.push_back(std::move(n));
3400Kate::TextRange *KTextEditor::ViewPrivate::newSecondarySelectionRange(KTextEditor::Range selRange)
3403 auto range =
new Kate::TextRange(&doc()->buffer(), selRange, expandBehaviour);
3406 selAttr =
new KTextEditor::Attribute;
3408 selAttr->setBackground(color);
3410 range->setZDepth(-999999.);
3411 range->setAttribute(selAttr);
3415bool KTextEditor::ViewPrivate::hasSelections()
const
3419 return std::any_of(m_secondaryCursors.cbegin(), m_secondaryCursors.cend(), [](
const SecondaryCursor &c) {
3420 return c.range && !c.range->isEmpty();
3424void KTextEditor::ViewPrivate::addSecondaryCursorDown()
3426 KTextEditor::Cursor last = cursorPosition();
3427 const auto &secondary = secondaryCursors();
3428 if (!secondary.empty()) {
3429 last = secondary.back().cursor();
3430 last = std::max(cursorPosition(), last);
3432 if (last.
line() >= doc()->lastLine()) {
3436 auto nextRange = m_viewInternal->nextLayout(last);
3437 if (!nextRange.isValid()) {
3440 auto primaryCursorLineLayout = m_viewInternal->currentLayout(cursorPosition());
3441 if (!primaryCursorLineLayout.isValid()) {
3445 int x = renderer()->cursorToX(primaryCursorLineLayout, cursorPosition().column(), !wrapCursor());
3446 auto next = renderer()->xToCursor(nextRange, x, !wrapCursor());
3447 addSecondaryCursor(next);
3450void KTextEditor::ViewPrivate::addSecondaryCursorUp()
3452 KTextEditor::Cursor last = cursorPosition();
3453 const auto &secondary = secondaryCursors();
3454 if (!secondary.empty()) {
3455 last = secondary.front().cursor();
3456 last = std::min(cursorPosition(), last);
3458 if (last.
line() == 0) {
3461 auto nextRange = m_viewInternal->previousLayout(last);
3462 if (!nextRange.isValid()) {
3466 auto primaryCursorLineLayout = m_viewInternal->currentLayout(cursorPosition());
3467 if (!primaryCursorLineLayout.isValid()) {
3471 int x = renderer()->cursorToX(primaryCursorLineLayout, cursorPosition().column(), !wrapCursor());
3472 auto next = renderer()->xToCursor(nextRange, x, !wrapCursor());
3473 addSecondaryCursor(next);
3476QList<KTextEditor::Cursor> KTextEditor::ViewPrivate::cursors()
const
3478 QList<KTextEditor::Cursor> ret;
3479 ret.
reserve(m_secondaryCursors.size() + 1);
3480 ret << cursorPosition();
3481 std::transform(m_secondaryCursors.begin(), m_secondaryCursors.end(), std::back_inserter(ret), [](
const SecondaryCursor &c) {
3487QList<KTextEditor::Range> KTextEditor::ViewPrivate::selectionRanges()
const
3493 QList<KTextEditor::Range> ret;
3494 ret.
reserve(m_secondaryCursors.size() + 1);
3495 ret << selectionRange();
3496 std::transform(m_secondaryCursors.begin(), m_secondaryCursors.end(), std::back_inserter(ret), [](
const SecondaryCursor &c) {
3498 qWarning() <<
"selectionRanges(): Unexpected null selection range, please fix";
3499 return KTextEditor::Range::invalid();
3501 return c.range->toRange();
3506void KTextEditor::ViewPrivate::setCursors(
const QList<KTextEditor::Cursor> &cursorPositions)
3508 if (isMulticursorNotAllowed()) {
3509 qWarning() <<
"setCursors failed: Multicursors not allowed because one of the following is true"
3510 <<
", blockSelection: " << blockSelection() <<
", overwriteMode: " << isOverwriteMode()
3515 clearSecondaryCursors();
3516 if (cursorPositions.
empty()) {
3520 const auto primary = cursorPositions.
front();
3524 setCursorPosition(primary);
3526 setSecondaryCursors(cursorPositions);
3529void KTextEditor::ViewPrivate::setSelections(
const QList<KTextEditor::Range> &selectionRanges)
3531 if (isMulticursorNotAllowed()) {
3532 qWarning() <<
"setSelections failed: Multicursors not allowed because one of the following is true"
3533 <<
", blockSelection: " << blockSelection() <<
", overwriteMode: " << isOverwriteMode()
3538 clearSecondaryCursors();
3540 if (selectionRanges.
isEmpty()) {
3544 auto first = selectionRanges.
front();
3545 setCursorPosition(first.end());
3546 setSelection(first);
3548 if (selectionRanges.
size() == 1) {
3553 for (
auto it = selectionRanges.
begin() + 1; it != selectionRanges.
end(); ++it) {
3554 KTextEditor::Range r = *it;
3555 KTextEditor::Cursor c = r.
end();
3556 if (c == cursorPosition() || !r.
isValid() || r.
isEmpty() || !docRange.contains(r)) {
3561 n.pos.reset(
static_cast<Kate::TextCursor *
>(doc()->newMovingCursor(c)));
3562 n.range.reset(newSecondarySelectionRange(r));
3563 n.anchor = r.
start();
3564 m_secondaryCursors.push_back(std::move(n));
3566 m_viewInternal->mergeSelections();
3572void KTextEditor::ViewPrivate::sortCursors()
3574 std::sort(m_secondaryCursors.begin(), m_secondaryCursors.end());
3575 ensureUniqueCursors();
3578void KTextEditor::ViewPrivate::paintCursors()
3580 if (m_viewInternal->m_cursorTimer.isActive()) {
3584 renderer()->setDrawCaret(
true);
3586 m_viewInternal->paintCursor();
3589bool KTextEditor::ViewPrivate::isCompletionActive()
const
3591 return completionWidget()->isCompletionActive();
3594KateCompletionWidget *KTextEditor::ViewPrivate::completionWidget()
const
3596 if (!m_completionWidget) {
3597 m_completionWidget =
new KateCompletionWidget(
const_cast<KTextEditor::ViewPrivate *
>(
this));
3600 return m_completionWidget;
3603void KTextEditor::ViewPrivate::startCompletion(KTextEditor::Range word, KTextEditor::CodeCompletionModel *model)
3605 completionWidget()->startCompletion(word, model);
3608void KTextEditor::ViewPrivate::startCompletion(
const Range &word,
3609 const QList<KTextEditor::CodeCompletionModel *> &models,
3610 KTextEditor::CodeCompletionModel::InvocationType invocationType)
3612 completionWidget()->startCompletion(word, models, invocationType);
3615void KTextEditor::ViewPrivate::abortCompletion()
3617 completionWidget()->abortCompletion();
3620void KTextEditor::ViewPrivate::forceCompletion()
3622 completionWidget()->execute();
3625void KTextEditor::ViewPrivate::registerCompletionModel(KTextEditor::CodeCompletionModel *model)
3627 completionWidget()->registerCompletionModel(model);
3630void KTextEditor::ViewPrivate::unregisterCompletionModel(KTextEditor::CodeCompletionModel *model)
3632 completionWidget()->unregisterCompletionModel(model);
3635bool KTextEditor::ViewPrivate::isCompletionModelRegistered(KTextEditor::CodeCompletionModel *model)
const
3637 return completionWidget()->isCompletionModelRegistered(model);
3640QList<KTextEditor::CodeCompletionModel *> KTextEditor::ViewPrivate::codeCompletionModels()
const
3642 return completionWidget()->codeCompletionModels();
3645bool KTextEditor::ViewPrivate::isAutomaticInvocationEnabled()
const
3647 return !m_temporaryAutomaticInvocationDisabled && m_config->automaticCompletionInvocation();
3650void KTextEditor::ViewPrivate::setAutomaticInvocationEnabled(
bool enabled)
3652 config()->setValue(KateViewConfig::AutomaticCompletionInvocation, enabled);
3655void KTextEditor::ViewPrivate::sendCompletionExecuted(
const KTextEditor::Cursor position, KTextEditor::CodeCompletionModel *model,
const QModelIndex &index)
3657 Q_EMIT completionExecuted(
this, position, model, index);
3660void KTextEditor::ViewPrivate::sendCompletionAborted()
3662 Q_EMIT completionAborted(
this);
3665void KTextEditor::ViewPrivate::paste(
const QString *textToPaste)
3667 const int cursorCount = m_secondaryCursors.size() + 1;
3668 if (!textToPaste && cursorCount > 1) {
3672 static const QRegularExpression lineEndings(QStringLiteral(
"\r\n?"));
3673 clipboard.
replace(lineEndings, QStringLiteral(
"\n"));
3678 if (texts.
size() != cursorCount) {
3681 for (
int i = 0; i < cursorCount; ++i) {
3687 if (doc()->multiPaste(
this, texts)) {
3692 m_temporaryAutomaticInvocationDisabled =
true;
3694 m_temporaryAutomaticInvocationDisabled =
false;
3697bool KTextEditor::ViewPrivate::setCursorPosition(KTextEditor::Cursor position)
3699 return setCursorPositionInternal(position, 1,
true);
3702KTextEditor::Cursor KTextEditor::ViewPrivate::cursorPosition()
const
3704 return m_viewInternal->cursorPosition();
3707KTextEditor::Cursor KTextEditor::ViewPrivate::cursorPositionVirtual()
const
3709 return KTextEditor::Cursor(m_viewInternal->cursorPosition().line(), virtualCursorColumn());
3712QPoint KTextEditor::ViewPrivate::cursorToCoordinate(KTextEditor::Cursor cursor)
const
3715 const QPoint pt = m_viewInternal->cursorToCoordinate(cursor,
true,
false);
3716 return pt == QPoint(-1, -1) ? pt : m_viewInternal->mapToParent(pt);
3719KTextEditor::Cursor KTextEditor::ViewPrivate::coordinatesToCursor(
const QPoint &coords)
const
3722 return m_viewInternal->coordinatesToCursor(m_viewInternal->mapFromParent(coords),
false);
3725QPoint KTextEditor::ViewPrivate::cursorPositionCoordinates()
const
3728 const QPoint pt = m_viewInternal->cursorCoordinates(
false);
3729 return pt == QPoint(-1, -1) ? pt : m_viewInternal->mapToParent(pt);
3732void KTextEditor::ViewPrivate::setScrollPositionInternal(KTextEditor::Cursor cursor)
3734 m_viewInternal->scrollPos(cursor,
false,
true,
false);
3737void KTextEditor::ViewPrivate::setHorizontalScrollPositionInternal(
int x)
3739 m_viewInternal->scrollColumns(x);
3742KTextEditor::Cursor KTextEditor::ViewPrivate::maxScrollPositionInternal()
const
3744 return m_viewInternal->maxStartPos(
true);
3747int KTextEditor::ViewPrivate::firstDisplayedLineInternal(LineType lineType)
const
3749 if (lineType == RealLine) {
3750 return m_textFolding.visibleLineToLine(m_viewInternal->startLine());
3752 return m_viewInternal->startLine();
3756int KTextEditor::ViewPrivate::lastDisplayedLineInternal(LineType lineType)
const
3758 if (lineType == RealLine) {
3759 return m_textFolding.visibleLineToLine(m_viewInternal->endLine());
3761 return m_viewInternal->endLine();
3765QRect KTextEditor::ViewPrivate::textAreaRectInternal()
const
3767 const auto sourceRect = m_viewInternal->rect();
3768 const auto topLeft = m_viewInternal->mapTo(
this, sourceRect.topLeft());
3769 const auto bottomRight = m_viewInternal->mapTo(
this, sourceRect.bottomRight());
3770 return {topLeft, bottomRight};
3773bool KTextEditor::ViewPrivate::setCursorPositionVisual(
const KTextEditor::Cursor position)
3775 return setCursorPositionInternal(position, doc()->config()->tabWidth(),
true);
3778QScrollBar *KTextEditor::ViewPrivate::verticalScrollBar()
const
3780 return m_viewInternal->m_lineScroll;
3783QScrollBar *KTextEditor::ViewPrivate::horizontalScrollBar()
const
3785 return m_viewInternal->m_columnScroll;
3788bool KTextEditor::ViewPrivate::isLineRTL(
int line)
const
3790 const QString s = doc()->
line(line);
3792 int line = cursorPosition().line();
3794 const int count = doc()->
lines();
3795 for (
int i = 1; i < count; ++i) {
3796 const QString ln = doc()->
line(i);
3803 int line = cursorPosition().line();
3804 for (; line >= 0; --line) {
3805 const QString s = doc()->
line(line);
3818const QTextLayout *KTextEditor::ViewPrivate::textLayout(
const KTextEditor::Cursor pos)
const
3820 KateLineLayout *thisLine = m_viewInternal->cache()->line(pos.
line());
3821 return thisLine && thisLine->isValid() ? &thisLine->layout() :
nullptr;
3824void KTextEditor::ViewPrivate::indent()
3826 if (blockSelect && selection()) {
3827 for (
int line = selectionRange().
start().line(); line <= selectionRange().end().line(); line++) {
3828 KTextEditor::Cursor c(line, 0);
3829 KTextEditor::Range r = KTextEditor::Range(c, c);
3830 doc()->indent(r, 1);
3833 KTextEditor::Cursor c(cursorPosition().line(), 0);
3834 QSet<int> indentedLines = {c.
line()};
3835 KTextEditor::Range r = selection() ? selectionRange() : KTextEditor::
Range(c, c);
3836 doc()->indent(r, 1);
3838 for (
const auto &cursor : secondaryCursors()) {
3839 int line = cursor.cursor().
line();
3840 if (indentedLines.
contains(line)) {
3843 indentedLines.
insert(line);
3844 KTextEditor::Cursor c(line, 0);
3845 KTextEditor::Range r = cursor.range ? cursor.range->toRange() : KTextEditor::Range(c, c);
3846 doc()->indent(r, 1);
3851void KTextEditor::ViewPrivate::unIndent()
3853 if (blockSelect && selection()) {
3854 for (
int line = selectionRange().
start().line(); line <= selectionRange().end().line(); line++) {
3855 KTextEditor::Cursor c(line, 0);
3856 KTextEditor::Range r = KTextEditor::Range(c, c);
3857 doc()->indent(r, -1);
3860 KTextEditor::Cursor c(cursorPosition().line(), 0);
3861 QSet<int> indentedLines = {c.
line()};
3862 KTextEditor::Range r = selection() ? selectionRange() : KTextEditor::
Range(c, c);
3863 doc()->indent(r, -1);
3865 for (
const auto &cursor : secondaryCursors()) {
3866 int line = cursor.cursor().
line();
3867 if (indentedLines.
contains(line)) {
3870 indentedLines.
insert(line);
3871 KTextEditor::Cursor c(line, 0);
3872 KTextEditor::Range r = cursor.range ? cursor.range->toRange() : KTextEditor::Range(c, c);
3873 doc()->indent(r, -1);
3878void KTextEditor::ViewPrivate::cleanIndent()
3880 KTextEditor::Cursor c(cursorPosition().line(), 0);
3881 KTextEditor::Range r = selection() ? selectionRange() : KTextEditor::
Range(c, c);
3882 doc()->indent(r, 0);
3885void KTextEditor::ViewPrivate::formatIndent()
3888 const int line = cursorPosition().line();
3889 KTextEditor::Range formatRange(KTextEditor::Cursor(line, 0), KTextEditor::Cursor(line, 0));
3891 formatRange = selectionRange();
3894 doc()->align(
this, formatRange);
3898void KTextEditor::ViewPrivate::align()
3903void KTextEditor::ViewPrivate::alignOn()
3905 static QString pattern;
3906 KTextEditor::Range range;
3910 range = selectionRange();
3917 doc()->alignOn(range, pattern, this->blockSelection());
3920void KTextEditor::ViewPrivate::comment()
3923 doc()->comment(
this, cursorPosition().line(), cursorPosition().column(), DocumentPrivate::Comment);
3927void KTextEditor::ViewPrivate::uncomment()
3929 doc()->comment(
this, cursorPosition().line(), cursorPosition().column(), DocumentPrivate::UnComment);
3932void KTextEditor::ViewPrivate::toggleComment()
3935 doc()->comment(
this, cursorPosition().line(), cursorPosition().column(), DocumentPrivate::ToggleComment);
3939void KTextEditor::ViewPrivate::uppercase()
3941 doc()->
transform(
this, cursorPosition(), KTextEditor::DocumentPrivate::Uppercase);
3944void KTextEditor::ViewPrivate::killLine()
3946 std::vector<int> linesToRemove;
3947 if (m_selection.isEmpty()) {
3949 linesToRemove.reserve(m_secondaryCursors.size() + 1);
3950 for (
const auto &c : m_secondaryCursors) {
3951 linesToRemove.push_back(c.pos->
line());
3954 linesToRemove.push_back(cursorPosition().line());
3956 linesToRemove.reserve(m_secondaryCursors.size() + 1);
3957 for (
const auto &c : m_secondaryCursors) {
3958 const auto &range = c.range;
3962 for (
int line = range->
end().
line(); line >= range->
start().
line(); line--) {
3963 linesToRemove.push_back(line);
3968 for (
int line = m_selection.end().line(), endLine = m_selection.start().line(); line >= endLine; line--) {
3969 linesToRemove.push_back(line);
3973 std::sort(linesToRemove.begin(), linesToRemove.end(), std::greater{});
3974 linesToRemove.erase(std::unique(linesToRemove.begin(), linesToRemove.end()), linesToRemove.end());
3979 clearSecondarySelections();
3980 int removeCount = 0;
3981 for (
int line : linesToRemove) {
3982 doc()->removeLine(line);
3985 if (removeCount++ > 1000) {
3986 ensureUniqueCursors();
3992 ensureUniqueCursors();
3995void KTextEditor::ViewPrivate::lowercase()
3997 doc()->
transform(
this, cursorPosition(), KTextEditor::DocumentPrivate::Lowercase);
4000void KTextEditor::ViewPrivate::capitalize()
4003 doc()->
transform(
this, cursorPosition(), KTextEditor::DocumentPrivate::Lowercase);
4004 doc()->
transform(
this, cursorPosition(), KTextEditor::DocumentPrivate::Capitalize);
4008void KTextEditor::ViewPrivate::keyReturn()
4010 doc()->newLine(
this);
4011 m_viewInternal->iconBorder()->updateForCursorLineChange();
4012 m_viewInternal->updateView();
4015void KTextEditor::ViewPrivate::smartNewline()
4017 const KTextEditor::Cursor cursor = cursorPosition();
4018 const int ln = cursor.
line();
4030 doc()->insertText(KTextEditor::Cursor(ln + 1, 0), line.
string(0, col));
4033 m_viewInternal->updateView();
4036void KTextEditor::ViewPrivate::noIndentNewline()
4038 doc()->newLine(
this, KTextEditor::DocumentPrivate::NoIndent);
4039 m_viewInternal->iconBorder()->updateForCursorLineChange();
4040 m_viewInternal->updateView();
4043void KTextEditor::ViewPrivate::newLineAbove()
4045 doc()->newLine(
this, KTextEditor::DocumentPrivate::Indent, KTextEditor::DocumentPrivate::Above);
4046 m_viewInternal->iconBorder()->updateForCursorLineChange();
4047 m_viewInternal->updateView();
4050void KTextEditor::ViewPrivate::newLineBelow()
4052 doc()->newLine(
this, KTextEditor::DocumentPrivate::Indent, KTextEditor::DocumentPrivate::Below);
4053 m_viewInternal->iconBorder()->updateForCursorLineChange();
4054 m_viewInternal->updateView();
4057void KTextEditor::ViewPrivate::backspace()
4060 doc()->backspace(
this);
4063void KTextEditor::ViewPrivate::insertTab()
4065 doc()->insertTab(
this, cursorPosition());
4068void KTextEditor::ViewPrivate::deleteWordLeft()
4071 m_viewInternal->wordPrev(
true);
4072 KTextEditor::Range selection = selectionRange();
4073 removeSelectedText();
4076 ensureUniqueCursors();
4078 m_viewInternal->tagRange(selection,
true);
4079 m_viewInternal->updateDirty();
4082void KTextEditor::ViewPrivate::keyDelete()
4084 KTextEditor::Document::EditingTransaction t(doc());
4087 KTextEditor::Range selection = m_selection;
4090 selection = {selection.
start(),
end};
4091 doc()->removeText(selection, blockSelect);
4098 if (removeSelectedText()) {
4102 for (
const auto &c : m_secondaryCursors) {
4104 doc()->removeText(c.range->toRange());
4106 doc()->del(
this, c.cursor());
4111 doc()->del(
this, cursorPosition());
4113 ensureUniqueCursors();
4116void KTextEditor::ViewPrivate::deleteWordRight()
4119 m_viewInternal->wordNext(
true);
4120 KTextEditor::Range selection = selectionRange();
4121 removeSelectedText();
4124 ensureUniqueCursors();
4126 m_viewInternal->tagRange(selection,
true);
4127 m_viewInternal->updateDirty();
4130void KTextEditor::ViewPrivate::transpose()
4133 for (
const auto &c : m_secondaryCursors) {
4134 doc()->transpose(c.cursor());
4136 doc()->transpose(cursorPosition());
4140void KTextEditor::ViewPrivate::transposeWord()
4142 const KTextEditor::Cursor originalCurPos = cursorPosition();
4143 const KTextEditor::Range firstWord = doc()->
wordRangeAt(originalCurPos);
4148 auto wordIsInvalid = [](QStringView word) {
4149 for (
const QChar &character : word) {
4150 if (character.isLetterOrNumber()) {
4157 if (wordIsInvalid(doc()->text(firstWord))) {
4161 setCursorPosition(firstWord.
end());
4163 KTextEditor::Cursor curPos = cursorPosition();
4166 setCursorPosition(firstWord.
start());
4168 curPos = cursorPosition();
4171 setCursorPosition(originalCurPos);
4176 if (wordIsInvalid(doc()->wordAt(curPos))) {
4177 setCursorPosition(originalCurPos);
4181 const KTextEditor::Range secondWord = doc()->
wordRangeAt(curPos);
4182 doc()->swapTextRanges(firstWord, secondWord);
4186 const int offsetFromWordEnd = firstWord.
end().
column() - originalCurPos.
column();
4187 setCursorPosition(cursorPosition() - KTextEditor::Cursor(0, offsetFromWordEnd));
4190void KTextEditor::ViewPrivate::cursorLeft()
4192 if (selection() && !config()->persistentSelection() && !m_markedSelection) {
4193 if (isLineRTL(cursorPosition().line())) {
4194 m_viewInternal->updateCursor(selectionRange().
end());
4197 m_viewInternal->updateCursor(selectionRange().
start());
4201 for (
const auto &c : m_secondaryCursors) {
4205 const bool rtl = isLineRTL(c.cursor().
line());
4208 clearSecondarySelections();
4210 if (isLineRTL(cursorPosition().line())) {
4211 m_viewInternal->cursorNextChar(m_markedSelection);
4213 m_viewInternal->cursorPrevChar(m_markedSelection);
4218void KTextEditor::ViewPrivate::shiftCursorLeft()
4220 if (isLineRTL(cursorPosition().line())) {
4221 m_viewInternal->cursorNextChar(
true);
4223 m_viewInternal->cursorPrevChar(
true);
4227void KTextEditor::ViewPrivate::cursorRight()
4229 if (selection() && !config()->persistentSelection() && !m_markedSelection) {
4230 if (isLineRTL(cursorPosition().line())) {
4231 m_viewInternal->updateCursor(selectionRange().
start());
4234 m_viewInternal->updateCursor(selectionRange().
end());
4238 for (
const auto &c : m_secondaryCursors) {
4245 clearSecondarySelections();
4247 if (isLineRTL(cursorPosition().line())) {
4248 m_viewInternal->cursorPrevChar(m_markedSelection);
4250 m_viewInternal->cursorNextChar(m_markedSelection);
4255void KTextEditor::ViewPrivate::shiftCursorRight()
4257 if (isLineRTL(cursorPosition().line())) {
4258 m_viewInternal->cursorPrevChar(
true);
4260 m_viewInternal->cursorNextChar(
true);
4264void KTextEditor::ViewPrivate::wordLeft()
4266 if (isLineRTL(cursorPosition().line())) {
4267 m_viewInternal->wordNext(m_markedSelection);
4269 m_viewInternal->wordPrev(m_markedSelection);
4273void KTextEditor::ViewPrivate::shiftWordLeft()
4275 if (isLineRTL(cursorPosition().line())) {
4276 m_viewInternal->wordNext(
true);
4278 m_viewInternal->wordPrev(
true);
4282void KTextEditor::ViewPrivate::wordRight()
4284 if (isLineRTL(cursorPosition().line())) {
4285 m_viewInternal->wordPrev(m_markedSelection);
4287 m_viewInternal->wordNext(m_markedSelection);
4291void KTextEditor::ViewPrivate::shiftWordRight()
4293 if (isLineRTL(cursorPosition().line())) {
4294 m_viewInternal->wordPrev(
true);
4296 m_viewInternal->wordNext(
true);
4300void KTextEditor::ViewPrivate::markSelection()
4302 if (m_markedSelection && selection()) {
4304 clearSecondarySelections();
4306 m_markedSelection = !m_markedSelection;
4310void KTextEditor::ViewPrivate::home()
4312 m_viewInternal->home(m_markedSelection);
4315void KTextEditor::ViewPrivate::shiftHome()
4317 m_viewInternal->home(
true);
4320void KTextEditor::ViewPrivate::end()
4322 m_viewInternal->end(m_markedSelection);
4325void KTextEditor::ViewPrivate::shiftEnd()
4327 m_viewInternal->end(
true);
4330void KTextEditor::ViewPrivate::up()
4332 m_viewInternal->cursorUp(m_markedSelection);
4335void KTextEditor::ViewPrivate::shiftUp()
4337 m_viewInternal->cursorUp(
true);
4340void KTextEditor::ViewPrivate::down()
4342 m_viewInternal->cursorDown(m_markedSelection);
4345void KTextEditor::ViewPrivate::shiftDown()
4347 m_viewInternal->cursorDown(
true);
4350void KTextEditor::ViewPrivate::scrollUp()
4352 m_viewInternal->scrollUp();
4355void KTextEditor::ViewPrivate::scrollDown()
4357 m_viewInternal->scrollDown();
4360void KTextEditor::ViewPrivate::topOfView()
4362 m_viewInternal->topOfView();
4365void KTextEditor::ViewPrivate::shiftTopOfView()
4367 m_viewInternal->topOfView(
true);
4370void KTextEditor::ViewPrivate::bottomOfView()
4372 m_viewInternal->bottomOfView();
4375void KTextEditor::ViewPrivate::shiftBottomOfView()
4377 m_viewInternal->bottomOfView(
true);
4380void KTextEditor::ViewPrivate::pageUp()
4382 m_viewInternal->pageUp(m_markedSelection);
4385void KTextEditor::ViewPrivate::shiftPageUp()
4387 m_viewInternal->pageUp(
true);
4390void KTextEditor::ViewPrivate::pageDown()
4392 m_viewInternal->pageDown(m_markedSelection);
4395void KTextEditor::ViewPrivate::shiftPageDown()
4397 m_viewInternal->pageDown(
true);
4400void KTextEditor::ViewPrivate::top()
4402 m_viewInternal->top_home(m_markedSelection);
4405void KTextEditor::ViewPrivate::shiftTop()
4407 m_viewInternal->top_home(
true);
4410void KTextEditor::ViewPrivate::bottom()
4412 m_viewInternal->bottom_end(m_markedSelection);
4415void KTextEditor::ViewPrivate::shiftBottom()
4417 m_viewInternal->bottom_end(
true);
4420void KTextEditor::ViewPrivate::toMatchingBracket()
4422 m_viewInternal->cursorToMatchingBracket();
4425void KTextEditor::ViewPrivate::shiftToMatchingBracket()
4427 m_viewInternal->cursorToMatchingBracket(
true);
4430void KTextEditor::ViewPrivate::toPrevModifiedLine()
4432 const int startLine = cursorPosition().line() - 1;
4435 KTextEditor::Cursor c(line, 0);
4436 m_viewInternal->updateSelection(c,
false);
4437 m_viewInternal->updateCursor(c);
4441void KTextEditor::ViewPrivate::toNextModifiedLine()
4443 const int startLine = cursorPosition().line() + 1;
4446 KTextEditor::Cursor c(line, 0);
4447 m_viewInternal->updateSelection(c,
false);
4448 m_viewInternal->updateCursor(c);
4452KTextEditor::Range KTextEditor::ViewPrivate::selectionRange()
const
4457KTextEditor::Document *KTextEditor::ViewPrivate::document()
const
4462void KTextEditor::ViewPrivate::setContextMenu(QMenu *menu)
4464 if (m_contextMenu) {
4465 disconnect(m_contextMenu.data(), &
QMenu::aboutToShow,
this, &KTextEditor::ViewPrivate::aboutToShowContextMenu);
4466 disconnect(m_contextMenu.data(), &
QMenu::aboutToHide,
this, &KTextEditor::ViewPrivate::aboutToHideContextMenu);
4468 m_contextMenu = menu;
4469 m_userContextMenuSet =
true;
4471 if (m_contextMenu) {
4477QMenu *KTextEditor::ViewPrivate::contextMenu()
const
4479 if (m_userContextMenuSet) {
4480 return m_contextMenu;
4482 KXMLGUIClient *client =
const_cast<KTextEditor::ViewPrivate *
>(
this);
4489 const QList<QWidget *> menuContainers = client->
factory()->containers(QStringLiteral(
"menu"));
4490 for (QWidget *w : menuContainers) {
4491 if (w->objectName() == QLatin1String(
"ktexteditor_popup")) {
4493 QMenu *menu = (QMenu *)w;
4511QMenu *KTextEditor::ViewPrivate::defaultContextMenu(QMenu *menu)
const
4514 menu =
new QMenu(
const_cast<KTextEditor::ViewPrivate *
>(
this));
4528 if (m_pasteSelection) {
4537 QAction *editing = actionCollection()->action(QStringLiteral(
"tools_scripts_Editing"));
4541 if (QAction *spellingSuggestions = actionCollection()->action(QStringLiteral(
"spelling_suggestions"))) {
4545 if (QAction *bookmark = actionCollection()->action(QStringLiteral(
"bookmarks"))) {
4553void KTextEditor::ViewPrivate::aboutToShowContextMenu()
4555 QMenu *menu = qobject_cast<QMenu *>(sender());
4558 Q_EMIT contextMenuAboutToShow(
this, menu);
4562void KTextEditor::ViewPrivate::aboutToHideContextMenu()
4564 m_spellingMenu->cleanUpAfterShown();
4568QStringList KTextEditor::ViewPrivate::configKeys()
const
4570 static const QStringList keys = {QStringLiteral(
"icon-bar"),
4571 QStringLiteral(
"line-numbers"),
4572 QStringLiteral(
"dynamic-word-wrap"),
4573 QStringLiteral(
"background-color"),
4574 QStringLiteral(
"selection-color"),
4575 QStringLiteral(
"search-highlight-color"),
4576 QStringLiteral(
"replace-highlight-color"),
4577 QStringLiteral(
"default-mark-type"),
4578 QStringLiteral(
"allow-mark-menu"),
4579 QStringLiteral(
"folding-bar"),
4580 QStringLiteral(
"folding-preview"),
4581 QStringLiteral(
"icon-border-color"),
4582 QStringLiteral(
"folding-marker-color"),
4583 QStringLiteral(
"line-number-color"),
4584 QStringLiteral(
"current-line-number-color"),
4585 QStringLiteral(
"modification-markers"),
4586 QStringLiteral(
"keyword-completion"),
4587 QStringLiteral(
"word-count"),
4588 QStringLiteral(
"line-count"),
4589 QStringLiteral(
"scrollbar-minimap"),
4590 QStringLiteral(
"scrollbar-preview"),
4591 QStringLiteral(
"font"),
4592 QStringLiteral(
"theme")};
4596QVariant KTextEditor::ViewPrivate::configValue(
const QString &key)
4598 if (key == QLatin1String(
"icon-bar")) {
4599 return config()->iconBar();
4600 }
else if (key == QLatin1String(
"line-numbers")) {
4601 return config()->lineNumbers();
4602 }
else if (key == QLatin1String(
"dynamic-word-wrap")) {
4603 return config()->dynWordWrap();
4604 }
else if (key == QLatin1String(
"background-color")) {
4605 return rendererConfig()->backgroundColor();
4606 }
else if (key == QLatin1String(
"selection-color")) {
4607 return rendererConfig()->selectionColor();
4608 }
else if (key == QLatin1String(
"search-highlight-color")) {
4609 return rendererConfig()->searchHighlightColor();
4610 }
else if (key == QLatin1String(
"replace-highlight-color")) {
4611 return rendererConfig()->replaceHighlightColor();
4612 }
else if (key == QLatin1String(
"default-mark-type")) {
4613 return config()->defaultMarkType();
4614 }
else if (key == QLatin1String(
"allow-mark-menu")) {
4615 return config()->allowMarkMenu();
4616 }
else if (key == QLatin1String(
"folding-bar")) {
4617 return config()->foldingBar();
4618 }
else if (key == QLatin1String(
"folding-preview")) {
4619 return config()->foldingPreview();
4620 }
else if (key == QLatin1String(
"icon-border-color")) {
4621 return rendererConfig()->iconBarColor();
4622 }
else if (key == QLatin1String(
"folding-marker-color")) {
4623 return rendererConfig()->foldingColor();
4624 }
else if (key == QLatin1String(
"line-number-color")) {
4625 return rendererConfig()->lineNumberColor();
4626 }
else if (key == QLatin1String(
"current-line-number-color")) {
4627 return rendererConfig()->currentLineNumberColor();
4628 }
else if (key == QLatin1String(
"modification-markers")) {
4629 return config()->lineModification();
4630 }
else if (key == QLatin1String(
"keyword-completion")) {
4631 return config()->keywordCompletion();
4632 }
else if (key == QLatin1String(
"word-count")) {
4633 return config()->showWordCount();
4634 }
else if (key == QLatin1String(
"line-count")) {
4635 return config()->showLineCount();
4636 }
else if (key == QLatin1String(
"scrollbar-minimap")) {
4637 return config()->scrollBarMiniMap();
4638 }
else if (key == QLatin1String(
"scrollbar-preview")) {
4639 return config()->scrollBarPreview();
4640 }
else if (key == QLatin1String(
"font")) {
4641 return rendererConfig()->baseFont();
4642 }
else if (key == QLatin1String(
"theme")) {
4643 return rendererConfig()->schema();
4650void KTextEditor::ViewPrivate::setConfigValue(
const QString &key,
const QVariant &value)
4653 if (config()->setValue(key, value)) {
4656 }
else if (rendererConfig()->setValue(key, value)) {
4662 if (key == QLatin1String(
"background-color")) {
4663 rendererConfig()->setBackgroundColor(value.
value<QColor>());
4664 }
else if (key == QLatin1String(
"selection-color")) {
4665 rendererConfig()->setSelectionColor(value.
value<QColor>());
4666 }
else if (key == QLatin1String(
"search-highlight-color")) {
4667 rendererConfig()->setSearchHighlightColor(value.
value<QColor>());
4668 }
else if (key == QLatin1String(
"replace-highlight-color")) {
4669 rendererConfig()->setReplaceHighlightColor(value.
value<QColor>());
4670 }
else if (key == QLatin1String(
"icon-border-color")) {
4671 rendererConfig()->setIconBarColor(value.
value<QColor>());
4672 }
else if (key == QLatin1String(
"folding-marker-color")) {
4673 rendererConfig()->setFoldingColor(value.
value<QColor>());
4674 }
else if (key == QLatin1String(
"line-number-color")) {
4675 rendererConfig()->setLineNumberColor(value.
value<QColor>());
4676 }
else if (key == QLatin1String(
"current-line-number-color")) {
4677 rendererConfig()->setCurrentLineNumberColor(value.
value<QColor>());
4683 if (key == QLatin1String(
"dynamic-word-wrap")) {
4684 config()->setDynWordWrap(value.
toBool());
4685 }
else if (key == QLatin1String(
"word-count")) {
4686 config()->setShowWordCount(value.
toBool());
4687 }
else if (key == QLatin1String(
"line-count")) {
4688 config()->setShowLineCount(value.
toBool());
4690 }
else if (key == QLatin1String(
"font") && value.
canConvert<QFont>()) {
4691 rendererConfig()->setFont(value.
value<QFont>());
4693 rendererConfig()->setSchema(value.
toString());
4700void KTextEditor::ViewPrivate::userInvokedCompletion()
4702 completionWidget()->userInvokedCompletion();
4705KateViewBar *KTextEditor::ViewPrivate::bottomViewBar()
const
4707 return m_bottomViewBar;
4710KateGotoBar *KTextEditor::ViewPrivate::gotoBar()
4713 m_gotoBar =
new KateGotoBar(
this);
4714 bottomViewBar()->addBarWidget(m_gotoBar);
4720KateDictionaryBar *KTextEditor::ViewPrivate::dictionaryBar()
4722 if (!m_dictionaryBar) {
4723 m_dictionaryBar =
new KateDictionaryBar(
this);
4724 bottomViewBar()->addBarWidget(m_dictionaryBar);
4727 return m_dictionaryBar;
4730void KTextEditor::ViewPrivate::setAnnotationModel(KTextEditor::AnnotationModel *model)
4732 KTextEditor::AnnotationModel *oldmodel = m_annotationModel;
4733 m_annotationModel = model;
4734 m_viewInternal->m_leftBorder->annotationModelChanged(oldmodel, m_annotationModel);
4737KTextEditor::AnnotationModel *KTextEditor::ViewPrivate::annotationModel()
const
4739 return m_annotationModel;
4742void KTextEditor::ViewPrivate::setAnnotationBorderVisible(
bool visible)
4744 m_viewInternal->m_leftBorder->setAnnotationBorderOn(visible);
4747bool KTextEditor::ViewPrivate::isAnnotationBorderVisible()
const
4749 return m_viewInternal->m_leftBorder->annotationBorderOn();
4752KTextEditor::AbstractAnnotationItemDelegate *KTextEditor::ViewPrivate::annotationItemDelegate()
const
4754 return m_viewInternal->m_leftBorder->annotationItemDelegate();
4757void KTextEditor::ViewPrivate::setAnnotationItemDelegate(KTextEditor::AbstractAnnotationItemDelegate *delegate)
4759 m_viewInternal->m_leftBorder->setAnnotationItemDelegate(delegate);
4762bool KTextEditor::ViewPrivate::uniformAnnotationItemSizes()
const
4764 return m_viewInternal->m_leftBorder->uniformAnnotationItemSizes();
4767void KTextEditor::ViewPrivate::setAnnotationUniformItemSizes(
bool enable)
4769 m_viewInternal->m_leftBorder->setAnnotationUniformItemSizes(enable);
4772KTextEditor::Range KTextEditor::ViewPrivate::visibleRange()
4775 if (!m_viewInternal->endPos().isValid()) {
4776 m_viewInternal->updateView();
4778 return KTextEditor::Range(m_viewInternal->toRealCursor(m_viewInternal->startPos()), m_viewInternal->toRealCursor(m_viewInternal->endPos()));
4781bool KTextEditor::ViewPrivate::event(QEvent *e)
4783 switch (e->
type()) {
4792void KTextEditor::ViewPrivate::toggleOnTheFlySpellCheck(
bool b)
4794 doc()->onTheFlySpellCheckingEnabled(b);
4797void KTextEditor::ViewPrivate::reflectOnTheFlySpellCheckStatus(
bool enabled)
4799 m_spellingMenu->setVisible(enabled);
4800 m_toggleOnTheFlySpellCheck->setChecked(enabled);
4803KateSpellingMenu *KTextEditor::ViewPrivate::spellingMenu()
4805 return m_spellingMenu;
4808void KTextEditor::ViewPrivate::notifyAboutRangeChange(KTextEditor::LineRange lineRange,
bool needsRepaint, Kate::TextRange *deleteRange)
4810#ifdef VIEW_RANGE_DEBUG
4812 qCDebug(LOG_KTE) <<
"trigger attribute changed in line range " << lineRange <<
"needsRepaint" << needsRepaint;
4816 m_rangesCaretIn.remove(deleteRange);
4817 m_rangesMouseIn.remove(deleteRange);
4821 if (needsRepaint && lineRange.
isValid()) {
4822 if (m_lineToUpdateRange.isValid()) {
4823 m_lineToUpdateRange.expandToRange(lineRange);
4825 m_lineToUpdateRange = lineRange;
4830 if (!m_delayedUpdateTimer.isActive()) {
4831 m_delayedUpdateTimer.start();
4835void KTextEditor::ViewPrivate::slotDelayedUpdateOfView()
4837#ifdef VIEW_RANGE_DEBUG
4839 qCDebug(LOG_KTE) <<
"delayed attribute changed in line range" << m_lineToUpdateRange;
4846 if (m_lineToUpdateRange.isValid()) {
4847 tagLines(m_lineToUpdateRange,
true);
4858 QSet<Kate::TextRange *> newRangesIn;
4864 KTextEditor::Cursor currentCursor =
4868 QSet<Kate::TextRange *> validRanges = oldSet;
4871 if (currentCursor.
isValid() && currentCursor.
line() < doc()->buffer().lines()) {
4873 const QList<Kate::TextRange *> rangesForCurrentCursor = doc()->
buffer().
rangesForLine(currentCursor.
line(),
this,
false);
4876 for (Kate::TextRange *range : rangesForCurrentCursor) {
4878 auto attribute = range->attribute();
4879 if ((!attribute || !attribute->dynamicAttribute(activationType)) && !range->feedback()) {
4885 : (currentCursor <= range->toRange().
start())) {
4890 : (range->toRange().
end() < currentCursor)) {
4895 auto it = validRanges.
find(range);
4896 if (it != validRanges.
end()) {
4898 newRangesIn.
insert(range);
4899 validRanges.
erase(it);
4904 newRangesIn.
insert(range);
4906 if (attribute && attribute->dynamicAttribute(activationType)) {
4907 notifyAboutRangeChange(range->
toLineRange(),
true,
nullptr);
4911 if (range->feedback()) {
4913 range->feedback()->mouseEnteredRange(range,
this);
4915 range->feedback()->caretEnteredRange(range,
this);
4916 Q_EMIT caretChangedRange(
this);
4920#ifdef VIEW_RANGE_DEBUG
4922 qCDebug(LOG_KTE) <<
"activated new range" << range <<
"by" << activationType;
4928 for (Kate::TextRange *range : std::as_const(validRanges)) {
4930 if (range->toRange().
isValid() && range->attribute() && range->attribute()->dynamicAttribute(activationType)) {
4931 notifyAboutRangeChange(range->
toLineRange(),
true,
nullptr);
4935 if (range->feedback()) {
4937 range->feedback()->mouseExitedRange(range,
this);
4939 range->feedback()->caretExitedRange(range,
this);
4940 Q_EMIT caretChangedRange(
this);
4946 oldSet = newRangesIn;
4949void KTextEditor::ViewPrivate::postMessage(KTextEditor::Message *message, QList<std::shared_ptr<QAction>> actions)
4952 auto messageWidget = m_messageWidgets[message->
position()];
4953 if (!messageWidget) {
4955 messageWidget =
new KateMessageWidget(m_viewInternal,
true);
4956 m_messageWidgets[message->
position()] = messageWidget;
4957 m_notificationLayout->addWidget(messageWidget, message->
position());
4961 messageWidget->postMessage(message, std::move(actions));
4964KateMessageWidget *KTextEditor::ViewPrivate::messageWidget()
4969void KTextEditor::ViewPrivate::saveFoldingState()
4971 m_savedFoldingState = m_textFolding.exportFoldingRanges();
4974void KTextEditor::ViewPrivate::clearFoldingState()
4976 m_savedFoldingState = {};
4979void KTextEditor::ViewPrivate::applyFoldingState()
4981 m_textFolding.importFoldingRanges(m_savedFoldingState);
4982 m_savedFoldingState = QJsonDocument();
4985void KTextEditor::ViewPrivate::exportHtmlToFile(
const QString &file)
4987 KateExporter(
this).exportToFile(file);
4990void KTextEditor::ViewPrivate::exportHtmlToClipboard()
4992 KateExporter(
this).exportToClipboard();
4995void KTextEditor::ViewPrivate::exportHtmlToFile()
4999 KateExporter(
this).exportToFile(file);
5003void KTextEditor::ViewPrivate::clearHighlights()
5005 m_rangesForHighlights.clear();
5006 m_currentTextForHighlights.clear();
5009void KTextEditor::ViewPrivate::selectionChangedForHighlights()
5013 if (!m_secondaryCursors.empty()) {
5014 for (
const auto &cursor : m_secondaryCursors) {
5022 if (selection() && selectionRange().onSingleLine()) {
5023 text = selectionText();
5024 if (text == m_currentTextForHighlights) {
5031 m_rangesForHighlights.
clear();
5039 m_currentTextForHighlights = text;
5043void KTextEditor::ViewPrivate::createHighlights()
5046 if (m_currentTextForHighlights.isEmpty()) {
5051 m_rangesForHighlights.clear();
5057 QColor fgColor = defaultStyleAttribute(KSyntaxHighlighting::Theme::TextStyle::Normal)->foreground().color();
5058 QColor bgColor = rendererConfig()->searchHighlightColor();
5059 attr->setForeground(fgColor);
5060 attr->setBackground(bgColor);
5062 KTextEditor::Cursor
start(visibleRange().
start());
5063 KTextEditor::Range searchRange;
5069 pattern.
prepend(QLatin1String(
"\\b"));
5073 pattern += QLatin1String(
"\\b");
5076 QList<KTextEditor::Range> matches;
5082 if (matches.
first().isValid()) {
5083 if (matches.
first() != selectionRange()) {
5084 std::unique_ptr<KTextEditor::MovingRange> mr(doc()->newMovingRange(matches.
first()));
5085 mr->setZDepth(-90000.0);
5086 mr->setAttribute(attr);
5088 mr->setAttributeOnlyForViews(
true);
5089 m_rangesForHighlights.push_back(std::move(mr));
5093 }
while (matches.
first().isValid());
5096KateAbstractInputMode *KTextEditor::ViewPrivate::currentInputMode()
const
5098 return m_viewInternal->m_currentInputMode;
5101void KTextEditor::ViewPrivate::toggleInputMode()
5103 if (QAction *a = qobject_cast<QAction *>(sender())) {
5108void KTextEditor::ViewPrivate::cycleInputMode()
5110 InputMode current = currentInputMode()->viewInputMode();
5116bool KTextEditor::ViewPrivate::print()
5118 return KatePrinter::print(
this);
5121void KTextEditor::ViewPrivate::printPreview()
5123 KatePrinter::printPreview(
this);
5129void KTextEditor::ViewPrivate::registerInlineNoteProvider(KTextEditor::InlineNoteProvider *provider)
5131 if (std::find(m_inlineNoteProviders.cbegin(), m_inlineNoteProviders.cend(), provider) == m_inlineNoteProviders.cend()) {
5132 m_inlineNoteProviders.push_back(provider);
5141void KTextEditor::ViewPrivate::unregisterInlineNoteProvider(KTextEditor::InlineNoteProvider *provider)
5143 auto it = std::find(m_inlineNoteProviders.cbegin(), m_inlineNoteProviders.cend(), provider);
5144 if (it != m_inlineNoteProviders.cend()) {
5145 m_inlineNoteProviders.erase(it);
5152QVarLengthArray<KateInlineNoteData, 8> KTextEditor::ViewPrivate::inlineNotes(
int line)
const
5154 QVarLengthArray<KateInlineNoteData, 8> allInlineNotes;
5155 for (KTextEditor::InlineNoteProvider *provider : m_inlineNoteProviders) {
5158 for (
int column : columns) {
5159 const bool underMouse =
Cursor(line, column) == m_viewInternal->m_activeInlineNote.m_position;
5160 KateInlineNoteData note =
5161 {provider,
this, {line, column}, index, underMouse, m_viewInternal->renderer()->currentFont(), m_viewInternal->renderer()->lineHeight()};
5162 allInlineNotes.
append(note);
5166 return allInlineNotes;
5169QRect KTextEditor::ViewPrivate::inlineNoteRect(
const KateInlineNoteData ¬e)
const
5171 return m_viewInternal->inlineNoteRect(note);
5174void KTextEditor::ViewPrivate::inlineNotesReset()
5176 m_viewInternal->m_activeInlineNote = {};
5177 tagLines(KTextEditor::LineRange(0, doc()->lastLine()),
true);
5180void KTextEditor::ViewPrivate::inlineNotesLineChanged(
int line)
5182 if (line == m_viewInternal->m_activeInlineNote.m_position.line()) {
5183 m_viewInternal->m_activeInlineNote = {};
5185 tagLines({line, line},
true);
5192 KateRendererConfig *renderConfig =
const_cast<KTextEditor::ViewPrivate *
>(
this)->rendererConfig();
5197 style =
new KTextEditor::Attribute(*style);
5198 style->setBackground(QBrush(renderConfig->backgroundColor()));
5203QList<KTextEditor::AttributeBlock> KTextEditor::ViewPrivate::lineAttributes(
int line)
5205 QList<KTextEditor::AttributeBlock> attribs;
5207 if (line < 0 || line >= doc()->lines()) {
5211 const Kate::TextLine kateLine = doc()->
kateTextLine(line);
5213 for (qsizetype i = 0; i < intAttrs.size(); ++i) {
5214 if (intAttrs[i].length > 0 && intAttrs[i].attributeValue > 0) {
5215 attribs << KTextEditor::AttributeBlock(intAttrs.at(i).offset, intAttrs.at(i).length, renderer()->attribute(intAttrs.at(i).attributeValue));
5222void KTextEditor::ViewPrivate::copyFileLocation()
const
5228#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)
Q_SCRIPTABLE Q_NOREPLY void start()
Q_SCRIPTABLE bool focusIn(int ms=-1)
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