From bb910055498f1a76967df90710ce5a6b3d8acb27 Mon Sep 17 00:00:00 2001 From: Tim Warren Date: Mon, 4 May 2015 16:27:21 -0400 Subject: [PATCH] New file style matches open file style, fiddling with find/replace logic --- src/widgets/EditPane.cpp | 68 +++++++++++++++++++++------------------ src/widgets/MainFrame.cpp | 59 +++++++++++++++++++++++++-------- 2 files changed, 81 insertions(+), 46 deletions(-) diff --git a/src/widgets/EditPane.cpp b/src/widgets/EditPane.cpp index 94f1d1b..594d08c 100644 --- a/src/widgets/EditPane.cpp +++ b/src/widgets/EditPane.cpp @@ -37,6 +37,41 @@ EditPane::EditPane( lexerMap["yaml"] = wxSTC_LEX_YAML; this->BindEvents(); + + // Some basic properties to set + this->SetStyleBits(8); + this->SetScrollWidthTracking(true);// Set scroll width by longest line + this->SetProperty("technology", "2"); + this->SetProperty("error.inline", "0"); + this->SetProperty("styling.within.preprocessor", "1"); + this->SetProperty("lexer.cpp.track.preprocessor", "1"); + this->SetProperty("font.quality", "3"); // LCD Optimized + + // Set up Code folding + this->SetProperty("fold", "1"); + this->SetProperty("fold.comment", "1"); + this->SetProperty("fold.compact", "1"); + this->SetProperty("fold.html", "1"); + this->SetFoldFlags(wxSTC_FOLDFLAG_LINEBEFORE_CONTRACTED | wxSTC_FOLDFLAG_LINEAFTER_CONTRACTED); + this->SetMarginType(MARGIN_FOLD, wxSTC_MARGIN_SYMBOL); + this->SetMarginWidth(MARGIN_FOLD, 16); + this->SetMarginSensitive(MARGIN_FOLD, true); + this->SetMarginMask(MARGIN_FOLD, wxSTC_MASK_FOLDERS); + this->MarkerDefine(wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUSCONNECTED, "WHITE", "BLACK"); + this->MarkerDefine(wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUSCONNECTED, "WHITE", "BLACK"); + this->MarkerDefine(wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_VLINE, "BLACK", "BLACK"); + this->MarkerDefine(wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_CIRCLEPLUSCONNECTED, "WHITE", "BLACK"); + this->MarkerDefine(wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_CIRCLEMINUSCONNECTED, "WHITE", "BLACK"); + this->MarkerDefine(wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_TCORNER, "BLACK", "BLACK"); + this->MarkerDefine(wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_LCORNER, "BLACK", "BLACK"); + + this->SetLayoutCache (wxSTC_CACHE_DOCUMENT); + + // set spaces and indention + this->SetTabWidth(4); + + // Blank highlight + this->Highlight(""); } EditPane::~EditPane() @@ -70,40 +105,9 @@ void EditPane::Highlight(wxString filePath) this->SetLexer(wxSTC_LEX_NULL); } - // Some basic properties to set - this->SetStyleBits(8); - this->SetProperty("technology", "2"); - this->SetProperty("error.inline", "0"); - this->SetProperty("styling.within.preprocessor", "1"); - this->SetProperty("lexer.cpp.track.preprocessor", "1"); - this->SetProperty("font.quality", "3"); // LCD Optimized - // Apply the theme this->ApplyTheme(lang); - // Set up Code folding - this->SetProperty("fold", "1"); - this->SetProperty("fold.comment", "1"); - this->SetProperty("fold.compact", "1"); - this->SetProperty("fold.html", "1"); - this->SetFoldFlags(wxSTC_FOLDFLAG_LINEBEFORE_CONTRACTED | wxSTC_FOLDFLAG_LINEAFTER_CONTRACTED); - this->SetMarginType(MARGIN_FOLD, wxSTC_MARGIN_SYMBOL); - this->SetMarginWidth(MARGIN_FOLD, 16); - this->SetMarginSensitive(MARGIN_FOLD, true); - this->SetMarginMask(MARGIN_FOLD, wxSTC_MASK_FOLDERS); - this->MarkerDefine (wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUSCONNECTED, "WHITE", "BLACK"); - this->MarkerDefine (wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUSCONNECTED, "WHITE", "BLACK"); - this->MarkerDefine (wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_VLINE, "BLACK", "BLACK"); - this->MarkerDefine (wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_CIRCLEPLUSCONNECTED, "WHITE", "BLACK"); - this->MarkerDefine (wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_CIRCLEMINUSCONNECTED, "WHITE", "BLACK"); - this->MarkerDefine (wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_TCORNER, "BLACK", "BLACK"); - this->MarkerDefine (wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_LCORNER, "BLACK", "BLACK"); - - this->SetLayoutCache (wxSTC_CACHE_DOCUMENT); - - // set spaces and indention - this->SetTabWidth(4); - bool use_tabs = (lang != "yaml"); this->SetUseTabs(use_tabs); @@ -400,7 +404,7 @@ void EditPane::_ApplyTheme(JsonValue &lexer_map) this->StyleSetForeground (wxSTC_STYLE_DEFAULT, default_foreground); this->StyleSetForeground(wxSTC_STYLE_INDENTGUIDE, wxColor(147, 161, 161)); - this->SetMarginWidth (MARGIN_LINE_NUMBERS, TextWidth(wxSTC_STYLE_LINENUMBER, _T("_99999"))); + this->SetMarginWidth (MARGIN_LINE_NUMBERS, TextWidth(wxSTC_STYLE_LINENUMBER, "_999")); this->StyleSetForeground (wxSTC_STYLE_LINENUMBER, line_number_foreground); this->StyleSetBackground (wxSTC_STYLE_LINENUMBER, line_number_background); this->SetMarginType (MARGIN_LINE_NUMBERS, wxSTC_MARGIN_NUMBER); diff --git a/src/widgets/MainFrame.cpp b/src/widgets/MainFrame.cpp index 26ed235..7aad60d 100644 --- a/src/widgets/MainFrame.cpp +++ b/src/widgets/MainFrame.cpp @@ -8,7 +8,7 @@ MainFrame::MainFrame(wxFrame *frame, const wxString &title) { #include "../../resources/xpm/tyro.xpm" - findReplaceData = new wxFindReplaceData(); + findReplaceData = new wxFindReplaceData(wxFR_DOWN); wxIcon app_icon(tyro_icon); this->SetIcon(app_icon); @@ -475,39 +475,70 @@ void MainFrame::OnFindDialog(wxFindDialogEvent &event) int stc_flags = 0; int fr_flags = event.GetFlags(); - if ((fr_flags & wxFR_WHOLEWORD) != 0) stc_flags |= wxSTC_FIND_WHOLEWORD; - if ((fr_flags & wxFR_MATCHCASE) != 0) stc_flags |= wxSTC_FIND_MATCHCASE; + if (fr_flags & wxFR_WHOLEWORD) stc_flags |= wxSTC_FIND_WHOLEWORD; + if (fr_flags & wxFR_MATCHCASE) stc_flags |= wxSTC_FIND_MATCHCASE; + + // Position after search + int new_pos = 0; + int new_line = 1; // Send find flags to editor control editor->SetSearchFlags(stc_flags); - + if (type == wxEVT_FIND) { - editor->SearchAnchor(); // Set staring search position at current position - editor->SearchNext(stc_flags, event.GetFindString()); - } - else if (type == wxEVT_FIND_NEXT) - { + wxLogDebug("wxEVT_FIND"); + + editor->SearchAnchor(); + if ((fr_flags & wxFR_DOWN) != 0) { - editor->SearchNext(stc_flags, event.GetFindString()); + new_pos = editor->SearchNext(stc_flags, event.GetFindString()); } else { - editor->SearchPrev(stc_flags, event.GetFindString()); + new_pos = editor->SearchPrev(stc_flags, event.GetFindString()); + } + + if (new_pos >= 0) + { + new_line = editor->LineFromPosition(new_pos); + editor->ScrollToLine(new_line); + } + } + else if (type == wxEVT_FIND_NEXT) + { + wxLogDebug("wxEVT_FIND_NEXT"); + + if ((fr_flags & wxFR_DOWN) != 0) + { + new_pos = editor->SearchNext(stc_flags, event.GetFindString()); + } + else + { + new_pos = editor->SearchPrev(stc_flags, event.GetFindString()); + } + + if (new_pos >= 0) + { + /*editor->SetSelectionStart(editor->GetAnchor()); + editor->SetSelectionEnd(new_pos);*/ + + new_line = editor->LineFromPosition(new_pos); + editor->ScrollToLine(new_line); } - editor->SearchAnchor(); } else if (type == wxEVT_FIND_REPLACE) { - + wxLogDebug("wxEVT_FIND_REPLACE"); } else if (type == wxEVT_FIND_REPLACE_ALL) { - + wxLogDebug("wxEVT_FIND_REPLACE_ALL"); } else if (type == wxEVT_FIND_CLOSE) { + wxLogDebug("wxEVT_FIND_CLOSE"); event.GetDialog()->Destroy(); } }