• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Kate

  • kde-4.14
  • applications
  • kate
  • part
  • vimode
kateviinputmodemanager.h
Go to the documentation of this file.
1 /* This file is part of the KDE libraries and the Kate part.
2  *
3  * Copyright (C) 2008 Erlend Hamberg <ehamberg@gmail.com>
4  * Copyright (C) 2011 Svyatoslav Kuzmich <svatoslav1@gmail.com>
5  * Copyright (C) 2012 - 2013 Simon St James <kdedevel@etotheipiplusone.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef KATE_VI_INPUT_MODE_MANAGER_INCLUDED
24 #define KATE_VI_INPUT_MODE_MANAGER_INCLUDED
25 
26 #include <QKeyEvent>
27 #include <QList>
28 #include "katepartprivate_export.h"
29 #include <ktexteditor/cursor.h>
30 #include "katedocument.h"
31 
32 class KConfigGroup;
33 class KateView;
34 class KateDocument;
35 class KateViewInternal;
36 class KateViModeBase;
37 class KateViNormalMode;
38 class KateViInsertMode;
39 class KateViVisualMode;
40 class KateViReplaceMode;
41 class KateViKeyParser;
42 class KateViKeyMapper;
43 class QString;
44 
48 enum ViMode {
49  NormalMode,
50  InsertMode,
51  VisualMode,
52  VisualLineMode,
53  VisualBlockMode,
54  ReplaceMode
55 };
56 
57 struct KateViJump {
58  int line;
59  int column;
60 };
61 
62 namespace KTextEditor {
63  class MovingCursor;
64  class Mark;
65  class MarkInterface;
66 }
67 
68 class KATEPART_TESTS_EXPORT KateViInputModeManager : public QObject
69 {
70  Q_OBJECT
71 
72 public:
73  KateViInputModeManager(KateView* view, KateViewInternal* viewInternal);
74  ~KateViInputModeManager();
75 
80  bool handleKeypress(const QKeyEvent *e);
81 
85  void feedKeyPresses(const QString &keyPresses) const;
86 
91  bool isHandlingKeypress() const;
92 
96  ViMode getCurrentViMode() const;
97 
101  ViMode getPreviousViMode() const;
102 
106  bool isAnyVisualMode() const;
107 
111  KateViModeBase* getCurrentViModeHandler() const;
112 
113  const QString getVerbatimKeys() const;
114 
118  void changeViMode(ViMode newMode);
119 
123  void viEnterNormalMode();
124 
128  void viEnterInsertMode();
129 
133  void viEnterVisualMode( ViMode visualMode = VisualMode );
134 
138  void viEnterReplaceMode();
139 
143  KateViNormalMode* getViNormalMode();
144 
148  KateViInsertMode* getViInsertMode();
149 
153  KateViVisualMode* getViVisualMode();
154 
158  KateViReplaceMode* getViReplaceMode();
159 
163  bool isReplayingLastChange() const { return m_isReplayingLastChange; }
164 
168  void appendKeyEventToLog(const QKeyEvent &e);
169 
173  void clearCurrentChangeLog() { m_currentChangeKeyEventsLog.clear(); m_currentChangeCompletionsLog.clear(); }
174 
178  void storeLastChangeCommand();
179 
183  void repeatLastChange();
184 
185  class Completion
186  {
187  public:
188  enum CompletionType { PlainText, FunctionWithoutArgs, FunctionWithArgs };
189  Completion(const QString& completedText, bool removeTail, CompletionType completionType);
190  QString completedText() const;
191  bool removeTail() const;
192  CompletionType completionType() const;
193  private:
194  QString m_completedText;
195  bool m_removeTail;
196  CompletionType m_completionType;
197  };
198  void startRecordingMacro(QChar macroRegister);
199  void finishRecordingMacro();
200  bool isRecordingMacro();
201  void replayMacro(QChar macroRegister);
202  bool isReplayingMacro();
203  void logCompletionEvent(const Completion& completion);
204  Completion nextLoggedCompletion();
205  void doNotLogCurrentKeypress();
206 
212  const QString getLastSearchPattern() const;
213 
219  void setLastSearchPattern( const QString &p );
220 
224  bool lastSearchBackwards() const { return m_lastSearchBackwards; }
225 
229  void setLastSearchBackwards( bool b ) { m_lastSearchBackwards = b; }
230 
231  void setLastSearchCaseSensitive(bool caseSensitive) { m_lastSearchCaseSensitive = caseSensitive; };
232 
233  void setLastSearchPlacesCursorAtEndOfMatch(bool b) { m_lastSearchPlacedCursorAtEndOfMatch = b; };
234 
235  bool lastSearchCaseSensitive() { return m_lastSearchCaseSensitive; };
236 
237  bool lastSearchPlacesCursorAtEndOfMatch() { return m_lastSearchPlacedCursorAtEndOfMatch; };
238 
239  bool getTemporaryNormalMode() { return m_temporaryNormalMode; }
240 
241  void setTemporaryNormalMode(bool b) { m_temporaryNormalMode = b; }
242 
243  void reset();
244 
245  // Jump Lists
246  void addJump(KTextEditor::Cursor cursor);
247  KTextEditor::Cursor getNextJump(KTextEditor::Cursor cursor);
248  KTextEditor::Cursor getPrevJump(KTextEditor::Cursor cursor);
249  void PrintJumpList();
250 
251  // session stuff
252  void readSessionConfig( const KConfigGroup& config );
253  void writeSessionConfig( KConfigGroup& config );
254 
255  // marks
268  void addMark( KateDocument* doc, const QChar& mark, const KTextEditor::Cursor& pos,
269  const bool moveoninsert = true, const bool showmark = true );
270  KTextEditor::Cursor getMarkPosition( const QChar& mark ) const;
271  void syncViMarksAndBookmarks();
272  QString getMarksOnTheLine(int line);
273 
279  static QString modeToString(ViMode mode);
280 
281  KateViKeyMapper* keyMapper();
282 
283 private Q_SLOTS:
284  void markChanged (KTextEditor::Document* doc,
285  KTextEditor::Mark mark,
286  KTextEditor::MarkInterface::MarkChangeAction action);
287 
288 private:
289  KateViNormalMode* m_viNormalMode;
290  KateViInsertMode* m_viInsertMode;
291  KateViVisualMode* m_viVisualMode;
292  KateViReplaceMode* m_viReplaceMode;
293 
294  ViMode m_currentViMode;
295  ViMode m_previousViMode;
296 
297  KateView *m_view;
298  KateViewInternal *m_viewInternal;
299  KateViKeyParser *m_keyParser;
300 
301  // Create a new keymapper for each macro event, to simplify expansion of mappings in macros
302  // where the macro itself was triggered by expanding a mapping!
303  QStack<QSharedPointer<KateViKeyMapper> > m_keyMapperStack;
304 
305  int m_insideHandlingKeyPressCount;
306 
310  bool m_isReplayingLastChange;
311 
312  bool m_isRecordingMacro;
313 
314  QChar m_recordingMacroRegister;
315  QList<QKeyEvent> m_currentMacroKeyEventsLog;
316 
317  int m_macrosBeingReplayedCount;
318  QChar m_lastPlayedMacroRegister;
319 
320  QList<Completion> m_currentMacroCompletionsLog;
321 
327  QStack<QList<Completion> > m_macroCompletionsToReplay;
328  QStack< int > m_nextLoggedMacroCompletionIndex;
329 
334  QList<QKeyEvent> m_currentChangeKeyEventsLog;
335  QList<Completion> m_currentChangeCompletionsLog;
336  QList<Completion> m_lastChangeCompletionsLog;
337  int m_nextLoggedLastChangeComplexIndex;
338 
342  QString m_lastChange;
343 
344  QString m_lastSearchPattern;
348  bool m_lastSearchBackwards;
352  bool m_lastSearchCaseSensitive;
353 
354  bool m_lastSearchPlacedCursorAtEndOfMatch;
355 
359  bool m_temporaryNormalMode;
360 
364  bool m_markSetInsideViInputModeManager;
365 
366  // jump list
367  QList<KateViJump> *jump_list;
368  QList<KateViJump>::iterator current_jump;
369 
370  // marks
371  QMap<QChar, KTextEditor::MovingCursor*> m_marks;
372 
373 };
374 
375 #endif
InsertMode
Definition: kateviinputmodemanager.h:50
KateViInputModeManager::getTemporaryNormalMode
bool getTemporaryNormalMode()
Definition: kateviinputmodemanager.h:239
QChar
KateViModeBase
Definition: katevimodebase.h:64
QMap< QChar, KTextEditor::MovingCursor * >
VisualMode
Definition: kateviinputmodemanager.h:51
KateViInputModeManager::setLastSearchBackwards
void setLastSearchBackwards(bool b)
set search direction of last search.
Definition: kateviinputmodemanager.h:229
ReplaceMode
Definition: kateviinputmodemanager.h:54
katedocument.h
KateViInputModeManager
Definition: kateviinputmodemanager.h:68
KATEPART_TESTS_EXPORT
#define KATEPART_TESTS_EXPORT
Definition: katepartprivate_export.h:36
NormalMode
Definition: kateviinputmodemanager.h:49
KateViJump
Definition: kateviinputmodemanager.h:57
KateViJump::line
int line
Definition: kateviinputmodemanager.h:58
KateViInputModeManager::Completion::PlainText
Definition: kateviinputmodemanager.h:188
QObject
katepartprivate_export.h
KateViJump::column
int column
Definition: kateviinputmodemanager.h:59
KateViewInternal
Definition: kateviewinternal.h:58
KateViInputModeManager::setLastSearchPlacesCursorAtEndOfMatch
void setLastSearchPlacesCursorAtEndOfMatch(bool b)
Definition: kateviinputmodemanager.h:233
KateViVisualMode
Definition: katevivisualmode.h:34
ViMode
ViMode
The four vi modes supported by Kate's vi input mode.
Definition: kateviinputmodemanager.h:48
QString
QList< QKeyEvent >
Kate::Mark
Mark
Definition: katedefaultcolors.h:55
KateViKeyMapper
Definition: katevikeymapper.h:33
KateView
Definition: kateview.h:77
VisualBlockMode
Definition: kateviinputmodemanager.h:53
KateDocument
Definition: katedocument.h:74
KateViInputModeManager::Completion::CompletionType
CompletionType
Definition: kateviinputmodemanager.h:188
KateViInputModeManager::Completion
Definition: kateviinputmodemanager.h:185
KateViNormalMode
Commands for the vi normal mode.
Definition: katevinormalmode.h:49
VisualLineMode
Definition: kateviinputmodemanager.h:52
KateViInputModeManager::lastSearchBackwards
bool lastSearchBackwards() const
get search direction of last search.
Definition: kateviinputmodemanager.h:224
QKeyEvent
KateViInputModeManager::lastSearchCaseSensitive
bool lastSearchCaseSensitive()
Definition: kateviinputmodemanager.h:235
KateViInputModeManager::isReplayingLastChange
bool isReplayingLastChange() const
Definition: kateviinputmodemanager.h:163
KateViKeyParser
for encoding keypresses w/ modifiers into an internal QChar representation and back again to a descri...
Definition: katevikeyparser.h:37
KateViReplaceMode
Commands for the vi replace mode.
Definition: katevireplacemode.h:35
KateViInputModeManager::clearCurrentChangeLog
void clearCurrentChangeLog()
clear the key event log
Definition: kateviinputmodemanager.h:173
KateViInsertMode
Definition: kateviinsertmode.h:45
KateViInputModeManager::lastSearchPlacesCursorAtEndOfMatch
bool lastSearchPlacesCursorAtEndOfMatch()
Definition: kateviinputmodemanager.h:237
KateViInputModeManager::setTemporaryNormalMode
void setTemporaryNormalMode(bool b)
Definition: kateviinputmodemanager.h:241
QStack
KateViInputModeManager::setLastSearchCaseSensitive
void setLastSearchCaseSensitive(bool caseSensitive)
Definition: kateviinputmodemanager.h:231
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal