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

Kate

  • sources
  • kde-4.12
  • 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/searchinterface.h>
30 
31 class KateView;
32 class KateViewConfig;
33 class QVBoxLayout;
34 class QComboBox;
35 
36 namespace Ui {
37  class IncrementalSearchBar;
38  class PowerSearchBar;
39 }
40 
41 namespace KTextEditor {
42  class MovingRange;
43  class Message;
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 
174  void showInfoMessage(const QString& text);
175 
176 private:
177  KateView *const m_view;
178  KateViewConfig *const m_config;
179  QList<KTextEditor::MovingRange*> m_hlRanges;
180  QPointer<KTextEditor::Message> m_infoMessage;
181 
182  // Shared by both dialogs
183  QVBoxLayout *const m_layout;
184  QWidget * m_widget;
185 
186  // Incremental search related
187  Ui::IncrementalSearchBar * m_incUi;
188  KTextEditor::Cursor m_incInitCursor;
189 
190  // Power search related
191  Ui::PowerSearchBar * m_powerUi;
192 
193  // attribute to highlight matches with
194  KTextEditor::Attribute::Ptr highlightMatchAttribute;
195  KTextEditor::Attribute::Ptr highlightReplacementAttribute;
196 
197  // Status backup
198  bool m_incHighlightAll : 1;
199  bool m_incFromCursor : 1;
200  bool m_incMatchCase : 1;
201  bool m_powerMatchCase : 1;
202  bool m_powerFromCursor : 1;
203  bool m_powerHighlightAll : 1;
204  unsigned int m_powerMode : 2;
205  bool m_unitTestMode :1 ;
206 };
207 
208 
209 
210 #endif // KATE_SEARCH_BAR_H
211 
212 // kate: space-indent on; indent-width 4; replace-tabs on;
KSharedPtr
KateSearchBar::MatchFound
Definition: katesearchbar.h:63
KateSearchBar::enableUnitTestMode
void enableUnitTestMode()
Definition: katesearchbar.h:93
QWidget
KateSearchBar
Definition: katesearchbar.h:47
KATEPART_TESTS_EXPORT
#define KATEPART_TESTS_EXPORT
Definition: katepartprivate_export.h:36
find
KAction * find(const QObject *recvr, const char *slot, QObject *parent)
QString
KateSearchBar::MatchMismatch
Definition: katesearchbar.h:66
KateSearchBar::MatchWrappedBackward
Definition: katesearchbar.h:65
KTextEditor::Cursor
findNext
KAction * findNext(const QObject *recvr, const char *slot, QObject *parent)
KateSearchBar::MatchNothing
Definition: katesearchbar.h:67
kateviewhelpers.h
KateViewBarWidget
Definition: kateviewhelpers.h:288
searchinterface.h
attribute.h
katepartprivate_export.h
QComboBox
KateSearchBar::SearchDirection
SearchDirection
Definition: katesearchbar.h:71
KateSearchBar::MatchWrappedForward
Definition: katesearchbar.h:64
KateSearchBar::SearchForward
Definition: katesearchbar.h:72
KateView
Definition: kateview.h:78
KateViewBarWidget::closed
virtual void closed()
Definition: kateviewhelpers.h:296
KTextEditor::Range
Message
Message
QPoint
KateSearchBar::SearchMode
SearchMode
Definition: katesearchbar.h:53
KateSearchBar::MatchResult
MatchResult
Definition: katesearchbar.h:62
KateViewConfig
Definition: kateconfig.h:381
QList< KTextEditor::MovingRange * >
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:52 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
  • Applications
  •   Libraries
  •     libkonq
  • 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