katesearch.h
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2004-2005 Anders Lund <anders@alweb.dk> 00003 Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org> 00004 Copyright (C) 2001-2004 Christoph Cullmann <cullmann@kde.org> 00005 Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> 00006 Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de> 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Library General Public 00010 License version 2 as published by the Free Software Foundation. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 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 <tqstring.h> 00032 #include <tqregexp.h> 00033 #include <tqstringlist.h> 00034 #include <tqvaluelist.h> 00035 00036 class KateView; 00037 class KateDocument; 00038 class KateSuperRangeList; 00039 00040 class TDEActionCollection; 00041 00042 class KateSearch : public TQObject 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; // after wraping around, search/replace until here 00070 bool wrapped; // have we allready wrapped around ? 00071 bool showNotFound; // pop up annoying dialogs? 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( TDEActionCollection* ); 00091 00092 public slots: 00093 void find(); 00105 void find( const TQString &pattern, long flags, bool add=true, bool shownotfound=false ); 00106 void replace(); 00115 void replace( const TQString &pattern, const TQString &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( TQStringList&, const TQString& ); 00125 static void addToSearchList( const TQString& s ) { addToList( s_searchList, s ); } 00126 static void addToReplaceList( const TQString& s ) { addToList( s_replaceList, s ); } 00127 static TQStringList s_searchList; 00128 static TQStringList s_replaceList; 00129 static TQString 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 TQString getSearchText(); 00142 KateTextCursor getCursor( SearchFlags flags ); 00143 bool doSearch( const TQString& 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 TQValueList<SConfig> m_searchResults; 00157 int m_resultIndex; 00158 00159 int replaces; 00160 TQDialog* replacePrompt; 00161 TQString m_replacement; 00162 TQRegExp m_re; 00163 }; 00164 00168 class KateReplacePrompt : public KDialogBase 00169 { 00170 Q_OBJECT 00171 00172 public: 00177 KateReplacePrompt(TQWidget *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 TQString &cmd, TQString &errorMsg); 00223 bool help(class Kate::View *, const TQString &, TQString &); 00224 TQStringList cmds(); 00225 bool wantsToProcessText( const TQString &/*cmdname*/ ); 00226 void processText( Kate::View *view, const TQString& text ); 00227 00228 private: 00232 void ifindInit( const TQString &cmd ); 00236 void ifindClear(); 00237 00238 long m_ifindFlags; 00239 }; 00240 00241 #endif 00242 00243 // kate: space-indent on; indent-width 2; replace-tabs on;