1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
#include "clRemoteFinderHelper.hpp"
#include "Notebook.h"
#include "asyncprocess.h"
#include "cl_command_event.h"
#include "event_notifier.h"
#include "file_logger.h"
#include "globals.h"
#include "imanager.h"
#include "macros.h"
#include "processreaderthread.h"
#include "search_thread.h"
#include <wx/tokenzr.h>
clRemoteFinderHelper::clRemoteFinderHelper() {}
clRemoteFinderHelper::~clRemoteFinderHelper() {}
void clRemoteFinderHelper::ProcessSearchOutput(const clFindInFilesEvent& event, bool is_completed)
{
auto search_tab = GetSearchTab();
if(!search_tab) {
clWARNING() << "clRemoteFinderHelper: search tab is hidden" << endl;
return;
}
// process the output
SearchResultList* resList = nullptr;
const auto& matches = event.GetMatches();
if(!matches.empty()) {
resList = new SearchResultList;
for(const auto& file_match : matches) {
const wxString& filename = file_match.file;
for(const auto& location : file_match.locations) {
SearchResult res;
res.SetColumn(location.column_start);
res.SetLen(location.column_end - location.column_start);
res.SetFileName(filename);
res.SetLineNumber(location.line);
res.SetPattern(location.pattern);
resList->push_back(res);
}
}
}
m_matches_found += (resList ? resList->size() : 0);
if(resList && !resList->empty()) {
wxCommandEvent matchs_event(wxEVT_SEARCH_THREAD_MATCHFOUND);
matchs_event.SetClientData(resList);
search_tab->GetEventHandler()->AddPendingEvent(matchs_event);
} else if(resList) {
wxDELETE(resList);
}
if(is_completed) {
// stop the clock
long elapsed_time = m_stopWatch.Time();
SearchSummary* summary = new SearchSummary;
summary->SetElapsedTime(elapsed_time);
// set the total number of matches found
summary->SetNumMatchesFound(m_matches_found);
wxCommandEvent end_event(wxEVT_SEARCH_THREAD_SEARCHEND);
summary->SetNumFileScanned(event.GetInt());
end_event.SetClientData(summary);
search_tab->GetEventHandler()->AddPendingEvent(end_event);
// prepare for next search
m_matches_found = 0;
}
}
void clRemoteFinderHelper::Search(const wxString& root_dir, const wxString& findString, const wxString& fileExtensions,
bool whole_word, bool icase)
{
// start ssh process
if(!m_codeliteRemote || !m_codeliteRemote->IsRunning()) {
return;
}
m_stopWatch.Start();
m_matches_found = 0;
if(!GetSearchTab()) {
clWARNING() << "clRemoteFinderHelper: search ignored, search tab is hidden" << endl;
return;
}
m_codeliteRemote->Search(root_dir, fileExtensions, findString, whole_word, icase);
SearchData sd;
sd.SetEncoding("UTF-8");
sd.SetFindString(findString);
sd.SetExtensions(fileExtensions);
wxCommandEvent start_event(wxEVT_SEARCH_THREAD_SEARCHSTARTED);
start_event.SetClientData(new SearchData(sd));
GetSearchTab()->GetEventHandler()->AddPendingEvent(start_event);
}
wxWindow* clRemoteFinderHelper::GetSearchTab()
{
auto book = clGetManager()->GetOutputPaneNotebook();
for(size_t i = 0; i < book->GetPageCount(); ++i) {
if(book->GetPageText(i) == _("Search")) {
return book->GetPage(i);
}
}
return nullptr;
}
void clRemoteFinderHelper::SetCodeLiteRemote(clCodeLiteRemoteProcess* clr) { m_codeliteRemote = clr; }
void clRemoteFinderHelper::NotifySearchCancelled()
{
CHECK_PTR_RET(GetSearchTab());
// Notify that the search is cancelled
wxCommandEvent event_cacnelled{ wxEVT_SEARCH_THREAD_SEARCHCANCELED };
GetSearchTab()->GetEventHandler()->AddPendingEvent(event_cacnelled);
// the UI is also expecting the wxEVT_SEARCH_THREAD_SEARCHEND event
wxCommandEvent end_event{ wxEVT_SEARCH_THREAD_SEARCHEND };
end_event.SetClientData(nullptr);
GetSearchTab()->GetEventHandler()->AddPendingEvent(end_event);
}
|