• 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
kateviemulatedcommandbar.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) 2013 Simon St James <kdedevel@etotheipiplusone.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 #ifndef KATEVIEMULATEDCOMMANDBAR_H
21 #define KATEVIEMULATEDCOMMANDBAR_H
22 
23 #include "kateviewhelpers.h"
24 #include "katecmds.h"
25 #include <ktexteditor/cursor.h>
26 #include <ktexteditor/attribute.h>
27 #include <ktexteditor/movingrange.h>
28 
29 class KateView;
30 class QLabel;
31 class QCompleter;
32 class QStringListModel;
33 
40 class KATEPART_TESTS_EXPORT KateViEmulatedCommandBar : public KateViewBarWidget
41 {
42  Q_OBJECT
43 public:
44  enum Mode { NoMode, SearchForward, SearchBackward, Command };
45  explicit KateViEmulatedCommandBar(KateView *view, QWidget* parent = 0);
46  virtual ~KateViEmulatedCommandBar();
47  void init(Mode mode, const QString& initialText = QString());
48  bool isActive();
49  void setCommandResponseMessageTimeout(long commandResponseMessageTimeOutMS);
50  virtual void closed();
51  bool handleKeyPress(const QKeyEvent* keyEvent);
52  bool isSendingSyntheticSearchCompletedKeypress();
53 
54  void startInteractiveSearchAndReplace(QSharedPointer<KateCommands::SedReplace::InteractiveSedReplacer> interactiveSedReplace);
55 
56 private:
57  bool m_isActive;
58  Mode m_mode;
59  KateView *m_view;
60  QLineEdit *m_edit;
61  QLabel *m_barTypeIndicator;
62  void showBarTypeIndicator(Mode mode);
63  KTextEditor::Cursor m_startingCursorPos;
64  bool m_wasAborted;
65  bool m_suspendEditEventFiltering;
66  bool m_waitingForRegister;
67  QLabel *m_waitingForRegisterIndicator;
68  bool m_insertedTextShouldBeEscapedForSearchingAsLiteral;
69 
70  QTimer *m_commandResponseMessageDisplayHide;
71  QLabel* m_commandResponseMessageDisplay;
72  long m_commandResponseMessageTimeOutMS;
73  QString executeCommand(const QString& commandToExecute);
74  void switchToCommandResponseDisplay(const QString& commandResponseMessage);
75 
76  QLabel *m_interactiveSedReplaceLabel;
77  bool m_interactiveSedReplaceActive;
78  void updateInteractiveSedReplaceLabelText();
79  QSharedPointer<KateCommands::SedReplace::InteractiveSedReplacer> m_interactiveSedReplacer;
80  void finishInteractiveSedReplace();
81 
82  void moveCursorTo(const KTextEditor::Cursor& cursorPos);
83 
84  QCompleter *m_completer;
85  QStringListModel *m_completionModel;
86  bool m_isNextTextChangeDueToCompletionChange;
87  enum CompletionType { None, SearchHistory, WordFromDocument, Commands, CommandHistory, SedFindHistory, SedReplaceHistory };
88  CompletionType m_currentCompletionType;
89  void updateCompletionPrefix();
90  void currentCompletionChanged();
91  bool m_completionActive;
92  QString m_textToRevertToIfCompletionAborted;
93  int m_cursorPosToRevertToIfCompletionAborted;
94 
95  KTextEditor::Attribute::Ptr m_highlightMatchAttribute;
96  KTextEditor::MovingRange* m_highlightedMatch;
97  void updateMatchHighlight(const KTextEditor::Range& matchRange);
98  enum BarBackgroundStatus { Normal, MatchFound, NoMatchFound };
99  void setBarBackground(BarBackgroundStatus status);
100 
101  QString m_currentSearchPattern;
102  bool m_currentSearchIsCaseSensitive;
103  bool m_currentSearchIsBackwards;
104  bool m_currentSearchPlacesCursorAtEndOfMatch;
105 
106  bool m_isSendingSyntheticSearchCompletedKeypress;
107 
108  virtual bool eventFilter(QObject* object, QEvent* event);
109  void deleteSpacesToLeftOfCursor();
110  void deleteWordCharsToLeftOfCursor();
111  bool deleteNonWordCharsToLeftOfCursor();
112  QString wordBeforeCursor();
113  QString commandBeforeCursor();
114  void replaceWordBeforeCursorWith(const QString& newWord);
115  void replaceCommandBeforeCursorWith(const QString& newCommand);
116 
117  void activateSearchHistoryCompletion();
118  void activateWordFromDocumentCompletion();
119  void activateCommandCompletion();
120  void activateCommandHistoryCompletion();
121  void activateSedFindHistoryCompletion();
122  void activateSedReplaceHistoryCompletion();
123  void deactivateCompletion();
124  void abortCompletionAndResetToPreCompletion();
125  void setCompletionIndex(int index);
126 
132  struct ParsedSedExpression
133  {
134  bool parsedSuccessfully;
135  int findBeginPos;
136  int findEndPos;
137  int replaceBeginPos;
138  int replaceEndPos;
139  QChar delimiter;
140  };
141  ParsedSedExpression parseAsSedExpression();
142  QString withSedFindTermReplacedWith(const QString& newFindTerm);
143  QString withSedReplaceTermReplacedWith(const QString& newReplaceTerm);
144  QString sedFindTerm();
145  QString sedReplaceTerm();
146  QString withSedDelimiterEscaped(const QString& text);
147 
148  bool isCursorInFindTermOfSed();
149  bool isCursorInReplaceTermOfSed();
150 
155  QString withoutRangeExpression();
156  QString rangeExpression();
157 private slots:
158  void editTextChanged(const QString& newText);
159  void updateMatchHighlightAttrib();
160  void startHideCommandResponseTimer();
161 };
162 
163 #endif
164 
QEvent
QWidget
KateViEmulatedCommandBar::Mode
Mode
Definition: kateviemulatedcommandbar.h:44
QChar
KATEPART_TESTS_EXPORT
#define KATEPART_TESTS_EXPORT
Definition: katepartprivate_export.h:36
kateviewhelpers.h
KateViewBarWidget
Definition: kateviewhelpers.h:294
QTimer
QSharedPointer< KateCommands::SedReplace::InteractiveSedReplacer >
QObject
QObject::eventFilter
virtual bool eventFilter(QObject *watched, QEvent *event)
QString
QStringListModel
KateView
Definition: kateview.h:77
KateViewBarWidget::closed
virtual void closed()
Definition: kateviewhelpers.h:302
QKeyEvent
KateViEmulatedCommandBar::SearchForward
Definition: kateviemulatedcommandbar.h:44
None
Definition: kateviinsertmode.h:39
QLineEdit
QCompleter
QLabel
katecmds.h
KateViEmulatedCommandBar
A KateViewBarWidget that attempts to emulate some of the features of Vim's own command bar...
Definition: kateviemulatedcommandbar.h:40
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:58 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