Skip to content

Commit 960dfe3

Browse files
committed
Removed the old style 'Replace' dialog with the quick find bar that shows the 'Replace' section
Quick Find Bar: added missing functionality to the 'Replace': "Replace in selected text only"
1 parent ba6a079 commit 960dfe3

File tree

11 files changed

+150
-89
lines changed

11 files changed

+150
-89
lines changed

LiteEditor/fileview.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,6 +2560,7 @@ void FileViewTree::DoCreateProjectContextMenu(wxMenu& menu, const wxString& proj
25602560

25612561
item = new wxMenuItem(&menu, XRCID("stop_build"), _("Stop Build"), _("Stop Build"));
25622562
menu.Append(item);
2563+
menu.AppendSeparator();
25632564

25642565
wxMenu* projectOnly = new wxMenu();
25652566
projectOnly->Append(XRCID("build_project_only"), _("Build"));

LiteEditor/frame.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ EVT_UPDATE_UI_RANGE(viewAsMenuItemID, viewAsMenuItemMaxID, clMainFrame::Dispatch
335335
// Search menu
336336
//-------------------------------------------------------
337337
EVT_MENU(wxID_FIND, clMainFrame::DispatchCommandEvent)
338-
EVT_MENU(wxID_REPLACE, clMainFrame::DispatchCommandEvent)
338+
EVT_MENU(wxID_REPLACE, clMainFrame::OnIncrementalReplace)
339339
EVT_MENU(XRCID("find_resource"), clMainFrame::OnFindResourceXXX)
340340
EVT_MENU(XRCID("incremental_search"), clMainFrame::OnIncrementalSearch)
341341
EVT_MENU(XRCID("incremental_replace"), clMainFrame::OnIncrementalReplace)
@@ -4631,13 +4631,13 @@ void clMainFrame::OnNextPrevTab_UI(wxUpdateUIEvent& e)
46314631
void clMainFrame::OnIncrementalSearch(wxCommandEvent& event)
46324632
{
46334633
wxUnusedVar(event);
4634-
GetMainBook()->ShowQuickBar(true);
4634+
GetMainBook()->ShowQuickBar(true, false);
46354635
}
46364636

46374637
void clMainFrame::OnIncrementalReplace(wxCommandEvent& event)
46384638
{
46394639
wxUnusedVar(event);
4640-
GetMainBook()->ToggleQuickReplaceBar();
4640+
GetMainBook()->ShowQuickBar(true, true);
46414641
}
46424642

46434643
void clMainFrame::OnRetagWorkspace(wxCommandEvent& event)

LiteEditor/mainbook.h

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,12 @@ class MainBook : public wxPanel
105105
void GetRecentlyOpenedFiles(wxArrayString& files);
106106
FileHistory& GetRecentlyOpenedFilesClass() { return m_recentFiles; }
107107
void ShowQuickBarForPlugins() { m_quickFindBar->ShowForPlugins(); }
108-
void ShowQuickBar(bool s = true) { m_quickFindBar->Show(s); }
109-
void ShowQuickBar(const wxString& findWhat) { m_quickFindBar->Show(findWhat); }
108+
void ShowQuickBar(bool s, bool replaceBar = false) { m_quickFindBar->Show(s, replaceBar); }
109+
void ShowQuickBar(const wxString& findWhat, bool replaceBar = false) { m_quickFindBar->Show(findWhat, replaceBar); }
110110
void ShowQuickReplaceBar(bool show) { m_quickFindBar->ShowReplacebar(show); }
111-
void ToggleQuickReplaceBar() { m_quickFindBar->ToggleReplacebar(); }
112-
void ShowMessage(const wxString& message,
113-
bool showHideButton = true,
114-
const wxBitmap& bmp = wxNullBitmap,
115-
const ButtonDetails& btn1 = ButtonDetails(),
116-
const ButtonDetails& btn2 = ButtonDetails(),
117-
const ButtonDetails& btn3 = ButtonDetails(),
118-
const CheckboxDetails& cb = CheckboxDetails());
111+
void ShowMessage(const wxString& message, bool showHideButton = true, const wxBitmap& bmp = wxNullBitmap,
112+
const ButtonDetails& btn1 = ButtonDetails(), const ButtonDetails& btn2 = ButtonDetails(),
113+
const ButtonDetails& btn3 = ButtonDetails(), const CheckboxDetails& cb = CheckboxDetails());
119114

120115
void ShowTabBar(bool b);
121116
void ShowNavBar(bool s = true);
@@ -152,29 +147,19 @@ class MainBook : public wxPanel
152147

153148
LEditor* NewEditor();
154149

155-
LEditor* OpenFile(const wxString& file_name,
156-
const wxString& projectName = wxEmptyString,
157-
int lineno = wxNOT_FOUND,
158-
long position = wxNOT_FOUND,
159-
OF_extra extra = OF_AddJump,
160-
bool preserveSelection = true);
150+
LEditor* OpenFile(const wxString& file_name, const wxString& projectName = wxEmptyString, int lineno = wxNOT_FOUND,
151+
long position = wxNOT_FOUND, OF_extra extra = OF_AddJump, bool preserveSelection = true);
161152
LEditor* OpenFile(const BrowseRecord& rec)
162153
{
163154
return OpenFile(rec.filename, rec.project, rec.lineno, rec.position, OF_None, false);
164155
}
165156

166-
bool AddPage(wxWindow* win,
167-
const wxString& text,
168-
const wxString& tooltip = wxEmptyString,
169-
const wxBitmap& bmp = wxNullBitmap,
170-
bool selected = false,
171-
int insert_at_index = wxNOT_FOUND);
157+
bool AddPage(wxWindow* win, const wxString& text, const wxString& tooltip = wxEmptyString,
158+
const wxBitmap& bmp = wxNullBitmap, bool selected = false, int insert_at_index = wxNOT_FOUND);
172159
bool SelectPage(wxWindow* win);
173160

174-
bool UserSelectFiles(std::vector<std::pair<wxFileName, bool> >& files,
175-
const wxString& title,
176-
const wxString& caption,
177-
bool cancellable = true);
161+
bool UserSelectFiles(std::vector<std::pair<wxFileName, bool> >& files, const wxString& title,
162+
const wxString& caption, bool cancellable = true);
178163

179164
bool SaveAll(bool askUser, bool includeUntitled);
180165

LiteEditor/quickfindbar.cpp

Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ QuickFindBar::QuickFindBar(wxWindow* parent, wxWindowID id)
8282
, m_eventsConnected(false)
8383
, m_optionsWindow(NULL)
8484
, m_regexType(kRegexNone)
85-
, m_disableTextUpdateEvent(false)
85+
, m_replaceInSelection(false)
8686
{
8787
m_bar = new wxFlatButtonBar(this, wxFlatButton::kThemeNormal, 0, 10);
8888

8989
//-------------------------------------------------------------
9090
// Find / Replace bar
9191
//-------------------------------------------------------------
92-
// [x][A]["][*][/][..............][find][find prev][find all]
93-
// [-][-][-][-][-][..............][replace][replace all]
92+
// [x][A]["][*][/][!][..............][find][find prev][find all]
93+
// [-][-][-][-][|][-][..............][replace][replace all]
9494
//-------------------------------------------------------------
9595
m_bar->SetExpandableColumn(6);
9696
GetSizer()->Add(m_bar, 1, wxEXPAND | wxALL, 2);
@@ -178,7 +178,13 @@ QuickFindBar::QuickFindBar(wxWindow* parent, wxWindowID id)
178178
m_bar->AddSpacer(0);
179179
m_bar->AddSpacer(0);
180180
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"));
182188

183189
// This spacer is for alinging with the "no match" bitmap
184190
m_bar->AddSpacer(0);
@@ -202,7 +208,7 @@ QuickFindBar::QuickFindBar(wxWindow* parent, wxWindowID id)
202208
m_buttonReplace->Bind(wxEVT_KEY_DOWN, &QuickFindBar::OnKeyDown, this);
203209

204210
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);
206212
m_buttonReplaceAll->Bind(wxEVT_KEY_DOWN, &QuickFindBar::OnKeyDown, this);
207213

208214
bool showreplace = EditorConfigST::Get()->GetOptions()->GetShowReplaceBar();
@@ -239,20 +245,12 @@ QuickFindBar::QuickFindBar(wxWindow* parent, wxWindowID id)
239245
m_replaceWith->Append(clConfig::Get().GetQuickFindReplaceItems());
240246
}
241247

242-
bool QuickFindBar::Show(bool show)
248+
bool QuickFindBar::Show(bool show, bool replaceBar)
243249
{
244250
if(!m_sci && show) {
245251
return false;
246252
}
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);
256254
}
257255

258256
void QuickFindBar::DoSearch(size_t searchFlags)
@@ -366,13 +364,7 @@ void QuickFindBar::OnPrev(wxCommandEvent& e)
366364
DoSearch(flags);
367365
}
368366

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(); }
376368

377369
void QuickFindBar::OnKeyDown(wxKeyEvent& e)
378370
{
@@ -550,12 +542,6 @@ void QuickFindBar::OnReplace(wxCommandEvent& event)
550542
DoSearch(kSearchForward);
551543
}
552544

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-
559545
void QuickFindBar::OnReplaceEnter(wxCommandEvent& e)
560546
{
561547
wxUnusedVar(e);
@@ -567,22 +553,22 @@ void QuickFindBar::SetEditor(wxStyledTextCtrl* sci)
567553
{
568554
m_sci = sci;
569555
if(!m_sci) {
570-
DoShow(false, "");
556+
DoShow(false, "", false);
571557
return;
572558
}
573559
}
574560

575561
int QuickFindBar::GetCloseButtonId() { return ID_TOOL_CLOSE; }
576562

577-
bool QuickFindBar::Show(const wxString& findWhat)
563+
bool QuickFindBar::Show(const wxString& findWhat, bool replaceBar)
578564
{
579565
// Same as Show() but set the 'findWhat' field with findWhat
580566
if(!m_sci) return false;
581567

582-
return DoShow(true, findWhat);
568+
return DoShow(true, findWhat, replaceBar);
583569
}
584570

585-
bool QuickFindBar::DoShow(bool s, const wxString& findWhat)
571+
bool QuickFindBar::DoShow(bool s, const wxString& findWhat, bool replaceBar)
586572
{
587573
bool res = wxPanel::Show(s);
588574

@@ -639,25 +625,16 @@ bool QuickFindBar::DoShow(bool s, const wxString& findWhat)
639625
m_noMatchBmp->Refresh();
640626
m_noMatchBmp->SetToolTip(wxEmptyString);
641627
}
628+
ShowReplacebar(replaceBar);
642629
return res;
643630
}
644631

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-
656632
void QuickFindBar::ShowReplacebar(bool show)
657633
{
658634
m_replaceWith->Show(show);
659635
m_buttonReplace->Show(show);
660636
m_buttonReplaceAll->Show(show);
637+
m_replaceInSelectionButton->Show(show);
661638
m_bar->GetSizer()->Layout();
662639
if(IsShown()) {
663640
clMainFrame::Get()->SendSizeEvent(); // Needed to show/hide the 'replace' bar itself
@@ -950,9 +927,9 @@ bool QuickFindBar::ShowForPlugins()
950927
{
951928
m_sci = DoCheckPlugins();
952929
if(!m_sci) {
953-
return DoShow(false, "");
930+
return DoShow(false, "", false);
954931
} else {
955-
return DoShow(true, "");
932+
return DoShow(true, "", false);
956933
}
957934
}
958935

@@ -1048,21 +1025,17 @@ void QuickFindBar::DoUpdateSearchHistory()
10481025
{
10491026
wxString findWhat = m_findWhat->GetValue();
10501027
if(findWhat.IsEmpty()) return;
1051-
m_disableTextUpdateEvent = true;
10521028
m_findWhat->Clear();
10531029
m_findWhat->ChangeValue(findWhat);
10541030
m_findWhat->Append(clConfig::Get().GetQuickFindSearchItems());
1055-
m_disableTextUpdateEvent = false;
10561031
}
10571032

10581033
void QuickFindBar::DoUpdateReplaceHistory()
10591034
{
1060-
m_disableTextUpdateEvent = true;
10611035
int where = m_replaceWith->FindString(m_replaceWith->GetValue());
10621036
if(where == wxNOT_FOUND) {
10631037
m_replaceWith->Insert(m_replaceWith->GetValue(), 0);
10641038
}
1065-
m_disableTextUpdateEvent = false;
10661039
}
10671040

10681041
void QuickFindBar::OnButtonNext(wxCommandEvent& e) { OnNext(e); }
@@ -1080,7 +1053,12 @@ size_t QuickFindBar::DoGetSearchFlags()
10801053

10811054
void QuickFindBar::OnFindAll(wxCommandEvent& e) { DoSelectAll(true); }
10821055
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+
10841062
void QuickFindBar::OnHideBar(wxFlatButtonEvent& e) { OnHide(e); }
10851063
void QuickFindBar::OnFindMouseWheel(wxMouseEvent& e)
10861064
{
@@ -1142,6 +1120,12 @@ void QuickFindBar::DoFixRegexParen(wxString& findwhat)
11421120
void QuickFindBar::DoSetCaretAtEndOfText() { m_findWhat->SetInsertionPointEnd(); }
11431121

11441122
void QuickFindBar::OnReplaceAll(wxCommandEvent& e)
1123+
{
1124+
wxUnusedVar(e);
1125+
DoReplaceAll(m_replaceInSelection);
1126+
}
1127+
1128+
void QuickFindBar::DoReplaceAll(bool selectionOnly)
11451129
{
11461130
if(!m_sci || m_sci->GetLength() == 0 || m_findWhat->GetValue().IsEmpty()) return;
11471131
clGetManager()->SetStatusMessage(wxEmptyString);
@@ -1155,16 +1139,25 @@ void QuickFindBar::OnReplaceAll(wxCommandEvent& e)
11551139
DoFixRegexParen(findwhat);
11561140
}
11571141

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+
11581151
// 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) {
11601153
clGetManager()->SetStatusMessage(_("No match found"), 2);
11611154
return;
11621155
}
11631156

11641157
int curpos = m_sci->GetCurrentPos();
11651158

11661159
// We got at least one match
1167-
m_sci->SetCurrentPos(0);
1160+
m_sci->SetCurrentPos(from);
11681161
m_sci->SetSelectionEnd(0);
11691162
m_sci->SetSelectionStart(0);
11701163

@@ -1222,6 +1215,12 @@ void QuickFindBar::OnReplaceAll(wxCommandEvent& e)
12221215
m_sci->SetSelectionEnd(newpos);
12231216
m_sci->SearchAnchor();
12241217
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+
}
12251224
++matchesCount;
12261225
}
12271226
m_sci->EndUndoAction();
@@ -1243,6 +1242,12 @@ void QuickFindBar::OnReplaceAll(wxCommandEvent& e)
12431242
clGetManager()->SetStatusMessage(message, 5);
12441243
}
12451244

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+
12461251
clNoMatchBitmap::clNoMatchBitmap(wxWindow* parent)
12471252
: wxPanel(parent)
12481253
, m_visible(false)

0 commit comments

Comments
 (0)