• 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
  • search
katesearchbar.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) 2009-2010 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
4  * Copyright (C) 2007 Sebastian Pipping <webmaster@hartwork.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef KATE_SEARCH_BAR_H
23 #define KATE_SEARCH_BAR_H 1
24 
25 #include "kateviewhelpers.h"
26 #include "katepartprivate_export.h"
27 
28 #include <ktexteditor/attribute.h>
29 #include <ktexteditor/messageinterface.h>
30 #include <ktexteditor/searchinterface.h>
31 
32 class KateView;
33 class KateViewConfig;
34 class QVBoxLayout;
35 class QComboBox;
36 
37 namespace Ui {
38  class IncrementalSearchBar;
39  class PowerSearchBar;
40 }
41 
42 namespace KTextEditor {
43  class MovingRange;
44 }
45 
46 
47 class KATEPART_TESTS_EXPORT KateSearchBar : public KateViewBarWidget {
48  Q_OBJECT
49 
50  friend class SearchBarTest;
51 
52 public:
53  enum SearchMode {
54  // NOTE: Concrete values are important here
55  // to work with the combobox index!
56  MODE_PLAIN_TEXT = 0,
57  MODE_WHOLE_WORDS = 1,
58  MODE_ESCAPE_SEQUENCES = 2,
59  MODE_REGEX = 3
60  };
61 
62  enum MatchResult {
63  MatchFound,
64  MatchWrappedForward,
65  MatchWrappedBackward,
66  MatchMismatch,
67  MatchNothing,
68  MatchNeutral
69  };
70 
71  enum SearchDirection {
72  SearchForward,
73  SearchBackward
74  };
75 
76 public:
77  explicit KateSearchBar(bool initAsPower, KateView* view, KateViewConfig *config);
78  ~KateSearchBar();
79 
80  virtual void closed();
81 
82  bool isPower() const;
83 
84  QString searchPattern() const;
85  QString replacementPattern() const;
86 
87  bool selectionOnly() const;
88  bool matchCase() const;
89 
90  // Only used by KateView
91  static void nextMatchForSelection(KateView * view, SearchDirection searchDirection);
92 
93  void enableUnitTestMode() { m_unitTestMode = true; }
94 
95 public Q_SLOTS:
100  void setSearchPattern(const QString &searchPattern);
101 
106  void setReplacementPattern(const QString &replacementPattern);
107 
108  void setSearchMode(SearchMode mode);
109  void setSelectionOnly(bool selectionOnly);
110  void setMatchCase(bool matchCase);
111 
112  // Called for <F3> and <Shift>+<F3>
113  void findNext();
114  void findPrevious();
115  void findAll();
116 
117  void replaceNext();
118  void replaceAll();
119 
120  // Also used by KateView
121  void enterPowerMode();
122  void enterIncrementalMode();
123 
124  bool clearHighlights();
125  void updateHighlightColors();
126 
127  // read write status of document changed
128  void slotReadWriteChanged ();
129 
130 protected:
131  // Overridden
132  virtual void showEvent(QShowEvent * event);
133 
134 private Q_SLOTS:
135  void onIncPatternChanged(const QString & pattern);
136  void onMatchCaseToggled(bool matchCase);
137 
138  void onReturnPressed();
139  void updateSelectionOnly();
140  void updateIncInitCursor();
141 
142  void onPowerPatternChanged(const QString & pattern);
143 
144  void onPowerModeChanged(int index);
145  void onPowerPatternContextMenuRequest();
146  void onPowerPatternContextMenuRequest(const QPoint&);
147  void onPowerReplacmentContextMenuRequest();
148  void onPowerReplacmentContextMenuRequest(const QPoint&);
149 
150 private:
151  // Helpers
152  bool find(SearchDirection searchDirection = SearchForward, const QString * replacement = 0);
153  int findAll(KTextEditor::Range inputRange, const QString * replacement);
154 
155  bool isPatternValid() const;
156 
157  KTextEditor::Search::SearchOptions searchOptions(SearchDirection searchDirection = SearchForward) const;
158 
159  void highlightMatch(const KTextEditor::Range & range);
160  void highlightReplacement(const KTextEditor::Range & range);
161  void indicateMatch(MatchResult matchResult);
162  static void selectRange(KateView * view, const KTextEditor::Range & range);
163  void selectRange2(const KTextEditor::Range & range);
164 
165  QVector<QString> getCapturePatterns(const QString & pattern) const;
166  void showExtendedContextMenu(bool forPattern, const QPoint& pos);
167 
168  void givePatternFeedback();
169  void addCurrentTextToHistory(QComboBox * combo);
170  void backupConfig(bool ofPower);
171  void sendConfig();
172  void fixForSingleLine(KTextEditor::Range & range, SearchDirection searchDirection);
173 
179  void updateMessage(QPointer<KTextEditor::Message>& message, bool visible, const QString& text,
180  KTextEditor::Message::MessageType type, KTextEditor::Message::MessagePosition position,
181  KTextEditor::Message::AutoHideMode autoHideMode, int durationMs, bool blink);
182 
183  void showInfoMessage(const QString& text);
184 
185 private:
186  KateView *const m_view;
187  KateViewConfig *const m_config;
188  QList<KTextEditor::MovingRange*> m_hlRanges;
189  QPointer<KTextEditor::Message> m_infoMessage;
190  QPointer<KTextEditor::Message> m_wrappedTopMessage;
191  QPointer<KTextEditor::Message> m_wrappedBottomMessage;
192  QPointer<KTextEditor::Message> m_notFoundMessage;
193 
194  // Shared by both dialogs
195  QVBoxLayout *const m_layout;
196  QWidget * m_widget;
197 
198  // Incremental search related
199  Ui::IncrementalSearchBar * m_incUi;
200  KTextEditor::Cursor m_incInitCursor;
201 
202  // Power search related
203  Ui::PowerSearchBar * m_powerUi;
204 
205  // attribute to highlight matches with
206  KTextEditor::Attribute::Ptr highlightMatchAttribute;
207  KTextEditor::Attribute::Ptr highlightReplacementAttribute;
208 
209  // Status backup
210  bool m_incHighlightAll : 1;
211  bool m_incFromCursor : 1;
212  bool m_incMatchCase : 1;
213  bool m_powerMatchCase : 1;
214  bool m_powerFromCursor : 1;
215  bool m_powerHighlightAll : 1;
216  unsigned int m_powerMode : 2;
217  bool m_unitTestMode :1 ;
218 };
219 
220 
221 
222 #endif // KATE_SEARCH_BAR_H
223 
224 // kate: space-indent on; indent-width 4; replace-tabs on;
QWidget
KateSearchBar::MatchFound
Definition: katesearchbar.h:63
KateSearchBar::enableUnitTestMode
void enableUnitTestMode()
Definition: katesearchbar.h:93
KateSearchBar
Definition: katesearchbar.h:47
QPointer< KTextEditor::Message >
KATEPART_TESTS_EXPORT
#define KATEPART_TESTS_EXPORT
Definition: katepartprivate_export.h:36
QPoint
KateSearchBar::MatchMismatch
Definition: katesearchbar.h:66
KateSearchBar::MatchWrappedBackward
Definition: katesearchbar.h:65
KateSearchBar::MatchNothing
Definition: katesearchbar.h:67
kateviewhelpers.h
KateViewBarWidget
Definition: kateviewhelpers.h:294
QWidget::showEvent
virtual void showEvent(QShowEvent *event)
QShowEvent
katepartprivate_export.h
KateSearchBar::SearchDirection
SearchDirection
Definition: katesearchbar.h:71
QVBoxLayout
QString
QList< KTextEditor::MovingRange * >
KateSearchBar::MatchWrappedForward
Definition: katesearchbar.h:64
KateSearchBar::SearchForward
Definition: katesearchbar.h:72
KateView
Definition: kateview.h:77
KateViewBarWidget::closed
virtual void closed()
Definition: kateviewhelpers.h:302
QVector
QWidget::find
QWidget * find(WId id)
KateSearchBar::SearchMode
SearchMode
Definition: katesearchbar.h:53
KateSearchBar::MatchResult
MatchResult
Definition: katesearchbar.h:62
KateViewConfig
Definition: kateconfig.h:381
QComboBox
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