diff --git a/src/EditorCtrl.cpp b/src/EditorCtrl.cpp index 964b05f0..b247608d 100644 --- a/src/EditorCtrl.cpp +++ b/src/EditorCtrl.cpp @@ -1468,6 +1468,57 @@ bool EditorCtrl::SmartTab() { return false; } +/** + * This uses the GetRealIndent method to calculate the 'correct' indentation for each line. + * It strips the indentation from the line and then sets it to the above string. + * This could be *much* faster if more time was spent analyzing the usage of GetRealIndent, there are probably a ton of duplicate calculations going on. + * It does remove any selections if they were there. This could probably be avoided if users want it. + */ +void EditorCtrl::IndentLines() { + std::vector intervals; + const vector selections = GetSelections(); + if(selections.size() == 0) { + intervals.push_back(0); + intervals.push_back(m_lines.GetLineCount()-1); + } else { + for(unsigned int c = 0; c < selections.size(); c++) { + intervals.push_back(m_lines.GetLineFromCharPos(selections[c].start)); + intervals.push_back(m_lines.GetLineFromCharPos(selections[c].end)); + } + } + + Freeze(); + for(unsigned int c = 0; c < intervals.size(); c += 2) { + unsigned int startLine = intervals[c]; + unsigned int endLine = intervals[c+1]; + + while(endLine >= startLine) { + wxString realIndent = GetRealIndent(startLine, false, true); + + const unsigned int startOfLine = m_lines.GetLineStartpos(startLine); + const unsigned int endOfLine = m_lines.GetLineEndpos(startLine); + unsigned int whitespaceEnd = startOfLine; + + cxLOCKDOC_READ(m_doc) + while(whitespaceEnd < endOfLine) { + const wxChar c = doc.GetChar(whitespaceEnd); + if(!(c == ' ' || c == '\t')) break; + whitespaceEnd++; + } + cxENDLOCK + + RawDelete(startOfLine, whitespaceEnd); + RawInsert(startOfLine, realIndent); + + startLine++; + } + } + + RemoveAllSelections(); + Freeze(); + DrawLayout(); +} + void EditorCtrl::GetLine(unsigned int lineid, vector& text) const { unsigned int start; unsigned int end; diff --git a/src/EditorCtrl.h b/src/EditorCtrl.h index 642f569a..62f957f4 100644 --- a/src/EditorCtrl.h +++ b/src/EditorCtrl.h @@ -355,6 +355,7 @@ class EditorCtrl : public KeyHookable, wxString GetLineIndentFromPos(unsigned int pos); void TabsToSpaces(); void SpacesToTabs(); + void IndentLines(); // Encoding wxFontEncoding GetEncoding() const; diff --git a/src/EditorFrame.cpp b/src/EditorFrame.cpp index da320ffa..4590ae88 100644 --- a/src/EditorFrame.cpp +++ b/src/EditorFrame.cpp @@ -301,6 +301,7 @@ BEGIN_EVENT_TABLE(EditorFrame, wxFrame) EVT_MENU(MENU_NAVIGATE_SELECTIONS_NEXT, EditorFrame::OnMenuNavigateSelectionsNext) EVT_MENU(MENU_NAVIGATE_SELECTIONS_PREVIOUS, EditorFrame::OnMenuNavigateSelectionsPrevious) EVT_MENU(MENU_ACCELERATORS, EditorFrame::OnMenuCustomizeAccelerators) + EVT_MENU(MENU_INDENT_LINES, EditorFrame::OnMenuIndentLines) //EVT_MENU(MENU_DOC_OPEN, EditorFrame::OnMenuDocOpen) //EVT_MENU(MENU_DOC_SHARE, EditorFrame::OnMenuDocShare) @@ -716,6 +717,8 @@ void EditorFrame::InitMenus() { textMenu->AppendSeparator(); textMenu->Append(MENU_FILTER, _("&Filter Through Command...\tCtrl-H"), _("Filter Through Command...")); textMenu->Append(MENU_RUN, _("&Run current line/selection\tCtrl-Alt-R"), _("Run current line/selection")); + textMenu->AppendSeparator(); + textMenu->Append(MENU_INDENT_LINES, _("&Indent Lines"), _("Indent Lines")); menuBar->Append(textMenu, _("&Text")); // Navigation menu @@ -4345,3 +4348,9 @@ void EditorFrame::OnMenuCustomizeAccelerators(wxCommandEvent& WXUNUSED(event)) { EditorCtrl* ctrl = GetEditorCtrl(); ctrl->DrawLayout(); } + +void EditorFrame::OnMenuIndentLines(wxCommandEvent& WXUNUSED(event)) { + EditorCtrl* ctrl = GetEditorCtrl(); + if(!ctrl) return; + ctrl->IndentLines(); +} \ No newline at end of file diff --git a/src/EditorFrame.h b/src/EditorFrame.h index 566d1a29..9c4da7ed 100644 --- a/src/EditorFrame.h +++ b/src/EditorFrame.h @@ -196,7 +196,8 @@ class EditorFrame : public KeyHookable, MENU_MACRO_PLAY, MENU_MACRO_EDIT, MENU_MACRO_CONTINUE, - MENU_ACCELERATORS + MENU_ACCELERATORS, + MENU_INDENT_LINES }; EditorFrame(CatalystWrapper cat, unsigned int frameId, const wxString& title, const wxRect& rect, TmSyntaxHandler& syntax_handler); @@ -535,6 +536,7 @@ class EditorFrame : public KeyHookable, //void OnMenuDocOpen(wxCommandEvent& event); //void OnMenuDocShare(wxCommandEvent& event); void OnMouseWheel(wxMouseEvent& event); + void OnMenuIndentLines(wxCommandEvent& event); DECLARE_EVENT_TABLE(); // Static Notification handlers diff --git a/src/FindInProjectDlg.cpp b/src/FindInProjectDlg.cpp index 727f65da..a9962e52 100644 --- a/src/FindInProjectDlg.cpp +++ b/src/FindInProjectDlg.cpp @@ -194,8 +194,13 @@ void FindInProjectDlg::OnIdle(wxIdleEvent& event) { wxString errorMsg; m_searchThread->GetCurrentPath(errorMsg); m_pathStatic->SetLabel(errorMsg); + } else { + if (!m_pathStatic->GetLabel().empty()) m_pathStatic->SetLabel(wxT("")); + + if (m_searchThread->UpdateOutput(m_output)) { + m_browser->LoadString(m_output); + } } - else if (!m_pathStatic->GetLabel().empty()) m_pathStatic->SetLabel(wxT("")); m_searchButton->SetLabel(_("Search")); m_inSearch = false; diff --git a/src/IFrameSearchService.h b/src/IFrameSearchService.h index 4fa036c7..f5bad055 100644 --- a/src/IFrameSearchService.h +++ b/src/IFrameSearchService.h @@ -7,6 +7,7 @@ class IFrameSearchService { public: virtual IEditorSearch* GetSearch() = 0; virtual void ShowSearch(bool show=true, bool replace=false) = 0; + virtual bool HandleChord(wxKeyEvent& event) = 0; }; diff --git a/src/SearchPanel.cpp b/src/SearchPanel.cpp index 6d9e9535..035389a4 100644 --- a/src/SearchPanel.cpp +++ b/src/SearchPanel.cpp @@ -437,6 +437,8 @@ void SearchEvtHandler::OnKeyDown(wxKeyEvent &event) { const int direction = wxGetKeyState(WXK_SHIFT) ? 0 : wxNavigationKeyEvent::IsForward; ((wxWindow*)event.GetEventObject())->Navigate(direction); return; + } else if(parent->GetSearchService().HandleChord(event)) { + return; } event.Skip(true); diff --git a/src/SearchPanel.h b/src/SearchPanel.h index 039e0a1b..ba446860 100644 --- a/src/SearchPanel.h +++ b/src/SearchPanel.h @@ -56,6 +56,8 @@ class SearchPanel : public wxPanel { void RefreshReplaceHistory(); void UpdateReplaceHistory(); + IFrameSearchService& GetSearchService() { return m_searchService; } + private: void InitAcceleratorTable(); int GetOptionFlags();