katesearch.h
/* This file is part of the KDE libraries
Copyright (C) 2004-2005 Anders Lund <anders@alweb.dk>
Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org>
Copyright (C) 2001-2004 Christoph Cullmann <cullmann@kde.org>
Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __KATE_SEARCH_H__
#define __KATE_SEARCH_H__
#include "katecursor.h"
#include "../interfaces/document.h"
#include <kdialogbase.h>
#include <qstring.h>
#include <qregexp.h>
#include <qstringlist.h>
#include <qvaluelist.h>
class KateView;
class KateDocument;
class KateSuperRangeList;
class KActionCollection;
class KateSearch : public QObject
{
Q_OBJECT
friend class KateDocument;
private:
class SearchFlags
{
public:
bool caseSensitive :1;
bool wholeWords :1;
bool fromBeginning :1;
bool backward :1;
bool selected :1;
bool prompt :1;
bool replace :1;
bool finished :1;
bool regExp :1;
bool useBackRefs :1;
};
class SConfig
{
public:
SearchFlags flags;
KateTextCursor cursor;
KateTextCursor wrappedEnd; // after wraping around, search/replace until here
bool wrapped; // have we allready wrapped around ?
bool showNotFound; // pop up annoying dialogs?
uint matchedLength;
KateTextCursor selBegin;
KateTextCursor selEnd;
};
public:
enum Dialog_results {
srCancel = KDialogBase::Cancel,
srAll = KDialogBase::User1,
srLast = KDialogBase::User2,
srNo = KDialogBase::User3,
srYes = KDialogBase::Ok
};
public:
KateSearch( KateView* );
~KateSearch();
void createActions( KActionCollection* );
public slots:
void find();
void find( const QString &pattern, long flags, bool add=true, bool shownotfound=false );
void replace();
void replace( const QString &pattern, const QString &replacement, long flags );
void findAgain( bool reverseDirection );
private slots:
void replaceSlot();
void slotFindNext() { findAgain( false ); }
void slotFindPrev() { findAgain( true ); }
private:
static void addToList( QStringList&, const QString& );
static void addToSearchList( const QString& s ) { addToList( s_searchList, s ); }
static void addToReplaceList( const QString& s ) { addToList( s_replaceList, s ); }
static QStringList s_searchList;
static QStringList s_replaceList;
static QString s_pattern;
void search( SearchFlags flags );
void wrapSearch();
bool askContinue();
void findAgain();
void promptReplace();
void replaceAll();
void replaceOne();
void skipOne();
QString getSearchText();
KateTextCursor getCursor( SearchFlags flags );
bool doSearch( const QString& text );
void exposeFound( KateTextCursor &cursor, int slen );
inline KateView* view() { return m_view; }
inline KateDocument* doc() { return m_doc; }
KateView* m_view;
KateDocument* m_doc;
KateSuperRangeList* m_arbitraryHLList;
SConfig s;
QValueList<SConfig> m_searchResults;
int m_resultIndex;
int replaces;
QDialog* replacePrompt;
QString m_replacement;
QRegExp m_re;
};
class KateReplacePrompt : public KDialogBase
{
Q_OBJECT
public:
KateReplacePrompt(QWidget *parent);
signals:
void clicked();
protected slots:
void slotOk ();
void slotClose ();
void slotUser1 ();
void slotUser2 ();
void slotUser3 ();
void done (int result);
};
class SearchCommand : public Kate::Command, public Kate::CommandExtension
{
public:
SearchCommand() : m_ifindFlags(0) {;}
bool exec(class Kate::View *view, const QString &cmd, QString &errorMsg);
bool help(class Kate::View *, const QString &, QString &);
QStringList cmds();
bool wantsToProcessText( const QString &/*cmdname*/ );
void processText( Kate::View *view, const QString& text );
private:
void ifindInit( const QString &cmd );
void ifindClear();
long m_ifindFlags;
};
#endif
// kate: space-indent on; indent-width 2; replace-tabs on;
KateTextCursor
Simple cursor class with no document pointer.
Definition: katecursor.h:33
KActionCollection
KateReplacePrompt::KateReplacePrompt
KateReplacePrompt(QWidget *parent)
Constructor.
Definition: katesearch.cpp:752
Kate::CommandExtension
Extension to the Command interface, allowing to interact with commands during typing.
Definition: document.h:129
KateReplacePrompt::done
void done(int result)
dialog done
Definition: katesearch.cpp:796
KateReplacePrompt::slotClose
void slotClose()
close pressed
Definition: katesearch.cpp:772
KateReplacePrompt::slotUser1
void slotUser1()
replace all pressed
Definition: katesearch.cpp:778
Kate::View
The Kate::View text editor interface.
Definition: view.h:42
KDialogBase
Kate::Command::help
virtual bool help(View *view, const QString &cmd, QString &msg)=0
Shows help for the given view and cmd string, return a bool about success, msg for status...
KateReplacePrompt
simple replace prompt dialog
Definition: katesearch.h:168
Kate::CommandExtension::wantsToProcessText
virtual bool wantsToProcessText(const QString &cmdname)
Definition: document.h:169
KStdAccel::replace
const KShortcut & replace()
KateReplacePrompt::slotUser3
void slotUser3()
Yes pressed.
Definition: katesearch.cpp:790
Kate::Command
Kate Commands.
Definition: document.h:96
Kate::Command::cmds
virtual QStringList cmds()=0
Pure text start part of the commands which can be handled by this object which means i...
Kate::Command::exec
virtual bool exec(View *view, const QString &cmd, QString &msg)=0
Execute this command for the given view and cmd string, return a bool about success, msg for status.
KateReplacePrompt::slotOk
void slotOk()
ok pressed
Definition: katesearch.cpp:766
Kate::CommandExtension::processText
virtual void processText(Kate::View *view, const QString &text)
This is called by the commandline each time the argument text for the command changes, if wantsToProcessText() returns true.
Definition: document.h:177
KateReplacePrompt::clicked
void clicked()
button clicked
KStdAccel::find
const KShortcut & find()
KateReplacePrompt::slotUser2
void slotUser2()
last pressed
Definition: katesearch.cpp:784

KDE Home | KDE Accessibility Home | Description of Access Keys