Menu

[r135]: / src / globalreplacedialog.cpp  Maximize  Restore  History

Download this file

203 lines (185 with data), 6.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
* Copyright 2005-2007 Gerald Schmidt.
*
* This file is part of Xml Copy Editor.
*
* Xml Copy Editor is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* Xml Copy Editor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xml Copy Editor; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <memory>
#include "globalreplacedialog.h"
#include "wrapregex.h"
BEGIN_EVENT_TABLE ( GlobalReplaceDialog, wxDialog )
EVT_BUTTON ( wxID_OK, GlobalReplaceDialog::OnOk )
EVT_HELP_RANGE ( ID_FIND, ID_ALLDOCUMENTS, GlobalReplaceDialog::OnContextHelp )
EVT_HELP ( wxID_OK, GlobalReplaceDialog::OnContextHelp )
EVT_HELP ( wxID_CANCEL, GlobalReplaceDialog::OnContextHelp )
EVT_UPDATE_UI ( wxID_OK, GlobalReplaceDialog::OnUpdateOk )
END_EVENT_TABLE()
GlobalReplaceDialog::GlobalReplaceDialog (
wxWindow *parent,
const wxString& findParameter,
const wxString& replaceParameter,
bool matchCaseParameter,
bool allDocumentsParameter,
bool regexParameter ) :
wxDialog(),
find ( findParameter ),
replace ( replaceParameter ),
matchCase ( matchCaseParameter ),
allDocuments ( allDocumentsParameter ),
regex ( regexParameter )
{
SetExtraStyle ( wxDIALOG_EX_CONTEXTHELP );
Create (
parent,
wxID_ANY,
wxString ( _ ( "Global Find and Replace" ) ),
wxDefaultPosition,
wxSize ( -1, -1 ),
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
wxBoxSizer *dialogSizer = new wxBoxSizer ( wxVERTICAL );
wxStaticText *findLabel = new wxStaticText ( this, ID_FIND, _ ( "&Find what: " ) );
wxStaticText *replaceLabel =
new wxStaticText ( this, ID_REPLACE, _ ( "Replace with: " ) );
findCtrl = new wxTextCtrl (
this,
ID_FIND,
find,
wxDefaultPosition,
wxSize ( 400, -1 ) );
replaceCtrl = new wxTextCtrl (
this,
ID_REPLACE,
replace,
wxDefaultPosition,
wxSize ( 400, -1 ) );
regexBox =
new wxCheckBox ( this, ID_REGEX, _ ( "&Regex" ) );
regexBox->SetValue ( regex );
matchCaseBox =
new wxCheckBox ( this, ID_MATCHCASE, _ ( "&Match case" ) );
matchCaseBox->SetValue ( matchCase );
allDocumentsBox =
new wxCheckBox ( this, ID_ALLDOCUMENTS, _ ( "R&eplace in all open documents" ) );
allDocumentsBox->SetValue ( allDocuments );
dialogSizer->Add ( findLabel, 0, wxTOP | wxLEFT | wxALIGN_LEFT, 5 );
dialogSizer->Add ( findCtrl, 0, wxALL | wxALIGN_LEFT | wxEXPAND, 5 );
dialogSizer->Add ( replaceLabel, 0, wxTOP | wxLEFT | wxALIGN_LEFT, 5 );
dialogSizer->Add ( replaceCtrl, 0, wxALL | wxALIGN_LEFT | wxEXPAND, 5 );
dialogSizer->Add ( matchCaseBox, 0, wxALL | wxALIGN_LEFT, 5 );
dialogSizer->Add ( regexBox, 0, wxALL | wxALIGN_LEFT, 5 );
dialogSizer->Add ( allDocumentsBox, 0, wxALL | wxALIGN_LEFT, 5 );
dialogSizer->Add (
CreateButtonSizer ( wxOK | wxCANCEL ), 0, wxTOP | wxBOTTOM | wxALIGN_RIGHT, 5 );
this->SetSizer ( dialogSizer );
dialogSizer->SetSizeHints ( this );
findCtrl->SetFocus();
}
GlobalReplaceDialog::~GlobalReplaceDialog()
{ }
void GlobalReplaceDialog::OnOk ( wxCommandEvent& e )
{
std::string findUtf8, replaceUtf8;
find = findCtrl->GetValue();
replace = replaceCtrl->GetValue();
findUtf8 = ( const char * ) find.mb_str ( wxConvUTF8 );
replaceUtf8 = ( const char * ) replace.mb_str ( wxConvUTF8 );
regex = regexBox->GetValue();
allDocuments = allDocumentsBox->GetValue();
matchCase = matchCaseBox->GetValue();
if ( regex )
{
try
{
std::auto_ptr<WrapRegex> wr ( new WrapRegex (
findUtf8,
matchCase,
replaceUtf8 ) );
}
catch ( std::exception& e )
{
std::string pcreError ( e.what() );
wxString widePcreError =
wxString ( pcreError.c_str(), wxConvUTF8, pcreError.size() );
wxMessageBox (
_ ( "Cannot compile regular expression '" ) +
findCtrl->GetValue() +
_T ( "': " ) +
widePcreError,
_ ( "Global Find and Replace" ) );
return;
}
}
e.Skip();
}
void GlobalReplaceDialog::OnContextHelp ( wxHelpEvent& e )
{
wxTipWindow *tw;
int id = e.GetId();
if ( id == ID_FIND )
tw = new wxTipWindow (
this,
_ ( "Provides a space for you to type the text you want to find" ) );
else if ( id == ID_REPLACE )
tw = new wxTipWindow (
this,
_ ( "Provides a space for you to type the text you want to replace the text you typed in Find what" ) );
else if ( id == ID_MATCHCASE )
tw = new wxTipWindow (
this,
_ ( "Finds only text with lowercase and uppercase letters as specified in Find what" ) );
else if ( id == ID_ALLDOCUMENTS )
tw = new wxTipWindow (
this,
_ ( "Extends the scope to all open documents" ) );
else if ( id == ID_REGEX )
tw = new wxTipWindow (
this,
_ ( "Interprets the text specified in Find what as a regular expression" ) );
else if ( id == wxID_OK )
tw = new wxTipWindow (
this,
_ ( "Finds all instances of the text specified in Find what and replaces them with the text in Replace with" ) );
else if ( id == wxID_CANCEL )
tw = new wxTipWindow (
this,
_ ( "Closes the dialog box without saving any changes you have made" ) );
else
{ }
e.Skip();
}
void GlobalReplaceDialog::OnUpdateOk ( wxUpdateUIEvent& e )
{
e.Enable ( !findCtrl->GetValue().empty() );
}
wxString GlobalReplaceDialog::getFindString()
{
return find;
}
wxString GlobalReplaceDialog::getReplaceString()
{
return replace;
}
bool GlobalReplaceDialog::getRegex()
{
return regex;
}
bool GlobalReplaceDialog::getAllDocuments()
{
return allDocuments;
}
bool GlobalReplaceDialog::getMatchCase()
{
return matchCase;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.