katesearch.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __KATE_SEARCH_H__
00024 #define __KATE_SEARCH_H__
00025
00026 #include "katecursor.h"
00027 #include "../interfaces/document.h"
00028
00029 #include <kdialogbase.h>
00030
00031 #include <qstring.h>
00032 #include <qregexp.h>
00033 #include <qstringlist.h>
00034 #include <qvaluelist.h>
00035
00036 class KateView;
00037 class KateDocument;
00038 class KateSuperRangeList;
00039
00040 class KActionCollection;
00041
00042 class KateSearch : public QObject
00043 {
00044 Q_OBJECT
00045
00046 friend class KateDocument;
00047
00048 private:
00049 class SearchFlags
00050 {
00051 public:
00052 bool caseSensitive :1;
00053 bool wholeWords :1;
00054 bool fromBeginning :1;
00055 bool backward :1;
00056 bool selected :1;
00057 bool prompt :1;
00058 bool replace :1;
00059 bool finished :1;
00060 bool regExp :1;
00061 bool useBackRefs :1;
00062 };
00063
00064 class SConfig
00065 {
00066 public:
00067 SearchFlags flags;
00068 KateTextCursor cursor;
00069 KateTextCursor wrappedEnd;
00070 bool wrapped;
00071 bool showNotFound;
00072 uint matchedLength;
00073 KateTextCursor selBegin;
00074 KateTextCursor selEnd;
00075 };
00076
00077 public:
00078 enum Dialog_results {
00079 srCancel = KDialogBase::Cancel,
00080 srAll = KDialogBase::User1,
00081 srLast = KDialogBase::User2,
00082 srNo = KDialogBase::User3,
00083 srYes = KDialogBase::Ok
00084 };
00085
00086 public:
00087 KateSearch( KateView* );
00088 ~KateSearch();
00089
00090 void createActions( KActionCollection* );
00091
00092 public slots:
00093 void find();
00105 void find( const QString &pattern, long flags, bool add=true, bool shownotfound=false );
00106 void replace();
00115 void replace( const QString &pattern, const QString &replacement, long flags );
00116 void findAgain( bool reverseDirection );
00117
00118 private slots:
00119 void replaceSlot();
00120 void slotFindNext() { findAgain( false ); }
00121 void slotFindPrev() { findAgain( true ); }
00122
00123 private:
00124 static void addToList( QStringList&, const QString& );
00125 static void addToSearchList( const QString& s ) { addToList( s_searchList, s ); }
00126 static void addToReplaceList( const QString& s ) { addToList( s_replaceList, s ); }
00127 static QStringList s_searchList;
00128 static QStringList s_replaceList;
00129 static QString s_pattern;
00130
00131 void search( SearchFlags flags );
00132 void wrapSearch();
00133 bool askContinue();
00134
00135 void findAgain();
00136 void promptReplace();
00137 void replaceAll();
00138 void replaceOne();
00139 void skipOne();
00140
00141 QString getSearchText();
00142 KateTextCursor getCursor( SearchFlags flags );
00143 bool doSearch( const QString& text );
00144 void exposeFound( KateTextCursor &cursor, int slen );
00145
00146 inline KateView* view() { return m_view; }
00147 inline KateDocument* doc() { return m_doc; }
00148
00149 KateView* m_view;
00150 KateDocument* m_doc;
00151
00152 KateSuperRangeList* m_arbitraryHLList;
00153
00154 SConfig s;
00155
00156 QValueList<SConfig> m_searchResults;
00157 int m_resultIndex;
00158
00159 int replaces;
00160 QDialog* replacePrompt;
00161 QString m_replacement;
00162 QRegExp m_re;
00163 };
00164
00168 class KateReplacePrompt : public KDialogBase
00169 {
00170 Q_OBJECT
00171
00172 public:
00177 KateReplacePrompt(QWidget *parent);
00178
00179 signals:
00183 void clicked();
00184
00185 protected slots:
00189 void slotOk ();
00190
00194 void slotClose ();
00195
00199 void slotUser1 ();
00200
00204 void slotUser2 ();
00205
00209 void slotUser3 ();
00210
00215 void done (int result);
00216 };
00217
00218 class SearchCommand : public Kate::Command, public Kate::CommandExtension
00219 {
00220 public:
00221 SearchCommand() : m_ifindFlags(0) {;}
00222 bool exec(class Kate::View *view, const QString &cmd, QString &errorMsg);
00223 bool help(class Kate::View *, const QString &, QString &);
00224 QStringList cmds();
00225 bool wantsToProcessText( const QString & );
00226 void processText( Kate::View *, const QString& );
00227
00228 private:
00232 void ifindInit( const QString &cmd );
00236 void ifindClear();
00237
00238 long m_ifindFlags;
00239 };
00240
00241 #endif
00242
00243
|