• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeutils
 

tdeutils

  • tdeutils
kreplacedialog.cpp
1 /*
2  Copyright (C) 2001, S.R.Haque <srhaque@iee.org>.
3  Copyright (C) 2002, David Faure <david@mandrakesoft.com>
4  This file is part of the KDE project
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2, as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "kreplacedialog.h"
22 
23 #include <tqcheckbox.h>
24 #include <tqgroupbox.h>
25 #include <tqlabel.h>
26 #include <tqlayout.h>
27 #include <tqregexp.h>
28 #include <kcombobox.h>
29 #include <tdelocale.h>
30 #include <tdemessagebox.h>
31 #include <kdebug.h>
32 
38 class KReplaceDialog::KReplaceDialogPrivate {
39  public:
40  KReplaceDialogPrivate() : m_initialShowDone(false) {}
41  TQStringList replaceStrings;
42  bool m_initialShowDone;
43 };
44 
45 KReplaceDialog::KReplaceDialog(TQWidget *parent, const char *name, long options, const TQStringList &findStrings, const TQStringList &replaceStrings, bool hasSelection) :
46  KFindDialog(parent, name, true)
47 {
48  d = new KReplaceDialogPrivate;
49  d->replaceStrings = replaceStrings;
50  init(true, findStrings, hasSelection);
51  setOptions(options);
52 }
53 
54 KReplaceDialog::~KReplaceDialog()
55 {
56  delete d;
57 }
58 
59 void KReplaceDialog::showEvent( TQShowEvent *e )
60 {
61  if ( !d->m_initialShowDone )
62  {
63  d->m_initialShowDone = true; // only once
64 
65  if (!d->replaceStrings.isEmpty())
66  {
67  setReplacementHistory(d->replaceStrings);
68  m_replace->lineEdit()->setText( d->replaceStrings[0] );
69  }
70  }
71 
72  KFindDialog::showEvent(e);
73 }
74 
75 long KReplaceDialog::options() const
76 {
77  long options = 0;
78 
79  options = KFindDialog::options();
80  if (m_promptOnReplace->isChecked())
81  options |= PromptOnReplace;
82  if (m_backRef->isChecked())
83  options |= BackReference;
84  return options;
85 }
86 
87 TQWidget *KReplaceDialog::replaceExtension()
88 {
89  if (!m_replaceExtension)
90  {
91  m_replaceExtension = new TQWidget(m_replaceGrp);
92  m_replaceLayout->addMultiCellWidget(m_replaceExtension, 3, 3, 0, 1);
93  }
94 
95  return m_replaceExtension;
96 }
97 
98 TQString KReplaceDialog::replacement() const
99 {
100  return m_replace->currentText();
101 }
102 
103 TQStringList KReplaceDialog::replacementHistory() const
104 {
105  TQStringList lst = m_replace->historyItems();
106  // historyItems() doesn't tell us about the case of replacing with an empty string
107  if ( m_replace->lineEdit()->text().isEmpty() )
108  lst.prepend( TQString::null );
109  return lst;
110 }
111 
112 void KReplaceDialog::setOptions(long options)
113 {
114  KFindDialog::setOptions(options);
115  m_promptOnReplace->setChecked(options & PromptOnReplace);
116  m_backRef->setChecked(options & BackReference);
117 }
118 
119 void KReplaceDialog::setReplacementHistory(const TQStringList &strings)
120 {
121  if (strings.count() > 0)
122  m_replace->setHistoryItems(strings, true);
123  else
124  m_replace->clearHistory();
125 }
126 
127 void KReplaceDialog::slotOk()
128 {
129  // If regex and backrefs are enabled, do a sanity check.
130  if ( m_regExp->isChecked() && m_backRef->isChecked() )
131  {
132  TQRegExp r ( pattern() );
133  int caps = r.numCaptures();
134  TQRegExp check(TQString("((?:\\\\)+)(\\d+)"));
135  int p = 0;
136  TQString rep = replacement();
137  while ( (p = check.search( rep, p ) ) > -1 )
138  {
139  if ( check.cap(1).length()%2 && check.cap(2).toInt() > caps )
140  {
141  KMessageBox::information( this, i18n(
142  "Your replacement string is referencing a capture greater than '\\%1', ").arg( caps ) +
143  ( caps ?
144  i18n("but your pattern only defines 1 capture.",
145  "but your pattern only defines %n captures.", caps ) :
146  i18n("but your pattern defines no captures.") ) +
147  i18n("\nPlease correct.") );
148  return; // abort OKing
149  }
150  p += check.matchedLength();
151  }
152 
153  }
154 
155  KFindDialog::slotOk();
156  m_replace->addToHistory(replacement());
157 }
158 #include "kreplacedialog.moc"
KFindDialog
A generic "find" dialog.
Definition: kfinddialog.h:76
KFindDialog::options
long options() const
Returns the state of the options.
Definition: kfinddialog.cpp:318
KFindDialog::pattern
TQString pattern() const
Returns the pattern to find.
Definition: kfinddialog.cpp:337
KFindDialog::setOptions
void setOptions(long options)
Set the options which are checked.
Definition: kfinddialog.cpp:426
KMessageBox::information
static void information(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const TQString &dontShowAgainName=TQString::null, int options=Notify)
KReplaceDialog::replacement
TQString replacement() const
Returns the replacement string.
Definition: kreplacedialog.cpp:98
KReplaceDialog::setReplacementHistory
void setReplacementHistory(const TQStringList &history)
Provide the list of strings to be displayed as the history of replacement strings.
Definition: kreplacedialog.cpp:119
KReplaceDialog::options
long options() const
Returns the state of the options.
Definition: kreplacedialog.cpp:75
KReplaceDialog::setOptions
void setOptions(long options)
Set the options which are enabled.
Definition: kreplacedialog.cpp:112
KReplaceDialog::KReplaceDialog
KReplaceDialog(TQWidget *parent=0, const char *name=0, long options=0, const TQStringList &findStrings=TQStringList(), const TQStringList &replaceStrings=TQStringList(), bool hasSelection=true)
Construct a replace dialog.read-only or rather select-only combo box with a parent object and a name.
Definition: kreplacedialog.cpp:45
KReplaceDialog::~KReplaceDialog
virtual ~KReplaceDialog()
Destructor.
Definition: kreplacedialog.cpp:54
KReplaceDialog::replacementHistory
TQStringList replacementHistory() const
Returns the list of history items.
Definition: kreplacedialog.cpp:103
KReplaceDialog::PromptOnReplace
@ PromptOnReplace
Should the user be prompted before the replace operation?
Definition: kreplacedialog.h:71
KReplaceDialog::replaceExtension
TQWidget * replaceExtension()
Returns an empty widget which the user may fill with additional UI elements as required.
Definition: kreplacedialog.cpp:87
tdelocale.h

tdeutils

Skip menu "tdeutils"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeutils

Skip menu "tdeutils"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeutils by doxygen 1.9.1
This website is maintained by Timothy Pearson.