Index: trunk/kdelibs/kdeui/keditcl.h =================================================================== --- trunk/kdelibs/kdeui/keditcl.h (revision 70266) +++ trunk/kdelibs/kdeui/keditcl.h (revision 70267) @@ -1,396 +1,418 @@ /* This file is part of the KDE libraries Copyright (C) 1996 Bernd Johannes Wuebben Copyright (C) 2000 Waldo Bastian This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef __KEDITCL_H__ #define __KEDITCL_H__ #include #include #include class QDropEvent; class QPushButton; class QCheckBox; class QRadioButton; class QLineEdit; class QTextStream; +class KHistoryCombo; class KIntNumInput; class KEdGotoLine : public KDialogBase { Q_OBJECT public: KEdGotoLine( QWidget *parent=0, const char *name=0, bool modal=true ); int getLineNumber(); public slots: void selected( int ); private: KIntNumInput *lineNum; class KEdGotoLinePrivate; KEdGotoLinePrivate *d; }; /// class KEdFind : public KDialogBase { Q_OBJECT Q_PROPERTY( QString text READ getText WRITE setText ) Q_PROPERTY( bool caseSensitivity READ case_sensitive WRITE setCaseSensitive ) Q_PROPERTY( bool direction READ get_direction WRITE setDirection ) public: KEdFind( QWidget *parent = 0, const char *name=0, bool modal=true); + ~KEdFind(); QString getText() const; void setText(QString string); void setCaseSensitive( bool b ); bool case_sensitive() const; void setDirection( bool b ); bool get_direction() const; + /** + * @returns the combobox containing the history of searches. Can be used + * to save and restore the history. + */ + KHistoryCombo *searchCombo() const; + protected slots: void slotCancel( void ); void slotUser1( void ); private: QCheckBox *sensitive; QCheckBox *direction; - QLineEdit *value; + QLineEdit *value; // FIXME: remove, unused class KEdFindPrivate; KEdFindPrivate *d; - virtual void done(int i ) { KDialogBase::done(i); } + virtual void done(int i ) { KDialogBase::done(i); } signals: void search(); void done(); }; /// class KEdReplace : public KDialogBase { Q_OBJECT public: KEdReplace ( QWidget *parent = 0, const char *name=0, bool modal=true ); + ~KEdReplace(); QString getText(); QString getReplaceText(); void setText(QString); - QLineEdit *value; - QLineEdit *replace_value; + + /** + * @returns the combobox containing the history of searches. Can be used + * to save and restore the history. + */ + KHistoryCombo *searchCombo() const; + + /** + * @returns the combobox containing the history of replaces. Can be used + * to save and restore the history. + */ + KHistoryCombo *replaceCombo() const; + + QLineEdit *value; // FIXME: remove, unused + QLineEdit *replace_value; // FIXME: remove, unused bool case_sensitive(); bool get_direction(); protected slots: void slotCancel( void ); void slotUser1( void ); void slotUser2( void ); void slotUser3( void ); private: QCheckBox *sensitive; QCheckBox *direction; class KEdReplacePrivate; KEdReplacePrivate *d; - virtual void done(int i ) { KDialogBase::done(i); } + virtual void done(int i ) { KDialogBase::done(i); } signals: void replace(); void find(); void replaceAll(); void done(); }; /** * A simple text editor for the KDE project. * * @author Bernd Johannes Wuebben , Waldo Bastian **/ class KEdit : public QMultiLineEdit { Q_OBJECT public: /** * The usual constructor. **/ KEdit (QWidget *_parent=NULL, const char *name=NULL); ~KEdit(); /** * Search directions. * @internal **/ enum { NONE, FORWARD, BACKWARD }; /** * Insert text from the text stream into the edit widget. **/ void insertText(QTextStream *); /** * Save text from the edit widget to a text stream. **/ void saveText(QTextStream *); /** * Retrieve the currently marked text. */ QString markedText(); /** * Let the user select a font and set the font of the textwidget to that * selected font. **/ void selectFont(); /** * Present a search dialog to the user **/ void search(); /** * Repeat the last search specified on the search dialog. * * If the user hasn't searched for anything until now, this method * will simply return without doing anything. * * @return @p true if a search was done. @p false if no search was done. **/ bool repeatSearch(); /** * Present a Search and Replace Dialog to the user. **/ void replace(); /** * Present a "Goto Line" dialog to the user. */ void doGotoLine(); /** * Clean up redundant whitespace from selected text. */ void cleanWhiteSpace(); /** * @return @p true if the document has been modified. */ bool isModified(); /** * Set the modification status of the document. * * @p true = Modified, @p false = UNMODIFIED. * This can be used to test whether the document needs to be saved. **/ void setModified( bool = true); /** * Install a context menu for @ref KEdit. * * The Popup Menu will be activated on a right mouse button press event. */ void installRBPopup( QPopupMenu* ); /** * Retrieve the current line number. * * The current line is the line the cursor is on. **/ int currentLine(); /** * Retrieve the actual column number the cursor is on. * * This call differs * from @ref QMultiLineEdit::getCursorPosition() in that it returns the actual cursor * position and not the character position. Use @ref currentLine() and @ref currentColumn() * if you want to display the current line or column in the status bar for * example. */ int currentColumn(); /** * Start spellchecking mode. */ void spellcheck_start(); /** * Exit spellchecking mode. */ void spellcheck_stop(); /** * Allow the user to toggle between insert mode and overwrite mode with * the "Insert" key. See also @ref toggle_overwrite_signal(); - * + * * The default is false: the user can not toggle. */ void setOverwriteEnabled(bool b); signals: /** This signal is emitted if the user dropped a URL over the text editor * @ref QMultiLineEdit widget. * * Note that the user can drop also Text on it, but * this is already handled internally by QMultiLineEdit. */ void gotUrlDrop(QDropEvent* e); /** This signal is emitted whenever the cursor position changes. * * Use this in conjunction with @ref currentLine(), @ref currentColumn() * if you need to know the cursor position. */ void CursorPositionChanged(); - /** + /** * This signal is emitted if the user toggles from insert to overwrite mode * or vice versa. * * The user can do so by pressing the "Insert" button on a PC keyboard. * - * This feature must be activated by calling @ref setOverwriteEnabled(true) + * This feature must be activated by calling @ref setOverwriteEnabled(true) * first. */ void toggle_overwrite_signal(); private slots: /** * @internal **/ void corrected (QString originalword, QString newword, unsigned pos); /** * @internal **/ void misspelling (QString word, QStringList *, unsigned pos); /** * @internal * Called from search dialog. **/ void search_slot(); /** * @internal **/ void searchdone_slot(); /** * @internal **/ void replace_slot(); /** * @internal **/ void replace_all_slot(); /** * @internal **/ void replace_search_slot(); /** * @internal **/ void replacedone_slot(); void computePosition(); /** * Repaint the widget. **/ void repaintAll(); protected: int doSearch(QString s_pattern, bool case_sensitive, bool regex, bool forward,int line, int col); int doReplace(QString s_pattern, bool case_sensitive, bool regex, bool forward,int line, int col,bool replace); /** * Sets line and col to the position pos, considering word wrap. **/ void posToRowCol(unsigned int pos, unsigned int &line, unsigned int &col); protected: bool eventFilter ( QObject *, QEvent * ); void keyPressEvent ( QKeyEvent * ); void mousePressEvent ( QMouseEvent* ); void mouseReleaseEvent( QMouseEvent* ); void mouseMoveEvent ( QMouseEvent* ); // DnD inteface void dragMoveEvent(QDragMoveEvent* e); void dragEnterEvent(QDragEnterEvent* e); void dropEvent(QDropEvent* e); private: QTimer* repaintTimer; QString killbufferstring; QWidget *parent; KEdFind *srchdialog; KEdReplace *replace_dialog; KEdGotoLine *gotodialog; QString pattern; bool can_replace; bool killing; bool killtrue; bool lastwasanewline; bool saved_readonlystate; int last_search; int last_replace; int replace_all_line; int replace_all_col; int line_pos, col_pos; bool fill_column_is_set; bool word_wrap_is_set; int fill_column_value; class KEditPrivate; KEditPrivate *d; }; #endif Index: trunk/kdelibs/kdeui/keditcl2.cpp =================================================================== --- trunk/kdelibs/kdeui/keditcl2.cpp (revision 70266) +++ trunk/kdelibs/kdeui/keditcl2.cpp (revision 70267) @@ -1,918 +1,984 @@ /* This file is part of the KDE libraries Copyright (C) 1997 Bernd Johannes Wuebben Copyright (C) 2000 Waldo Bastian This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include // INT_MAX #include #include #include #include #include #include #include +#include #include #include #include #include #include "keditcl.h" ////////////////////////////////////////////////////////////////////////// // // Find Methods // void KEdit::search(){ if( replace_dialog != 0 && replace_dialog->isVisible() == true ) { replace_dialog->hide(); } if( srchdialog == 0 ) { srchdialog = new KEdFind( parentWidget(), "searchdialog", false); connect(srchdialog,SIGNAL(search()),this,SLOT(search_slot())); connect(srchdialog,SIGNAL(done()),this,SLOT(searchdone_slot())); } // If we already searched / replaced something before make sure it shows // up in the find dialog line-edit. - QString string; - string = srchdialog->getText(); - if(string.isEmpty()) - srchdialog->setText(pattern); +// QString string; +// string = srchdialog->getText(); +// if(string.isEmpty()) +// srchdialog->setText(pattern); this->deselect(); last_search = NONE; srchdialog->show(); srchdialog->result(); } void KEdit::search_slot(){ int line, col; if (!srchdialog) return; QString to_find_string = srchdialog->getText(); getCursorPosition(&line,&col); // srchdialog->get_direction() is true if searching backward if (last_search != NONE && srchdialog->get_direction()){ col = col - pattern.length() - 1 ; } again: int result = doSearch(to_find_string, srchdialog->case_sensitive(), FALSE, (!srchdialog->get_direction()),line,col); if(result == 0){ if(!srchdialog->get_direction()){ // forward search int query = KMessageBox::questionYesNo( srchdialog, i18n("End of document reached.\n"\ "Continue from the beginning?"), i18n("Find")); if (query == KMessageBox::Yes){ line = 0; col = 0; goto again; } } else{ //backward search int query = KMessageBox::questionYesNo( srchdialog, i18n("Beginning of document reached.\n"\ "Continue from the end?"), i18n("Find")); if (query == KMessageBox::Yes){ QString string = textLine( numLines() - 1 ); line = numLines() - 1; col = string.length(); last_search = BACKWARD; goto again; } } } else{ emit CursorPositionChanged(); } } void KEdit::searchdone_slot(){ if (!srchdialog) return; srchdialog->hide(); this->setFocus(); last_search = NONE; } int KEdit::doSearch(QString s_pattern, bool case_sensitive, bool wildcard, bool forward, int line, int col){ (void) wildcard; // reserved for possible extension to regex int i, length; int pos = -1; if(forward){ QString string; for(i = line; i < numLines(); i++) { string = textLine(i); pos = string.find(s_pattern, i == line ? col : 0, case_sensitive); if( pos != -1){ length = s_pattern.length(); setCursorPosition(i,pos,FALSE); for(int l = 0 ; l < length; l++){ cursorRight(TRUE); } setCursorPosition( i , pos + length, TRUE ); pattern = s_pattern; last_search = FORWARD; return 1; } } } else{ // searching backwards QString string; for(i = line; i >= 0; i--) { string = textLine(i); int line_length = string.length(); pos = string.findRev(s_pattern, line == i ? col : line_length , case_sensitive); if (pos != -1){ length = s_pattern.length(); if( ! (line == i && pos > col ) ){ setCursorPosition(i ,pos ,FALSE ); for(int l = 0 ; l < length; l++){ cursorRight(TRUE); } setCursorPosition(i ,pos + length ,TRUE ); pattern = s_pattern; last_search = BACKWARD; return 1; } } } } return 0; } bool KEdit::repeatSearch() { if(!srchdialog) return false; if(pattern.isEmpty()) // there wasn't a previous search return false; search_slot(); this->setFocus(); return true; } ////////////////////////////////////////////////////////////////////////// // // Replace Methods // void KEdit::replace() { if( srchdialog != 0 && srchdialog->isVisible() == true) { srchdialog->hide(); } if( replace_dialog == 0 ) { replace_dialog = new KEdReplace( parentWidget(), "replace_dialog" ); connect(replace_dialog,SIGNAL(find()),this,SLOT(replace_search_slot())); connect(replace_dialog,SIGNAL(replace()),this,SLOT(replace_slot())); connect(replace_dialog,SIGNAL(replaceAll()),this,SLOT(replace_all_slot())); connect(replace_dialog,SIGNAL(done()),this,SLOT(replacedone_slot())); } - QString string = replace_dialog->getText(); - - if(string.isEmpty()) - replace_dialog->setText(pattern); +// QString string = replace_dialog->getText(); +// if(string.isEmpty()) +// replace_dialog->setText(pattern); this->deselect(); last_replace = NONE; replace_dialog->show(); replace_dialog->result(); } void KEdit::replace_slot(){ if (!replace_dialog) return; if(!can_replace){ kapp->beep(); return; } int line,col, length; QString string = replace_dialog->getReplaceText(); length = string.length(); this->cut(); getCursorPosition(&line,&col); insertAt(string,line,col); setModified(); can_replace = FALSE; setCursorPosition(line,col); for( int k = 0; k < length; k++){ cursorRight(TRUE); } } void KEdit::replace_all_slot(){ if (!replace_dialog) return; QString to_find_string = replace_dialog->getText(); getCursorPosition(&replace_all_line,&replace_all_col); // replace_dialog->get_direction() is true if searching backward if (last_replace != NONE && replace_dialog->get_direction()){ replace_all_col = replace_all_col - pattern.length() - 1 ; } deselect(); again: setAutoUpdate(FALSE); int result = 1; while(result){ result = doReplace(to_find_string, replace_dialog->case_sensitive(), FALSE, (!replace_dialog->get_direction()), replace_all_line,replace_all_col,TRUE); } setAutoUpdate(TRUE); update(); if(!replace_dialog->get_direction()){ // forward search int query = KMessageBox::questionYesNo( srchdialog, i18n("End of document reached.\n"\ "Continue from the beginning?"), i18n("Find")); if (query == KMessageBox::Yes){ replace_all_line = 0; replace_all_col = 0; goto again; } } else{ //backward search int query = KMessageBox::questionYesNo( srchdialog, i18n("Beginning of document reached.\n"\ "Continue from the end?"), i18n("Find")); if (query == KMessageBox::Yes){ QString string = textLine( numLines() - 1 ); replace_all_line = numLines() - 1; replace_all_col = string.length(); last_replace = BACKWARD; goto again; } } emit CursorPositionChanged(); } void KEdit::replace_search_slot(){ int line, col; if (!replace_dialog) return; QString to_find_string = replace_dialog->getText(); getCursorPosition(&line,&col); // replace_dialog->get_direction() is true if searching backward //printf("col %d length %d\n",col, pattern.length()); if (last_replace != NONE && replace_dialog->get_direction()){ col = col - pattern.length() -1; if (col < 0 ) { if(line !=0){ col = textLine(line - 1).length(); line --; } else{ int query = KMessageBox::questionYesNo( replace_dialog, i18n("Beginning of document reached.\n"\ "Continue from the end?"), i18n("Replace")); if (query == KMessageBox::Yes){ QString string = textLine( numLines() - 1 ); line = numLines() - 1; col = string.length(); last_replace = BACKWARD; } } } } again: // printf("Col %d \n",col); int result = doReplace(to_find_string, replace_dialog->case_sensitive(), FALSE, (!replace_dialog->get_direction()), line, col, FALSE ); if(result == 0){ if(!replace_dialog->get_direction()){ // forward search int query = KMessageBox::questionYesNo( replace_dialog, i18n("End of document reached.\n"\ "Continue from the beginning?"), i18n("Replace")); if (query == KMessageBox::Yes){ line = 0; col = 0; goto again; } } else{ //backward search int query = KMessageBox::questionYesNo( replace_dialog, i18n("Beginning of document reached.\n"\ "Continue from the end?"), i18n("Replace")); if (query == KMessageBox::Yes){ QString string = textLine( numLines() - 1 ); line = numLines() - 1; col = string.length(); last_replace = BACKWARD; goto again; } } } else{ emit CursorPositionChanged(); } } void KEdit::replacedone_slot(){ if (!replace_dialog) return; replace_dialog->hide(); // replace_dialog->clearFocus(); this->setFocus(); last_replace = NONE; can_replace = FALSE; } int KEdit::doReplace(QString s_pattern, bool case_sensitive, bool wildcard, bool forward, int line, int col, bool replace_all){ (void) wildcard; // reserved for possible extension to regex int line_counter, length; int pos = -1; QString string; QString stringnew; QString replacement; replacement = replace_dialog->getReplaceText(); line_counter = line; replace_all_col = col; if(forward){ int num_lines = numLines(); while (line_counter < num_lines){ string = ""; string = textLine(line_counter); if (replace_all){ pos = string.find(s_pattern, replace_all_col, case_sensitive); } else{ pos = string.find(s_pattern, line_counter == line ? col : 0, case_sensitive); } if (pos == -1 ){ line_counter ++; replace_all_col = 0; replace_all_line = line_counter; } if( pos != -1){ length = s_pattern.length(); if(replace_all){ // automatic stringnew = string.copy(); stringnew.replace(pos,length,replacement); removeLine(line_counter); insertLine(stringnew,line_counter); replace_all_col = replace_all_col + replacement.length(); replace_all_line = line_counter; setModified(); } else{ // interactive setCursorPosition( line_counter , pos, FALSE ); for(int l = 0 ; l < length; l++){ cursorRight(TRUE); } setCursorPosition( line_counter , pos + length, TRUE ); pattern = s_pattern; last_replace = FORWARD; can_replace = TRUE; return 1; } } } } else{ // searching backwards while(line_counter >= 0){ string = ""; string = textLine(line_counter); int line_length = string.length(); if( replace_all ){ pos = string.findRev(s_pattern, replace_all_col , case_sensitive); } else{ pos = string.findRev(s_pattern, line == line_counter ? col : line_length , case_sensitive); } if (pos == -1 ){ line_counter --; if(line_counter >= 0){ string = ""; string = textLine(line_counter); replace_all_col = string.length(); } replace_all_line = line_counter; } if (pos != -1){ length = s_pattern.length(); if(replace_all){ // automatic stringnew = string.copy(); stringnew.replace(pos,length,replacement); removeLine(line_counter); insertLine(stringnew,line_counter); replace_all_col = replace_all_col - replacement.length(); replace_all_line = line_counter; setModified(); } else{ // interactive // printf("line_counter %d pos %d col %d\n",line_counter, pos,col); if( ! (line == line_counter && pos > col ) ){ setCursorPosition(line_counter ,pos ,FALSE ); for(int l = 0 ; l < length; l++){ cursorRight(TRUE); } setCursorPosition(line_counter ,pos + length ,TRUE ); pattern = s_pattern; last_replace = BACKWARD; can_replace = TRUE; return 1; } } } } } return 0; } //////////////////////////////////////////////////////////////////// // // Find Dialog // + +class KEdFind::KEdFindPrivate +{ +public: + KEdFindPrivate( QWidget *parent ) { + combo = new KHistoryCombo( parent, "value" ); + } + ~KEdFindPrivate() { + delete combo; + } + + KHistoryCombo *combo; +}; + + KEdFind::KEdFind( QWidget *parent, const char *name, bool modal ) :KDialogBase( parent, name, modal, i18n("Find"), User1|Cancel, User1, false, i18n("&Find") ) { QWidget *page = new QWidget( this ); setMainWidget(page); QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() ); + d = new KEdFindPrivate( page ); + QString text = i18n("Find:"); QLabel *label = new QLabel( text, page , "find" ); topLayout->addWidget( label ); - value = new QLineEdit( page, "value"); - value->setMinimumWidth(fontMetrics().maxWidth()*20); - value->setFocus(); - topLayout->addWidget(value); + d->combo->setMinimumWidth(fontMetrics().maxWidth()*20); + d->combo->setFocus(); + topLayout->addWidget(d->combo); QButtonGroup *group = new QButtonGroup( i18n("Options"), page ); topLayout->addWidget( group ); QGridLayout *gbox = new QGridLayout( group, 3, 2, spacingHint() ); gbox->addRowSpacing( 0, fontMetrics().lineSpacing() ); text = i18n("Case Sensitive"); sensitive = new QCheckBox( text, group, "case"); text = i18n("Find Backwards"); direction = new QCheckBox( text, group, "direction" ); gbox->addWidget( sensitive, 1, 0 ); gbox->addWidget( direction, 1, 1 ); gbox->setRowStretch( 2, 10 ); } +KEdFind::~KEdFind() +{ + delete d; +} + void KEdFind::slotCancel( void ) { emit done(); + d->combo->clearEdit(); } void KEdFind::slotUser1( void ) { - if( value->text().isEmpty() == false ) + if( !d->combo->currentText().isEmpty() ) { + d->combo->addToHistory( d->combo->currentText() ); emit search(); } } QString KEdFind::getText() const { - return value->text(); + return d->combo->currentText(); } void KEdFind::setText(QString string) { - value->setText(string); - value->selectAll(); + d->combo->setEditText(string); + d->combo->lineEdit()->selectAll(); } void KEdFind::setCaseSensitive( bool b ) { sensitive->setChecked( b ); } bool KEdFind::case_sensitive() const { return sensitive->isChecked(); } void KEdFind::setDirection( bool b ) { direction->setChecked( b ); } bool KEdFind::get_direction() const { return direction->isChecked(); } +KHistoryCombo * KEdFind::searchCombo() const +{ + return d->combo; +} + + //////////////////////////////////////////////////////////////////// // // Replace Dialog // + +class KEdReplace::KEdReplacePrivate +{ +public: + KEdReplacePrivate( QWidget *parent ) { + searchCombo = new KHistoryCombo( parent, "value" ); + replaceCombo = new KHistoryCombo( parent, "replace_value" ); + } + ~KEdReplacePrivate() { + delete searchCombo; + delete replaceCombo; + } + + KHistoryCombo *searchCombo, *replaceCombo; +}; + KEdReplace::KEdReplace( QWidget *parent, const char *name, bool modal ) :KDialogBase( parent, name, modal, i18n("Replace"), User3|User2|User1|Cancel, User3, false, i18n("Replace &All"), i18n("&Replace"), i18n("&Find") ) { setButtonBoxOrientation( Vertical ); QFrame *page = makeMainWidget(); QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() ); + d = new KEdReplacePrivate( page ); + QString text = i18n("Find:"); QLabel *label = new QLabel( text, page, "find" ); topLayout->addWidget( label ); - value = new QLineEdit( page, "value"); - value->setMinimumWidth(fontMetrics().maxWidth()*20); - value->setFocus(); - topLayout->addWidget(value); + d->searchCombo->setMinimumWidth(fontMetrics().maxWidth()*20); + d->searchCombo->setFocus(); + topLayout->addWidget(d->searchCombo); text = i18n("Replace with:"); label = new QLabel( text, page, "replace" ); topLayout->addWidget( label ); - replace_value = new QLineEdit( page, "value"); - replace_value->setMinimumWidth(fontMetrics().maxWidth()*20); - topLayout->addWidget(replace_value); + d->replaceCombo->setMinimumWidth(fontMetrics().maxWidth()*20); + topLayout->addWidget(d->replaceCombo); QButtonGroup *group = new QButtonGroup( i18n("Options"), page ); topLayout->addWidget( group ); QGridLayout *gbox = new QGridLayout( group, 3, 2, spacingHint() ); gbox->addRowSpacing( 0, fontMetrics().lineSpacing() ); text = i18n("Case Sensitive"); sensitive = new QCheckBox( text, group, "case"); text = i18n("Find Backwards"); direction = new QCheckBox( text, group, "direction" ); gbox->addWidget( sensitive, 1, 0 ); gbox->addWidget( direction, 1, 1 ); gbox->setRowStretch( 2, 10 ); } +KEdReplace::~KEdReplace() +{ + delete d; +} + + void KEdReplace::slotCancel( void ) { emit done(); + d->searchCombo->clearEdit(); + d->replaceCombo->clearEdit(); } void KEdReplace::slotUser1( void ) { + d->replaceCombo->addToHistory( d->replaceCombo->currentText() ); emit replaceAll(); } void KEdReplace::slotUser2( void ) { + d->replaceCombo->addToHistory( d->replaceCombo->currentText() ); emit replace(); } void KEdReplace::slotUser3( void ) { - if( value->text().isEmpty() == false ) + if( !d->searchCombo->currentText().isEmpty() ) { + d->searchCombo->addToHistory( d->searchCombo->currentText() ); emit find(); } } QString KEdReplace::getText() { - return value->text(); + return d->searchCombo->currentText(); } QString KEdReplace::getReplaceText() { - return replace_value->text(); + return d->replaceCombo->currentText(); } void KEdReplace::setText(QString string) { - value->setText(string); + d->searchCombo->setEditText(string); + d->searchCombo->lineEdit()->selectAll(); } bool KEdReplace::case_sensitive() { return sensitive->isChecked(); } bool KEdReplace::get_direction() { return direction->isChecked(); } +KHistoryCombo * KEdReplace::searchCombo() const +{ + return d->searchCombo; +} + +KHistoryCombo * KEdReplace::replaceCombo() const +{ + return d->replaceCombo; +} KEdGotoLine::KEdGotoLine( QWidget *parent, const char *name, bool modal ) :KDialogBase( parent, name, modal, i18n("Goto Line"), Ok|Cancel, Ok, false ) { QWidget *page = new QWidget( this ); setMainWidget(page); QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() ); lineNum = new KIntNumInput( 1, page); lineNum->setLabel(i18n("Goto Line:"), AlignVCenter | AlignLeft); // lineNum->setMinimumWidth(fontMetrics().maxWidth()*20); topLayout->addWidget( lineNum ); topLayout->addStretch(10); } void KEdGotoLine::selected(int) { - accept(); + accept(); } int KEdGotoLine::getLineNumber() { return lineNum->value(); } ////////////////////////////////////////////////////////////////////////////// // // Spell Checking // void KEdit::spellcheck_start() { saved_readonlystate = isReadOnly(); setReadOnly(true); } void KEdit::misspelling (QString word, QStringList *, unsigned pos) { unsigned int l = 0; unsigned int cnt = 0; posToRowCol (pos, l, cnt); setCursorPosition (l, cnt); setCursorPosition (l, cnt+word.length(), TRUE); /* if (cursorPoint().y()>height()/2) kspell->moveDlg (10, height()/2-kspell->heightDlg()-15); else kspell->moveDlg (10, height()/2 + 15); */ } //need to use pos for insert, not cur, so forget cur altogether void KEdit::corrected (QString originalword, QString newword, unsigned pos) { //we'll reselect the original word in case the user has played with //the selection in eframe or the word was auto-replaced unsigned int l = 0; unsigned int cnt = 0; if( newword != originalword ) { posToRowCol (pos, l, cnt); setCursorPosition (l, cnt); setCursorPosition (l, cnt+originalword.length(), TRUE); cut(); insertAt (newword, l, cnt); } deselect(); } void KEdit::posToRowCol(unsigned int pos, unsigned int &line, unsigned int &col) { for (line = 0; line < static_cast(numLines()) && col <= pos; line++) { col += lineLength(line); if( isEndOfParagraph(line) ) { col++; } } line--; col = pos - col + lineLength(line); if( isEndOfParagraph(line) ) { col++; } } void KEdit::spellcheck_stop() { deselect(); setReadOnly ( saved_readonlystate); }