45
47
FindInFilesDialog* FindResultsTab::m_find = NULL;
47
FindResultsTab::FindResultsTab(wxWindow *parent, wxWindowID id, const wxString &name, size_t numpages)
48
: OutputTabWindow(parent, id, name)
49
FindResultsTab::FindResultsTab(wxWindow *parent, wxWindowID id, const wxString &name, bool useBook)
50
: OutputTabWindow(parent, id, name)
52
m_matchInfo.resize(numpages);
54
m_book = new Notebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVB_BOTTOM|wxVB_NODND|wxVB_BG_GRADIENT);
55
for (size_t i = 1; i <= numpages; i++) {
56
wxScintilla *sci = new wxScintilla(m_book);
58
m_book->AddPage(sci, wxString::Format(wxT("Find Results %u"), i), wxEmptyString);
60
m_book->SetSelection(size_t(0));
57
// load the book style from the settings file
58
long bookStyle = wxVB_BOTTOM|wxVB_NODND|wxVB_HAS_X|wxVB_MOUSE_MIDDLE_CLOSE_TAB|wxVB_FIXED_WIDTH;
59
EditorConfigST::Get()->GetLongValue(wxT("FindResults"), bookStyle);
61
m_book = new Notebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, bookStyle);
62
m_book->SetFixedTabWidth(120);
61
64
m_book->Connect(wxEVT_COMMAND_BOOK_PAGE_CHANGED, NotebookEventHandler(FindResultsTab::OnPageChanged), NULL, this);
65
m_book->Connect(wxEVT_COMMAND_BOOK_PAGE_CLOSED , NotebookEventHandler(FindResultsTab::OnPageClosed) , NULL, this);
63
67
// get rid of base class scintilla component
64
68
wxSizer *sz = GetSizer();
68
// use base class scintilla ptr as ref to currently selected Find Results tab
69
// so that base class functions (eg AppendText) go to the correct tab
70
m_sci = dynamic_cast<wxScintilla*>(m_book->GetCurrentPage());
72
73
sz->Add(m_book, 1, wxALL|wxEXPAND);
91
MatchInfo& FindResultsTab::GetMatchInfo(size_t idx)
93
// assert(idx < m_matchInfo.size());
94
ListMatchInfos::iterator itMatchInfo = m_matchInfo.begin();
96
for (size_t i = 0; i < idx; ++i) {
90
103
void FindResultsTab::LoadFindInFilesData()
92
105
if (m_find != NULL)
95
108
FindReplaceData data;
96
109
EditorConfigST::Get()->ReadObject(wxT("FindInFilesData"), &data);
97
m_find = new FindInFilesDialog(NULL, wxID_ANY, data, Frame::Get()->GetOutputPane()->GetFindResultsTab()->GetPageCount());
110
m_find = new FindInFilesDialog(NULL, wxID_ANY, data);
100
113
void FindResultsTab::SaveFindInFilesData()
107
120
void FindResultsTab::SetStyles(wxScintilla *sci)
109
InitStyle(sci, wxSCI_LEX_FIF, true);
122
InitStyle(sci, wxSCI_LEX_FIF, true);
111
124
sci->StyleSetForeground(wxSCI_LEX_FIF_DEFAULT, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
112
125
sci->StyleSetBackground(wxSCI_LEX_FIF_DEFAULT, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
173
187
m_tb->ToggleTool(XRCID("word_wrap_output"), m_sci->GetWrapMode() == wxSCI_WRAP_WORD);
190
void FindResultsTab::OnPageClosed(NotebookEvent& e)
192
// this function can't be called unless m_book != NULL
193
ListMatchInfos::iterator itMatchInfo = m_matchInfo.begin();
194
for (size_t i = 0; i < e.GetSelection(); ++i) {
197
m_matchInfo.erase(itMatchInfo);
199
// Create a page if there is no more
200
if (m_book->GetPageCount() == 0) {
176
205
void FindResultsTab::OnFindInFiles(wxCommandEvent &e)
178
207
LoadFindInFilesData();
192
221
void FindResultsTab::OnSearchStart(wxCommandEvent& e)
195
m_book->SetSelection(e.GetInt());
223
SearchData *data = (SearchData*) e.GetClientData();
224
wxString label = data ? data->GetFindString() : wxT("");
226
if (e.GetInt() != 0 || m_sci == NULL) {
228
wxScintilla *sci = new wxScintilla(m_book);
232
m_book->AddPage(sci, label, label, wxNullBitmap, true);
233
size_t where = m_book->GetPageCount() - 1;
235
// keep the search data used for this tab
236
CustomTab *tab = m_book->GetTabContainer()->IndexToTab(where);
238
tab->SetUserData(data);
241
m_matchInfo.push_back(MatchInfo());
245
// using current tab, update the tab title and the search data
246
size_t where = m_book->GetPageIndex(m_sci);
247
if (where != Notebook::npos) {
248
m_book->SetPageText(where, label, label);
249
// delete the old search data
250
CustomTab *tab = m_book->GetTabContainer()->IndexToTab(where);
251
SearchData *oldData = (SearchData *)tab->GetUserData();
255
// set the new search data
256
tab->SetUserData(data);
200
SearchData *data = (SearchData*) e.GetClientData();
201
m_data = data ? *data : SearchData();
205
message << wxT("====== Searching for: '") << m_data.GetFindString()
206
<< wxT("'; Match case: ") << (m_data.IsMatchCase() ? wxT("true") : wxT("false"))
207
<< wxT(" ; Match whole word: ") << (m_data.IsMatchWholeWord() ? wxT("true") : wxT("false"))
208
<< wxT(" ; Regular expression: ") << (m_data.IsRegularExpression() ? wxT("true") : wxT("false"))
265
message << wxT("====== Searching for: '") << data->GetFindString()
266
<< wxT("'; Match case: ") << (data->IsMatchCase() ? wxT("true") : wxT("false"))
267
<< wxT(" ; Match whole word: ") << (data->IsMatchWholeWord() ? wxT("true") : wxT("false"))
268
<< wxT(" ; Regular expression: ") << (data->IsRegularExpression() ? wxT("true") : wxT("false"))
270
AppendText( message );
213
274
void FindResultsTab::OnSearchMatch(wxCommandEvent& e)
215
276
SearchResultList *res = (SearchResultList*) e.GetClientData();
218
int m = m_book ? m_book->GetPageIndex(m_recv) : 0;
280
size_t m = m_book ? m_book->GetPageIndex(m_recv) : 0;
281
MatchInfo& matchInfo = GetMatchInfo(m);
219
282
for (SearchResultList::iterator iter = res->begin(); iter != res->end(); iter++) {
220
if (m_matchInfo[m].empty() || m_matchInfo[m].rbegin()->second.GetFileName() != iter->GetFileName()) {
283
if (matchInfo.empty() || matchInfo.rbegin()->second.GetFileName() != iter->GetFileName()) {
221
284
AppendText(iter->GetFileName() + wxT("\n"));
223
286
int lineno = m_recv->GetLineCount()-1;
224
m_matchInfo[m].insert(std::make_pair(lineno, *iter));
287
matchInfo.insert(std::make_pair(lineno, *iter));
225
288
wxString text = iter->GetPattern();
226
289
int delta = -text.Length();
227
290
text.Trim(false);
228
291
delta += text.Length();
230
293
wxString linenum = wxString::Format(wxT(" %4u: "), iter->GetLineNumber());
231
if (m_data.GetDisplayScope()) {
295
SearchData d = GetSearchData(m_recv);
296
if (d.GetDisplayScope()) {
232
297
TagEntryPtr tag = TagsManagerST::Get()->FunctionFromFileLine(iter->GetFileName(), iter->GetLineNumber());
234
299
linenum << wxT("[") << tag->GetPath() << wxT("] ");
267
332
void FindResultsTab::OnClearAll(wxCommandEvent &e)
270
if (m_recv != NULL) {
271
SearchThreadST::Get()->StopSearch();
335
if (m_recv != NULL) {
336
SearchThreadST::Get()->StopSearch();
276
341
void FindResultsTab::OnClearAllUI(wxUpdateUIEvent& e)
278
e.Enable(m_recv != NULL || m_sci->GetLength() > 0);
343
e.Enable(m_recv != NULL || (m_sci && m_sci->GetLength() > 0));
281
346
void FindResultsTab::OnRepeatOutput(wxCommandEvent &e)
284
SearchThreadST::Get()->PerformSearch(m_data);
351
size_t sel = m_book->GetSelection();
352
if (sel != Notebook::npos) {
353
// get the search data used to generate the output on the selected tab
354
CustomTab *tab = m_book->GetTabContainer()->IndexToTab(sel);
356
SearchData *searchData = (SearchData *)tab->GetUserData();
357
searchData->UseNewTab(false);
358
SearchThreadST::Get()->PerformSearch(*searchData);
287
364
void FindResultsTab::OnRepeatOutputUI(wxUpdateUIEvent& e)
289
e.Enable(m_recv == NULL && m_sci->GetLength() > 0);
366
e.Enable(m_recv == NULL && m_sci && m_sci->GetLength() > 0);
292
369
void FindResultsTab::OnMouseDClick(wxScintillaEvent &e)
298
375
if (style == wxSCI_LEX_FIF_FILE || style == wxSCI_LEX_FIF_PROJECT) {
299
376
m_sci->ToggleFold(line);
301
int n = m_book ? m_book->GetSelection() : 0;
302
std::map<int,SearchResult>::iterator m = m_matchInfo[n].find(line);
303
if (m != m_matchInfo[n].end() && !m->second.GetFileName().IsEmpty()) {
378
size_t n = m_book ? m_book->GetSelection() : 0;
379
const MatchInfo& matchInfo = GetMatchInfo(n);
380
MatchInfo::const_iterator m = matchInfo.find(line);
381
if (m != matchInfo.end() && !m->second.GetFileName().IsEmpty()) {
304
382
LEditor *editor = Frame::Get()->GetMainBook()->OpenFile(m->second.GetFileName(), wxEmptyString, m->second.GetLineNumber()-1);
305
383
if (editor && m->second.GetColumn() >= 0 && m->second.GetLen() >= 0) {
306
384
int offset = editor->PositionFromLine(m->second.GetLineNumber()-1) + m->second.GetColumn();
313
391
m_sci->SetSelection(wxNOT_FOUND, pos);
394
long FindResultsTab::GetBookStyle()
396
return m_book->GetBookStyle();
399
SearchData FindResultsTab::GetSearchData(wxScintilla* sci)
402
size_t i = m_book->GetPageIndex(sci);
403
if (i != Notebook::npos) {
404
CustomTab *tab = m_book->GetTabContainer()->IndexToTab(i);
406
SearchData *data = (SearchData *) tab->GetUserData();