You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1128 lines
24 KiB
1128 lines
24 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
|
||
|
Copyright (C) 1997 Bernd Johannes Wuebben <wuebben@math.cornell.edu>
|
||
|
Copyright (C) 2000 Waldo Bastian <bastian@kde.org>
|
||
|
|
||
|
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., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include <limits.h> // INT_MAX
|
||
|
|
||
15 years ago
|
#include <tqframe.h>
|
||
|
#include <tqlabel.h>
|
||
|
#include <tqlineedit.h>
|
||
|
#include <tqvbuttongroup.h>
|
||
|
#include <tqcheckbox.h>
|
||
|
#include <tqlayout.h>
|
||
|
#include <tqpushbutton.h>
|
||
|
#include <tqhbox.h>
|
||
|
#include <tqpopupmenu.h>
|
||
15 years ago
|
|
||
|
#include <kapplication.h>
|
||
|
#include <kcombobox.h>
|
||
|
#include <knuminput.h>
|
||
|
#include <kmessagebox.h>
|
||
|
#include <knotifyclient.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <kiconloader.h>
|
||
|
|
||
|
#include "keditcl.h"
|
||
|
|
||
|
|
||
|
//////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// Find Methods
|
||
|
//
|
||
|
|
||
|
void KEdit::search(){
|
||
|
|
||
14 years ago
|
if( replace_dialog && replace_dialog->isVisible() )
|
||
15 years ago
|
{
|
||
14 years ago
|
replace_dialog->hide();
|
||
15 years ago
|
}
|
||
|
|
||
|
if( !srchdialog )
|
||
|
{
|
||
|
srchdialog = new KEdFind( this, "searchdialog", false);
|
||
15 years ago
|
connect(srchdialog,TQT_SIGNAL(search()),this,TQT_SLOT(search_slot()));
|
||
|
connect(srchdialog,TQT_SIGNAL(done()),this,TQT_SLOT(searchdone_slot()));
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
// If we already searched / replaced something before make sure it shows
|
||
|
// up in the find dialog line-edit.
|
||
15 years ago
|
|
||
15 years ago
|
TQString string;
|
||
15 years ago
|
string = srchdialog->getText();
|
||
|
srchdialog->setText(string.isEmpty() ? pattern : string);
|
||
|
|
||
|
deselect();
|
||
|
last_search = NONE;
|
||
|
|
||
|
srchdialog->show();
|
||
|
srchdialog->result();
|
||
|
}
|
||
|
|
||
|
|
||
|
void KEdit::search_slot(){
|
||
|
|
||
|
int line, col;
|
||
|
|
||
|
if (!srchdialog)
|
||
|
return;
|
||
|
|
||
15 years ago
|
TQString to_find_string = srchdialog->getText();
|
||
15 years ago
|
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){
|
||
|
if(!srchdialog->get_direction()){ // forward search
|
||
|
|
||
|
int query = KMessageBox::questionYesNo(
|
||
|
srchdialog,
|
||
|
i18n("End of document reached.\n"\
|
||
|
"Continue from the beginning?"),
|
||
|
i18n("Find"),KStdGuiItem::cont(),i18n("Stop"));
|
||
|
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"),KStdGuiItem::cont(),i18n("Stop"));
|
||
|
if (query == KMessageBox::Yes){
|
||
15 years ago
|
TQString string = textLine( numLines() - 1 );
|
||
15 years ago
|
line = numLines() - 1;
|
||
|
col = string.length();
|
||
|
last_search = BACKWARD;
|
||
|
goto again;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
emit CursorPositionChanged();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
void KEdit::searchdone_slot(){
|
||
|
|
||
|
if (!srchdialog)
|
||
|
return;
|
||
|
|
||
|
srchdialog->hide();
|
||
|
setFocus();
|
||
|
last_search = NONE;
|
||
|
}
|
||
|
|
||
15 years ago
|
/* antlarr: KDE 4: make it const TQString & */
|
||
|
int KEdit::doSearch(TQString s_pattern, bool case_sensitive,
|
||
15 years ago
|
bool wildcard, bool forward, int line, int col){
|
||
|
|
||
|
(void) wildcard; // reserved for possible extension to regex
|
||
|
|
||
|
|
||
|
int i, length;
|
||
|
int pos = -1;
|
||
|
|
||
|
if(forward){
|
||
|
|
||
15 years ago
|
TQString string;
|
||
15 years ago
|
|
||
|
for(i = line; i < numLines(); i++) {
|
||
|
|
||
|
string = textLine(i);
|
||
|
|
||
13 years ago
|
pos = string.find(s_pattern, i == line ? col : 0, case_sensitive);
|
||
15 years ago
|
|
||
|
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
|
||
|
|
||
15 years ago
|
TQString string;
|
||
15 years ago
|
|
||
|
for(i = line; i >= 0; i--) {
|
||
|
|
||
|
string = textLine(i);
|
||
|
int line_length = string.length();
|
||
|
|
||
13 years ago
|
pos = string.findRev(s_pattern, line == i ? col : line_length , case_sensitive);
|
||
15 years ago
|
|
||
|
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 || pattern.isEmpty())
|
||
|
{
|
||
|
search();
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
search_slot();
|
||
|
|
||
|
setFocus();
|
||
|
return true;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
//////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// Replace Methods
|
||
|
//
|
||
|
|
||
|
|
||
14 years ago
|
void KEdit::replace()
|
||
15 years ago
|
{
|
||
|
if( srchdialog && srchdialog->isVisible() )
|
||
|
{
|
||
|
srchdialog->hide();
|
||
|
}
|
||
|
|
||
14 years ago
|
if( !replace_dialog )
|
||
15 years ago
|
{
|
||
14 years ago
|
replace_dialog = new KEdReplace( this, "replace_dialog", false );
|
||
|
connect(replace_dialog,TQT_SIGNAL(find()),this,TQT_SLOT(replace_search_slot()));
|
||
|
connect(replace_dialog,TQT_SIGNAL(replace()),this,TQT_SLOT(replace_slot()));
|
||
|
connect(replace_dialog,TQT_SIGNAL(replaceAll()),this,TQT_SLOT(replace_all_slot()));
|
||
|
connect(replace_dialog,TQT_SIGNAL(done()),this,TQT_SLOT(replacedone_slot()));
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
TQString string = replace_dialog->getText();
|
||
|
replace_dialog->setText(string.isEmpty() ? pattern : string);
|
||
15 years ago
|
|
||
|
|
||
|
deselect();
|
||
14 years ago
|
last_replace = NONE;
|
||
15 years ago
|
|
||
14 years ago
|
replace_dialog->show();
|
||
|
replace_dialog->result();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void KEdit::replace_slot(){
|
||
15 years ago
|
|
||
14 years ago
|
if (!replace_dialog)
|
||
15 years ago
|
return;
|
||
|
|
||
14 years ago
|
if(!can_replace){
|
||
15 years ago
|
KNotifyClient::beep();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
int line,col, length;
|
||
|
|
||
14 years ago
|
TQString string = replace_dialog->getReplaceText();
|
||
15 years ago
|
length = string.length();
|
||
|
|
||
|
this->cut();
|
||
|
|
||
|
getCursorPosition(&line,&col);
|
||
|
|
||
|
insertAt(string,line,col);
|
||
|
setModified(true);
|
||
14 years ago
|
can_replace = false;
|
||
15 years ago
|
|
||
14 years ago
|
if (replace_dialog->get_direction())
|
||
15 years ago
|
{
|
||
|
// Backward
|
||
|
setCursorPosition(line,col+length);
|
||
|
for( int k = 0; k < length; k++){
|
||
|
cursorLeft(true);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// Forward
|
||
|
setCursorPosition(line,col);
|
||
|
for( int k = 0; k < length; k++){
|
||
|
cursorRight(true);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void KEdit::replace_all_slot(){
|
||
15 years ago
|
|
||
14 years ago
|
if (!replace_dialog)
|
||
15 years ago
|
return;
|
||
|
|
||
14 years ago
|
TQString to_find_string = replace_dialog->getText();
|
||
15 years ago
|
|
||
|
int lineFrom, lineTo, colFrom, colTo;
|
||
|
getSelection(&lineFrom, &colFrom, &lineTo, &colTo);
|
||
|
|
||
14 years ago
|
// replace_dialog->get_direction() is true if searching backward
|
||
|
if (replace_dialog->get_direction())
|
||
15 years ago
|
{
|
||
|
if (colTo != -1)
|
||
|
{
|
||
14 years ago
|
replace_all_col = colTo - to_find_string.length();
|
||
|
replace_all_line = lineTo;
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
14 years ago
|
getCursorPosition(&replace_all_line,&replace_all_col);
|
||
|
replace_all_col--;
|
||
15 years ago
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (colFrom != -1)
|
||
|
{
|
||
14 years ago
|
replace_all_col = colFrom;
|
||
|
replace_all_line = lineFrom;
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
14 years ago
|
getCursorPosition(&replace_all_line,&replace_all_col);
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
deselect();
|
||
|
|
||
|
again:
|
||
|
|
||
|
setAutoUpdate(false);
|
||
|
int result = 1;
|
||
|
|
||
|
while(result){
|
||
|
|
||
14 years ago
|
result = doReplace(to_find_string, replace_dialog->case_sensitive(),
|
||
|
false, (!replace_dialog->get_direction()),
|
||
|
replace_all_line,replace_all_col,true);
|
||
15 years ago
|
|
||
|
}
|
||
|
|
||
|
setAutoUpdate(true);
|
||
|
update();
|
||
|
|
||
14 years ago
|
if(!replace_dialog->get_direction()){ // forward search
|
||
15 years ago
|
|
||
|
int query = KMessageBox::questionYesNo(
|
||
|
srchdialog,
|
||
|
i18n("End of document reached.\n"\
|
||
|
"Continue from the beginning?"),
|
||
|
i18n("Find"),KStdGuiItem::cont(),i18n("Stop"));
|
||
|
if (query == KMessageBox::Yes){
|
||
14 years ago
|
replace_all_line = 0;
|
||
|
replace_all_col = 0;
|
||
15 years ago
|
goto again;
|
||
|
}
|
||
|
}
|
||
|
else{ //backward search
|
||
|
|
||
|
int query = KMessageBox::questionYesNo(
|
||
|
srchdialog,
|
||
|
i18n("Beginning of document reached.\n"\
|
||
|
"Continue from the end?"),
|
||
|
i18n("Find"),KStdGuiItem::cont(),i18n("Stop"));
|
||
|
if (query == KMessageBox::Yes){
|
||
15 years ago
|
TQString string = textLine( numLines() - 1 );
|
||
14 years ago
|
replace_all_line = numLines() - 1;
|
||
|
replace_all_col = string.length();
|
||
|
last_replace = BACKWARD;
|
||
15 years ago
|
goto again;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
emit CursorPositionChanged();
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void KEdit::replace_search_slot(){
|
||
15 years ago
|
|
||
|
int line, col;
|
||
|
|
||
14 years ago
|
if (!replace_dialog)
|
||
15 years ago
|
return;
|
||
|
|
||
14 years ago
|
TQString to_find_string = replace_dialog->getText();
|
||
15 years ago
|
|
||
|
int lineFrom, lineTo, colFrom, colTo;
|
||
|
getSelection(&lineFrom, &colFrom, &lineTo, &colTo);
|
||
|
|
||
14 years ago
|
// replace_dialog->get_direction() is true if searching backward
|
||
|
if (replace_dialog->get_direction())
|
||
15 years ago
|
{
|
||
|
if (colFrom != -1)
|
||
|
{
|
||
|
col = colFrom - to_find_string.length();
|
||
|
line = lineFrom;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
getCursorPosition(&line,&col);
|
||
|
col--;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (colTo != -1)
|
||
|
{
|
||
|
col = colTo;
|
||
|
line = lineTo;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
getCursorPosition(&line,&col);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
again:
|
||
|
|
||
14 years ago
|
int result = doReplace(to_find_string, replace_dialog->case_sensitive(),
|
||
|
false, (!replace_dialog->get_direction()), line, col, false );
|
||
15 years ago
|
|
||
|
if(!result){
|
||
14 years ago
|
if(!replace_dialog->get_direction()){ // forward search
|
||
15 years ago
|
|
||
|
int query = KMessageBox::questionYesNo(
|
||
14 years ago
|
replace_dialog,
|
||
15 years ago
|
i18n("End of document reached.\n"\
|
||
|
"Continue from the beginning?"),
|
||
|
i18n("Replace"),KStdGuiItem::cont(),i18n("Stop"));
|
||
|
if (query == KMessageBox::Yes){
|
||
|
line = 0;
|
||
|
col = 0;
|
||
|
goto again;
|
||
|
}
|
||
|
}
|
||
|
else{ //backward search
|
||
|
|
||
|
int query = KMessageBox::questionYesNo(
|
||
14 years ago
|
replace_dialog,
|
||
15 years ago
|
i18n("Beginning of document reached.\n"\
|
||
|
"Continue from the end?"),
|
||
|
i18n("Replace"),KStdGuiItem::cont(),i18n("Stop"));
|
||
|
if (query == KMessageBox::Yes){
|
||
15 years ago
|
TQString string = textLine( numLines() - 1 );
|
||
15 years ago
|
line = numLines() - 1;
|
||
|
col = string.length();
|
||
14 years ago
|
last_replace = BACKWARD;
|
||
15 years ago
|
goto again;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
|
||
|
emit CursorPositionChanged();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
14 years ago
|
void KEdit::replacedone_slot(){
|
||
15 years ago
|
|
||
14 years ago
|
if (!replace_dialog)
|
||
15 years ago
|
return;
|
||
|
|
||
14 years ago
|
replace_dialog->hide();
|
||
|
// replace_dialog->clearFocus();
|
||
15 years ago
|
|
||
|
setFocus();
|
||
|
|
||
14 years ago
|
last_replace = NONE;
|
||
|
can_replace = false;
|
||
15 years ago
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
15 years ago
|
/* antlarr: KDE 4: make it const TQString & */
|
||
|
int KEdit::doReplace(TQString s_pattern, bool case_sensitive,
|
||
14 years ago
|
bool wildcard, bool forward, int line, int col, bool replace_all){
|
||
15 years ago
|
|
||
|
|
||
|
(void) wildcard; // reserved for possible extension to regex
|
||
|
|
||
|
int line_counter, length;
|
||
|
int pos = -1;
|
||
|
|
||
15 years ago
|
TQString string;
|
||
|
TQString stringnew;
|
||
14 years ago
|
TQString replacement;
|
||
15 years ago
|
|
||
14 years ago
|
replacement = replace_dialog->getReplaceText();
|
||
15 years ago
|
line_counter = line;
|
||
14 years ago
|
replace_all_col = col;
|
||
15 years ago
|
|
||
|
if(forward){
|
||
|
|
||
|
int num_lines = numLines();
|
||
|
|
||
|
while (line_counter < num_lines){
|
||
|
|
||
|
string = textLine(line_counter);
|
||
|
|
||
14 years ago
|
if (replace_all){
|
||
13 years ago
|
pos = string.find(s_pattern, replace_all_col, case_sensitive);
|
||
15 years ago
|
}
|
||
|
else{
|
||
13 years ago
|
pos = string.find(s_pattern, line_counter == line ? col : 0, case_sensitive);
|
||
15 years ago
|
}
|
||
|
|
||
|
if (pos == -1 ){
|
||
|
line_counter++;
|
||
14 years ago
|
replace_all_col = 0;
|
||
|
replace_all_line = line_counter;
|
||
15 years ago
|
}
|
||
|
|
||
|
if( pos != -1){
|
||
|
|
||
|
length = s_pattern.length();
|
||
|
|
||
14 years ago
|
if(replace_all){ // automatic
|
||
15 years ago
|
|
||
|
stringnew = string.copy();
|
||
|
do
|
||
|
{
|
||
14 years ago
|
stringnew.replace(pos,length,replacement);
|
||
15 years ago
|
|
||
14 years ago
|
replace_all_col = pos + replacement.length();
|
||
|
replace_all_line = line_counter;
|
||
15 years ago
|
|
||
13 years ago
|
pos = stringnew.find(s_pattern, replace_all_col, case_sensitive);
|
||
15 years ago
|
}
|
||
|
while( pos != -1);
|
||
|
|
||
|
removeLine(line_counter);
|
||
|
insertLine(stringnew,line_counter);
|
||
|
|
||
|
setModified(true);
|
||
|
}
|
||
|
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;
|
||
14 years ago
|
last_replace = FORWARD;
|
||
|
can_replace = true;
|
||
15 years ago
|
|
||
|
return 1;
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else{ // searching backwards
|
||
|
|
||
|
while(line_counter >= 0){
|
||
|
|
||
|
string = textLine(line_counter);
|
||
|
|
||
|
int line_length = string.length();
|
||
|
|
||
14 years ago
|
if( replace_all ){
|
||
|
if (replace_all_col < 0)
|
||
15 years ago
|
pos = -1;
|
||
|
else
|
||
13 years ago
|
pos = string.findRev(s_pattern, replace_all_col , case_sensitive);
|
||
15 years ago
|
}
|
||
|
else{
|
||
|
if ((line == line_counter) && (col < 0))
|
||
|
pos = -1;
|
||
|
else
|
||
13 years ago
|
pos = string.findRev(s_pattern,
|
||
15 years ago
|
line == line_counter ? col : line_length , case_sensitive);
|
||
|
}
|
||
|
|
||
|
if (pos == -1 ){
|
||
|
line_counter--;
|
||
|
|
||
14 years ago
|
replace_all_col = 0;
|
||
15 years ago
|
if(line_counter >= 0){
|
||
|
string = textLine(line_counter);
|
||
14 years ago
|
replace_all_col = string.length();
|
||
15 years ago
|
|
||
|
}
|
||
14 years ago
|
replace_all_line = line_counter;
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
if (pos != -1){
|
||
|
length = s_pattern.length();
|
||
|
|
||
14 years ago
|
if(replace_all){ // automatic
|
||
15 years ago
|
|
||
|
stringnew = string.copy();
|
||
14 years ago
|
stringnew.replace(pos,length,replacement);
|
||
15 years ago
|
|
||
|
removeLine(line_counter);
|
||
|
insertLine(stringnew,line_counter);
|
||
|
|
||
14 years ago
|
replace_all_col = pos-length;
|
||
|
replace_all_line = line_counter;
|
||
|
if (replace_all_col < 0)
|
||
15 years ago
|
{
|
||
|
line_counter--;
|
||
|
|
||
|
if(line_counter >= 0){
|
||
|
string = textLine(line_counter);
|
||
14 years ago
|
replace_all_col = string.length();
|
||
15 years ago
|
}
|
||
14 years ago
|
replace_all_line = line_counter;
|
||
15 years ago
|
}
|
||
|
|
||
|
setModified(true);
|
||
|
}
|
||
|
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 + length ,false );
|
||
|
|
||
|
for(int l = 0 ; l < length; l++){
|
||
|
cursorLeft(true);
|
||
|
}
|
||
|
|
||
|
setCursorPosition(line_counter, pos ,true );
|
||
|
pattern = s_pattern;
|
||
|
|
||
14 years ago
|
last_replace = BACKWARD;
|
||
|
can_replace = true;
|
||
15 years ago
|
|
||
|
return 1;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// Find Dialog
|
||
|
//
|
||
|
|
||
|
class KEdFind::KEdFindPrivate
|
||
|
{
|
||
|
public:
|
||
15 years ago
|
KEdFindPrivate( TQWidget *parent ) {
|
||
15 years ago
|
combo = new KHistoryCombo( parent, "value" );
|
||
|
combo->setMaxCount( 20 ); // just some default
|
||
|
}
|
||
|
~KEdFindPrivate() {
|
||
|
delete combo;
|
||
|
}
|
||
|
|
||
|
KHistoryCombo *combo;
|
||
|
};
|
||
|
|
||
|
|
||
15 years ago
|
KEdFind::KEdFind( TQWidget *parent, const char *name, bool modal )
|
||
15 years ago
|
:KDialogBase( parent, name, modal, i18n("Find"),
|
||
14 years ago
|
modal ? User1|Cancel : User1|Close, User1, false, KGuiItem( i18n("&Find"), "find") )
|
||
15 years ago
|
{
|
||
|
setWFlags( WType_TopLevel );
|
||
|
|
||
15 years ago
|
TQWidget *page = new TQWidget( this );
|
||
15 years ago
|
setMainWidget(page);
|
||
15 years ago
|
TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
|
||
15 years ago
|
|
||
|
d = new KEdFindPrivate( page );
|
||
|
|
||
15 years ago
|
TQString text = i18n("Find:");
|
||
14 years ago
|
TQLabel *label = new TQLabel( text, page , "find" );
|
||
15 years ago
|
topLayout->addWidget( label );
|
||
|
|
||
|
d->combo->setMinimumWidth(fontMetrics().maxWidth()*20);
|
||
|
d->combo->setFocus();
|
||
|
|
||
15 years ago
|
connect(d->combo, TQT_SIGNAL(textChanged ( const TQString & )),
|
||
|
this,TQT_SLOT(textSearchChanged ( const TQString & )));
|
||
15 years ago
|
|
||
|
topLayout->addWidget(d->combo);
|
||
|
|
||
15 years ago
|
group = new TQVButtonGroup( i18n("Options"), page );
|
||
15 years ago
|
topLayout->addWidget( group );
|
||
|
|
||
15 years ago
|
TQHBox* row1 = new TQHBox( group );
|
||
15 years ago
|
|
||
|
text = i18n("Case &sensitive");
|
||
15 years ago
|
sensitive = new TQCheckBox( text, row1, "case");
|
||
15 years ago
|
text = i18n("Find &backwards");
|
||
15 years ago
|
direction = new TQCheckBox( text, row1, "direction" );
|
||
15 years ago
|
|
||
|
|
||
|
enableButton( KDialogBase::User1, !d->combo->currentText().isEmpty() );
|
||
|
|
||
|
if ( !modal )
|
||
15 years ago
|
connect( this, TQT_SIGNAL( closeClicked() ), this, TQT_SLOT( slotCancel() ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
KEdFind::~KEdFind()
|
||
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KEdFind::textSearchChanged ( const TQString &text )
|
||
15 years ago
|
{
|
||
|
enableButton( KDialogBase::User1, !text.isEmpty() );
|
||
|
}
|
||
|
|
||
|
void KEdFind::slotCancel( void )
|
||
|
{
|
||
|
emit done();
|
||
|
KDialogBase::slotCancel();
|
||
|
}
|
||
|
|
||
|
void KEdFind::slotUser1( void )
|
||
|
{
|
||
|
if( !d->combo->currentText().isEmpty() )
|
||
|
{
|
||
|
d->combo->addToHistory( d->combo->currentText() );
|
||
|
emit search();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQString KEdFind::getText() const
|
||
15 years ago
|
{
|
||
|
return d->combo->currentText();
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
/* antlarr: KDE 4: make it const TQString & */
|
||
|
void KEdFind::setText(TQString string)
|
||
15 years ago
|
{
|
||
|
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:
|
||
15 years ago
|
KEdReplacePrivate( TQWidget *parent ) {
|
||
15 years ago
|
searchCombo = new KHistoryCombo( parent, "value" );
|
||
14 years ago
|
replaceCombo = new KHistoryCombo( parent, "replace_value" );
|
||
15 years ago
|
|
||
|
searchCombo->setMaxCount( 20 ); // just some defaults
|
||
14 years ago
|
replaceCombo->setMaxCount( 20 );
|
||
15 years ago
|
}
|
||
|
~KEdReplacePrivate() {
|
||
|
delete searchCombo;
|
||
14 years ago
|
delete replaceCombo;
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
KHistoryCombo *searchCombo, *replaceCombo;
|
||
15 years ago
|
};
|
||
|
|
||
15 years ago
|
KEdReplace::KEdReplace( TQWidget *parent, const char *name, bool modal )
|
||
15 years ago
|
:KDialogBase( parent, name, modal, i18n("Replace"),
|
||
|
modal ? User3|User2|User1|Cancel : User3|User2|User1|Close,
|
||
|
User3, false,
|
||
14 years ago
|
i18n("Replace &All"), i18n("&Replace"), KGuiItem( i18n("&Find"), "find") )
|
||
15 years ago
|
{
|
||
|
setWFlags( WType_TopLevel );
|
||
|
|
||
14 years ago
|
setButtonBoxOrientation( Qt::Vertical );
|
||
15 years ago
|
|
||
15 years ago
|
TQFrame *page = makeMainWidget();
|
||
|
TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
|
||
15 years ago
|
|
||
|
d = new KEdReplacePrivate( page );
|
||
|
|
||
15 years ago
|
TQString text = i18n("Find:");
|
||
14 years ago
|
TQLabel *label = new TQLabel( text, page, "find" );
|
||
15 years ago
|
topLayout->addWidget( label );
|
||
|
|
||
|
d->searchCombo->setMinimumWidth(fontMetrics().maxWidth()*20);
|
||
|
d->searchCombo->setFocus();
|
||
|
topLayout->addWidget(d->searchCombo);
|
||
|
|
||
|
text = i18n("Replace with:");
|
||
14 years ago
|
label = new TQLabel( text, page, "replace" );
|
||
15 years ago
|
topLayout->addWidget( label );
|
||
|
|
||
14 years ago
|
d->replaceCombo->setMinimumWidth(fontMetrics().maxWidth()*20);
|
||
|
topLayout->addWidget(d->replaceCombo);
|
||
15 years ago
|
|
||
15 years ago
|
connect(d->searchCombo, TQT_SIGNAL(textChanged ( const TQString & )),
|
||
|
this,TQT_SLOT(textSearchChanged ( const TQString & )));
|
||
15 years ago
|
|
||
15 years ago
|
TQButtonGroup *group = new TQButtonGroup( i18n("Options"), page );
|
||
15 years ago
|
topLayout->addWidget( group );
|
||
|
|
||
15 years ago
|
TQGridLayout *gbox = new TQGridLayout( group, 3, 2, spacingHint() );
|
||
15 years ago
|
gbox->addRowSpacing( 0, fontMetrics().lineSpacing() );
|
||
|
|
||
|
text = i18n("Case &sensitive");
|
||
15 years ago
|
sensitive = new TQCheckBox( text, group, "case");
|
||
15 years ago
|
text = i18n("Find &backwards");
|
||
15 years ago
|
direction = new TQCheckBox( text, group, "direction" );
|
||
15 years ago
|
gbox->addWidget( sensitive, 1, 0 );
|
||
|
gbox->addWidget( direction, 1, 1 );
|
||
|
gbox->setRowStretch( 2, 10 );
|
||
|
}
|
||
|
|
||
|
|
||
|
KEdReplace::~KEdReplace()
|
||
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KEdReplace::textSearchChanged ( const TQString &text )
|
||
15 years ago
|
{
|
||
|
bool state=text.isEmpty();
|
||
|
enableButton( KDialogBase::User1, !state );
|
||
|
enableButton( KDialogBase::User2, !state );
|
||
|
enableButton( KDialogBase::User3, !state );
|
||
|
}
|
||
|
|
||
|
void KEdReplace::slotCancel( void )
|
||
|
{
|
||
|
emit done();
|
||
|
d->searchCombo->clearEdit();
|
||
14 years ago
|
d->replaceCombo->clearEdit();
|
||
15 years ago
|
KDialogBase::slotCancel();
|
||
|
}
|
||
|
|
||
|
void KEdReplace::slotClose( void )
|
||
|
{
|
||
|
slotCancel();
|
||
|
}
|
||
|
|
||
|
void KEdReplace::slotUser1( void )
|
||
|
{
|
||
|
if( !d->searchCombo->currentText().isEmpty() )
|
||
|
{
|
||
14 years ago
|
d->replaceCombo->addToHistory( d->replaceCombo->currentText() );
|
||
|
emit replaceAll();
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void KEdReplace::slotUser2( void )
|
||
|
{
|
||
|
if( !d->searchCombo->currentText().isEmpty() )
|
||
|
{
|
||
14 years ago
|
d->replaceCombo->addToHistory( d->replaceCombo->currentText() );
|
||
|
emit replace();
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void KEdReplace::slotUser3( void )
|
||
|
{
|
||
|
if( !d->searchCombo->currentText().isEmpty() )
|
||
|
{
|
||
|
d->searchCombo->addToHistory( d->searchCombo->currentText() );
|
||
14 years ago
|
emit find();
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQString KEdReplace::getText()
|
||
15 years ago
|
{
|
||
|
return d->searchCombo->currentText();
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQString KEdReplace::getReplaceText()
|
||
15 years ago
|
{
|
||
14 years ago
|
return d->replaceCombo->currentText();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
15 years ago
|
/* antlarr: KDE 4: make it const TQString & */
|
||
|
void KEdReplace::setText(TQString string)
|
||
15 years ago
|
{
|
||
|
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;
|
||
|
}
|
||
|
|
||
14 years ago
|
KHistoryCombo * KEdReplace::replaceCombo() const
|
||
15 years ago
|
{
|
||
14 years ago
|
return d->replaceCombo;
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
15 years ago
|
KEdGotoLine::KEdGotoLine( TQWidget *parent, const char *name, bool modal )
|
||
15 years ago
|
:KDialogBase( parent, name, modal, i18n("Go to Line"), modal ? Ok|Cancel : Ok|Close, Ok, false )
|
||
|
{
|
||
15 years ago
|
TQWidget *page = new TQWidget( this );
|
||
15 years ago
|
setMainWidget(page);
|
||
15 years ago
|
TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
|
||
15 years ago
|
|
||
|
lineNum = new KIntNumInput( 1, page);
|
||
|
lineNum->setRange(1, 1000000, 1, false);
|
||
|
lineNum->setLabel(i18n("Go to line:"), AlignVCenter | AlignLeft);
|
||
|
// lineNum->setMinimumWidth(fontMetrics().maxWidth()*20);
|
||
|
topLayout->addWidget( lineNum );
|
||
|
|
||
|
topLayout->addStretch(10);
|
||
|
lineNum->setFocus();
|
||
|
}
|
||
|
|
||
|
|
||
|
void KEdGotoLine::selected(int)
|
||
|
{
|
||
|
accept();
|
||
|
}
|
||
|
|
||
|
|
||
|
int KEdGotoLine::getLineNumber()
|
||
|
{
|
||
|
return lineNum->value();
|
||
|
}
|
||
|
|
||
|
|
||
|
//////////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// Spell Checking
|
||
|
//
|
||
|
|
||
|
void KEdit::spellcheck_start()
|
||
|
{
|
||
|
saved_readonlystate = isReadOnly();
|
||
|
setReadOnly(true);
|
||
|
}
|
||
|
|
||
15 years ago
|
void KEdit::misspelling (const TQString &word, const TQStringList &, unsigned int pos)
|
||
15 years ago
|
{
|
||
|
|
||
|
unsigned int l = 0;
|
||
|
unsigned int cnt = 0;
|
||
|
posToRowCol (pos, l, cnt);
|
||
|
setSelection(l, cnt, l, cnt+word.length());
|
||
|
|
||
|
/*
|
||
|
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
|
||
15 years ago
|
void KEdit::corrected (const TQString &originalword, const TQString &newword, unsigned int pos)
|
||
15 years ago
|
{
|
||
|
//we'll reselect the original word in case the user has played with
|
||
14 years ago
|
//the selection in eframe or the word was auto-replaced
|
||
15 years ago
|
|
||
|
unsigned int l = 0;
|
||
|
unsigned int cnt = 0;
|
||
|
|
||
|
if( newword != originalword )
|
||
|
{
|
||
|
posToRowCol (pos, l, cnt);
|
||
|
setSelection(l, cnt, l, cnt+originalword.length());
|
||
|
|
||
|
setReadOnly ( false );
|
||
|
removeSelectedText();
|
||
|
insert(newword);
|
||
|
setReadOnly ( true );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
deselect();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KEdit::posToRowCol(unsigned int pos, unsigned int &line, unsigned int &col)
|
||
|
{
|
||
|
for (line = 0; line < static_cast<uint>(numLines()) && col <= pos; line++)
|
||
|
{
|
||
|
col += lineLength(line)+1;
|
||
|
}
|
||
|
line--;
|
||
|
col = pos - col + lineLength(line) + 1;
|
||
|
}
|
||
|
|
||
|
void KEdit::spellcheck_stop()
|
||
|
{
|
||
|
deselect();
|
||
|
|
||
|
setReadOnly ( saved_readonlystate);
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KEdit::selectWordUnderCursor( )
|
||
15 years ago
|
{
|
||
|
int parag;
|
||
|
int pos;
|
||
|
|
||
|
getCursorPosition(¶g, &pos);
|
||
|
|
||
15 years ago
|
TQString txt = text(parag);
|
||
15 years ago
|
|
||
|
// Find start
|
||
|
int start = pos;
|
||
|
while( start > 0 )
|
||
|
{
|
||
15 years ago
|
const TQChar &ch = txt[start-1];
|
||
15 years ago
|
if (ch.isSpace() || ch.isPunct())
|
||
|
break;
|
||
|
start--;
|
||
|
}
|
||
|
|
||
|
// Find end
|
||
|
int end = pos;
|
||
|
int len = txt.length();
|
||
|
while( end < len )
|
||
|
{
|
||
15 years ago
|
const TQChar &ch = txt[end];
|
||
15 years ago
|
if (ch.isSpace() || ch.isPunct())
|
||
|
break;
|
||
|
end++;
|
||
|
}
|
||
|
setSelection(parag, start, parag, end);
|
||
|
return txt.mid(start, end-start);
|
||
|
}
|
||
|
|
||
15 years ago
|
TQPopupMenu *KEdit::createPopupMenu( const TQPoint& pos )
|
||
15 years ago
|
{
|
||
|
enum { IdUndo, IdRedo, IdSep1, IdCut, IdCopy, IdPaste, IdClear, IdSep2, IdSelectAll };
|
||
|
|
||
15 years ago
|
TQPopupMenu *menu = TQMultiLineEdit::createPopupMenu( pos );
|
||
15 years ago
|
|
||
|
if ( isReadOnly() )
|
||
|
menu->changeItem( menu->idAt(0), SmallIconSet("editcopy"), menu->text( menu->idAt(0) ) );
|
||
|
else {
|
||
|
int id = menu->idAt(0);
|
||
|
menu->changeItem( id - IdUndo, SmallIconSet("undo"), menu->text( id - IdUndo) );
|
||
|
menu->changeItem( id - IdRedo, SmallIconSet("redo"), menu->text( id - IdRedo) );
|
||
|
menu->changeItem( id - IdCut, SmallIconSet("editcut"), menu->text( id - IdCut) );
|
||
|
menu->changeItem( id - IdCopy, SmallIconSet("editcopy"), menu->text( id - IdCopy) );
|
||
|
menu->changeItem( id - IdPaste, SmallIconSet("editpaste"), menu->text( id - IdPaste) );
|
||
|
menu->changeItem( id - IdClear, SmallIconSet("editclear"), menu->text( id - IdClear) );
|
||
|
}
|
||
|
|
||
|
return menu;
|
||
|
}
|