From bc0f97dd0b13f73295b215b03d58c9203a871c7b Mon Sep 17 00:00:00 2001 From: Tim Warren Date: Mon, 1 Jun 2015 16:51:00 -0400 Subject: [PATCH] First shot at search --- src/widgets/MainFrame.cpp | 42 +++++++++++++++++++++++++++------------ src/widgets/TyroMenu.cpp | 8 +++++--- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/widgets/MainFrame.cpp b/src/widgets/MainFrame.cpp index 79d43b9..b3a4c25 100644 --- a/src/widgets/MainFrame.cpp +++ b/src/widgets/MainFrame.cpp @@ -475,7 +475,6 @@ void MainFrame::OnFindDialog(wxFindDialogEvent &event) // Position after search int new_pos = 0; - int new_line = 1; // Send find flags to editor control editor->SetSearchFlags(stc_flags); @@ -484,27 +483,44 @@ void MainFrame::OnFindDialog(wxFindDialogEvent &event) { wxLogDebug("wxEVT_FIND"); - editor->SetAnchor(0); + /*if (editor->GetCurrentPos() < 1) + { + editor->GotoPos(1); + }*/ + editor->SearchAnchor(); } if (type == wxEVT_FIND_NEXT || type == wxEVT_FIND) - { - if ((fr_flags & wxFR_DOWN) != 0) + { + if (type == wxEVT_FIND_NEXT) { - new_pos = editor->SearchNext(stc_flags, event.GetFindString()); - } - else - { - new_pos = editor->SearchPrev(stc_flags, event.GetFindString()); + wxLogDebug("wxEVT_FIND_NEXT"); } + new_pos = ((fr_flags & wxFR_DOWN) != 0) + ? editor->SearchNext(stc_flags, event.GetFindString()) + : editor->SearchPrev(stc_flags, event.GetFindString()); + + int sel_start = editor->GetSelectionStart(); + int sel_end = editor->GetSelectionEnd(); + if (new_pos > 0) - { - new_line = editor->LineFromPosition(new_pos); - editor->ScrollToLine(new_line); - //editor->SetAnchor(new_pos); + { + if ((fr_flags & wxFR_DOWN) != 0) + { + editor->GotoPos(sel_end + 1); + } + else + { + ((sel_start - 1) > 0) + ? editor->GotoPos(sel_start - 1) + : editor->GotoPos(sel_start); + } + editor->SearchAnchor(); + editor->SetSelectionStart(sel_start); + editor->SetSelectionEnd(sel_end); } return; diff --git a/src/widgets/TyroMenu.cpp b/src/widgets/TyroMenu.cpp index 43c1e09..6e99656 100644 --- a/src/widgets/TyroMenu.cpp +++ b/src/widgets/TyroMenu.cpp @@ -61,11 +61,11 @@ void TyroMenu::SetupMainMenus() editMenu->Append(wxID_COPY, "&Copy\tCtrl+C", "Copy selected text"); editMenu->Append(wxID_PASTE, "&Paste\tCtrl+V", "Paste contents of clipboard"); //editMenu->Append(wxID_DELETE, "&Delete\tDel"); - //editMenu->AppendSeparator(); - //editMenu->Append(wxID_FIND, "&Find\tCtrl+F"); + editMenu->AppendSeparator(); + editMenu->Append(wxID_FIND, "&Find\tCtrl+F"); //editMenu->Append(wxID_REPLACE, "&Replace\tCtrl+R"); - //editMenu->AppendSeparator(); + editMenu->AppendSeparator(); editMenu->Append(wxID_SELECTALL, "Select All\tCtrl+A", "Select all the text in the current document"); editMenu->AppendSeparator(); editMenu->Append(wxID_PREFERENCES, "&Preferences\tCtrl+P"); @@ -111,6 +111,8 @@ void TyroMenu::EnableEditControls(bool enable) this->editMenu->Enable(wxID_COPY, enable); this->editMenu->Enable(wxID_PASTE, enable); this->editMenu->Enable(wxID_SELECTALL, enable); + this->editMenu->Enable(wxID_FIND, enable); + //this->editMenu->Enable(wxID_REPLACE, enable); // Enable/disable top level menus this->EnableEntireMenu(myVIEW_MENU, this->viewMenu, enable);