24 #include "katesearch.h"
25 #include "katesearch.moc"
28 #include "katedocument.h"
29 #include "katesupercursor.h"
30 #include "katearbitraryhighlight.h"
31 #include "kateconfig.h"
32 #include "katehighlight.h"
35 #include <kstdaction.h>
36 #include <tdemessagebox.h>
37 #include <kstringhandler.h>
39 #include <kfinddialog.h>
40 #include <kreplacedialog.h>
41 #include <kpushbutton.h>
47 TQStringList KateSearch::s_searchList = TQStringList();
48 TQStringList KateSearch::s_replaceList = TQStringList();
49 TQString KateSearch::s_pattern = TQString();
50 static const bool arbitraryHLExample =
false;
52 KateSearch::KateSearch( KateView* view )
53 : TQObject( view,
"kate search" )
55 , m_doc( view->doc() )
58 m_arbitraryHLList =
new KateSuperRangeList();
59 if (arbitraryHLExample) m_doc->arbitraryHL()->addHighlightToView(m_arbitraryHLList, m_view);
61 connect(replacePrompt,TQ_SIGNAL(clicked()),
this,TQ_SLOT(replaceSlot()));
64 KateSearch::~KateSearch()
66 delete m_arbitraryHLList;
72 i18n(
"Look up the first occurrence of a piece of text or regular expression."));
74 i18n(
"Look up the next occurrence of the search phrase."));
76 i18n(
"Look up the previous occurrence of the search phrase."));
78 i18n(
"Look up a piece of text or regular expression and replace the result with some given text."));
81 void KateSearch::addToList( TQStringList& list,
const TQString& s )
83 if( list.count() > 0 ) {
84 TQStringList::Iterator it = list.find( s );
87 if( list.count() >= 16 )
88 list.remove( list.fromLast() );
93 void KateSearch::find()
96 long searchf = KateViewConfig::global()->searchFlags();
97 if (m_view->hasSelection() && m_view->selStartLine() != m_view->selEndLine())
98 searchf |= KFindDialog::SelectedText;
100 KFindDialog *findDialog =
new KFindDialog ( m_view,
"", searchf,
101 s_searchList, m_view->hasSelection() );
103 findDialog->setPattern (getSearchText());
106 if( findDialog->exec() == TQDialog::Accepted ) {
107 s_searchList = findDialog->findHistory () ;
109 find( TQString(s_searchList.first()), findDialog->options(),
true,
true );
113 m_view->repaintText ();
116 void KateSearch::find(
const TQString &pattern,
long flags,
bool add,
bool shownotfound )
118 KateViewConfig::global()->setSearchFlags( flags );
120 addToList( s_searchList, pattern );
124 SearchFlags searchFlags;
126 searchFlags.caseSensitive = KateViewConfig::global()->searchFlags() & KFindDialog::CaseSensitive;
127 searchFlags.wholeWords = KateViewConfig::global()->searchFlags() & KFindDialog::WholeWordsOnly;
128 searchFlags.fromBeginning = !(KateViewConfig::global()->searchFlags() & KFindDialog::FromCursor)
129 && !(KateViewConfig::global()->searchFlags() & KFindDialog::SelectedText);
130 searchFlags.backward = KateViewConfig::global()->searchFlags() & KFindDialog::FindBackwards;
131 searchFlags.selected = KateViewConfig::global()->searchFlags() & KFindDialog::SelectedText;
132 searchFlags.prompt =
false;
133 searchFlags.replace =
false;
134 searchFlags.finished =
false;
135 searchFlags.regExp = KateViewConfig::global()->searchFlags() & KFindDialog::RegularExpression;
136 searchFlags.useBackRefs = KateViewConfig::global()->searchFlags() & KReplaceDialog::BackReference;
138 if ( searchFlags.selected )
140 s.selBegin =
KateTextCursor( m_view->selStartLine(), m_view->selStartCol() );
141 s.selEnd =
KateTextCursor( m_view->selEndLine(), m_view->selEndCol() );
142 s.cursor = s.flags.backward ? s.selEnd : s.selBegin;
144 s.cursor = getCursor( searchFlags );
147 s.wrappedEnd = s.cursor;
149 s.showNotFound = shownotfound;
151 search( searchFlags );
154 void KateSearch::replace()
156 if (!doc()->isReadWrite())
return;
159 long searchf = KateViewConfig::global()->searchFlags();
160 if (m_view->hasSelection() && m_view->selStartLine() != m_view->selEndLine())
161 searchf |= KFindDialog::SelectedText;
163 KReplaceDialog *replaceDialog =
new KReplaceDialog ( m_view,
"", searchf,
164 s_searchList, s_replaceList, m_view->hasSelection() );
166 replaceDialog->setPattern (getSearchText());
168 if( replaceDialog->exec() == TQDialog::Accepted ) {
169 long opts = replaceDialog->options();
170 m_replacement = replaceDialog->replacement();
171 s_searchList = replaceDialog->findHistory () ;
172 s_replaceList = replaceDialog->replacementHistory () ;
175 replace( TQString(s_searchList.first()), m_replacement, opts );
178 delete replaceDialog;
182 void KateSearch::replace(
const TQString& pattern,
const TQString &replacement,
long flags )
184 if (!doc()->isReadWrite())
return;
186 addToList( s_searchList, pattern );
188 addToList( s_replaceList, replacement );
189 m_replacement = replacement;
190 KateViewConfig::global()->setSearchFlags( flags );
192 SearchFlags searchFlags;
193 searchFlags.caseSensitive = KateViewConfig::global()->searchFlags() & KFindDialog::CaseSensitive;
194 searchFlags.wholeWords = KateViewConfig::global()->searchFlags() & KFindDialog::WholeWordsOnly;
195 searchFlags.fromBeginning = !(KateViewConfig::global()->searchFlags() & KFindDialog::FromCursor)
196 && !(KateViewConfig::global()->searchFlags() & KFindDialog::SelectedText);
197 searchFlags.backward = KateViewConfig::global()->searchFlags() & KFindDialog::FindBackwards;
198 searchFlags.selected = KateViewConfig::global()->searchFlags() & KFindDialog::SelectedText;
199 searchFlags.prompt = KateViewConfig::global()->searchFlags() & KReplaceDialog::PromptOnReplace;
200 searchFlags.replace =
true;
201 searchFlags.finished =
false;
202 searchFlags.regExp = KateViewConfig::global()->searchFlags() & KFindDialog::RegularExpression;
203 searchFlags.useBackRefs = KateViewConfig::global()->searchFlags() & KReplaceDialog::BackReference;
204 if ( searchFlags.selected )
206 s.selBegin =
KateTextCursor( m_view->selStartLine(), m_view->selStartCol() );
207 s.selEnd =
KateTextCursor( m_view->selEndLine(), m_view->selEndCol() );
208 s.cursor = s.flags.backward ? s.selEnd : s.selBegin;
210 s.cursor = getCursor( searchFlags );
213 s.wrappedEnd = s.cursor;
216 search( searchFlags );
219 void KateSearch::findAgain(
bool reverseDirection )
221 SearchFlags searchFlags;
222 searchFlags.caseSensitive = KateViewConfig::global()->searchFlags() & KFindDialog::CaseSensitive;
223 searchFlags.wholeWords = KateViewConfig::global()->searchFlags() & KFindDialog::WholeWordsOnly;
224 searchFlags.fromBeginning = !(KateViewConfig::global()->searchFlags() & KFindDialog::FromCursor)
225 && !(KateViewConfig::global()->searchFlags() & KFindDialog::SelectedText);
226 searchFlags.backward = KateViewConfig::global()->searchFlags() & KFindDialog::FindBackwards;
227 searchFlags.selected = KateViewConfig::global()->searchFlags() & KFindDialog::SelectedText;
228 searchFlags.prompt = KateViewConfig::global()->searchFlags() & KReplaceDialog::PromptOnReplace;
229 searchFlags.replace =
false;
230 searchFlags.finished =
false;
231 searchFlags.regExp = KateViewConfig::global()->searchFlags() & KFindDialog::RegularExpression;
232 searchFlags.useBackRefs = KateViewConfig::global()->searchFlags() & KReplaceDialog::BackReference;
234 if (reverseDirection)
235 searchFlags.backward = !searchFlags.backward;
237 searchFlags.fromBeginning =
false;
238 searchFlags.prompt =
true;
240 s.cursor = getCursor( searchFlags );
241 search( searchFlags );
244 void KateSearch::search( SearchFlags flags )
248 if( s.flags.fromBeginning ) {
249 if( !s.flags.backward ) {
250 s.cursor.setPos(0, 0);
252 s.cursor.setLine(doc()->numLines() - 1);
253 s.cursor.setCol(doc()->lineLength( s.cursor.line() ));
257 if((!s.flags.backward &&
258 s.cursor.col() == 0 &&
259 s.cursor.line() == 0 ) ||
260 ( s.flags.backward &&
261 s.cursor.col() == doc()->lineLength( s.cursor.line() ) &&
262 s.cursor.line() == (((
int)doc()->numLines()) - 1) ) ) {
263 s.flags.finished =
true;
266 if( s.flags.replace ) {
277 void KateSearch::wrapSearch()
279 if( s.flags.selected )
285 if (m_view->blockSelectionMode())
287 start.setCol (kMin(s.selBegin.col(), s.selEnd.col()));
288 end.setCol (kMax(s.selBegin.col(), s.selEnd.col()));
291 s.cursor = s.flags.backward ?
end : start;
295 if( !s.flags.backward ) {
296 s.cursor.setPos(0, 0);
298 s.cursor.setLine(doc()->numLines() - 1);
299 s.cursor.setCol(doc()->lineLength( s.cursor.line() ) );
305 s.wrapped = s.flags.replace;
308 s.flags.finished =
true;
311 void KateSearch::findAgain()
313 if( s_pattern.isEmpty() ) {
318 if ( doSearch( s_pattern ) ) {
319 exposeFound( s.cursor, s.matchedLength );
320 }
else if( !s.flags.finished ) {
321 if( askContinue() ) {
325 if (arbitraryHLExample) m_arbitraryHLList->clear();
328 if (arbitraryHLExample) m_arbitraryHLList->clear();
329 if ( s.showNotFound )
331 i18n(
"Search string '%1' not found!")
337 void KateSearch::replaceAll()
341 while( doSearch( s_pattern ) )
346 if( !s.flags.finished ) {
347 if( askContinue() ) {
353 i18n(
"%n replacement made.",
"%n replacements made.",replaces),
358 void KateSearch::promptReplace()
360 if ( doSearch( s_pattern ) ) {
361 exposeFound( s.cursor, s.matchedLength );
362 replacePrompt->show();
363 replacePrompt->setFocus ();
364 }
else if( !s.flags.finished && askContinue() ) {
368 if (arbitraryHLExample) m_arbitraryHLList->clear();
369 replacePrompt->hide();
371 i18n(
"%n replacement made.",
"%n replacements made.",replaces),
376 void KateSearch::replaceOne()
378 TQString replaceWith = m_replacement;
379 if ( s.flags.regExp && s.flags.useBackRefs ) {
384 TQRegExp br(
"\\\\(.)");
385 int pos = br.search( replaceWith );
386 int ncaps = m_re.numCaptures();
389 TQChar argument = TQString(br.cap(1)).at(0);
390 if ( argument.isDigit() ) {
392 int ccap = argument.digitValue();
393 if (ccap <= ncaps ) {
394 substitute = m_re.cap( ccap );
396 kdDebug()<<
"KateSearch::replaceOne(): you don't have "<<ccap<<
" backreferences in regexp '"<<TQString(m_re.pattern())<<
"'"<<
endl;
399 }
else if ( argument ==
'n' ) {
401 }
else if ( argument ==
't' ) {
405 substitute = argument;
407 replaceWith.replace( pos, br.matchedLength(), substitute );
408 pos = br.search( replaceWith, pos + substitute.length() );
413 doc()->removeText( s.cursor.line(), s.cursor.col(),
414 s.cursor.line(), s.cursor.col() + s.matchedLength );
415 doc()->insertText( s.cursor.line(), s.cursor.col(), replaceWith );
421 uint newlines = replaceWith.contains(
'\n');
424 if ( ! s.flags.backward )
426 s.cursor.setLine( s.cursor.line() + newlines );
427 s.cursor.setCol( replaceWith.length() - replaceWith.findRev(
'\n') );
430 if ( s.flags.selected )
431 s.selEnd.setLine( s.selEnd.line() + newlines );
436 if( s.flags.selected && s.cursor.line() == s.selEnd.line() )
438 s.selEnd.setCol(s.selEnd.col() + replaceWith.length() - s.matchedLength );
442 if( s.cursor.line() == s.wrappedEnd.line() && s.cursor.col() <= s.wrappedEnd.col())
444 s.wrappedEnd.setCol(s.wrappedEnd.col() + replaceWith.length() - s.matchedLength );
447 if( !s.flags.backward ) {
448 s.cursor.setCol(s.cursor.col() + replaceWith.length());
449 }
else if( s.cursor.col() > 0 ) {
450 s.cursor.setCol(s.cursor.col() - 1);
452 s.cursor.setLine(s.cursor.line() - 1);
453 if( s.cursor.line() >= 0 ) {
454 s.cursor.setCol(doc()->lineLength( s.cursor.line() ));
459 void KateSearch::skipOne()
461 if( !s.flags.backward ) {
462 s.cursor.setCol(s.cursor.col() + s.matchedLength);
463 }
else if( s.cursor.col() > 0 ) {
464 s.cursor.setCol(s.cursor.col() - 1);
466 s.cursor.setLine(s.cursor.line() - 1);
467 if( s.cursor.line() >= 0 ) {
468 s.cursor.setCol(doc()->lineLength(s.cursor.line()));
473 void KateSearch::replaceSlot() {
474 switch( (Dialog_results)replacePrompt->result() ) {
475 case srCancel: replacePrompt->hide();
break;
476 case srAll: replacePrompt->hide(); replaceAll();
break;
477 case srYes: replaceOne(); promptReplace();
break;
478 case srLast: replacePrompt->hide(), replaceOne();
break;
479 case srNo: skipOne(); promptReplace();
break;
483 bool KateSearch::askContinue()
486 i18n(
"%n replacement made.",
487 "%n replacements made.",
490 TQString reached = !s.flags.backward ?
491 i18n(
"End of document reached." ) :
492 i18n(
"Beginning of document reached." );
494 if (KateViewConfig::global()->searchFlags() & KFindDialog::SelectedText)
496 reached = !s.flags.backward ?
497 i18n(
"End of selection reached." ) :
498 i18n(
"Beginning of selection reached." );
501 TQString question = !s.flags.backward ?
502 i18n(
"Continue from the beginning?" ) :
503 i18n(
"Continue from the end?" );
505 TQString text = s.flags.replace ?
506 made +
"\n" + reached +
"\n" + question :
507 reached +
"\n" + question;
510 view(), text, s.flags.
replace ? i18n(
"Replace") : i18n(
"Find"),
514 TQString KateSearch::getSearchText()
522 int getFrom = view()->config()->textToSearchMode();
525 case KateViewConfig::SelectionOnly:
527 if( m_view->hasSelection() )
528 str = m_view->selection();
531 case KateViewConfig::SelectionWord:
533 if( m_view->hasSelection() )
534 str = m_view->selection();
539 case KateViewConfig::WordOnly:
544 case KateViewConfig::WordSelection:
547 if (str.isEmpty() && m_view->hasSelection() )
548 str = m_view->selection();
556 str.replace( TQRegExp(
"^\\n"),
"" );
557 str.replace( TQRegExp(
"\\n.*"),
"" );
564 if (flags.backward && !flags.selected && view()->hasSelection())
568 return kMin(
KateTextCursor(view()->selStartLine(), view()->selStartCol()),
569 KateTextCursor(view()->cursorLine(), view()->cursorColumnReal()));
571 return KateTextCursor(view()->cursorLine(), view()->cursorColumnReal());
574 bool KateSearch::doSearch(
const TQString& text )
593 static int oldLine = -1;
594 static int oldCol = -1;
597 uint line = s.cursor.line();
598 uint col = s.cursor.col();
599 bool backward = s.flags.backward;
600 bool caseSensitive = s.flags.caseSensitive;
601 bool regExp = s.flags.regExp;
602 bool wholeWords = s.flags.wholeWords;
603 uint foundLine, foundCol, matchLen;
613 if (docCursor.line() == 0 && docCursor.col() == 0)
618 docCursor.moveBackward(1);
619 line = docCursor.line();
620 col = docCursor.col();
625 m_re = TQRegExp( text, caseSensitive );
626 found = doc()->searchText( line, col, m_re,
627 &foundLine, &foundCol,
628 &matchLen, backward );
630 else if ( wholeWords )
632 bool maybefound =
false;
635 maybefound = doc()->searchText( line, col, text,
636 &foundLine, &foundCol,
637 &matchLen, caseSensitive, backward );
642 ! doc()->highlight()->isInWord( doc()->textLine( foundLine ).at( foundCol - 1 ) ) ) &&
643 ( foundCol + matchLen == doc()->lineLength( foundLine ) ||
644 ! doc()->highlight()->isInWord( doc()->textLine( foundLine ).at( foundCol + matchLen ) ) )
650 else if ( backward && foundCol == 0 )
663 }
while ( maybefound );
666 found = doc()->searchText( line, col, text,
667 &foundLine, &foundCol,
668 &matchLen, caseSensitive, backward );
671 if ( found && s.flags.selected )
677 if (m_view->blockSelectionMode())
679 start.setCol (kMin(s.selBegin.col(), s.selEnd.col()));
680 end.setCol (kMax(s.selBegin.col(), s.selEnd.col()));
683 if ( !s.flags.backward &&
KateTextCursor( foundLine, foundCol ) >= end
684 || s.flags.backward &&
KateTextCursor( foundLine, foundCol ) < start )
688 else if (m_view->blockSelectionMode())
690 if ((
int)foundCol >= start.col() && (
int)foundCol <
end.col())
698 while (s.flags.selected && m_view->blockSelectionMode() && found);
701 if( !found )
return false;
704 s.cursor.setPos(foundLine, foundCol);
705 s.matchedLength = matchLen;
710 if (s.flags.backward)
712 if ( (s.cursor.line() < s.wrappedEnd.line())
713 || ( (s.cursor.line() == s.wrappedEnd.line()) && ((s.cursor.col()+matchLen) <= uint(s.wrappedEnd.col())) ) )
718 if ( (s.cursor.line() > s.wrappedEnd.line())
719 || ( (s.cursor.line() == s.wrappedEnd.line()) && (s.cursor.col() > s.wrappedEnd.col()) ) )
729 if (arbitraryHLExample) {
730 KateArbitraryHighlightRange* hl =
new KateArbitraryHighlightRange(
new KateSuperCursor(m_doc,
true, s.cursor),
new KateSuperCursor(m_doc,
true, s.cursor.line(), s.cursor.col() + s.matchedLength),
this);
732 hl->setTextColor(TQt::white);
733 hl->setBGColor(TQt::black);
735 connect(hl, TQ_SIGNAL(contentsChanged()), hl, TQ_SIGNAL(eliminated()));
736 m_arbitraryHLList->append(hl);
756 view()->setCursorPositionInternal ( cursor.line(), cursor.col() + slen, 1 );
757 view()->setSelection( cursor.line(), cursor.col(), cursor.line(), cursor.col() + slen );
758 view()->syncSelectionCache();
765 :
KDialogBase ( parent, 0L, false, i18n(
"Replace Confirmation" ),
766 User3 | User2 | User1 | Close | Ok , Ok, true,
767 i18n(
"Replace &All"), i18n(
"Re&place && Close"), i18n(
"&Replace") )
770 TQWidget *page =
new TQWidget(
this);
773 TQBoxLayout *topLayout =
new TQVBoxLayout( page, 0,
spacingHint() );
774 TQLabel *label =
new TQLabel(i18n(
"Found an occurrence of your search term. What do you want to do?"),page);
775 topLayout->addWidget(label );
780 done(KateSearch::srNo);
786 done(KateSearch::srCancel);
792 done(KateSearch::srAll);
798 done(KateSearch::srLast);
804 done(KateSearch::srYes);
817 bool SearchCommand::exec(
class Kate::View *view,
const TQString &cmd, TQString &msg)
819 TQString flags, pattern, replacement;
820 if ( cmd.startsWith(
"find" ) )
823 static TQRegExp re_find(
"find(?::([bcersw]*))?\\s+(.+)");
824 if ( re_find.search( cmd ) < 0 )
826 msg = i18n(
"Usage: find[:[bcersw]] PATTERN");
829 flags = re_find.cap( 1 );
830 pattern = re_find.cap( 2 );
833 else if ( cmd.startsWith(
"ifind" ) )
835 static TQRegExp re_ifind(
"ifind(?::([bcrs]*))?\\s+(.*)");
836 if ( re_ifind.search( cmd ) < 0 )
838 msg = i18n(
"Usage: ifind[:[bcrs]] PATTERN");
845 else if ( cmd.startsWith(
"replace" ) )
848 static TQRegExp re_rep(
"replace(?::([bceprsw]*))?\\s+([\"'])((?:[^\\\\\\\\2]|\\\\.)*)\\2\\s+\\2((?:[^\\\\\\\\2]|\\\\.)*)\\2\\s*$");
850 TQRegExp re_rep1(
"replace(?::([bceprsw]*))?\\s+([\"'])((?:[^\\\\\\\\2]|\\\\.)*)\\2\\s*$");
852 TQRegExp re_rep2(
"replace(?::([bceprsw]*))?\\s+(\\S+)(.*)");
853 #define unbackslash(s) p=0;\
854 while ( (p = pattern.find( '\\' + delim, p )) > -1 )\
856 if ( !p || pattern[p-1] != '\\' )\
857 pattern.remove( p, 1 );\
861 if ( re_rep.search( cmd ) >= 0 )
863 flags = re_rep.cap(1);
864 pattern = re_rep.cap( 3 );
865 replacement = re_rep.cap( 4 );
870 TQString delim = re_rep.cap( 2 );
871 unbackslash(pattern);
873 unbackslash(replacement);
875 else if ( re_rep1.search( cmd ) >= 0 )
877 flags = re_rep1.cap(1);
878 pattern = re_rep1.cap( 3 );
881 TQString delim = re_rep1.cap( 2 );
882 unbackslash(pattern);
884 else if ( re_rep2.search( cmd ) >= 0 )
886 flags = re_rep2.cap( 1 );
887 pattern = re_rep2.cap( 2 );
888 replacement = TQString(re_rep2.cap( 3 )).stripWhiteSpace();
892 msg = i18n(
"Usage: replace[:[bceprsw]] PATTERN [REPLACEMENT]");
895 kdDebug()<<
"replace '"<<pattern<<
"' with '"<<replacement<<
"'"<<
endl;
900 if ( flags.contains(
'b' ) ) f |= KFindDialog::FindBackwards;
901 if ( flags.contains(
'c' ) ) f |= KFindDialog::FromCursor;
902 if ( flags.contains(
'e' ) ) f |= KFindDialog::SelectedText;
903 if ( flags.contains(
'r' ) ) f |= KFindDialog::RegularExpression;
904 if ( flags.contains(
'p' ) ) f |= KReplaceDialog::PromptOnReplace;
905 if ( flags.contains(
's' ) ) f |= KFindDialog::CaseSensitive;
906 if ( flags.contains(
'w' ) ) f |= KFindDialog::WholeWordsOnly;
908 if ( cmd.startsWith(
"find" ) )
910 ((KateView*)view)->find( pattern, f );
913 else if ( cmd.startsWith(
"replace" ) )
915 f |= KReplaceDialog::BackReference;
916 ((KateView*)view)->replace( pattern, replacement, f );
923 bool SearchCommand::help(
class Kate::View *,
const TQString &cmd, TQString &msg)
926 msg = i18n(
"<p>Usage: <code>find[:bcersw] PATTERN</code></p>");
928 else if ( cmd ==
"ifind" )
929 msg = i18n(
"<p>Usage: <code>ifind:[:bcrs] PATTERN</code>"
930 "<br>ifind does incremental or 'as-you-type' search</p>");
933 msg = i18n(
"<p>Usage: <code>replace[:bceprsw] PATTERN REPLACEMENT</code></p>");
936 "<h4><caption>Options</h4><p>"
937 "<b>b</b> - Search backward"
938 "<br><b>c</b> - Search from cursor"
939 "<br><b>r</b> - Pattern is a regular expression"
940 "<br><b>s</b> - Case sensitive search"
945 "<br><b>e</b> - Search in selected text only"
946 "<br><b>w</b> - Search whole words only"
949 if ( cmd ==
"replace" )
951 "<br><b>p</b> - Prompt for replace</p>"
952 "<p>If REPLACEMENT is not present, an empty string is used.</p>"
953 "<p>If you want to have whitespace in your PATTERN, you need to "
954 "quote both PATTERN and REPLACEMENT with either single or double "
955 "quotes. To have the quote characters in the strings, prepend them "
956 "with a backslash.");
962 TQStringList SearchCommand::cmds()
965 l <<
"find" <<
"replace" <<
"ifind";
969 bool SearchCommand::wantsToProcessText(
const TQString &cmdname )
971 return cmdname ==
"ifind";
974 void SearchCommand::processText(
Kate::View *view,
const TQString &cmd )
976 static TQRegExp re_ifind(
"ifind(?::([bcrs]*))?\\s(.*)");
977 if ( re_ifind.search( cmd ) > -1 )
979 TQString flags = re_ifind.cap( 1 );
980 TQString pattern = re_ifind.cap( 2 );
984 if ( ! m_ifindFlags || pattern.isEmpty() )
987 else if ( ! ( m_ifindFlags & KFindDialog::FromCursor ) && ! pattern.isEmpty() )
988 m_ifindFlags |= KFindDialog::FromCursor;
991 if ( ! pattern.isEmpty() )
993 KateView *v = (KateView*)view;
999 if ( pattern.startsWith( v->selection() ) &&
1000 v->selection().length() + 1 == pattern.length() )
1001 v->setCursorPositionInternal( v->selStartLine(), v->selStartCol() );
1003 v->find( pattern, m_ifindFlags,
false );
1008 void SearchCommand::ifindInit(
const TQString &flags )
1011 if ( flags.contains(
'b' ) ) f |= KFindDialog::FindBackwards;
1012 if ( flags.contains(
'c' ) ) f |= KFindDialog::FromCursor;
1013 if ( flags.contains(
'r' ) ) f |= KFindDialog::RegularExpression;
1014 if ( flags.contains(
's' ) ) f |= KFindDialog::CaseSensitive;
1018 void SearchCommand::ifindClear()
void setButtonOK(const KGuiItem &item=KStdGuiItem::ok())
void setMainWidget(TQWidget *widget)
TQPushButton * actionButton(ButtonCode id)
static void information(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const TQString &dontShowAgainName=TQString::null, int options=Notify)
static int questionYesNo(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const KGuiItem &buttonYes=KStdGuiItem::yes(), const KGuiItem &buttonNo=KStdGuiItem::no(), const TQString &dontAskAgainName=TQString::null, int options=Notify)
static void sorry(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
static TQString csqueeze(const TQString &str, uint maxlen=40)
Cursor class with a pointer to its document.
simple replace prompt dialog
void slotUser3()
Yes pressed.
void slotUser2()
last pressed
KateReplacePrompt(TQWidget *parent)
Constructor.
void done(int result)
dialog done
void slotClose()
close pressed
void slotUser1()
replace all pressed
void clicked()
button clicked
Possible additional features:
Simple cursor class with no document pointer.
The Kate::View text editor interface.
virtual TQString currentWord()
Gets the word where the cursor is on.
virtual void replace()
Presents a replace dialog to the user.
virtual void setWhatsThis(const TQString &text)
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)
TDEAction * findPrev(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * replace(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * findNext(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * find(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
const TDEShortcut & end()
const TDEShortcut & find()
const TDEShortcut & replace()