~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/plugins/contrib/codesnippets/finddialogs.cpp

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////////
 
2
// File:        dialogs.cpp
 
3
// Purpose:     Find/Replace, Goto dialogs
 
4
// Maintainer:  Otto Wyss
 
5
// Created:     2003-01-20
 
6
// RCS-ID:      $Id: finddialogs.cpp 7443 2011-09-01 16:29:16Z mortenmacfly $
 
7
// Copyright:   (c) 2005 wyoGuide
 
8
// Licence:     wxWindows
 
9
//////////////////////////////////////////////////////////////////////////////
 
10
 
 
11
//----------------------------------------------------------------------------
 
12
// information
 
13
//----------------------------------------------------------------------------
 
14
/*
 
15
        This file is part of Code Snippets, a plugin for Code::Blocks
 
16
        Copyright (C) 2006 Arto Jonsson
 
17
        Copyright (C) 2007 Pecan Heber
 
18
 
 
19
        This program is free software; you can redistribute it and/or
 
20
        modify it under the terms of the GNU General Public License
 
21
        as published by the Free Software Foundation; either version 2
 
22
        of the License, or (at your option) any later version.
 
23
 
 
24
        This program is distributed in the hope that it will be useful,
 
25
        but WITHOUT ANY WARRANTY; without even the implied warranty of
 
26
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
27
        GNU General Public License for more details.
 
28
 
 
29
        You should have received a copy of the GNU General Public License
 
30
        along with this program; if not, write to the Free Software
 
31
        Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
32
*/
 
33
// RCS-ID: $Id: finddialogs.cpp 7443 2011-09-01 16:29:16Z mortenmacfly $
 
34
 
 
35
 
 
36
//----------------------------------------------------------------------------
 
37
// headers
 
38
//----------------------------------------------------------------------------
 
39
 
 
40
// For compilers that support precompilation, includes <wx/wx.h>.
 
41
#include <wx/wxprec.h>
 
42
 
 
43
#ifdef __BORLANDC__
 
44
    #pragma hdrstop
 
45
#endif
 
46
 
 
47
// for all others, include the necessary headers (this file is usually all you
 
48
// need because it includes almost all 'standard' wxWidgets headers)
 
49
#ifndef WX_PRECOMP
 
50
    #include <wx/wx.h>
 
51
#endif
 
52
 
 
53
// wxWidgets headers
 
54
#include <wx/accel.h>    // accelerator support
 
55
#include <wx/config.h>
 
56
//#include <wx/confbase.h>
 
57
//#include <wx/fileconf.h>
 
58
//#include <wx/msw/regconf.h> (wxRegConfig class)
 
59
 
 
60
 
 
61
#include "defsext.h"     // Additional definitions
 
62
#include "finddialogs.h"     // Dialogs
 
63
 
 
64
#define g_appname wxT("Find")
 
65
//----------------------------------------------------------------------------
 
66
// resources
 
67
//----------------------------------------------------------------------------
 
68
 
 
69
 
 
70
//============================================================================
 
71
// declarations
 
72
//============================================================================
 
73
 
 
74
const int MAXHISTORY = 10;
 
75
const wxString FINDREPLACEDLG = _T("FindReplaceDlg");
 
76
const wxString DIRECTORYHISTORY = _T("History/Directory");
 
77
const wxString FINDSTRHISTORY = _T("History/Findtext");
 
78
const wxString REPLACESTRHISTORY = _T("History/Replacetext");
 
79
 
 
80
 
 
81
//============================================================================
 
82
// implementation
 
83
//============================================================================
 
84
 
 
85
//----------------------------------------------------------------------------
 
86
// myFindReplaceDlg
 
87
//----------------------------------------------------------------------------
 
88
 
 
89
// static variables
 
90
static wxArrayString m_finddirHist;
 
91
static wxArrayString m_findstrHist;
 
92
static wxArrayString m_replacestrHist;
 
93
 
 
94
BEGIN_EVENT_TABLE (myFindReplaceDlg, wxScrollingDialog)
 
95
    EVT_BUTTON (wxID_CANCEL,     myFindReplaceDlg::OnCancel)
 
96
    EVT_BUTTON (wxID_OK,         myFindReplaceDlg::OnOkay)
 
97
    EVT_BUTTON (myID_REPLACE,    myFindReplaceDlg::OnReplace)
 
98
    EVT_BUTTON (myID_REPLACEALL, myFindReplaceDlg::OnReplaceAll)
 
99
    EVT_MENU   (wxID_HELP,       myFindReplaceDlg::OnHelp)
 
100
END_EVENT_TABLE()
 
101
 
 
102
myFindReplaceDlg::myFindReplaceDlg (wxWindow *parent,
 
103
                                    const wxString &findstr,
 
104
                                    const wxString &replacestr,
 
105
                                    wxUint32 flags,
 
106
                                    long style)
 
107
               : wxScrollingDialog (parent, -1, _("Dialog"),
 
108
                           wxDefaultPosition, wxDefaultSize,
 
109
                           style | wxDEFAULT_DIALOG_STYLE) {
 
110
 
 
111
    m_style = 0;
 
112
 
 
113
    //accelerators (for help)
 
114
    const int nEntries = 1 ;
 
115
    wxAcceleratorEntry entries[nEntries];
 
116
    entries[0].Set (wxACCEL_NORMAL, WXK_F1, wxID_HELP);
 
117
    wxAcceleratorTable accel (nEntries, entries);
 
118
    SetAcceleratorTable (accel);
 
119
 
 
120
    // layout the dialog
 
121
    m_findpane = new wxBoxSizer (wxVERTICAL);
 
122
 
 
123
    // find, replace text and options, direction
 
124
    wxBoxSizer *findsizer = new wxBoxSizer (wxHORIZONTAL);
 
125
    findsizer->Add (new wxStaticText (this, -1, _("Search for:"),
 
126
                                      wxDefaultPosition, wxSize(80, -1)),
 
127
                    0, wxALIGN_CENTRE_VERTICAL | wxRIGHT, 6);
 
128
    m_findstr = new wxComboBox (this, myID_DLG_FIND_TEXT, findstr,
 
129
                                 wxDefaultPosition, wxSize(200, -1));
 
130
    findsizer->Add (m_findstr, 1, wxALIGN_CENTRE_VERTICAL);
 
131
    m_findpane->Add (findsizer, 0, wxEXPAND | wxBOTTOM, 6);
 
132
 
 
133
    m_fdirsizer = new wxBoxSizer (wxHORIZONTAL);
 
134
    m_fdirsizer->Add (new wxStaticText (this, -1, _("In directories:"),
 
135
                                        wxDefaultPosition, wxSize(80, -1)),
 
136
                      0, wxALIGN_CENTRE_VERTICAL | wxRIGHT, 6);
 
137
    wxString finddir;
 
138
    m_finddir = new wxComboBox (this, -1, finddir,
 
139
                                wxDefaultPosition, wxSize(200, -1),
 
140
                                //0, NULL); //AMD64 ambiguity betw int vs wxArray
 
141
                                (int)0, (const wxString*) NULL);
 
142
    m_fdirsizer->Add (m_finddir, 1, wxALIGN_CENTRE_VERTICAL);
 
143
    m_findpane->Show (m_fdirsizer, false);
 
144
    m_findpane->Add (m_fdirsizer, 0, wxEXPAND | wxBOTTOM, 6);
 
145
 
 
146
    m_specsizer = new wxBoxSizer (wxHORIZONTAL);
 
147
    m_specsizer->Add (new wxStaticText (this, -1, _("With filespec:"),
 
148
                                        wxDefaultPosition, wxSize(80, -1)),
 
149
                      0, wxALIGN_CENTRE_VERTICAL | wxRIGHT, 6);
 
150
    m_findspec = new wxTextCtrl (this, -1, wxEmptyString,
 
151
                                 wxDefaultPosition, wxSize(200, -1));
 
152
    m_specsizer->Add (m_findspec, 1, wxALIGN_CENTRE_VERTICAL);
 
153
    m_findpane->Show (m_specsizer, false);
 
154
    m_findpane->Add (m_specsizer, 0, wxEXPAND | wxBOTTOM, 6);
 
155
 
 
156
    m_replsizer = new wxBoxSizer (wxHORIZONTAL);
 
157
    m_replsizer->Add (new wxStaticText (this, -1, _("Replace with:"),
 
158
                                        wxDefaultPosition, wxSize(80, -1)),
 
159
                      0, wxALIGN_CENTRE_VERTICAL | wxRIGHT, 6);
 
160
    m_replacestr = new wxComboBox (this, -1, replacestr,
 
161
                                    wxDefaultPosition, wxSize(200, -1));
 
162
    m_replsizer->Add (m_replacestr, 1, wxALIGN_CENTRE_VERTICAL);
 
163
    m_findpane->Show (m_replsizer, false);
 
164
    m_findpane->Add (m_replsizer, 0, wxEXPAND | wxBOTTOM, 6);
 
165
 
 
166
    // options
 
167
    m_optionsizer = new wxBoxSizer (wxVERTICAL);
 
168
    m_matchcase = new wxCheckBox (this, -1, _("Match &case"));
 
169
    m_matchcase->SetValue ((flags & myFR_MATCHCASE) > 0);
 
170
    m_optionsizer->Add (m_matchcase, 0, wxBOTTOM, 6);
 
171
    m_wholeword = new wxCheckBox (this, -1, _("Whole &word"));
 
172
    m_wholeword->SetValue ((flags & myFR_WHOLEWORD) > 0);
 
173
    m_wholeword->Enable (false);
 
174
    m_optionsizer->Add (m_wholeword, 0, wxBOTTOM, 6);
 
175
    m_findregex = new wxCheckBox (this, -1, _("Regular &expression"));
 
176
    m_findregex->SetValue ((flags & myFR_FINDREGEX) > 0);
 
177
    m_optionsizer->Add (m_findregex, 0, wxBOTTOM, 6);
 
178
    m_subfolder = new wxCheckBox (this, -1, _("Sub &directories"));
 
179
    m_subfolder->SetValue ((flags & myFR_SUBFOLDER) > 0);
 
180
    m_optionsizer->Add (m_subfolder, 0);
 
181
 
 
182
    // directions
 
183
    m_dirssizer = new wxBoxSizer (wxVERTICAL);
 
184
    static const wxString directions[] = {_("&Upwards"), _("&Downwards")};
 
185
    m_direction = new wxRadioBox (this, -1, _("Direction"),
 
186
                                  wxDefaultPosition, wxDefaultSize,
 
187
                                  WXSIZEOF(directions), directions,
 
188
                                  1, wxRA_SPECIFY_COLS);
 
189
    m_direction->SetSelection(1);
 
190
    m_dirssizer->Add (m_direction, 0);
 
191
 
 
192
    // options and directions
 
193
    m_optionpane = new wxBoxSizer (wxHORIZONTAL);
 
194
    m_optionpane->Add (m_optionsizer, 1, wxALIGN_TOP|wxALIGN_LEFT);
 
195
    m_optionpane->Add (m_dirssizer, 0, wxALIGN_TOP|wxALIGN_RIGHT);
 
196
    m_findpane->Add (0, 6);
 
197
    m_findpane->Add (m_optionpane, 0, wxEXPAND);
 
198
 
 
199
    // buttons
 
200
    m_buttonpane = new wxBoxSizer (wxVERTICAL);
 
201
    m_findButton = new wxButton (this, wxID_OK, _("&Find"));
 
202
    m_findButton->SetDefault();
 
203
    m_buttonpane->Add (m_findButton, 0, wxEXPAND|wxALIGN_TOP|wxBOTTOM, 6);
 
204
    m_replaceButton = new wxButton (this, myID_REPLACE, _("&Replace"));
 
205
    m_buttonpane->Add (m_replaceButton, 0, wxEXPAND|wxALIGN_TOP|wxBOTTOM, 6);
 
206
    m_buttonpane->Show (m_replaceButton, false);
 
207
    m_replaceAllButton = new wxButton (this, myID_REPLACEALL, _("Replace &all"));
 
208
    m_buttonpane->Add (m_replaceAllButton, 0, wxEXPAND|wxALIGN_TOP|wxBOTTOM, 6);
 
209
    m_buttonpane->Show (m_replaceAllButton, false);
 
210
    m_cancelButton = new wxButton (this, wxID_CANCEL, _("Cancel"));
 
211
    m_buttonpane->Add (m_cancelButton, 0, wxEXPAND|wxALIGN_BOTTOM);
 
212
 
 
213
    m_totalpane = new wxBoxSizer (wxHORIZONTAL);
 
214
    m_totalpane->Add (m_findpane, 0, wxEXPAND | wxALL, 10);
 
215
    m_totalpane->Add (m_buttonpane, 0, wxEXPAND | wxALL, 10);
 
216
 
 
217
    m_findstr->SetFocus();
 
218
    m_findstr->SetSelection (-1, -1);
 
219
    SetSizerAndFit (m_totalpane);
 
220
 
 
221
    // load history
 
222
    LoadDirHistory ();
 
223
    LoadFindHistory ();
 
224
    LoadReplaceHistory ();
 
225
    UpdateDirHistory ();
 
226
    UpdateFindHistory ();
 
227
    UpdateReplaceHistory ();
 
228
 
 
229
}
 
230
 
 
231
myFindReplaceDlg::~myFindReplaceDlg () {
 
232
 
 
233
    // store history
 
234
    StoreDirHistory ();
 
235
    StoreFindHistory ();
 
236
    StoreReplaceHistory ();
 
237
 
 
238
}
 
239
 
 
240
//----------------------------------------------------------------------------
 
241
// event handlers
 
242
 
 
243
void myFindReplaceDlg::OnCancel (wxCommandEvent &WXUNUSED(event)) {
 
244
    EndModal (wxID_CANCEL);
 
245
}
 
246
 
 
247
void myFindReplaceDlg::OnHelp (wxCommandEvent &WXUNUSED(event)) {
 
248
    ////(pecan 2007/4/05)
 
249
    //-g_help->Display(_T("dialogs.html#findreplace"));
 
250
}
 
251
 
 
252
void myFindReplaceDlg::OnOkay (wxCommandEvent &WXUNUSED(event)) {
 
253
    UpdateFindHistory (m_findstr->GetValue ());
 
254
    if (m_style & myFR_REPLACEDIALOG) {
 
255
        UpdateReplaceHistory (m_replacestr->GetValue ());
 
256
    }else if (m_style & myFR_FINDINFILES) {
 
257
        UpdateDirHistory (m_finddir->GetValue ());
 
258
    }
 
259
    EndModal (wxID_OK);
 
260
}
 
261
 
 
262
void myFindReplaceDlg::OnReplace (wxCommandEvent &WXUNUSED(event)) {
 
263
    UpdateFindHistory (m_findstr->GetValue ());
 
264
    if (m_style & myFR_REPLACEDIALOG) {
 
265
        UpdateReplaceHistory (m_replacestr->GetValue ());
 
266
    }else if (m_style & myFR_FINDINFILES) {
 
267
        UpdateDirHistory (m_finddir->GetValue ());
 
268
    }
 
269
    EndModal (myID_REPLACE);
 
270
}
 
271
 
 
272
void myFindReplaceDlg::OnReplaceAll (wxCommandEvent &WXUNUSED(event)) {
 
273
    UpdateFindHistory (m_findstr->GetValue ());
 
274
    if (m_style & myFR_REPLACEDIALOG) {
 
275
        UpdateReplaceHistory (m_replacestr->GetValue ());
 
276
    }else if (m_style & myFR_FINDINFILES) {
 
277
        UpdateDirHistory (m_finddir->GetValue ());
 
278
    }
 
279
    EndModal (myID_REPLACEALL);
 
280
}
 
281
 
 
282
//----------------------------------------------------------------------------
 
283
// private functions
 
284
 
 
285
wxString myFindReplaceDlg::GetFindDirectory () {
 
286
    return m_finddir->GetValue ();
 
287
}
 
288
 
 
289
void myFindReplaceDlg::SetFindDirectory (const wxString &finddir) {
 
290
    m_finddir->SetValue (finddir);
 
291
}
 
292
 
 
293
wxString myFindReplaceDlg::GetFindFilespec () {
 
294
    return m_findspec->GetValue ();
 
295
}
 
296
 
 
297
void myFindReplaceDlg::SetFindFilespec (const wxString &findspec) {
 
298
    m_findspec->SetValue (findspec);
 
299
}
 
300
 
 
301
wxString myFindReplaceDlg::GetFindString () {
 
302
    return m_findstr->GetValue ();
 
303
}
 
304
 
 
305
void myFindReplaceDlg::SetFindString (const wxString &findstr) {
 
306
    m_findstr->SetSelection (0);
 
307
    m_findstr->SetValue (findstr);
 
308
}
 
309
 
 
310
wxString myFindReplaceDlg::GetReplaceString () {
 
311
    return m_replacestr->GetValue ();
 
312
}
 
313
 
 
314
void myFindReplaceDlg::SetReplaceString (const wxString &replacestr) {
 
315
    m_replacestr->SetSelection (0);
 
316
    m_replacestr->SetValue (replacestr);
 
317
}
 
318
 
 
319
int myFindReplaceDlg::GetFlags () {
 
320
    // flags (myFR_DOWN, myFR_MATCHCASE, myFR_WHOLEWORD, myFR_FINDREGEX)
 
321
    int flags = 0;
 
322
    if (m_direction->GetSelection()!=0) flags |= myFR_DOWN;
 
323
    if (m_matchcase->GetValue()) flags |= myFR_MATCHCASE;
 
324
    if (m_wholeword->GetValue()) flags |= myFR_WHOLEWORD;
 
325
    if (m_findregex->GetValue()) flags |= myFR_FINDREGEX;
 
326
    if (m_subfolder->GetValue()) flags |= myFR_SUBFOLDER;
 
327
    return flags;
 
328
}
 
329
 
 
330
void myFindReplaceDlg::SetFlags (int flags) {
 
331
    if (flags & myFR_DOWN) {
 
332
        m_direction->SetSelection (1);
 
333
    }else{
 
334
        m_direction->SetSelection (0);
 
335
    }
 
336
    m_matchcase->SetValue ((flags & myFR_MATCHCASE) > 0);
 
337
    m_wholeword->SetValue ((flags & myFR_WHOLEWORD) > 0);
 
338
    m_findregex->SetValue ((flags & myFR_FINDREGEX) > 0);
 
339
    m_subfolder->SetValue ((flags & myFR_SUBFOLDER) > 0);
 
340
}
 
341
 
 
342
int myFindReplaceDlg::ShowModal (long style) {
 
343
    UpdateDirHistory ();
 
344
    UpdateFindHistory ();
 
345
    UpdateReplaceHistory ();
 
346
    m_style = style;
 
347
    if (m_style & myFR_REPLACEDIALOG) {
 
348
        SetTitle(_("Find and Replace"));
 
349
        m_findpane->Show (m_fdirsizer, false);
 
350
        m_findpane->Show (m_specsizer, false);
 
351
        m_findpane->Show (m_replsizer, true);
 
352
        m_optionsizer->Show (m_wholeword, true);
 
353
        m_optionsizer->Show (m_subfolder, false);
 
354
        m_dirssizer->Show (m_direction, true);
 
355
        m_buttonpane->Show (m_replaceButton, true);
 
356
        m_buttonpane->Show (m_replaceAllButton, true);
 
357
    }else if (m_style & myFR_FINDINFILES) {
 
358
        SetTitle(_("Find in Files"));
 
359
        m_findpane->Show (m_fdirsizer, true);
 
360
        m_findpane->Show (m_specsizer, true);
 
361
        m_findpane->Show (m_replsizer, false);
 
362
        m_optionsizer->Show (m_wholeword, false);
 
363
        m_optionsizer->Show (m_subfolder, true);
 
364
        m_dirssizer->Show (m_direction, false);
 
365
        m_buttonpane->Show (m_replaceButton, false);
 
366
        m_buttonpane->Show (m_replaceAllButton, false);
 
367
        m_wholeword->Enable (false);
 
368
    }else{
 
369
        SetTitle(_("Find"));
 
370
        m_findpane->Show (m_fdirsizer, false);
 
371
        m_findpane->Show (m_specsizer, false);
 
372
        m_findpane->Show (m_replsizer, false);
 
373
        m_optionsizer->Show (m_wholeword, true);
 
374
        m_optionsizer->Show (m_subfolder, false);
 
375
        m_dirssizer->Show (m_direction, true);
 
376
        m_buttonpane->Show (m_replaceButton, false);
 
377
        m_buttonpane->Show (m_replaceAllButton, false);
 
378
        m_wholeword->Enable (true);
 
379
    }
 
380
    m_direction->Enable (true);
 
381
    m_matchcase->Enable (!(style & myFR_NOMATCHCASE));
 
382
    m_wholeword->Enable (!(style & myFR_NOWHOLEWORD));
 
383
    m_findregex->Enable (!(style & myFR_NOFINDREGEX));
 
384
    m_findstr->SetFocus();
 
385
    m_findstr->SetSelection (-1, -1);
 
386
    Fit ();
 
387
    return wxScrollingDialog::ShowModal ();
 
388
}
 
389
 
 
390
void myFindReplaceDlg::LoadDirHistory () {
 
391
    if (!m_finddirHist.IsEmpty()) return;
 
392
    wxConfig *cfg = new wxConfig (g_appname);
 
393
    wxString group = FINDREPLACEDLG + _T("/") + DIRECTORYHISTORY;
 
394
    wxString key;
 
395
    wxString value;
 
396
    int i;
 
397
    for (i = 0; i < MAXHISTORY; ++i) {
 
398
        key = group + wxString::Format (_T("%d"), i);
 
399
        if (cfg->Read (key, &value)) m_finddirHist.Add (value);
 
400
    }
 
401
    delete cfg;
 
402
}
 
403
 
 
404
void myFindReplaceDlg::StoreDirHistory () {
 
405
    wxConfig *cfg = new wxConfig (g_appname);
 
406
    wxString group = FINDREPLACEDLG + _T("/") + DIRECTORYHISTORY;
 
407
    wxString key;
 
408
    wxString value;
 
409
    int i;
 
410
    for (i = 0; i < (int)m_finddirHist.GetCount(); ++i) {
 
411
        key = group + wxString::Format (_T("%d"), i);
 
412
        cfg->Write (key, m_finddirHist[i]);
 
413
    }
 
414
    delete cfg;
 
415
}
 
416
 
 
417
void myFindReplaceDlg::UpdateDirHistory (wxString item) {
 
418
// FIXME:   //(pecan 2007/4/05)
 
419
//    wxString value = m_finddir->GetValue();
 
420
//    if (!item.IsEmpty()) {
 
421
//        int i = m_finddirHist.Index (item);
 
422
//        if (i != wxNOT_FOUND) m_finddirHist.Remove (item);
 
423
//        if (m_finddirHist.GetCount() == MAXHISTORY) {
 
424
//            m_finddirHist.Remove (m_finddirHist.Last());
 
425
//        }
 
426
//        m_finddirHist.Insert (item, 0);
 
427
//    }
 
428
//    // since m_finddir->Clear() clears to much
 
429
//    while (m_finddir->GetCount() > 0) m_finddir->Delete (0);
 
430
//    int i;
 
431
//    for (i = 0; i < (int)m_finddirHist.GetCount(); ++i) {
 
432
//        m_finddir->Append (m_finddirHist[i]);
 
433
//    }
 
434
//    m_finddir->SetValue(value);
 
435
}
 
436
 
 
437
void myFindReplaceDlg::LoadFindHistory () {
 
438
// FIXME: //(pecan 2007/4/05)
 
439
//    if (!m_findstrHist.IsEmpty()) return;
 
440
//    wxConfig *cfg = new wxConfig (g_appname);
 
441
//    wxString group = FINDREPLACEDLG + _T("/") + FINDSTRHISTORY;
 
442
//    wxString key;
 
443
//    wxString value;
 
444
//    int i;
 
445
//    for (i = 0; i < MAXHISTORY; ++i) {
 
446
//        key = group + wxString::Format (_T("%d"), i);
 
447
//        if (cfg->Read (key, &value)) m_findstrHist.Add (value);
 
448
//    }
 
449
//    delete cfg;
 
450
}
 
451
 
 
452
void myFindReplaceDlg::StoreFindHistory () {
 
453
    wxConfig *cfg = new wxConfig (g_appname);
 
454
    wxString group = FINDREPLACEDLG + _T("/") + FINDSTRHISTORY;
 
455
    wxString key;
 
456
    wxString value;
 
457
    int i;
 
458
    for (i = 0; i < (int)m_findstrHist.GetCount(); ++i) {
 
459
        key = group + wxString::Format (_T("%d"), i);
 
460
        cfg->Write (key, m_findstrHist[i]);
 
461
    }
 
462
    delete cfg;
 
463
}
 
464
 
 
465
void myFindReplaceDlg::UpdateFindHistory (wxString item) {
 
466
// FIXME: //(pecan 2007/4/05)
 
467
//    wxString value = m_findstr->GetValue();
 
468
//    if (!item.IsEmpty()) {
 
469
//        int i = m_findstrHist.Index (item);
 
470
//        if (i != wxNOT_FOUND) m_findstrHist.Remove (item);
 
471
//        if (m_findstrHist.GetCount() == MAXHISTORY) {
 
472
//            m_findstrHist.Remove (m_findstrHist.Last());
 
473
//        }
 
474
//        m_findstrHist.Insert (item, 0);
 
475
//    }
 
476
//    // since m_findstr->Clear() clears to much
 
477
//    while (m_findstr->GetCount() > 0) m_findstr->Delete (0);
 
478
//    int i;
 
479
//    for (i = 0; i < (int)m_findstrHist.GetCount(); ++i) {
 
480
//        m_findstr->Append (m_findstrHist[i]);
 
481
//    }
 
482
//    m_findstr->SetValue(value);
 
483
}
 
484
 
 
485
void myFindReplaceDlg::LoadReplaceHistory ()
 
486
{// FIXME: //(pecan 2007/4/05)
 
487
//    if (!m_replacestrHist.IsEmpty()) return;
 
488
//    wxConfig *cfg = new wxConfig (g_appname);
 
489
//    wxString group = FINDREPLACEDLG + _T("/") + REPLACESTRHISTORY;
 
490
//    wxString key;
 
491
//    wxString value;
 
492
//    int i;
 
493
//    for (i = 0; i < MAXHISTORY; ++i) {
 
494
//        key = group + wxString::Format (_T("%d"), i);
 
495
//        if (cfg->Read (key, &value)) m_replacestrHist.Add (value);
 
496
//    }
 
497
//    delete cfg;
 
498
}
 
499
 
 
500
void myFindReplaceDlg::StoreReplaceHistory ()
 
501
{// FIXME: //(pecan 2007/4/05)
 
502
//    wxConfig *cfg = new wxConfig (g_appname);
 
503
//    wxString group = FINDREPLACEDLG + _T("/") + REPLACESTRHISTORY;
 
504
//    wxString key;
 
505
//    wxString value;
 
506
//    int i;
 
507
//    for (i = 0; i < (int)m_replacestrHist.GetCount(); ++i) {
 
508
//        key = group + wxString::Format (_T("%d"), i);
 
509
//        cfg->Write (key, m_replacestrHist[i]);
 
510
//    }
 
511
//    delete cfg;
 
512
}
 
513
 
 
514
void myFindReplaceDlg::UpdateReplaceHistory (wxString item)
 
515
{// FIXME: //(pecan 2007/4/05)
 
516
//    wxString value = m_replacestr->GetValue();
 
517
//    if (!item.IsEmpty()) {
 
518
//        int i = m_replacestrHist.Index (item);
 
519
//        if (i != wxNOT_FOUND) m_replacestrHist.Remove (item);
 
520
//        if (m_replacestrHist.GetCount() == MAXHISTORY) {
 
521
//            m_replacestrHist.Remove (m_replacestrHist.Last());
 
522
//        }
 
523
//        m_replacestrHist.Insert (item, 0);
 
524
//    }
 
525
//    // since m_replacestr->Clear() clears to much
 
526
//    while (m_replacestr->GetCount() > 0) m_replacestr->Delete (0);
 
527
//    int i;
 
528
//    for (i = 0; i < (int)m_replacestrHist.GetCount(); ++i) {
 
529
//        m_replacestr->Append (m_replacestrHist[i]);
 
530
//    }
 
531
//    m_replacestr->SetValue(value);
 
532
}
 
533
 
 
534
 
 
535
//----------------------------------------------------------------------------
 
536
// myGotoDlg
 
537
//----------------------------------------------------------------------------
 
538
 
 
539
BEGIN_EVENT_TABLE (myGotoDlg, wxScrollingDialog)
 
540
    EVT_MENU   (wxID_HELP, myGotoDlg::OnHelp)
 
541
END_EVENT_TABLE()
 
542
 
 
543
myGotoDlg::myGotoDlg (wxWindow *parent,
 
544
                      long style)
 
545
         : wxScrollingDialog (parent, -1, _("Goto line"),
 
546
                     wxDefaultPosition, wxDefaultSize,
 
547
                     style | wxDEFAULT_DIALOG_STYLE) {
 
548
 
 
549
    //accelerators (for help)
 
550
    const int nEntries = 1 ;
 
551
    wxAcceleratorEntry entries[nEntries];
 
552
    entries[0].Set (wxACCEL_NORMAL, WXK_F1, wxID_HELP);
 
553
    wxAcceleratorTable accel (nEntries, entries);
 
554
    SetAcceleratorTable (accel);
 
555
 
 
556
    // goto
 
557
    wxBoxSizer *gotopane = new wxBoxSizer (wxHORIZONTAL);
 
558
    gotopane->Add (new wxStaticText (this, -1, _("Go to:"),
 
559
                                     wxDefaultPosition, wxSize(60, -1)),
 
560
                   0, wxALIGN_TOP | wxALIGN_LEFT);
 
561
    gotopane->Add (6, 0);
 
562
    m_position = new wxTextCtrl (this, -1, _T(""),
 
563
                                 wxDefaultPosition, wxSize(60, -1));
 
564
    gotopane->Add (m_position, 0, wxALIGN_TOP | wxALIGN_RIGHT);
 
565
 
 
566
    // buttons
 
567
    wxBoxSizer *buttonpane = new wxBoxSizer (wxVERTICAL);
 
568
    m_gotoButton = new wxButton (this, wxID_OK, _("&Goto"));
 
569
    m_gotoButton->SetDefault();
 
570
    buttonpane->Add (m_gotoButton, 0, wxEXPAND | wxALIGN_TOP | wxBOTTOM, 6);
 
571
    m_cancelButton = new wxButton (this, wxID_CANCEL, _("Cancel"));
 
572
    buttonpane->Add (m_cancelButton, 0, wxEXPAND | wxALIGN_BOTTOM);
 
573
 
 
574
    wxBoxSizer *totalpane = new wxBoxSizer (wxHORIZONTAL);
 
575
    totalpane->Add (gotopane, 0, wxEXPAND | wxALL, 10);
 
576
    totalpane->Add (buttonpane, 0, wxEXPAND | wxALL, 10);
 
577
 
 
578
    m_position->SetFocus();
 
579
    m_position->SetSelection (-1, -1);
 
580
    SetSizerAndFit (totalpane);
 
581
 
 
582
}
 
583
 
 
584
//----------------------------------------------------------------------------
 
585
// event handlers
 
586
 
 
587
void myGotoDlg::OnHelp (wxCommandEvent &WXUNUSED(event)) {
 
588
    // //(pecan 2007/4/05)
 
589
    //g_help->Display(_T("dialogs.html#gotoposition"));
 
590
}
 
591
 
 
592
//----------------------------------------------------------------------------
 
593
// private functions
 
594
 
 
595
int myGotoDlg::GetPosition () {
 
596
    long position;
 
597
    if (m_position->GetValue ().ToLong(&position)) return position;
 
598
    return -1;
 
599
}
 
600
 
 
601
void myGotoDlg::SetPosition (int position) {
 
602
    m_position->SetValue (wxString::Format(_T("%d"), position));
 
603
}
 
604
 
 
605
int myGotoDlg::ShowModal (long WXUNUSED(style)) {
 
606
    m_position->SetFocus();
 
607
    m_position->SetSelection (-1, -1);
 
608
    return wxScrollingDialog::ShowModal ();
 
609
}