Warning, file /office/calligra/libs/text/KoReplaceStrategy.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2008 Thorsten Zachmann <zachmann@kde.org> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KoReplaceStrategy.h" 0021 0022 #include <QTextCursor> 0023 #include <kfind.h> 0024 #include <kreplacedialog.h> 0025 #include <kmessagebox.h> 0026 #include <klocalizedstring.h> 0027 0028 #include "FindDirection_p.h" 0029 0030 KoReplaceStrategy::KoReplaceStrategy(QWidget * parent) 0031 : m_dialog(new KReplaceDialog(parent)) 0032 , m_replaced(0) 0033 { 0034 m_dialog->setOptions(KFind::FromCursor); 0035 } 0036 0037 KoReplaceStrategy::~KoReplaceStrategy() 0038 { 0039 if (m_dialog->parent()==0) 0040 delete m_dialog; 0041 } 0042 0043 KFindDialog *KoReplaceStrategy::dialog() const 0044 { 0045 return m_dialog; 0046 } 0047 0048 void KoReplaceStrategy::reset() 0049 { 0050 m_replaced = 0; 0051 } 0052 0053 void KoReplaceStrategy::displayFinalDialog() 0054 { 0055 if (m_replaced == 0) { 0056 KMessageBox::information(m_dialog->parentWidget(), i18n("Found no match\n\nNo text was replaced")); 0057 } else { 0058 KMessageBox::information(m_dialog->parentWidget(), 0059 i18np("1 replacement made", 0060 "%1 replacements made", m_replaced)); 0061 } 0062 reset(); 0063 } 0064 0065 bool KoReplaceStrategy::foundMatch(QTextCursor &cursor, FindDirection *findDirection) 0066 { 0067 bool replace = true; 0068 if ((m_dialog->options() & KReplaceDialog::PromptOnReplace) != 0) { 0069 findDirection->select(cursor); 0070 // TODO: not only Yes and No, but Yes, No, All and Cancel 0071 int value = KMessageBox::questionYesNo(m_dialog->parentWidget(), 0072 i18n("Replace %1 with %2?", m_dialog->pattern(), m_dialog->replacement())); 0073 if (value != KMessageBox::Yes) { 0074 replace = false; 0075 } 0076 } 0077 0078 if (replace) { 0079 cursor.insertText(m_dialog->replacement()); 0080 ++m_replaced; 0081 } 0082 0083 return true; 0084 }