@@ -82,15 +82,15 @@ QuickFindBar::QuickFindBar(wxWindow* parent, wxWindowID id)
82
82
, m_eventsConnected(false )
83
83
, m_optionsWindow(NULL )
84
84
, m_regexType(kRegexNone )
85
- , m_disableTextUpdateEvent (false )
85
+ , m_replaceInSelection (false )
86
86
{
87
87
m_bar = new wxFlatButtonBar (this , wxFlatButton::kThemeNormal , 0 , 10 );
88
88
89
89
// -------------------------------------------------------------
90
90
// Find / Replace bar
91
91
// -------------------------------------------------------------
92
- // [x][A]["][*][/][..............][find][find prev][find all]
93
- // [-][-][-][-][-][..............][replace][replace all]
92
+ // [x][A]["][*][/][!][ ..............][find][find prev][find all]
93
+ // [-][-][-][-][|][ -][..............][replace][replace all]
94
94
// -------------------------------------------------------------
95
95
m_bar->SetExpandableColumn (6 );
96
96
GetSizer ()->Add (m_bar, 1 , wxEXPAND | wxALL, 2 );
@@ -178,7 +178,13 @@ QuickFindBar::QuickFindBar(wxWindow* parent, wxWindowID id)
178
178
m_bar->AddSpacer (0 );
179
179
m_bar->AddSpacer (0 );
180
180
m_bar->AddSpacer (0 );
181
- m_bar->AddSpacer (0 );
181
+ // Replace in selection
182
+ m_replaceInSelectionButton = m_bar->AddButton (" " , bmps->LoadBitmap (" text_selection" ), wxSize (24 , -1 ));
183
+ m_replaceInSelectionButton->SetTogglable (true );
184
+ m_replaceInSelectionButton->Bind (wxEVT_CMD_FLATBUTTON_CLICK, &QuickFindBar::OnReplaceInSelection, this );
185
+ m_replaceInSelectionButton->Bind (wxEVT_UPDATE_UI, &QuickFindBar::OnReplaceInSelectionUI, this );
186
+ m_replaceInSelectionButton->Bind (wxEVT_KEY_DOWN, &QuickFindBar::OnKeyDown, this );
187
+ m_replaceInSelectionButton->SetToolTip (_ (" Replace in selected text" ));
182
188
183
189
// This spacer is for alinging with the "no match" bitmap
184
190
m_bar->AddSpacer (0 );
@@ -202,7 +208,7 @@ QuickFindBar::QuickFindBar(wxWindow* parent, wxWindowID id)
202
208
m_buttonReplace->Bind (wxEVT_KEY_DOWN, &QuickFindBar::OnKeyDown, this );
203
209
204
210
m_buttonReplaceAll->Bind (wxEVT_BUTTON, &QuickFindBar::OnReplaceAll, this );
205
- m_buttonReplaceAll->Bind (wxEVT_UPDATE_UI, &QuickFindBar::OnButtonReplaceUI , this );
211
+ m_buttonReplaceAll->Bind (wxEVT_UPDATE_UI, &QuickFindBar::OnButtonReplaceAllUI , this );
206
212
m_buttonReplaceAll->Bind (wxEVT_KEY_DOWN, &QuickFindBar::OnKeyDown, this );
207
213
208
214
bool showreplace = EditorConfigST::Get ()->GetOptions ()->GetShowReplaceBar ();
@@ -239,20 +245,12 @@ QuickFindBar::QuickFindBar(wxWindow* parent, wxWindowID id)
239
245
m_replaceWith->Append (clConfig::Get ().GetQuickFindReplaceItems ());
240
246
}
241
247
242
- bool QuickFindBar::Show (bool show)
248
+ bool QuickFindBar::Show (bool show, bool replaceBar )
243
249
{
244
250
if (!m_sci && show) {
245
251
return false ;
246
252
}
247
- return DoShow (show, wxEmptyString);
248
- }
249
-
250
- void QuickFindBar::ToggleReplacebar ()
251
- {
252
- if (!m_sci || !IsShown ()) {
253
- return ;
254
- }
255
- DoToggleReplacebar ();
253
+ return DoShow (show, wxEmptyString, replaceBar);
256
254
}
257
255
258
256
void QuickFindBar::DoSearch (size_t searchFlags)
@@ -366,13 +364,7 @@ void QuickFindBar::OnPrev(wxCommandEvent& e)
366
364
DoSearch (flags);
367
365
}
368
366
369
- void QuickFindBar::OnText (wxCommandEvent& e)
370
- {
371
- e.Skip ();
372
- if (!m_disableTextUpdateEvent) {
373
- CallAfter (&QuickFindBar::DoSearch, kSearchForward );
374
- }
375
- }
367
+ void QuickFindBar::OnText (wxCommandEvent& e) { e.Skip (); }
376
368
377
369
void QuickFindBar::OnKeyDown (wxKeyEvent& e)
378
370
{
@@ -550,12 +542,6 @@ void QuickFindBar::OnReplace(wxCommandEvent& event)
550
542
DoSearch (kSearchForward );
551
543
}
552
544
553
- void QuickFindBar::OnReplaceUI (wxUpdateUIEvent& e)
554
- {
555
- e.Enable (ManagerST::Get ()->IsShutdownInProgress () == false && m_sci && !m_sci->GetReadOnly () &&
556
- m_sci->GetLength () > 0 && !m_findWhat->GetValue ().IsEmpty ());
557
- }
558
-
559
545
void QuickFindBar::OnReplaceEnter (wxCommandEvent& e)
560
546
{
561
547
wxUnusedVar (e);
@@ -567,22 +553,22 @@ void QuickFindBar::SetEditor(wxStyledTextCtrl* sci)
567
553
{
568
554
m_sci = sci;
569
555
if (!m_sci) {
570
- DoShow (false , " " );
556
+ DoShow (false , " " , false );
571
557
return ;
572
558
}
573
559
}
574
560
575
561
int QuickFindBar::GetCloseButtonId () { return ID_TOOL_CLOSE; }
576
562
577
- bool QuickFindBar::Show (const wxString& findWhat)
563
+ bool QuickFindBar::Show (const wxString& findWhat, bool replaceBar )
578
564
{
579
565
// Same as Show() but set the 'findWhat' field with findWhat
580
566
if (!m_sci) return false ;
581
567
582
- return DoShow (true , findWhat);
568
+ return DoShow (true , findWhat, replaceBar );
583
569
}
584
570
585
- bool QuickFindBar::DoShow (bool s, const wxString& findWhat)
571
+ bool QuickFindBar::DoShow (bool s, const wxString& findWhat, bool replaceBar )
586
572
{
587
573
bool res = wxPanel::Show (s);
588
574
@@ -639,25 +625,16 @@ bool QuickFindBar::DoShow(bool s, const wxString& findWhat)
639
625
m_noMatchBmp->Refresh ();
640
626
m_noMatchBmp->SetToolTip (wxEmptyString);
641
627
}
628
+ ShowReplacebar (replaceBar);
642
629
return res;
643
630
}
644
631
645
- void QuickFindBar::DoToggleReplacebar ()
646
- {
647
- OptionsConfigPtr options = EditorConfigST::Get ()->GetOptions ();
648
- bool show = !options->GetShowReplaceBar ();
649
-
650
- options->SetShowReplaceBar (show);
651
- EditorConfigST::Get ()->SetOptions (options);
652
-
653
- ShowReplacebar (show);
654
- }
655
-
656
632
void QuickFindBar::ShowReplacebar (bool show)
657
633
{
658
634
m_replaceWith->Show (show);
659
635
m_buttonReplace->Show (show);
660
636
m_buttonReplaceAll->Show (show);
637
+ m_replaceInSelectionButton->Show (show);
661
638
m_bar->GetSizer ()->Layout ();
662
639
if (IsShown ()) {
663
640
clMainFrame::Get ()->SendSizeEvent (); // Needed to show/hide the 'replace' bar itself
@@ -950,9 +927,9 @@ bool QuickFindBar::ShowForPlugins()
950
927
{
951
928
m_sci = DoCheckPlugins ();
952
929
if (!m_sci) {
953
- return DoShow (false , " " );
930
+ return DoShow (false , " " , false );
954
931
} else {
955
- return DoShow (true , " " );
932
+ return DoShow (true , " " , false );
956
933
}
957
934
}
958
935
@@ -1048,21 +1025,17 @@ void QuickFindBar::DoUpdateSearchHistory()
1048
1025
{
1049
1026
wxString findWhat = m_findWhat->GetValue ();
1050
1027
if (findWhat.IsEmpty ()) return ;
1051
- m_disableTextUpdateEvent = true ;
1052
1028
m_findWhat->Clear ();
1053
1029
m_findWhat->ChangeValue (findWhat);
1054
1030
m_findWhat->Append (clConfig::Get ().GetQuickFindSearchItems ());
1055
- m_disableTextUpdateEvent = false ;
1056
1031
}
1057
1032
1058
1033
void QuickFindBar::DoUpdateReplaceHistory ()
1059
1034
{
1060
- m_disableTextUpdateEvent = true ;
1061
1035
int where = m_replaceWith->FindString (m_replaceWith->GetValue ());
1062
1036
if (where == wxNOT_FOUND) {
1063
1037
m_replaceWith->Insert (m_replaceWith->GetValue (), 0 );
1064
1038
}
1065
- m_disableTextUpdateEvent = false ;
1066
1039
}
1067
1040
1068
1041
void QuickFindBar::OnButtonNext (wxCommandEvent& e) { OnNext (e); }
@@ -1080,7 +1053,12 @@ size_t QuickFindBar::DoGetSearchFlags()
1080
1053
1081
1054
void QuickFindBar::OnFindAll (wxCommandEvent& e) { DoSelectAll (true ); }
1082
1055
void QuickFindBar::OnButtonReplace (wxCommandEvent& e) { OnReplace (e); }
1083
- void QuickFindBar::OnButtonReplaceUI (wxUpdateUIEvent& e) { e.Enable (!m_findWhat->GetValue ().IsEmpty ()); }
1056
+
1057
+ void QuickFindBar::OnButtonReplaceUI (wxUpdateUIEvent& e)
1058
+ {
1059
+ e.Enable (!m_findWhat->GetValue ().IsEmpty () && !m_replaceInSelection);
1060
+ }
1061
+
1084
1062
void QuickFindBar::OnHideBar (wxFlatButtonEvent& e) { OnHide (e); }
1085
1063
void QuickFindBar::OnFindMouseWheel (wxMouseEvent& e)
1086
1064
{
@@ -1142,6 +1120,12 @@ void QuickFindBar::DoFixRegexParen(wxString& findwhat)
1142
1120
void QuickFindBar::DoSetCaretAtEndOfText () { m_findWhat->SetInsertionPointEnd (); }
1143
1121
1144
1122
void QuickFindBar::OnReplaceAll (wxCommandEvent& e)
1123
+ {
1124
+ wxUnusedVar (e);
1125
+ DoReplaceAll (m_replaceInSelection);
1126
+ }
1127
+
1128
+ void QuickFindBar::DoReplaceAll (bool selectionOnly)
1145
1129
{
1146
1130
if (!m_sci || m_sci->GetLength () == 0 || m_findWhat->GetValue ().IsEmpty ()) return ;
1147
1131
clGetManager ()->SetStatusMessage (wxEmptyString);
@@ -1155,16 +1139,25 @@ void QuickFindBar::OnReplaceAll(wxCommandEvent& e)
1155
1139
DoFixRegexParen (findwhat);
1156
1140
}
1157
1141
1142
+ int from, to;
1143
+ if (selectionOnly && m_sci->GetSelectedText ().IsEmpty ()) return ;
1144
+ if (selectionOnly) {
1145
+ m_sci->GetSelection (&from, &to);
1146
+ } else {
1147
+ from = 0 ;
1148
+ to = m_sci->GetLastPosition ();
1149
+ }
1150
+
1158
1151
// Ensure that we have at least one match before we continue
1159
- if (m_sci->FindText (0 , m_sci-> GetLastPosition () , findwhat, searchFlags) == wxNOT_FOUND) {
1152
+ if (m_sci->FindText (from, to , findwhat, searchFlags) == wxNOT_FOUND) {
1160
1153
clGetManager ()->SetStatusMessage (_ (" No match found" ), 2 );
1161
1154
return ;
1162
1155
}
1163
1156
1164
1157
int curpos = m_sci->GetCurrentPos ();
1165
1158
1166
1159
// We got at least one match
1167
- m_sci->SetCurrentPos (0 );
1160
+ m_sci->SetCurrentPos (from );
1168
1161
m_sci->SetSelectionEnd (0 );
1169
1162
m_sci->SetSelectionStart (0 );
1170
1163
@@ -1222,6 +1215,12 @@ void QuickFindBar::OnReplaceAll(wxCommandEvent& e)
1222
1215
m_sci->SetSelectionEnd (newpos);
1223
1216
m_sci->SearchAnchor ();
1224
1217
pos = m_sci->SearchNext (searchFlags, findwhat);
1218
+
1219
+ // When replacing in "Selected Text" don't count matches
1220
+ // that are out of range
1221
+ if (selectionOnly && (pos > to)) {
1222
+ break ;
1223
+ }
1225
1224
++matchesCount;
1226
1225
}
1227
1226
m_sci->EndUndoAction ();
@@ -1243,6 +1242,12 @@ void QuickFindBar::OnReplaceAll(wxCommandEvent& e)
1243
1242
clGetManager ()->SetStatusMessage (message, 5 );
1244
1243
}
1245
1244
1245
+ void QuickFindBar::OnReplaceInSelection (wxFlatButtonEvent& e) { m_replaceInSelection = e.IsChecked (); }
1246
+
1247
+ void QuickFindBar::OnReplaceInSelectionUI (wxUpdateUIEvent& event) {}
1248
+
1249
+ void QuickFindBar::OnButtonReplaceAllUI (wxUpdateUIEvent& e) { e.Enable (!m_findWhat->GetValue ().IsEmpty ()); }
1250
+
1246
1251
clNoMatchBitmap::clNoMatchBitmap (wxWindow* parent)
1247
1252
: wxPanel(parent)
1248
1253
, m_visible(false )
0 commit comments