~ubuntu-branches/ubuntu/utopic/pgadmin3/utopic-proposed

« back to all changes in this revision

Viewing changes to pgadmin/dlg/dlgFindReplace.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2011-06-07 23:03:54 UTC
  • mfrom: (1.3.1 upstream) (13 sid)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20110607230354-3td4j9y71u4ahcvj
Tags: 1.14.0~beta1-1
* New upstream development release, adding Build-Depends on
  postgresql-server-dev-all >= 117~.
* Add Build-Depends on quilt, (un)patch to debian/rules and patch for fixing
  the include for kwlist.h in pgadmin/db/keywords.c.
* Add pg_config --includedir-server output to CPPFLAGS.
* Remove unrecognized configure options: --with-wx-config,
  --with-pgsql-include, --enable-gtk2, --enable-unicode.
* Clean up manually the files that are left behind after the broken
  distclean.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//////////////////////////////////////////////////////////////////////////
2
2
//
3
3
// pgAdmin III - PostgreSQL Tools
4
 
// 
5
 
// Copyright (C) 2002 - 2010, The pgAdmin Development Team
 
4
//
 
5
// Copyright (C) 2002 - 2011, The pgAdmin Development Team
6
6
// This software is released under the PostgreSQL Licence
7
7
//
8
8
// dlgFindReplace.cpp - Search and replace
18
18
#include "ctl/ctlSQLBox.h"
19
19
 
20
20
BEGIN_EVENT_TABLE(dlgFindReplace, pgDialog)
21
 
    EVT_BUTTON (wxID_FIND,                          dlgFindReplace::OnFind)
22
 
    EVT_BUTTON (wxID_REPLACE,                       dlgFindReplace::OnReplace)
23
 
    EVT_BUTTON (XRCID("wxID_REPLACEALL"),           dlgFindReplace::OnReplaceAll)
24
 
    EVT_BUTTON (wxID_CANCEL,                        dlgFindReplace::OnCancel)
25
 
    EVT_RADIOBUTTON(XRCID("rdOriginCursor"),        dlgFindReplace::OnChange)
26
 
    EVT_RADIOBUTTON(XRCID("rdOriginTop"),           dlgFindReplace::OnChange)
27
 
    EVT_CHECKBOX(XRCID("chkOptionsUseRegexps"),     dlgFindReplace::OnChange)
28
 
    EVT_CLOSE(                                      dlgFindReplace::OnClose)
 
21
        EVT_BUTTON (wxID_FIND,                          dlgFindReplace::OnFind)
 
22
        EVT_BUTTON (wxID_REPLACE,                       dlgFindReplace::OnReplace)
 
23
        EVT_BUTTON (XRCID("wxID_REPLACEALL"),           dlgFindReplace::OnReplaceAll)
 
24
        EVT_BUTTON (wxID_CANCEL,                        dlgFindReplace::OnCancel)
 
25
        EVT_RADIOBUTTON(XRCID("rdOriginCursor"),        dlgFindReplace::OnChange)
 
26
        EVT_RADIOBUTTON(XRCID("rdOriginTop"),           dlgFindReplace::OnChange)
 
27
        EVT_CHECKBOX(XRCID("chkOptionsUseRegexps"),     dlgFindReplace::OnChange)
 
28
        EVT_CLOSE(                                      dlgFindReplace::OnClose)
29
29
END_EVENT_TABLE()
30
30
 
31
31
 
32
32
#define btnFind                      CTRL_BUTTON("wxID_FIND")
33
33
#define btnReplace                   CTRL_BUTTON("wxID_REPLACE")
34
34
#define btnReplaceAll        CTRL_BUTTON("wxID_REPLACEALL")
 
35
#define btnCancel                        CTRL_BUTTON("wxID_CANCEL")
35
36
#define txtFind                  CTRL_TEXT("txtFind")
36
37
#define txtReplace                   CTRL_TEXT("txtReplace")
37
38
#define rdOriginTop          CTRL_RADIOBUTTON("rdOriginTop")
43
44
#define chkOptionsUseRegexps CTRL_CHECKBOX("chkOptionsUseRegexps")
44
45
 
45
46
dlgFindReplace::dlgFindReplace(ctlSQLBox *parent) :
46
 
pgDialog()
 
47
        pgDialog()
47
48
{
48
 
    sqlbox = parent;
49
 
 
50
 
    wxWindowBase::SetFont(settings->GetSystemFont());
51
 
    LoadResource(parent, wxT("dlgFindReplace"));
52
 
    RestorePosition();
53
 
 
54
 
    // Icon
55
 
    appearanceFactory->SetIcons(this);
56
 
 
57
 
    // Accelerator table
58
 
    wxAcceleratorEntry entries[1];
59
 
    entries[0].Set(wxACCEL_NORMAL, WXK_F3, wxID_FIND);
60
 
    wxAcceleratorTable accel(1, entries);
61
 
    SetAcceleratorTable(accel);
62
 
 
63
 
 
64
 
    // Load up the defaults
65
 
    wxString val;
66
 
    bool bVal;
67
 
 
68
 
    // Find/Replace values
69
 
    settings->Read(wxT("FindReplace/Find"), &val, wxT(""));
70
 
    txtFind->SetValue(val);
71
 
 
72
 
    settings->Read(wxT("FindReplace/Replace"), &val, wxT(""));
73
 
    txtReplace->SetValue(val);
74
 
 
75
 
    // Origin
76
 
    settings->Read(wxT("FindReplace/Origin"), &val, wxT("c"));
77
 
    if (val == wxT("t"))
78
 
    {
79
 
        rdOriginCursor->SetValue(false);
80
 
        rdOriginTop->SetValue(true);
81
 
    }
82
 
    else
83
 
    {
84
 
        rdOriginCursor->SetValue(true);
85
 
        rdOriginTop->SetValue(false);
86
 
    }
87
 
 
88
 
    // Origin
89
 
    settings->Read(wxT("FindReplace/Direction"), &val, wxT("f"));
90
 
    if (val == wxT("b"))
91
 
    {
92
 
        rdDirectionForward->SetValue(false);
93
 
        rdDirectionBackward->SetValue(true);
94
 
    }
95
 
    else
96
 
    {
97
 
        rdDirectionForward->SetValue(true);
98
 
        rdDirectionBackward->SetValue(false);
99
 
    }
100
 
 
101
 
    // WholeWord
102
 
    settings->Read(wxT("FindReplace/WholeWord"), &bVal, false);
103
 
    chkOptionsWholeWord->SetValue(bVal);
104
 
 
105
 
    // MatchCase
106
 
    settings->Read(wxT("FindReplace/MatchCase"), &bVal, false);
107
 
    chkOptionsMatchCase->SetValue(bVal);
108
 
 
109
 
    // UseRegexps
110
 
    settings->Read(wxT("FindReplace/UseRegexps"), &bVal, false);
111
 
    chkOptionsUseRegexps->SetValue(bVal);
112
 
 
113
 
    wxCommandEvent ev;
114
 
    OnChange(ev);
 
49
        sqlbox = parent;
 
50
 
 
51
        wxWindowBase::SetFont(settings->GetSystemFont());
 
52
        LoadResource(parent, wxT("dlgFindReplace"));
 
53
        RestorePosition();
 
54
 
 
55
        // Icon
 
56
        appearanceFactory->SetIcons(this);
 
57
 
 
58
        // Accelerator table
 
59
        wxAcceleratorEntry entries[1];
 
60
        entries[0].Set(wxACCEL_NORMAL, WXK_F3, wxID_FIND);
 
61
        wxAcceleratorTable accel(1, entries);
 
62
        SetAcceleratorTable(accel);
 
63
 
 
64
 
 
65
        // Load up the defaults
 
66
        wxString val;
 
67
        bool bVal;
 
68
 
 
69
        // Find/Replace values
 
70
        settings->Read(wxT("FindReplace/Find"), &val, wxT(""));
 
71
        txtFind->SetValue(val);
 
72
 
 
73
        settings->Read(wxT("FindReplace/Replace"), &val, wxT(""));
 
74
        txtReplace->SetValue(val);
 
75
 
 
76
        // Origin
 
77
        settings->Read(wxT("FindReplace/Origin"), &val, wxT("c"));
 
78
        if (val == wxT("t"))
 
79
        {
 
80
                rdOriginCursor->SetValue(false);
 
81
                rdOriginTop->SetValue(true);
 
82
        }
 
83
        else
 
84
        {
 
85
                rdOriginCursor->SetValue(true);
 
86
                rdOriginTop->SetValue(false);
 
87
        }
 
88
 
 
89
        // Origin
 
90
        settings->Read(wxT("FindReplace/Direction"), &val, wxT("f"));
 
91
        if (val == wxT("b"))
 
92
        {
 
93
                rdDirectionForward->SetValue(false);
 
94
                rdDirectionBackward->SetValue(true);
 
95
        }
 
96
        else
 
97
        {
 
98
                rdDirectionForward->SetValue(true);
 
99
                rdDirectionBackward->SetValue(false);
 
100
        }
 
101
 
 
102
        // WholeWord
 
103
        settings->Read(wxT("FindReplace/WholeWord"), &bVal, false);
 
104
        chkOptionsWholeWord->SetValue(bVal);
 
105
 
 
106
        // MatchCase
 
107
        settings->Read(wxT("FindReplace/MatchCase"), &bVal, false);
 
108
        chkOptionsMatchCase->SetValue(bVal);
 
109
 
 
110
        // UseRegexps
 
111
        settings->Read(wxT("FindReplace/UseRegexps"), &bVal, false);
 
112
        chkOptionsUseRegexps->SetValue(bVal);
 
113
 
 
114
        wxCommandEvent ev;
 
115
        OnChange(ev);
 
116
        ResetTabOrder();
115
117
}
116
118
 
117
119
dlgFindReplace::~dlgFindReplace()
118
120
{
119
 
    SavePosition();
 
121
        SavePosition();
120
122
}
121
123
 
122
124
void dlgFindReplace::FocusSearch()
123
125
{
124
 
    txtFind->SetFocus();
125
 
    txtFind->SetSelection(-1, -1);
126
 
}
127
 
 
128
 
void dlgFindReplace::OnClose(wxCloseEvent& ev)
129
 
{
130
 
    // Save settings
131
 
    settings->Write(wxT("FindReplace/Find"), txtFind->GetValue());
132
 
    settings->Write(wxT("FindReplace/Replace"), txtReplace->GetValue());
133
 
 
134
 
    if (rdOriginTop->GetValue())
135
 
        settings->Write(wxT("FindReplace/Origin"), wxT("t"));
136
 
    else
137
 
        settings->Write(wxT("FindReplace/Origin"), wxT("c"));
138
 
 
139
 
    if (rdDirectionBackward->GetValue())
140
 
        settings->Write(wxT("FindReplace/Direction"), wxT("b"));
141
 
    else
142
 
        settings->Write(wxT("FindReplace/Direction"), wxT("f"));
143
 
 
144
 
    settings->Write(wxT("FindReplace/WholeWord"), chkOptionsWholeWord->GetValue());
145
 
    settings->Write(wxT("FindReplace/MatchCase"), chkOptionsMatchCase->GetValue());
146
 
    settings->Write(wxT("FindReplace/UseRegexps"), chkOptionsUseRegexps->GetValue());
147
 
 
148
 
    this->Hide();
149
 
    if (ev.CanVeto())
150
 
        ev.Veto();
151
 
}
152
 
 
153
 
void dlgFindReplace::OnCancel(wxCommandEvent& ev)
154
 
{
155
 
    this->Hide();
156
 
}
157
 
 
158
 
void dlgFindReplace::OnChange(wxCommandEvent& ev)
159
 
{
160
 
    if (chkOptionsUseRegexps->GetValue() == true || rdOriginTop->GetValue() == true)
161
 
    {
162
 
        rdDirectionForward->SetValue(true);
163
 
        rdDirectionBackward->SetValue(false);
164
 
        rdDirectionBackward->Enable(false);
165
 
    }
166
 
    else
167
 
    {
168
 
        rdDirectionBackward->Enable(true);
169
 
    }
170
 
    
171
 
    if (chkOptionsUseRegexps->GetValue() == true)
172
 
    {
173
 
        chkOptionsWholeWord->Enable(false);
174
 
        chkOptionsMatchCase->Enable(false);
175
 
    }
176
 
    else
177
 
    {
178
 
        chkOptionsWholeWord->Enable(true);
179
 
        chkOptionsMatchCase->Enable(true);
180
 
    }
181
 
}
182
 
 
183
 
void dlgFindReplace::OnFind(wxCommandEvent& ev)
184
 
{
185
 
    if (txtFind->GetValue().IsEmpty())
186
 
        return;
187
 
 
188
 
    bool wholeWord = false, 
189
 
         matchCase = false, 
190
 
         useRegexps = false, 
191
 
         startAtTop = false,
192
 
         reverse = false;
193
 
 
194
 
    if (rdOriginTop->GetValue() == true)
195
 
        startAtTop = true;
196
 
 
197
 
    if (rdDirectionBackward->GetValue() == true)
198
 
        reverse = true;
199
 
 
200
 
    if (chkOptionsWholeWord->GetValue() == true)
201
 
        wholeWord = true;
202
 
 
203
 
    if (chkOptionsMatchCase->GetValue() == true)
204
 
        matchCase = true;
205
 
 
206
 
    if (chkOptionsUseRegexps->GetValue() == true)
207
 
        useRegexps = true;
208
 
 
209
 
    if (sqlbox->Find(txtFind->GetValue(), wholeWord, matchCase, useRegexps, startAtTop, reverse))
210
 
    {
211
 
        if (startAtTop)
212
 
        {
213
 
            rdOriginTop->SetValue(false);
214
 
            rdOriginCursor->SetValue(true);
215
 
            wxCommandEvent nullEvent;
216
 
            OnChange(nullEvent);
217
 
        }
218
 
    }
219
 
}
220
 
 
221
 
void dlgFindReplace::OnReplace(wxCommandEvent& ev)
222
 
{
223
 
    if (txtFind->GetValue().IsEmpty())
224
 
        return;
225
 
 
226
 
    bool wholeWord = false, 
227
 
         matchCase = false, 
228
 
         useRegexps = false, 
229
 
         startAtTop = false,
230
 
         reverse = false;
231
 
 
232
 
    if (rdOriginTop->GetValue() == true)
233
 
        startAtTop = true;
234
 
 
235
 
    if (rdDirectionBackward->GetValue() == true)
236
 
        reverse = true;
237
 
 
238
 
    if (chkOptionsWholeWord->GetValue() == true)
239
 
        wholeWord = true;
240
 
 
241
 
    if (chkOptionsMatchCase->GetValue() == true)
242
 
        matchCase = true;
243
 
 
244
 
    if (chkOptionsUseRegexps->GetValue() == true)
245
 
        useRegexps = true;
246
 
 
247
 
    if (sqlbox->Replace(txtFind->GetValue(), txtReplace->GetValue(), wholeWord, matchCase, useRegexps, startAtTop, reverse))
248
 
    {
249
 
        if (startAtTop)
250
 
        {
251
 
            rdOriginTop->SetValue(false);
252
 
            rdOriginCursor->SetValue(true);
253
 
            wxCommandEvent nullEvent;
254
 
            OnChange(nullEvent);
255
 
        }
256
 
    }
257
 
}
258
 
 
259
 
void dlgFindReplace::OnReplaceAll(wxCommandEvent& ev)
260
 
{
261
 
    if (txtFind->GetValue().IsEmpty())
262
 
        return;
263
 
 
264
 
    bool wholeWord = false, 
265
 
         matchCase = false, 
266
 
         useRegexps = false;
267
 
 
268
 
    if (chkOptionsWholeWord->GetValue() == true)
269
 
        wholeWord = true;
270
 
 
271
 
    if (chkOptionsMatchCase->GetValue() == true)
272
 
        matchCase = true;
273
 
 
274
 
    if (chkOptionsUseRegexps->GetValue() == true)
275
 
        useRegexps = true;
276
 
 
277
 
    sqlbox->ReplaceAll(txtFind->GetValue(), txtReplace->GetValue(), wholeWord, matchCase, useRegexps);
278
 
}
279
 
 
280
 
void dlgFindReplace::FindNext() 
281
 
282
 
    if (btnFind->IsEnabled() && !txtFind->IsEmpty())
283
 
    {
284
 
        wxCommandEvent ev; 
285
 
        OnFind(ev);
286
 
    }
 
126
        txtFind->SetFocus();
 
127
        txtFind->SetSelection(-1, -1);
 
128
}
 
129
 
 
130
void dlgFindReplace::OnClose(wxCloseEvent &ev)
 
131
{
 
132
        // Save settings
 
133
        settings->Write(wxT("FindReplace/Find"), txtFind->GetValue());
 
134
        settings->Write(wxT("FindReplace/Replace"), txtReplace->GetValue());
 
135
 
 
136
        if (rdOriginTop->GetValue())
 
137
                settings->Write(wxT("FindReplace/Origin"), wxT("t"));
 
138
        else
 
139
                settings->Write(wxT("FindReplace/Origin"), wxT("c"));
 
140
 
 
141
        if (rdDirectionBackward->GetValue())
 
142
                settings->Write(wxT("FindReplace/Direction"), wxT("b"));
 
143
        else
 
144
                settings->Write(wxT("FindReplace/Direction"), wxT("f"));
 
145
 
 
146
        settings->WriteBool(wxT("FindReplace/WholeWord"), chkOptionsWholeWord->GetValue());
 
147
        settings->WriteBool(wxT("FindReplace/MatchCase"), chkOptionsMatchCase->GetValue());
 
148
        settings->WriteBool(wxT("FindReplace/UseRegexps"), chkOptionsUseRegexps->GetValue());
 
149
 
 
150
        this->Hide();
 
151
        if (ev.CanVeto())
 
152
                ev.Veto();
 
153
}
 
154
 
 
155
void dlgFindReplace::OnCancel(wxCommandEvent &ev)
 
156
{
 
157
        this->Hide();
 
158
}
 
159
 
 
160
void dlgFindReplace::OnChange(wxCommandEvent &ev)
 
161
{
 
162
        if (chkOptionsUseRegexps->GetValue() == true || rdOriginTop->GetValue() == true)
 
163
        {
 
164
                rdDirectionForward->SetValue(true);
 
165
                rdDirectionBackward->SetValue(false);
 
166
                rdDirectionBackward->Enable(false);
 
167
        }
 
168
        else
 
169
        {
 
170
                rdDirectionBackward->Enable(true);
 
171
        }
 
172
 
 
173
        if (chkOptionsUseRegexps->GetValue() == true)
 
174
        {
 
175
                chkOptionsWholeWord->Enable(false);
 
176
                chkOptionsMatchCase->Enable(false);
 
177
        }
 
178
        else
 
179
        {
 
180
                chkOptionsWholeWord->Enable(true);
 
181
                chkOptionsMatchCase->Enable(true);
 
182
        }
 
183
}
 
184
 
 
185
void dlgFindReplace::OnFind(wxCommandEvent &ev)
 
186
{
 
187
        if (txtFind->GetValue().IsEmpty())
 
188
                return;
 
189
 
 
190
        bool wholeWord = false,
 
191
             matchCase = false,
 
192
             useRegexps = false,
 
193
             startAtTop = false,
 
194
             reverse = false;
 
195
 
 
196
        if (rdOriginTop->GetValue() == true)
 
197
                startAtTop = true;
 
198
 
 
199
        if (rdDirectionBackward->GetValue() == true)
 
200
                reverse = true;
 
201
 
 
202
        if (chkOptionsWholeWord->GetValue() == true)
 
203
                wholeWord = true;
 
204
 
 
205
        if (chkOptionsMatchCase->GetValue() == true)
 
206
                matchCase = true;
 
207
 
 
208
        if (chkOptionsUseRegexps->GetValue() == true)
 
209
                useRegexps = true;
 
210
 
 
211
        if (sqlbox->Find(txtFind->GetValue(), wholeWord, matchCase, useRegexps, startAtTop, reverse))
 
212
        {
 
213
                if (startAtTop)
 
214
                {
 
215
                        rdOriginTop->SetValue(false);
 
216
                        rdOriginCursor->SetValue(true);
 
217
                        wxCommandEvent nullEvent;
 
218
                        OnChange(nullEvent);
 
219
                }
 
220
        }
 
221
}
 
222
 
 
223
void dlgFindReplace::OnReplace(wxCommandEvent &ev)
 
224
{
 
225
        if (txtFind->GetValue().IsEmpty())
 
226
                return;
 
227
 
 
228
        bool wholeWord = false,
 
229
             matchCase = false,
 
230
             useRegexps = false,
 
231
             startAtTop = false,
 
232
             reverse = false;
 
233
 
 
234
        if (rdOriginTop->GetValue() == true)
 
235
                startAtTop = true;
 
236
 
 
237
        if (rdDirectionBackward->GetValue() == true)
 
238
                reverse = true;
 
239
 
 
240
        if (chkOptionsWholeWord->GetValue() == true)
 
241
                wholeWord = true;
 
242
 
 
243
        if (chkOptionsMatchCase->GetValue() == true)
 
244
                matchCase = true;
 
245
 
 
246
        if (chkOptionsUseRegexps->GetValue() == true)
 
247
                useRegexps = true;
 
248
 
 
249
        if (sqlbox->Replace(txtFind->GetValue(), txtReplace->GetValue(), wholeWord, matchCase, useRegexps, startAtTop, reverse))
 
250
        {
 
251
                if (startAtTop)
 
252
                {
 
253
                        rdOriginTop->SetValue(false);
 
254
                        rdOriginCursor->SetValue(true);
 
255
                        wxCommandEvent nullEvent;
 
256
                        OnChange(nullEvent);
 
257
                }
 
258
        }
 
259
}
 
260
 
 
261
void dlgFindReplace::OnReplaceAll(wxCommandEvent &ev)
 
262
{
 
263
        if (txtFind->GetValue().IsEmpty())
 
264
                return;
 
265
 
 
266
        bool wholeWord = false,
 
267
             matchCase = false,
 
268
             useRegexps = false;
 
269
 
 
270
        if (chkOptionsWholeWord->GetValue() == true)
 
271
                wholeWord = true;
 
272
 
 
273
        if (chkOptionsMatchCase->GetValue() == true)
 
274
                matchCase = true;
 
275
 
 
276
        if (chkOptionsUseRegexps->GetValue() == true)
 
277
                useRegexps = true;
 
278
 
 
279
        sqlbox->ReplaceAll(txtFind->GetValue(), txtReplace->GetValue(), wholeWord, matchCase, useRegexps);
 
280
}
 
281
 
 
282
void dlgFindReplace::FindNext()
 
283
{
 
284
        if (btnFind->IsEnabled() && !txtFind->IsEmpty())
 
285
        {
 
286
                wxCommandEvent ev;
 
287
                OnFind(ev);
 
288
        }
 
289
}
 
290
 
 
291
void dlgFindReplace::SetFindString(const wxString &val)
 
292
{
 
293
        txtFind->SetValue(val);
 
294
}
 
295
 
 
296
void dlgFindReplace::ResetTabOrder()
 
297
{
 
298
        btnFind->MoveAfterInTabOrder(chkOptionsUseRegexps);
 
299
        btnReplace->MoveAfterInTabOrder(btnFind);
 
300
        btnReplaceAll->MoveAfterInTabOrder(btnReplace);
 
301
        btnCancel->MoveAfterInTabOrder(btnReplaceAll);
287
302
}
288
303