Warning, file /frameworks/ktexteditor/src/inputmode/katenormalinputmode.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: KDE Developers 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "katenormalinputmode.h" 0008 #include "katecompletionwidget.h" 0009 #include "kateconfig.h" 0010 #include "katedocument.h" 0011 #include "katesearchbar.h" 0012 #include "kateview.h" 0013 #include "kateviewinternal.h" 0014 0015 #include <KLocalizedString> 0016 0017 KateNormalInputMode::KateNormalInputMode(KateViewInternal *viewInternal) 0018 : KateAbstractInputMode(viewInternal) 0019 { 0020 } 0021 0022 void KateNormalInputMode::activate() 0023 { 0024 view()->activateEditActions(); 0025 } 0026 0027 void KateNormalInputMode::deactivate() 0028 { 0029 view()->deactivateEditActions(); 0030 } 0031 0032 void KateNormalInputMode::reset() 0033 { 0034 // nothing todo 0035 } 0036 0037 bool KateNormalInputMode::overwrite() const 0038 { 0039 return view()->doc()->config()->ovr(); 0040 } 0041 0042 void KateNormalInputMode::overwrittenChar(const QChar &) 0043 { 0044 // nothing todo 0045 } 0046 0047 void KateNormalInputMode::clearSelection() 0048 { 0049 view()->clearSelection(); 0050 } 0051 0052 bool KateNormalInputMode::stealKey(QKeyEvent *) 0053 { 0054 return false; 0055 } 0056 0057 KTextEditor::View::InputMode KateNormalInputMode::viewInputMode() const 0058 { 0059 return KTextEditor::View::NormalInputMode; 0060 } 0061 0062 QString KateNormalInputMode::viewInputModeHuman() const 0063 { 0064 return i18n("Normal"); 0065 } 0066 0067 KTextEditor::View::ViewMode KateNormalInputMode::viewMode() const 0068 { 0069 return view()->isOverwriteMode() ? KTextEditor::View::NormalModeOverwrite : KTextEditor::View::NormalModeInsert; 0070 } 0071 0072 QString KateNormalInputMode::viewModeHuman() const 0073 { 0074 return view()->isOverwriteMode() ? i18n("OVERWRITE") : i18n("INSERT"); 0075 } 0076 0077 void KateNormalInputMode::gotFocus() 0078 { 0079 view()->activateEditActions(); 0080 } 0081 0082 void KateNormalInputMode::lostFocus() 0083 { 0084 view()->deactivateEditActions(); 0085 } 0086 0087 void KateNormalInputMode::readSessionConfig(const KConfigGroup &) 0088 { 0089 // do nothing 0090 } 0091 0092 void KateNormalInputMode::writeSessionConfig(KConfigGroup &) 0093 { 0094 // do nothing 0095 } 0096 0097 void KateNormalInputMode::updateConfig() 0098 { 0099 // do nothing 0100 } 0101 0102 void KateNormalInputMode::readWriteChanged(bool) 0103 { 0104 // inform search bar 0105 if (m_searchBar) { 0106 m_searchBar->slotReadWriteChanged(); 0107 } 0108 } 0109 0110 void KateNormalInputMode::find() 0111 { 0112 KateSearchBar *const bar = searchBar(IncrementalSearchBar); 0113 view()->bottomViewBar()->addBarWidget(bar); 0114 view()->bottomViewBar()->showBarWidget(bar); 0115 bar->setFocus(); 0116 } 0117 0118 void KateNormalInputMode::findSelectedForwards() 0119 { 0120 searchBar(IncrementalSearchBarOrKeepMode)->nextMatchForSelection(view(), KateSearchBar::SearchForward); 0121 } 0122 0123 void KateNormalInputMode::findSelectedBackwards() 0124 { 0125 searchBar(IncrementalSearchBarOrKeepMode)->nextMatchForSelection(view(), KateSearchBar::SearchBackward); 0126 } 0127 0128 void KateNormalInputMode::findReplace() 0129 { 0130 KateSearchBar *const bar = searchBar(PowerSearchBar); 0131 view()->bottomViewBar()->addBarWidget(bar); 0132 view()->bottomViewBar()->showBarWidget(bar); 0133 bar->setFocus(); 0134 } 0135 0136 void KateNormalInputMode::findNext() 0137 { 0138 searchBar(IncrementalSearchBarOrKeepMode)->findNext(); 0139 } 0140 0141 void KateNormalInputMode::findPrevious() 0142 { 0143 searchBar(IncrementalSearchBarOrKeepMode)->findPrevious(); 0144 } 0145 0146 void KateNormalInputMode::activateCommandLine() 0147 { 0148 const KTextEditor::Range selection = view()->selectionRange(); 0149 0150 // if the user has selected text, insert the selection's range (start line to end line) in the 0151 // command line when opened 0152 if (selection.start().line() != -1 && selection.end().line() != -1) { 0153 cmdLineBar()->setText(QString::number(selection.start().line() + 1) + QLatin1Char(',') + QString::number(selection.end().line() + 1)); 0154 } 0155 view()->bottomViewBar()->showBarWidget(cmdLineBar()); 0156 cmdLineBar()->setFocus(); 0157 } 0158 0159 KateSearchBar *KateNormalInputMode::searchBar(const SearchBarMode mode) 0160 { 0161 // power mode wanted? 0162 const bool wantPowerMode = (mode == PowerSearchBar); 0163 0164 // create search bar is not there? use right mode 0165 if (!m_searchBar) { 0166 m_searchBar.reset(new KateSearchBar(wantPowerMode, view(), KateViewConfig::global())); 0167 } 0168 0169 // else: switch mode if needed! 0170 else if (mode != IncrementalSearchBarOrKeepMode) { 0171 if (wantPowerMode) { 0172 m_searchBar->enterPowerMode(); 0173 } else { 0174 m_searchBar->enterIncrementalMode(); 0175 } 0176 } 0177 0178 return m_searchBar.get(); 0179 } 0180 0181 KateCommandLineBar *KateNormalInputMode::cmdLineBar() 0182 { 0183 if (!m_cmdLine) { 0184 m_cmdLine.reset(new KateCommandLineBar(view(), view()->bottomViewBar())); 0185 view()->bottomViewBar()->addBarWidget(m_cmdLine.get()); 0186 } 0187 0188 return m_cmdLine.get(); 0189 } 0190 0191 void KateNormalInputMode::updateRendererConfig() 0192 { 0193 if (m_searchBar) { 0194 m_searchBar->updateHighlightColors(); 0195 } 0196 } 0197 0198 bool KateNormalInputMode::keyPress(QKeyEvent *e) 0199 { 0200 // Note: AND'ing with <Shift> is a quick hack to fix Key_Enter 0201 const int key = e->key() | (e->modifiers() & Qt::ShiftModifier); 0202 0203 if (view()->isCompletionActive()) { 0204 if (key == Qt::Key_Tab || key == Qt::SHIFT + Qt::Key_Backtab || key == Qt::Key_Backtab) { 0205 if (KateViewConfig::global()->tabCompletion()) { 0206 e->accept(); 0207 using W = KateCompletionWidget; 0208 const auto direction = key == Qt::Key_Tab ? W::Down : W::Up; 0209 view()->completionWidget()->tabCompletion(direction); 0210 return true; 0211 } 0212 } 0213 0214 if (key == Qt::Key_Enter || key == Qt::Key_Return || key == Qt::Key_Tab) { 0215 if (view()->completionWidget()->execute()) { 0216 e->accept(); 0217 return true; 0218 } 0219 } 0220 } 0221 0222 return false; 0223 } 0224 0225 bool KateNormalInputMode::blinkCaret() const 0226 { 0227 return true; 0228 } 0229 0230 KateRenderer::caretStyles KateNormalInputMode::caretStyle() const 0231 { 0232 return view()->isOverwriteMode() ? KateRenderer::Block : KateRenderer::Line; 0233 } 0234 0235 void KateNormalInputMode::toggleInsert() 0236 { 0237 view()->toggleInsert(); 0238 } 0239 0240 void KateNormalInputMode::launchInteractiveCommand(const QString &command) 0241 { 0242 KateCommandLineBar *cmdLine = cmdLineBar(); 0243 view()->bottomViewBar()->showBarWidget(cmdLine); 0244 cmdLine->setText(command, false); 0245 } 0246 0247 QString KateNormalInputMode::bookmarkLabel(int) const 0248 { 0249 return QString(); 0250 }