kexi

kexifinddialog.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004-2007 Jaroslaw Staniek <js@iidea.pl>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kexifinddialog.h"
21
22#include <kstdguiitem.h>
23#include <kstdaction.h>
24#include <kpushbutton.h>
25#include <kcombobox.h>
26#include <tdelocale.h>
27#include <kdebug.h>
28#include <kdialog.h>
29#include <tdeaction.h>
30#include <kiconloader.h>
31
32#include <tqcheckbox.h>
33#include <tqlabel.h>
34#include <tqguardedptr.h>
35#include <tqlayout.h>
36#include <tqaccel.h>
37
39class KexiFindDialog::Private
40{
41 public:
42 Private()
43 {
44 accels.setAutoDelete(true);
45 }
46 ~Private()
47 {
48 }
52 void setActionAndAccel(TDEAction *action, TQWidget* parent, const char* member)
53 {
54 if (!action)
55 return;
56 TQObject::connect(parent, member, action, TQ_SLOT(activate()));
57 if (action->shortcut().isNull())
58 return;
59 TQAccel *accel = new TQAccel(parent); // we want to handle dialog-wide shortcut as well
60 accels.append( accel );
61 accel->connectItem(
62 accel->insertItem( action->shortcut() ), parent, member );
63 }
64
65 TQStringList lookInColumnNames;
66 TQStringList lookInColumnCaptions;
67 TQString objectName;
68 TQGuardedPtr<TDEAction> findnextAction;
69 TQGuardedPtr<TDEAction> findprevAction;
70 TQGuardedPtr<TDEAction> replaceAction;
71 TQGuardedPtr<TDEAction> replaceallAction;
72 TQPtrList<TQAccel> accels;
73 bool replaceMode : 1;
74};
75
76//------------------------------------------
77
79 : KexiFindDialogBase(parent, "KexiFindDialog", false,
80 TQt::WType_Dialog|TQt::WStyle_NormalBorder|TQt::WStyle_Title
81 |TQt::WStyle_SysMenu|TQt::WStyle_Customize|TQt::WStyle_Tool)
82 , d( new Private() )
83{
84 m_search->setCurrentItem((int)KexiSearchAndReplaceViewInterface::Options::SearchDown);
85 layout()->setMargin( KDialog::marginHint() );
86 layout()->setSpacing( KDialog::spacingHint() );
87 TDEAction *a = KStdAction::findNext(0, 0, 0);
88 m_btnFind->setText(a->text());
89 m_btnFind->setIconSet(a->iconSet());
90 delete a;
91 m_btnClose->setText(KStdGuiItem::close().text());
92 m_btnClose->setIconSet(KStdGuiItem::close().iconSet());
93 connect(m_btnFind, TQ_SIGNAL(clicked()), this, TQ_SIGNAL(findNext()));
94 connect(m_btnClose, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotCloseClicked()));
95 connect(m_btnReplace, TQ_SIGNAL(clicked()), this, TQ_SIGNAL(replaceNext()));
96 connect(m_btnReplaceAll, TQ_SIGNAL(clicked()), this, TQ_SIGNAL(replaceAll()));
97 // clear message after the text is changed
98 connect(m_textToFind, TQ_SIGNAL(textChanged()), this, TQ_SIGNAL(updateMessage()));
99 connect(m_textToReplace, TQ_SIGNAL(textChanged()), this, TQ_SIGNAL(updateMessage()));
100
101 d->replaceMode = true; //to force updating by setReplaceMode()
102 setReplaceMode(false);
103
104 setLookInColumnList(TQStringList(), TQStringList());
105}
106
107KexiFindDialog::~KexiFindDialog()
108{
109 delete d;
110}
111
112void KexiFindDialog::setActions( TDEAction *findnext, TDEAction *findprev,
113 TDEAction *replace, TDEAction *replaceall )
114{
115 d->findnextAction = findnext;
116 d->findprevAction = findprev;
117 d->replaceAction = replace;
118 d->replaceallAction = replaceall;
119 d->accels.clear();
120 d->setActionAndAccel(d->findnextAction, this, TQ_SIGNAL(findNext()));
121 d->setActionAndAccel(d->findprevAction, this, TQ_SIGNAL(findPrevious()));
122 d->setActionAndAccel(d->replaceAction, this, TQ_SIGNAL(replaceNext()));
123 d->setActionAndAccel(d->replaceallAction, this, TQ_SIGNAL(replaceAll()));
124}
125
127{
128 return d->lookInColumnNames;
129}
130
132{
133 return d->lookInColumnCaptions;
134}
135
137{
138 int index = m_lookIn->currentItem();
139 if (index <= 0 || index >= (int)d->lookInColumnNames.count())
140 return TQString();
141 else if (index == 1)
142 return "(field)";
143 return d->lookInColumnNames[index - 1/*"(All fields)"*/ - 1/*"(Current field)"*/];
144}
145
147{
148 return m_textToFind->currentText();
149}
150
152{
153 return m_textToReplace->currentText();
154}
155
156void KexiFindDialog::setLookInColumnList(const TQStringList& columnNames,
157 const TQStringList& columnCaptions)
158{
159 d->lookInColumnNames = columnNames;
160 d->lookInColumnCaptions = columnCaptions;
161 m_lookIn->clear();
162 m_lookIn->insertItem(i18n("(All fields)"));
163 m_lookIn->insertItem(i18n("(Current field)"));
164 m_lookIn->insertStringList(d->lookInColumnCaptions);
165}
166
167void KexiFindDialog::setCurrentLookInColumnName(const TQString& columnName)
168{
169 int index;
170 if (columnName.isEmpty())
171 index = 0;
172 else if (columnName == "(field)")
173 index = 1;
174 else {
175 index = d->lookInColumnNames.findIndex( columnName );
176 if (index == -1) {
177 kdWarning() << TQString("KexiFindDialog::setCurrentLookInColumn(%1) column name not found on the list")
178 .arg(columnName) << endl;
179 return;
180 }
181 index = index + 1/*"(All fields)"*/ + 1/*"(Current field)"*/;
182 }
183 m_lookIn->setCurrentItem(index);
184}
185
187{
188 if (d->replaceMode == set)
189 return;
190 d->replaceMode = set;
191 if (d->replaceMode) {
192 m_promptOnReplace->show();
193 m_replaceLbl->show();
194 m_textToReplace->show();
195 m_btnReplace->show();
196 m_btnReplaceAll->show();
197 }
198 else {
199 m_promptOnReplace->hide();
200 m_replaceLbl->hide();
201 m_textToReplace->hide();
202 m_btnReplace->hide();
203 m_btnReplaceAll->hide();
204 resize(width(),height()-30);
205 }
206 setObjectNameForCaption(d->objectName);
207 updateGeometry();
208}
209
211{
212 d->objectName = name;
213 if (d->replaceMode) {
214 if (name.isEmpty())
215 setCaption(i18n("Replace"));
216 else
217 setCaption(i18n("Replace in \"%1\"").arg(name));
218 }
219 else {
220 if (name.isEmpty())
221 setCaption(i18n("Find"));
222 else
223 setCaption(i18n("Find in \"%1\"").arg(name));
224 }
225}
226
228{
229 m_btnFind->setEnabled(enable);
230 m_btnReplace->setEnabled(enable);
231 m_btnReplaceAll->setEnabled(enable);
232 if (!enable)
233 setObjectNameForCaption(TQString());
234}
235
236void KexiFindDialog::setMessage(const TQString& message)
237{
238 m_messageLabel->setText(message);
239}
240
242{
243 if (found)
244 setMessage(TQString());
245 else
246 setMessage(i18n("The search item was not found"));
247}
248
249void KexiFindDialog::slotCloseClicked()
250{
251 reject();
252}
253
255{
256 m_textToFind->setFocus();
257 TQDialog::show();
258}
259
261{
263 if (m_lookIn->currentItem() <= 0) //"(All fields)"
265 else if (m_lookIn->currentItem() == 1) //"(Current field)"
267 else
268 options.columnNumber = m_lookIn->currentItem() - 1/*"(All fields)"*/ - 1/*"(Current field)"*/;
269 options.textMatching
271 options.searchDirection
273 options.caseSensitive = m_caseSensitive->isChecked();
274 options.wholeWordsOnly = m_wholeWords->isChecked();
275 options.promptOnReplace = m_promptOnReplace->isChecked();
276 return options;
277}
278
279#include "kexifinddialog.moc"
void setCurrentLookInColumnName(const TQString &columnName)
void setActions(TDEAction *findnext, TDEAction *findprev, TDEAction *replace, TDEAction *replaceall)
Sets actions that receive button clicks and shortcuts within the dialog. Should be called once.
void setObjectNameForCaption(const TQString &name)
void updateMessage(bool found=true)
TQVariant valueToFind() const
void replaceAll()
Emitted after clicking "Replace All" button or pressing appropriate shortcut set by setActions().
TQStringList lookInColumnCaptions() const
void replaceNext()
Emitted after clicking "Replace" button or pressing appropriate shortcut set by setActions().
TQVariant valueToReplaceWith() const
void setMessage(const TQString &message)
TQStringList lookInColumnNames() const
void findNext()
Emitted after clicking "Find next" button or pressing appropriate shortcut set by setActions().
void findPrevious()
Emitted after pressing appropriate shortcut set by setActions().
virtual void show()
Shows the dialog as a modal dialog.
void setButtonsEnabled(bool enable)
TQString currentLookInColumnName() const
KexiFindDialog(TQWidget *parent)
Creates a new find dialog. Replace mode is off by default.
void setReplaceMode(bool set)
KexiSearchAndReplaceViewInterface::Options options() const
void setLookInColumnList(const TQStringList &columnNames, const TQStringList &columnCaptions)
Specifies options for find and replace operations.
TextMatching
Specifies possible options for text matching.
@ SearchDown
Search down (next) from the current position (the default).