class KReplace


Module kdeui
Namespace
Class KReplace
Inherits KFind
A generic implementation of the "replace" function.

Author S.R.Haque , David Faure

Detail:

This class includes prompt handling etc. Also provides some static functions which can be used to create custom behavior instead of using the class directly.

Example:

To use the class to implement a complete replace feature:

In the slot connect to the replace action, after using KReplaceDialog:

// This creates a replace-on-prompt dialog if needed. m_replace = new KReplace(pattern, replacement, options, this);

// Connect signals to code which handles highlighting // of found text, and on-the-fly replacement. connect( m_replace, SIGNAL( highlight( const QString &, int, int ) ), this, SLOT( slotHighlight( const QString &, int, int ) ) ); // Connect findNext signal - called when pressing the button in the dialog connect( m_replace, SIGNAL( findNext() ), this, SLOT( slotReplaceNext() ) ); // Connect replace signal - called when doing a replacement connect( m_replace, SIGNAL( replace(const QString &, int, int, int) ), this, SLOT( slotReplace(const QString &, int, int, int) ) );

Then initialize the variables determining the "current position" (to the cursor, if the option FromCursor is set, to the beginning of the selection if the option SelectedText is set, and to the beginning of the document otherwise). Initialize the "end of search" variables as well (end of doc or end of selection). Swap begin and end if FindBackwards. Finally, call slotReplaceNext();

void slotReplaceNext()
{
KFind.Result res = KFind.NoMatch;
while ( res == KFind.NoMatch &&  ) {
if ( m_replace->needData() )
m_replace->setData(  );

// Let KReplace inspect the text fragment, and display a dialog if a match is found res = m_replace->replace();

if ( res == KFind.NoMatch ) { } }

if ( res == KFind.NoMatch ) // i.e. at end displayFinalDialog(); delete m_replace; m_replace = 0; or if ( m_replace->shouldRestart() ) { reinit (w/o FromCursor) and call slotReplaceNext(); } else { m_replace->closeReplaceNextDialog(); }> }

Don't forget delete m_find in the destructor of your class, unless you gave it a parent widget on construction.



methods