~ubuntu-branches/ubuntu/maverick/codelite/maverick

« back to all changes in this revision

Viewing changes to LiteEditor/findresultstab.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-04-30 02:46:27 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090430024627-7xp71gerfvw00xtt
Tags: 1.0.2822+dfsg-0ubuntu1
* New upstream release (LP: #369466)
* debian/copyright:
  + Added Files section for sdk/wxpropgrid
  + Made license text RFC compliant (add . for empty lines)
* debian/control:
  + Bump Standards-Version to 3.8.1
* debian/patches/02_fix-desktop.patch,
  + Refreshed to patch cleanly
* debian/*.install,
  debian/codelite.dirs,
  debian/codelite.links,
  debian/patches/03_fix-sh.patch,
  debian/patches/04_change-installpath.patch,
  + Updated for new upstream directory structure
  + Patches dropped, no longer needed.
* debian/patches/03_cstdio-include.patch,
  + Include cstdio for C++ and stdio.h for C, since it seems to be missing
* debian/codelite.menu,
  debian/*.1,
  debian/codelite.manpages:
  + Updated to reflect change in command names
    - CodeLite    => codelite
    - le_exec     => codelite_exec
    - le_dos2unix => codelite_fix_files
    - le_killproc => codelite_kill_children
* debian/README.source,
  debian/rules,
  debian/copyright:
  + Remove sdk/curl from the list of excluded files, since it doesn't exist
    any more

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
//////////////////////////////////////////////////////////////////////////////
24
24
//////////////////////////////////////////////////////////////////////////////
25
25
#include <wx/xrc/xmlres.h>
 
26
#include "custom_tabcontainer.h"
 
27
#include "custom_tab.h"
26
28
#include <wx/tokenzr.h>
27
29
#include "globals.h"
28
30
#include "manager.h"
44
46
 
45
47
FindInFilesDialog* FindResultsTab::m_find = NULL;
46
48
 
47
 
FindResultsTab::FindResultsTab(wxWindow *parent, wxWindowID id, const wxString &name, size_t numpages)
48
 
    : OutputTabWindow(parent, id, name)
49
 
    , m_book(NULL)
50
 
    , m_recv(NULL)
 
49
FindResultsTab::FindResultsTab(wxWindow *parent, wxWindowID id, const wxString &name, bool useBook)
 
50
                : OutputTabWindow(parent, id, name)
 
51
                , m_book(NULL)
 
52
                , m_recv(NULL)
 
53
                , m_matchInfo(1)
51
54
{
52
 
        m_matchInfo.resize(numpages);
53
 
        if (numpages > 1) {
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);
57
 
                        SetStyles(sci);
58
 
                        m_book->AddPage(sci, wxString::Format(wxT("Find Results %u"), i), wxEmptyString);
59
 
                }
60
 
                m_book->SetSelection(size_t(0));
 
55
        if (useBook) {
 
56
 
 
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);
 
60
 
 
61
                m_book = new Notebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, bookStyle);
 
62
                m_book->SetFixedTabWidth(120);
 
63
 
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);
62
66
 
63
67
                // get rid of base class scintilla component
64
68
                wxSizer *sz = GetSizer();
65
69
                sz->Detach(m_sci);
66
70
                m_sci->Destroy();
67
 
 
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());
 
71
                m_sci = NULL;
71
72
 
72
73
                sz->Add(m_book, 1, wxALL|wxEXPAND);
73
74
                sz->Layout();
87
88
        }
88
89
}
89
90
 
 
91
MatchInfo& FindResultsTab::GetMatchInfo(size_t idx)
 
92
{
 
93
        // assert(idx < m_matchInfo.size());
 
94
        ListMatchInfos::iterator itMatchInfo = m_matchInfo.begin();
 
95
        if (m_book) {
 
96
                for (size_t i = 0; i < idx; ++i) {
 
97
                        ++itMatchInfo;
 
98
                }
 
99
        }
 
100
        return *itMatchInfo;
 
101
}
 
102
 
90
103
void FindResultsTab::LoadFindInFilesData()
91
104
{
92
105
        if (m_find != NULL)
94
107
 
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);
98
111
}
99
112
 
100
113
void FindResultsTab::SaveFindInFilesData()
106
119
 
107
120
void FindResultsTab::SetStyles(wxScintilla *sci)
108
121
{
109
 
    InitStyle(sci, wxSCI_LEX_FIF, true);
 
122
        InitStyle(sci, wxSCI_LEX_FIF, true);
110
123
 
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));
162
175
 
163
176
void FindResultsTab::Clear()
164
177
{
165
 
        m_matchInfo[m_book ? m_book->GetSelection() : 0].clear();
 
178
        MatchInfo& matchInfo = GetMatchInfo(m_book ? m_book->GetSelection() : 0);
 
179
        matchInfo.clear();
166
180
        OutputTabWindow::Clear();
167
181
}
168
182
 
173
187
        m_tb->ToggleTool(XRCID("word_wrap_output"), m_sci->GetWrapMode() == wxSCI_WRAP_WORD);
174
188
}
175
189
 
 
190
void FindResultsTab::OnPageClosed(NotebookEvent& e)
 
191
{
 
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) {
 
195
                ++itMatchInfo;
 
196
        }
 
197
        m_matchInfo.erase(itMatchInfo);
 
198
 
 
199
        // Create a page if there is no more
 
200
        if (m_book->GetPageCount() == 0) {
 
201
                m_sci = NULL;
 
202
        }
 
203
}
 
204
 
176
205
void FindResultsTab::OnFindInFiles(wxCommandEvent &e)
177
206
{
178
207
        LoadFindInFilesData();
191
220
 
192
221
void FindResultsTab::OnSearchStart(wxCommandEvent& e)
193
222
{
194
 
        if (m_book) {
195
 
                m_book->SetSelection(e.GetInt());
 
223
        SearchData *data = (SearchData*) e.GetClientData();
 
224
        wxString label = data ? data->GetFindString() : wxT("");
 
225
 
 
226
        if (e.GetInt() != 0 || m_sci == NULL) {
 
227
                if(m_book){
 
228
                        wxScintilla *sci = new wxScintilla(m_book);
 
229
                        SetStyles(sci);
 
230
 
 
231
                        // add new page
 
232
                        m_book->AddPage(sci, label, label, wxNullBitmap, true);
 
233
                        size_t where = m_book->GetPageCount() - 1;
 
234
 
 
235
                        // keep the search data used for this tab
 
236
                        CustomTab *tab = m_book->GetTabContainer()->IndexToTab(where);
 
237
                        if (tab) {
 
238
                                tab->SetUserData(data);
 
239
                        }
 
240
 
 
241
                        m_matchInfo.push_back(MatchInfo());
 
242
                        m_sci = sci;
 
243
                }
 
244
        } else if(m_book){
 
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();
 
252
                        if (oldData) {
 
253
                                delete oldData;
 
254
                        }
 
255
                        // set the new search data
 
256
                        tab->SetUserData(data);
 
257
                }
196
258
        }
 
259
 
197
260
        m_recv = m_sci;
198
261
        Clear();
199
262
 
200
 
        SearchData *data = (SearchData*) e.GetClientData();
201
 
        m_data = data ? *data : SearchData();
202
 
        delete data;
203
 
 
204
 
        wxString message;
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"))
209
 
        << wxT(" ======\n");
210
 
        AppendText(message);
 
263
        if (data) {
 
264
                wxString message;
 
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"))
 
269
                << wxT(" ======\n");
 
270
                AppendText( message );
 
271
        }
211
272
}
212
273
 
213
274
void FindResultsTab::OnSearchMatch(wxCommandEvent& e)
215
276
        SearchResultList *res = (SearchResultList*) e.GetClientData();
216
277
        if (!res)
217
278
                return;
218
 
        int m = m_book ? m_book->GetPageIndex(m_recv) : 0;
 
279
 
 
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"));
222
285
                }
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();
229
292
                text.Trim();
230
293
                wxString linenum = wxString::Format(wxT(" %4u: "), iter->GetLineNumber());
231
 
                if (m_data.GetDisplayScope()) {
 
294
 
 
295
                SearchData d = GetSearchData(m_recv);
 
296
                if (d.GetDisplayScope()) {
232
297
                        TagEntryPtr tag = TagsManagerST::Get()->FunctionFromFileLine(iter->GetFileName(), iter->GetLineNumber());
233
298
                        if (tag) {
234
299
                                linenum << wxT("[") << tag->GetPath() << wxT("] ");
267
332
void FindResultsTab::OnClearAll(wxCommandEvent &e)
268
333
{
269
334
        wxUnusedVar(e);
270
 
    if (m_recv != NULL) {
271
 
        SearchThreadST::Get()->StopSearch();
272
 
    }
273
 
    Clear();
 
335
        if (m_recv != NULL) {
 
336
                SearchThreadST::Get()->StopSearch();
 
337
        }
 
338
        Clear();
274
339
}
275
340
 
276
341
void FindResultsTab::OnClearAllUI(wxUpdateUIEvent& e)
277
342
{
278
 
    e.Enable(m_recv != NULL || m_sci->GetLength() > 0);
 
343
        e.Enable(m_recv != NULL || (m_sci && m_sci->GetLength() > 0));
279
344
}
280
345
 
281
346
void FindResultsTab::OnRepeatOutput(wxCommandEvent &e)
282
347
{
283
348
        wxUnusedVar(e);
284
 
        SearchThreadST::Get()->PerformSearch(m_data);
 
349
 
 
350
        if (m_book) {
 
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);
 
355
                        if (tab) {
 
356
                                SearchData *searchData = (SearchData *)tab->GetUserData();
 
357
                                searchData->UseNewTab(false);
 
358
                                SearchThreadST::Get()->PerformSearch(*searchData);
 
359
                        }
 
360
                }
 
361
        }
285
362
}
286
363
 
287
364
void FindResultsTab::OnRepeatOutputUI(wxUpdateUIEvent& e)
288
365
{
289
 
    e.Enable(m_recv == NULL && m_sci->GetLength() > 0);
 
366
        e.Enable(m_recv == NULL && m_sci && m_sci->GetLength() > 0);
290
367
}
291
368
 
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);
300
377
        } else {
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);
314
392
}
315
393
 
 
394
long FindResultsTab::GetBookStyle()
 
395
{
 
396
        return m_book->GetBookStyle();
 
397
}
 
398
 
 
399
SearchData FindResultsTab::GetSearchData(wxScintilla* sci)
 
400
{
 
401
        if (m_book) {
 
402
                size_t i = m_book->GetPageIndex(sci);
 
403
                if (i != Notebook::npos) {
 
404
                        CustomTab *tab = m_book->GetTabContainer()->IndexToTab(i);
 
405
                        if (tab) {
 
406
                                SearchData *data = (SearchData *) tab->GetUserData();
 
407
                                if (data) {
 
408
                                        return *data;
 
409
                                }
 
410
                        }
 
411
                }
 
412
        }
 
413
        return SearchData();
 
414
}