26 #include <tqlineedit.h>
27 #include <tqvbuttongroup.h>
28 #include <tqcheckbox.h>
30 #include <tqpushbutton.h>
32 #include <tqpopupmenu.h>
34 #include <kapplication.h>
35 #include <kcombobox.h>
36 #include <knuminput.h>
37 #include <kmessagebox.h>
38 #include <knotifyclient.h>
41 #include <kiconloader.h>
53 if( replace_dialog && replace_dialog->isVisible() )
55 replace_dialog->hide();
60 srchdialog =
new KEdFind(
this,
"searchdialog",
false);
61 connect(srchdialog,TQT_SIGNAL(
search()),
this,TQT_SLOT(search_slot()));
62 connect(srchdialog,TQT_SIGNAL(done()),
this,TQT_SLOT(searchdone_slot()));
69 string = srchdialog->getText();
70 srchdialog->setText(
string.isEmpty() ? pattern :
string);
80 void KEdit::search_slot(){
87 TQString to_find_string = srchdialog->getText();
88 getCursorPosition(&line,&col);
92 if (last_search != NONE && srchdialog->get_direction()){
93 col = col - pattern.length() - 1 ;
97 int result = doSearch(to_find_string, srchdialog->case_sensitive(),
98 false, (!srchdialog->get_direction()),line,col);
101 if(!srchdialog->get_direction()){
105 i18n(
"End of document reached.\n"\
106 "Continue from the beginning?"),
108 if (query == KMessageBox::Yes){
118 i18n(
"Beginning of document reached.\n"\
119 "Continue from the end?"),
121 if (query == KMessageBox::Yes){
122 TQString
string = textLine( numLines() - 1 );
123 line = numLines() - 1;
124 col =
string.length();
125 last_search = BACKWARD;
137 void KEdit::searchdone_slot(){
148 int KEdit::doSearch(TQString s_pattern,
bool case_sensitive,
149 bool wildcard,
bool forward,
int line,
int col){
161 for(i = line; i < numLines(); i++) {
163 string = textLine(i);
165 pos =
string.find(s_pattern, i == line ? col : 0, case_sensitive);
169 length = s_pattern.length();
171 setCursorPosition(i,pos,
false);
173 for(
int l = 0 ; l < length; l++){
177 setCursorPosition( i , pos + length,
true );
179 last_search = FORWARD;
189 for(i = line; i >= 0; i--) {
191 string = textLine(i);
192 int line_length =
string.length();
194 pos =
string.findRev(s_pattern, line == i ? col : line_length , case_sensitive);
198 length = s_pattern.length();
200 if( ! (line == i && pos > col ) ){
202 setCursorPosition(i ,pos ,
false );
204 for(
int l = 0 ; l < length; l++){
208 setCursorPosition(i ,pos + length ,
true );
210 last_search = BACKWARD;
227 if(!srchdialog || pattern.isEmpty())
249 if( srchdialog && srchdialog->isVisible() )
254 if( !replace_dialog )
256 replace_dialog =
new KEdReplace(
this,
"replace_dialog",
false );
257 connect(replace_dialog,TQT_SIGNAL(find()),
this,TQT_SLOT(replace_search_slot()));
258 connect(replace_dialog,TQT_SIGNAL(
replace()),
this,TQT_SLOT(replace_slot()));
259 connect(replace_dialog,TQT_SIGNAL(replaceAll()),
this,TQT_SLOT(replace_all_slot()));
260 connect(replace_dialog,TQT_SIGNAL(done()),
this,TQT_SLOT(replacedone_slot()));
263 TQString
string = replace_dialog->getText();
264 replace_dialog->setText(
string.isEmpty() ? pattern :
string);
270 replace_dialog->show();
271 replace_dialog->result();
275 void KEdit::replace_slot(){
285 int line,col, length;
287 TQString
string = replace_dialog->getReplaceText();
288 length =
string.length();
292 getCursorPosition(&line,&col);
294 insertAt(
string,line,col);
298 if (replace_dialog->get_direction())
301 setCursorPosition(line,col+length);
302 for(
int k = 0; k < length; k++){
309 setCursorPosition(line,col);
310 for(
int k = 0; k < length; k++){
316 void KEdit::replace_all_slot(){
321 TQString to_find_string = replace_dialog->getText();
323 int lineFrom, lineTo, colFrom, colTo;
324 getSelection(&lineFrom, &colFrom, &lineTo, &colTo);
327 if (replace_dialog->get_direction())
331 replace_all_col = colTo - to_find_string.length();
332 replace_all_line = lineTo;
336 getCursorPosition(&replace_all_line,&replace_all_col);
344 replace_all_col = colFrom;
345 replace_all_line = lineFrom;
349 getCursorPosition(&replace_all_line,&replace_all_col);
357 setAutoUpdate(
false);
362 result = doReplace(to_find_string, replace_dialog->case_sensitive(),
363 false, (!replace_dialog->get_direction()),
364 replace_all_line,replace_all_col,
true);
371 if(!replace_dialog->get_direction()){
375 i18n(
"End of document reached.\n"\
376 "Continue from the beginning?"),
378 if (query == KMessageBox::Yes){
379 replace_all_line = 0;
388 i18n(
"Beginning of document reached.\n"\
389 "Continue from the end?"),
391 if (query == KMessageBox::Yes){
392 TQString
string = textLine( numLines() - 1 );
393 replace_all_line = numLines() - 1;
394 replace_all_col =
string.length();
395 last_replace = BACKWARD;
405 void KEdit::replace_search_slot(){
412 TQString to_find_string = replace_dialog->getText();
414 int lineFrom, lineTo, colFrom, colTo;
415 getSelection(&lineFrom, &colFrom, &lineTo, &colTo);
418 if (replace_dialog->get_direction())
422 col = colFrom - to_find_string.length();
427 getCursorPosition(&line,&col);
440 getCursorPosition(&line,&col);
446 int result = doReplace(to_find_string, replace_dialog->case_sensitive(),
447 false, (!replace_dialog->get_direction()), line, col,
false );
450 if(!replace_dialog->get_direction()){
454 i18n(
"End of document reached.\n"\
455 "Continue from the beginning?"),
457 if (query == KMessageBox::Yes){
467 i18n(
"Beginning of document reached.\n"\
468 "Continue from the end?"),
470 if (query == KMessageBox::Yes){
471 TQString
string = textLine( numLines() - 1 );
472 line = numLines() - 1;
473 col =
string.length();
474 last_replace = BACKWARD;
487 void KEdit::replacedone_slot(){
492 replace_dialog->hide();
505 int KEdit::doReplace(TQString s_pattern,
bool case_sensitive,
506 bool wildcard,
bool forward,
int line,
int col,
bool replace_all){
511 int line_counter, length;
516 TQString replacement;
518 replacement = replace_dialog->getReplaceText();
520 replace_all_col = col;
524 int num_lines = numLines();
526 while (line_counter < num_lines){
528 string = textLine(line_counter);
531 pos =
string.find(s_pattern, replace_all_col, case_sensitive);
534 pos =
string.find(s_pattern, line_counter == line ? col : 0, case_sensitive);
540 replace_all_line = line_counter;
545 length = s_pattern.length();
549 stringnew =
string.copy();
552 stringnew.replace(pos,length,replacement);
554 replace_all_col = pos + replacement.length();
555 replace_all_line = line_counter;
557 pos = stringnew.find(s_pattern, replace_all_col, case_sensitive);
561 removeLine(line_counter);
562 insertLine(stringnew,line_counter);
568 setCursorPosition( line_counter , pos,
false );
570 for(
int l = 0 ; l < length; l++){
574 setCursorPosition( line_counter , pos + length,
true );
576 last_replace = FORWARD;
588 while(line_counter >= 0){
590 string = textLine(line_counter);
592 int line_length =
string.length();
595 if (replace_all_col < 0)
598 pos =
string.findRev(s_pattern, replace_all_col , case_sensitive);
601 if ((line == line_counter) && (col < 0))
604 pos =
string.findRev(s_pattern,
605 line == line_counter ? col : line_length , case_sensitive);
612 if(line_counter >= 0){
613 string = textLine(line_counter);
614 replace_all_col =
string.length();
617 replace_all_line = line_counter;
622 length = s_pattern.length();
626 stringnew =
string.copy();
627 stringnew.replace(pos,length,replacement);
629 removeLine(line_counter);
630 insertLine(stringnew,line_counter);
632 replace_all_col = pos-length;
633 replace_all_line = line_counter;
634 if (replace_all_col < 0)
638 if(line_counter >= 0){
639 string = textLine(line_counter);
640 replace_all_col =
string.length();
642 replace_all_line = line_counter;
650 if( ! (line == line_counter && pos > col ) ){
652 setCursorPosition(line_counter, pos + length ,
false );
654 for(
int l = 0 ; l < length; l++){
658 setCursorPosition(line_counter, pos ,
true );
661 last_replace = BACKWARD;
684 class KEdFind::KEdFindPrivate
687 KEdFindPrivate( TQWidget *parent ) {
689 combo->setMaxCount( 20 );
699 KEdFind::KEdFind( TQWidget *parent,
const char *name,
bool modal )
701 modal ? User1|Cancel : User1|Close, User1, false,
KGuiItem( i18n(
"&Find"),
"find") )
703 setWFlags( WType_TopLevel );
705 TQWidget *page =
new TQWidget(
this );
707 TQVBoxLayout *topLayout =
new TQVBoxLayout( page, 0, spacingHint() );
709 d =
new KEdFindPrivate( page );
711 TQString text = i18n(
"Find:");
712 TQLabel *
label =
new TQLabel( text, page ,
"find" );
713 topLayout->addWidget( label );
715 d->combo->setMinimumWidth(fontMetrics().maxWidth()*20);
716 d->combo->setFocus();
718 connect(d->combo, TQT_SIGNAL(textChanged (
const TQString & )),
719 this,TQT_SLOT(textSearchChanged (
const TQString & )));
721 topLayout->addWidget(d->combo);
723 group =
new TQVButtonGroup( i18n(
"Options"), page );
724 topLayout->addWidget( group );
726 TQHBox* row1 =
new TQHBox( group );
728 text = i18n(
"Case &sensitive");
729 sensitive =
new TQCheckBox( text, row1,
"case");
730 text = i18n(
"Find &backwards");
731 direction =
new TQCheckBox( text, row1,
"direction" );
737 connect(
this, TQT_SIGNAL( closeClicked() ),
this, TQT_SLOT( slotCancel() ) );
745 void KEdFind::textSearchChanged (
const TQString &text )
750 void KEdFind::slotCancel(
void )
756 void KEdFind::slotUser1(
void )
758 if( !d->combo->currentText().isEmpty() )
760 d->combo->addToHistory( d->combo->currentText() );
766 TQString KEdFind::getText()
const
768 return d->combo->currentText();
773 void KEdFind::setText(TQString
string)
775 d->combo->setEditText(
string);
776 d->combo->lineEdit()->selectAll();
779 void KEdFind::setCaseSensitive(
bool b )
781 sensitive->setChecked( b );
784 bool KEdFind::case_sensitive()
const
786 return sensitive->isChecked();
789 void KEdFind::setDirection(
bool b )
791 direction->setChecked( b );
794 bool KEdFind::get_direction()
const
796 return direction->isChecked();
811 class KEdReplace::KEdReplacePrivate
814 KEdReplacePrivate( TQWidget *parent ) {
818 searchCombo->setMaxCount( 20 );
819 replaceCombo->setMaxCount( 20 );
821 ~KEdReplacePrivate() {
829 KEdReplace::KEdReplace( TQWidget *parent,
const char *name,
bool modal )
830 :
KDialogBase( parent, name, modal, i18n(
"Replace"),
831 modal ? User3|User2|User1|Cancel : User3|User2|User1|Close,
833 i18n(
"Replace &All"), i18n(
"&Replace"),
KGuiItem( i18n(
"&Find"),
"find") )
835 setWFlags( WType_TopLevel );
839 TQFrame *page = makeMainWidget();
840 TQVBoxLayout *topLayout =
new TQVBoxLayout( page, 0, spacingHint() );
842 d =
new KEdReplacePrivate( page );
844 TQString text = i18n(
"Find:");
845 TQLabel *label =
new TQLabel( text, page,
"find" );
846 topLayout->addWidget( label );
848 d->searchCombo->setMinimumWidth(fontMetrics().maxWidth()*20);
849 d->searchCombo->setFocus();
850 topLayout->addWidget(d->searchCombo);
852 text = i18n(
"Replace with:");
853 label =
new TQLabel( text, page,
"replace" );
854 topLayout->addWidget( label );
856 d->replaceCombo->setMinimumWidth(fontMetrics().maxWidth()*20);
857 topLayout->addWidget(d->replaceCombo);
859 connect(d->searchCombo, TQT_SIGNAL(textChanged (
const TQString & )),
860 this,TQT_SLOT(textSearchChanged (
const TQString & )));
862 TQButtonGroup *group =
new TQButtonGroup( i18n(
"Options"), page );
863 topLayout->addWidget( group );
865 TQGridLayout *gbox =
new TQGridLayout( group, 3, 2, spacingHint() );
866 gbox->addRowSpacing( 0, fontMetrics().lineSpacing() );
868 text = i18n(
"Case &sensitive");
869 sensitive =
new TQCheckBox( text, group,
"case");
870 text = i18n(
"Find &backwards");
871 direction =
new TQCheckBox( text, group,
"direction" );
872 gbox->addWidget( sensitive, 1, 0 );
873 gbox->addWidget( direction, 1, 1 );
874 gbox->setRowStretch( 2, 10 );
878 KEdReplace::~KEdReplace()
883 void KEdReplace::textSearchChanged (
const TQString &text )
885 bool state=text.isEmpty();
891 void KEdReplace::slotCancel(
void )
894 d->searchCombo->clearEdit();
895 d->replaceCombo->clearEdit();
899 void KEdReplace::slotClose(
void )
904 void KEdReplace::slotUser1(
void )
906 if( !d->searchCombo->currentText().isEmpty() )
908 d->replaceCombo->addToHistory( d->replaceCombo->currentText() );
914 void KEdReplace::slotUser2(
void )
916 if( !d->searchCombo->currentText().isEmpty() )
918 d->replaceCombo->addToHistory( d->replaceCombo->currentText() );
923 void KEdReplace::slotUser3(
void )
925 if( !d->searchCombo->currentText().isEmpty() )
927 d->searchCombo->addToHistory( d->searchCombo->currentText() );
933 TQString KEdReplace::getText()
935 return d->searchCombo->currentText();
939 TQString KEdReplace::getReplaceText()
941 return d->replaceCombo->currentText();
946 void KEdReplace::setText(TQString
string)
948 d->searchCombo->setEditText(
string);
949 d->searchCombo->lineEdit()->selectAll();
953 bool KEdReplace::case_sensitive()
955 return sensitive->isChecked();
959 bool KEdReplace::get_direction()
961 return direction->isChecked();
966 return d->searchCombo;
971 return d->replaceCombo;
975 KEdGotoLine::KEdGotoLine( TQWidget *parent,
const char *name,
bool modal )
976 :
KDialogBase( parent, name, modal, i18n(
"Go to Line"), modal ? Ok|Cancel : Ok|Close, Ok, false )
978 TQWidget *page =
new TQWidget(
this );
980 TQVBoxLayout *topLayout =
new TQVBoxLayout( page, 0, spacingHint() );
983 lineNum->setRange(1, 1000000, 1,
false);
984 lineNum->setLabel(i18n(
"Go to line:"), AlignVCenter | AlignLeft);
986 topLayout->addWidget( lineNum );
988 topLayout->addStretch(10);
993 void KEdGotoLine::selected(
int)
999 int KEdGotoLine::getLineNumber()
1001 return lineNum->value();
1012 saved_readonlystate = isReadOnly();
1020 unsigned int cnt = 0;
1022 setSelection(l, cnt, l, cnt+word.length());
1034 void KEdit::corrected (
const TQString &originalword,
const TQString &newword,
unsigned int pos)
1040 unsigned int cnt = 0;
1042 if( newword != originalword )
1045 setSelection(l, cnt, l, cnt+originalword.length());
1047 setReadOnly (
false );
1048 removeSelectedText();
1050 setReadOnly (
true );
1060 for (line = 0; line < static_cast<uint>(numLines()) && col <= pos; line++)
1062 col += lineLength(line)+1;
1065 col = pos - col + lineLength(line) + 1;
1072 setReadOnly ( saved_readonlystate);
1075 TQString KEdit::selectWordUnderCursor( )
1080 getCursorPosition(¶g, &pos);
1082 TQString txt = text(parag);
1088 const TQChar &ch = txt[start-1];
1089 if (ch.isSpace() || ch.isPunct())
1096 int len = txt.length();
1099 const TQChar &ch = txt[end];
1100 if (ch.isSpace() || ch.isPunct())
1104 setSelection(parag, start, parag, end);
1105 return txt.mid(start, end-start);
1110 enum { IdUndo, IdRedo, IdSep1, IdCut, IdCopy, IdPaste, IdClear, IdSep2, IdSelectAll };
1112 TQPopupMenu *menu = TQMultiLineEdit::createPopupMenu( pos );
1115 menu->changeItem( menu->idAt(0), SmallIconSet(
"editcopy"), menu->text( menu->idAt(0) ) );
1117 int id = menu->idAt(0);
1118 menu->changeItem(
id - IdUndo, SmallIconSet(
"undo"), menu->text(
id - IdUndo) );
1119 menu->changeItem(
id - IdRedo, SmallIconSet(
"redo"), menu->text(
id - IdRedo) );
1120 menu->changeItem(
id - IdCut, SmallIconSet(
"editcut"), menu->text(
id - IdCut) );
1121 menu->changeItem(
id - IdCopy, SmallIconSet(
"editcopy"), menu->text(
id - IdCopy) );
1122 menu->changeItem(
id - IdPaste, SmallIconSet(
"editpaste"), menu->text(
id - IdPaste) );
1123 menu->changeItem(
id - IdClear, SmallIconSet(
"editclear"), menu->text(
id - IdClear) );
KAction * deselect(const TQObject *recvr, const char *slot, KActionCollection *parent, const char *name)
Deselect any selected elements in the current document.
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)
Display a simple "question" dialog.
void beep(const TQString &reason=TQString::null)
void replace()
Present a Search and Replace Dialog to the user.
TQString label(StdAccel id)
void misspelling(const TQString &word, const TQStringList &, unsigned int pos)
void spellcheck_stop()
Exit spellchecking mode.
static KGuiItem cont()
Returns a "continue" item.
A dialog base class with standard buttons and predefined layouts.
void spellcheck_start()
Start spellchecking mode.
void corrected(const TQString &originalword, const TQString &newword, unsigned int pos)
Show User defined button 1.
void search()
Present a search dialog to the user.
An abstract class for GUI data such as ToolTip and Icon.
const KShortcut & replace()
Show User defined button 2.
void CursorPositionChanged()
This signal is emitted whenever the cursor position changes.
virtual void slotCancel()
Activated when the Cancel button has been clicked.
void posToRowCol(unsigned int pos, unsigned int &line, unsigned int &col)
Sets line and col to the position pos, considering word wrap.
TQPopupMenu * createPopupMenu(const TQPoint &pos)
bool repeatSearch()
Repeat the last search specified on the search dialog.
A combobox for offering a history and completion.
Show User defined button 3.