~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

Viewing changes to src/plugins/contrib/ThreadSearch/ThreadSearchLoggerTree.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
 
11
11
#include <sdk.h> // Code::Blocks SDK
12
12
#ifndef CB_PRECOMP
13
 
        // Required extra includes
 
13
    // Required extra includes
14
14
#endif
15
15
 
 
16
#include "ThreadSearch.h"
16
17
#include "ThreadSearchLoggerTree.h"
17
18
#include "ThreadSearchEvent.h"
18
 
#include "ThreadSearchView.h"
 
19
#include "ThreadSearchView.h"
 
20
#include "ThreadSearchControlIds.h"
19
21
 
20
22
ThreadSearchLoggerTree::ThreadSearchLoggerTree(ThreadSearchView& threadSearchView,
21
 
                                                                                           ThreadSearch& threadSearchPlugin,
22
 
                                                                                           InsertIndexManager::eFileSorting fileSorting,
23
 
                                                                                           wxPanel* pParent,
24
 
                                                                                           long id)
25
 
                                           : ThreadSearchLoggerBase(threadSearchView, threadSearchPlugin, fileSorting)
26
 
                                           , m_pTreeLog(NULL)
27
 
                                           , m_FirstItemProcessed(false)
 
23
                                               ThreadSearch& threadSearchPlugin,
 
24
                                               InsertIndexManager::eFileSorting fileSorting,
 
25
                                               wxPanel* pParent,
 
26
                                               long id)
 
27
                       : ThreadSearchLoggerBase(threadSearchView, threadSearchPlugin, fileSorting)
 
28
                       , m_pTreeLog(NULL)
 
29
                       , m_FirstItemProcessed(false)
28
30
{
29
31
    m_pTreeLog = new wxTreeCtrl(pParent, id, wxDefaultPosition, wxSize(1,1), wxTR_HAS_BUTTONS|wxTR_LINES_AT_ROOT|wxTR_FULL_ROW_HIGHLIGHT|wxTR_HIDE_ROOT|wxTR_DEFAULT_STYLE|wxSUNKEN_BORDER);
30
32
    m_pTreeLog->SetMinSize(wxSize(100, 100));
31
 
    m_pTreeLog->AddRoot(wxEmptyString);
 
33
    m_FilesParentId = m_pTreeLog->AddRoot(wxEmptyString);
32
34
 
33
 
        // Events are managed dynamically to be able to stop/start management when required.
34
 
        ConnectEvents(pParent);
 
35
    // Events are managed dynamically to be able to stop/start management when required.
 
36
    ConnectEvents(pParent);
35
37
}
36
38
 
37
39
 
38
40
ThreadSearchLoggerTree::~ThreadSearchLoggerTree()
39
41
{
40
 
        wxWindow* pParent = m_pTreeLog->GetParent();
41
 
        if ( pParent != NULL )
42
 
        {
43
 
                // Events are managed dynamically to be able to stop/start management when required.
44
 
                DisconnectEvents(pParent);
45
 
        }
46
 
        m_pTreeLog->Destroy();
47
 
        m_pTreeLog = NULL;
 
42
    wxWindow* pParent = m_pTreeLog->GetParent();
 
43
    if ( pParent != NULL )
 
44
    {
 
45
        // Events are managed dynamically to be able to stop/start management when required.
 
46
        DisconnectEvents(pParent);
 
47
    }
 
48
    m_pTreeLog->Destroy();
 
49
    m_pTreeLog = NULL;
48
50
}
49
51
 
50
52
 
51
53
wxWindow* ThreadSearchLoggerTree::GetWindow()
52
54
{
53
 
        return m_pTreeLog;
 
55
    return m_pTreeLog;
54
56
}
55
57
 
56
58
 
57
59
void ThreadSearchLoggerTree::SetFocus()
58
60
{
59
 
        m_pTreeLog->SetFocus();
 
61
    m_pTreeLog->SetFocus();
60
62
}
61
63
 
62
64
 
63
65
void ThreadSearchLoggerTree::ConnectEvents(wxEvtHandler* pEvtHandler)
64
66
{
65
 
        // Dynamic event connections.
66
 
        int id = m_pTreeLog->GetId();
67
 
        pEvtHandler->Connect(id, wxEVT_COMMAND_TREE_SEL_CHANGED,
68
 
                        (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)
69
 
                        &ThreadSearchLoggerTree::OnLoggerTreeClick, NULL, this);
70
 
 
71
 
        pEvtHandler->Connect(id, wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
72
 
                        (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)
73
 
                        &ThreadSearchLoggerTree::OnLoggerTreeDoubleClick, NULL, this);
 
67
    // Dynamic event connections.
 
68
    int id = m_pTreeLog->GetId();
 
69
    pEvtHandler->Connect(id, wxEVT_COMMAND_TREE_SEL_CHANGED,
 
70
            (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)
 
71
            &ThreadSearchLoggerTree::OnLoggerTreeClick, NULL, this);
 
72
 
 
73
    pEvtHandler->Connect(id, wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
 
74
            (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)
 
75
            &ThreadSearchLoggerTree::OnLoggerTreeDoubleClick, NULL, this);
 
76
 
 
77
#if wxUSE_MENUS
 
78
    pEvtHandler->Connect(id, wxEVT_COMMAND_TREE_ITEM_MENU,
 
79
            (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)
 
80
            &ThreadSearchLoggerTree::OnLoggerTreeContextualMenu, NULL, this);
 
81
 
 
82
    pEvtHandler->Connect(idMenuCtxDeleteItem, wxEVT_COMMAND_MENU_SELECTED,
 
83
            wxCommandEventHandler(ThreadSearchLoggerTree::OnDeleteTreeItem), NULL, this);
 
84
 
 
85
    pEvtHandler->Connect(idMenuCtxDeleteAllItems, wxEVT_COMMAND_MENU_SELECTED,
 
86
            wxCommandEventHandler(ThreadSearchLoggerTree::OnDeleteAllTreeItems), NULL, this);
 
87
#endif // wxUSE_MENUS
74
88
}
75
89
 
76
90
 
77
91
void ThreadSearchLoggerTree::DisconnectEvents(wxEvtHandler* pEvtHandler)
78
92
{
79
 
        // Dynamic event disconnections.
80
 
        int id = m_pTreeLog->GetId();
81
 
        pEvtHandler->Disconnect(id, wxEVT_COMMAND_TREE_SEL_CHANGED,
82
 
                        (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)
83
 
                        &ThreadSearchLoggerTree::OnLoggerTreeClick, NULL, this);
84
 
 
85
 
        pEvtHandler->Disconnect(id, wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
86
 
                        (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)
87
 
                        &ThreadSearchLoggerTree::OnLoggerTreeDoubleClick, NULL, this);
 
93
    // Dynamic event disconnections.
 
94
    int id = m_pTreeLog->GetId();
 
95
    pEvtHandler->Disconnect(id, wxEVT_COMMAND_TREE_SEL_CHANGED,
 
96
            (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)
 
97
            &ThreadSearchLoggerTree::OnLoggerTreeClick, NULL, this);
 
98
 
 
99
    pEvtHandler->Disconnect(id, wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
 
100
            (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)
 
101
            &ThreadSearchLoggerTree::OnLoggerTreeDoubleClick, NULL, this);
 
102
 
 
103
#if wxUSE_MENUS
 
104
    pEvtHandler->Disconnect(id, wxEVT_COMMAND_TREE_ITEM_MENU,
 
105
            (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)
 
106
            &ThreadSearchLoggerTree::OnLoggerTreeContextualMenu, NULL, this);
 
107
 
 
108
    pEvtHandler->Disconnect(idMenuCtxDeleteItem, wxEVT_COMMAND_MENU_SELECTED,
 
109
            wxCommandEventHandler(ThreadSearchLoggerTree::OnDeleteTreeItem), NULL, this);
 
110
 
 
111
    pEvtHandler->Disconnect(idMenuCtxDeleteAllItems, wxEVT_COMMAND_MENU_SELECTED,
 
112
            wxCommandEventHandler(ThreadSearchLoggerTree::OnDeleteAllTreeItems), NULL, this);
 
113
#endif // wxUSE_MENUS
88
114
}
89
115
 
90
116
 
91
117
void ThreadSearchLoggerTree::OnLoggerTreeClick(wxTreeEvent& event)
92
118
{
93
 
        // Manages list log left double click
94
 
    // Gets file path and line from list control
95
 
    wxString filepath(wxEmptyString);
96
 
    long line;
97
 
    if ( GetFileLineFromTreeEvent(event, filepath, line) == false )
 
119
    // Manages list log left single click
 
120
    wxTreeItemId itemId = event.GetItem();
 
121
    if ( itemId.IsOk() && hasResultLineForTreeItem(itemId) )
98
122
    {
99
 
                cbMessageBox(wxT("Failed to retrieve file path and line number"), wxT("Error"), wxICON_ERROR);
100
 
        return;
 
123
        // Gets file path and line from list control
 
124
        wxString filepath(wxEmptyString);
 
125
        long line;
 
126
        if ( GetFileLineFromTreeEvent(event, filepath, line) == false )
 
127
        {
 
128
            cbMessageBox(_("Failed to retrieve file path and line number"), _("Error"), wxICON_ERROR);
 
129
            return;
 
130
        }
 
131
        m_ThreadSearchView.OnLoggerClick(filepath, line);
101
132
    }
102
 
    m_ThreadSearchView.OnLoggerClick(filepath, line);
103
133
    event.Skip();
104
134
}
105
135
 
106
136
 
107
137
void ThreadSearchLoggerTree::OnLoggerTreeDoubleClick(wxTreeEvent& event)
108
138
{
109
 
        // Manages list log left double click
110
 
    // Gets file path and line from list control
111
 
    wxString filepath(wxEmptyString);
112
 
    long line;
113
 
    if ( GetFileLineFromTreeEvent(event, filepath, line) == false )
 
139
    // Manages list log left double click
 
140
    wxTreeItemId itemId = event.GetItem();
 
141
    if ( itemId.IsOk() && hasResultLineForTreeItem(itemId) )
114
142
    {
115
 
                cbMessageBox(wxT("Failed to retrieve file path and line number"), wxT("Error"), wxICON_ERROR);
116
 
        return;
 
143
        // Gets file path and line from list control
 
144
        wxString filepath(wxEmptyString);
 
145
        long line;
 
146
        if ( GetFileLineFromTreeEvent(event, filepath, line) == false )
 
147
        {
 
148
            cbMessageBox(_("Failed to retrieve file path and line number"), _("Error"), wxICON_ERROR);
 
149
            return;
 
150
        }
 
151
        m_ThreadSearchView.OnLoggerDoubleClick(filepath, line);
117
152
    }
118
 
    m_ThreadSearchView.OnLoggerDoubleClick(filepath, line);
119
153
 
120
154
    event.Skip();
121
155
}
122
156
 
123
157
 
 
158
void ThreadSearchLoggerTree::OnLoggerTreeContextualMenu(wxTreeEvent& event)
 
159
{
 
160
    wxPoint clientPoint = event.GetPoint();
 
161
    m_ToDeleteItemId = event.GetItem();
 
162
    ShowMenu(clientPoint);
 
163
    // No event skipping, otherwise, Message notebook contextual menu pops up
 
164
}
 
165
 
 
166
 
 
167
bool ThreadSearchLoggerTree::hasResultLineForTreeItem(wxTreeItemId treeItemId)
 
168
{
 
169
    return (m_pTreeLog->GetItemText(treeItemId).StartsWith(_("=>")) == false) || (m_pTreeLog->ItemHasChildren(treeItemId));
 
170
}
 
171
 
 
172
 
124
173
bool ThreadSearchLoggerTree::GetFileLineFromTreeEvent(wxTreeEvent& event, wxString& filepath, long &line)
125
174
{
126
 
        wxTreeItemId lineItemId;
127
 
        wxTreeItemId fileItemId;
128
 
        wxTreeItemId rootItemId = m_pTreeLog->GetRootItem();
129
 
        wxTreeItemId eventItemId = event.GetItem();
130
 
        bool success(false);
131
 
 
132
 
        filepath = wxEmptyString;
133
 
        line = 0;
134
 
 
135
 
        do
136
 
        {
137
 
                // We test if we are on a file item or a line item.
138
 
                // As root is hidden, we have only file and line items on tree.
139
 
                if ( m_pTreeLog->GetItemParent(eventItemId) == rootItemId )
140
 
                {
141
 
                        fileItemId = eventItemId;
142
 
                        wxTreeItemIdValue cookie;
143
 
                        lineItemId = m_pTreeLog->GetFirstChild(eventItemId, cookie);
144
 
                        if ( lineItemId.IsOk() == false )
145
 
                                break;
146
 
                }
147
 
                else
148
 
                {
149
 
                        lineItemId = eventItemId;
150
 
                        fileItemId = m_pTreeLog->GetItemParent(lineItemId);
151
 
                }
152
 
 
153
 
                // We extract line and file path values
154
 
                // Look at ThreadSearchLoggerTree::OnThreadSearchEvent to have format
155
 
 
156
 
                // Line:
157
 
                const wxString& lineText = m_pTreeLog->GetItemText(lineItemId);
158
 
                int columnPos = lineText.Find(':');
159
 
                if ( columnPos == wxNOT_FOUND )
160
 
                        break;
161
 
 
162
 
                if ( lineText.Left(columnPos).ToLong(&line) == false )
163
 
                        break;
164
 
 
165
 
                // File:
166
 
                const wxString& fileText = m_pTreeLog->GetItemText(fileItemId);
167
 
                int fileLength = fileText.Find(wxT(" ("));
168
 
                if ( fileLength == wxNOT_FOUND )
169
 
                        break;
170
 
 
171
 
                int dirBegin   = fileLength + 2; // 2 for " ("
172
 
                int dirLength  = fileText.Length() - dirBegin - 1;
173
 
                if ( dirLength <= 0 )
174
 
                        break;
175
 
 
176
 
                wxFileName filename(fileText.Mid(dirBegin, dirLength), fileText.Left(fileLength));
177
 
                filepath = filename.GetFullPath();
178
 
 
179
 
                success = true;
180
 
        } while ( false );
181
 
 
182
 
        return success;
 
175
    wxTreeItemId lineItemId;
 
176
    wxTreeItemId fileItemId;
 
177
    wxTreeItemId tmpItemId;
 
178
    wxTreeItemId eventItemId = event.GetItem();
 
179
    bool success(false);
 
180
 
 
181
    filepath = wxEmptyString;
 
182
    line = 0;
 
183
 
 
184
    do
 
185
    {
 
186
        // Looks for deepest child, which is the first interesting item (line item)
 
187
        wxTreeItemIdValue cookie;
 
188
        tmpItemId = eventItemId;
 
189
        do {
 
190
            lineItemId = tmpItemId;
 
191
            tmpItemId = m_pTreeLog->GetFirstChild(lineItemId, cookie);
 
192
        } while ( tmpItemId.IsOk() == true );
 
193
        fileItemId = m_pTreeLog->GetItemParent(lineItemId);
 
194
 
 
195
        // We extract line and file path values
 
196
        // Look at ThreadSearchLoggerTree::OnThreadSearchEvent to have format
 
197
 
 
198
        // Line:
 
199
        const wxString& lineText = m_pTreeLog->GetItemText(lineItemId);
 
200
        int columnPos = lineText.Find(':');
 
201
        if ( columnPos == wxNOT_FOUND )
 
202
            break;
 
203
 
 
204
        if ( lineText.Left(columnPos).ToLong(&line) == false )
 
205
            break;
 
206
 
 
207
        // File:
 
208
        const wxString& fileText = m_pTreeLog->GetItemText(fileItemId);
 
209
        int fileLength = fileText.Find(wxT(" ("));
 
210
        if ( fileLength == wxNOT_FOUND )
 
211
            break;
 
212
 
 
213
        int dirBegin   = fileLength + 2; // 2 for " ("
 
214
        int dirLength  = fileText.Length() - dirBegin - 1;
 
215
        if ( dirLength <= 0 )
 
216
            break;
 
217
 
 
218
        wxFileName filename(fileText.Mid(dirBegin, dirLength), fileText.Left(fileLength));
 
219
        filepath = filename.GetFullPath();
 
220
 
 
221
        success = true;
 
222
    } while ( false );
 
223
 
 
224
    return success;
183
225
}
184
226
 
185
227
 
186
228
void ThreadSearchLoggerTree::OnThreadSearchEvent(const ThreadSearchEvent& event)
187
229
{
188
 
        // A search event has been sent by the worker thread.
189
 
        // Tree log upddate
190
 
        const wxArrayString& words  = event.GetLineTextArray();
191
 
        const wxFileName&    filename(event.GetString());
192
 
        bool                 setFocus(false);
193
 
        wxTreeItemId         rootItemId(m_pTreeLog->GetRootItem());
194
 
        wxTreeItemId         fileItemId;
195
 
        long                 index    = m_IndexManager.GetInsertionIndex(filename.GetFullPath());
196
 
        long                 nb_items = m_pTreeLog->GetChildrenCount(rootItemId, false);
197
 
 
198
 
        wxASSERT(index != wxNOT_FOUND);
199
 
        wxASSERT((words.GetCount() % 2) == 0);
200
 
 
201
 
        // Use of Freeze Thaw to enhance speed and limit blink effect
202
 
        m_pTreeLog->Freeze();
203
 
        wxTreeItemId lineItemId;
204
 
 
205
 
        if ( index == nb_items )
206
 
        {
207
 
                fileItemId = m_pTreeLog->AppendItem(rootItemId,
208
 
                                                                                                         wxString::Format(wxT("%s (%s)"),
209
 
                                                                                                                                          filename.GetFullName().c_str(),
210
 
                                                                                                                                          filename.GetPath().c_str()));
211
 
        }
212
 
        else
213
 
        {
214
 
                fileItemId = m_pTreeLog->InsertItem(rootItemId, index,
215
 
                                                                                        wxString::Format(wxT("%s (%s)"),
216
 
                                                                                                                         filename.GetFullName().c_str(),
217
 
                                                                                                                         filename.GetPath().c_str()));
218
 
        }
219
 
 
220
 
        for (size_t i = 0; i < words.GetCount(); i += 2)
221
 
        {
222
 
                lineItemId = m_pTreeLog->AppendItem(fileItemId, wxString::Format(wxT("%s: %s"),
223
 
                                                                                                                                                 words[i].c_str(),     // Line index starting from 1
224
 
                                                                                                                                                 words[i+1].c_str())); // File line matching search expression
225
 
 
226
 
                // We update preview log for first list item
227
 
                if ( (m_FirstItemProcessed == false)                        &&
228
 
                         (m_pTreeLog->GetChildrenCount(fileItemId, false) == 1) &&
229
 
                         (m_pTreeLog->GetChildrenCount(rootItemId, false) == 1) )
230
 
                {
231
 
                        // Expand first file item
232
 
                        m_pTreeLog->Expand(fileItemId);
233
 
 
234
 
                        // Select first item (generates selection event to update ThreadSearchView code preview)
235
 
                        m_pTreeLog->SelectItem(lineItemId);
236
 
 
237
 
                        // to avoid lots of preview that freezes app
238
 
                        m_FirstItemProcessed = true;
239
 
 
240
 
                        // It is useful to give focus to tree to navigate in results
241
 
                        // just after running a search
242
 
                        setFocus = true;
243
 
                }
244
 
        }
245
 
        m_pTreeLog->Thaw();
246
 
 
247
 
        if ( setFocus == true )
248
 
        {
249
 
                // On Linux, executing SetFocus just after SelectItem
250
 
                // does not work. Probbly because of Thaw...
251
 
                m_pTreeLog->SetFocus();
252
 
        }
 
230
    // A search event has been sent by the worker thread.
 
231
    // Tree log upddate
 
232
    const wxArrayString& words  = event.GetLineTextArray();
 
233
    const wxFileName&    filename(event.GetString());
 
234
    bool                 setFocus(false);
 
235
    wxTreeItemId         fileItemId;
 
236
    long                 index    = m_IndexManager.GetInsertionIndex(filename.GetFullPath());
 
237
    long                 nb_items = m_pTreeLog->GetChildrenCount(m_FilesParentId, false);
 
238
 
 
239
    wxASSERT(index != wxNOT_FOUND);
 
240
    wxASSERT((words.GetCount() % 2) == 0);
 
241
 
 
242
    // Use of Freeze Thaw to enhance speed and limit blink effect
 
243
    m_pTreeLog->Freeze();
 
244
    wxTreeItemId lineItemId;
 
245
 
 
246
    if ( index == nb_items )
 
247
    {
 
248
        fileItemId = m_pTreeLog->AppendItem(m_FilesParentId,
 
249
                                            wxString::Format(wxT("%s (%s)"),
 
250
                                                            filename.GetFullName().c_str(),
 
251
                                                            filename.GetPath().c_str()));
 
252
    }
 
253
    else
 
254
    {
 
255
        fileItemId = m_pTreeLog->InsertItem(m_FilesParentId, index,
 
256
                                            wxString::Format(wxT("%s (%s)"),
 
257
                                                             filename.GetFullName().c_str(),
 
258
                                                             filename.GetPath().c_str()));
 
259
    }
 
260
 
 
261
    for (size_t i = 0; i < words.GetCount(); i += 2)
 
262
    {
 
263
        lineItemId = m_pTreeLog->AppendItem(fileItemId, wxString::Format(wxT("%s: %s"),
 
264
                                                                         words[i].c_str(),     // Line index starting from 1
 
265
                                                                         words[i+1].c_str())); // File line matching search expression
 
266
 
 
267
        // We update preview log for first list item
 
268
        if ( (m_FirstItemProcessed == false)                        &&
 
269
             (m_pTreeLog->GetChildrenCount(fileItemId, false) == 1) &&
 
270
             (m_pTreeLog->GetChildrenCount(m_FilesParentId, false) == 1) )
 
271
        {
 
272
            // Expand first file item
 
273
            m_pTreeLog->Expand(fileItemId);
 
274
 
 
275
            // Select first item (generates selection event to update ThreadSearchView code preview)
 
276
            m_pTreeLog->SelectItem(lineItemId);
 
277
 
 
278
            // to avoid lots of preview that freezes app
 
279
            m_FirstItemProcessed = true;
 
280
 
 
281
            // It is useful to give focus to tree to navigate in results
 
282
            // just after running a search
 
283
            setFocus = true;
 
284
        }
 
285
    }
 
286
    m_pTreeLog->Thaw();
 
287
 
 
288
    if ( setFocus == true )
 
289
    {
 
290
        // On Linux, executing SetFocus just after SelectItem
 
291
        // does not work. Probbly because of Thaw...
 
292
        m_pTreeLog->SetFocus();
 
293
    }
253
294
}
254
295
 
255
296
 
256
297
void ThreadSearchLoggerTree::Clear()
257
298
{
258
 
        // As wxTreeCtrl::DeleteChildren sends lots of selected events
259
 
        // and because we don't want any wxTreeCtrl event to be processed
260
 
        // during delete, we disable events management during tree cleaning
261
 
        // (DisconnectEvents then ConnectEvents).
262
 
        wxWindow* pParent = m_pTreeLog->GetParent();
263
 
        if ( pParent == NULL ) return;
 
299
    // As wxTreeCtrl::DeleteChildren sends lots of selected events
 
300
    // and because we don't want any wxTreeCtrl event to be processed
 
301
    // during delete, we disable events management during tree cleaning
 
302
    // (DisconnectEvents then ConnectEvents).
 
303
    wxWindow* pParent = m_pTreeLog->GetParent();
 
304
    if ( pParent == NULL ) return;
264
305
 
265
 
        DisconnectEvents(pParent);
 
306
    DisconnectEvents(pParent);
266
307
 
267
308
    m_pTreeLog->DeleteChildren(m_pTreeLog->GetRootItem());
268
309
    m_FirstItemProcessed = false;
271
312
 
272
313
    ConnectEvents(pParent);
273
314
}
 
315
 
 
316
 
 
317
void ThreadSearchLoggerTree::OnSearchBegin(const ThreadSearchFindData& findData)
 
318
{
 
319
    if ( m_ThreadSearchPlugin.GetDeletePreviousResults() )
 
320
    {
 
321
        Clear();
 
322
        m_FilesParentId = m_pTreeLog->GetRootItem();
 
323
    }
 
324
    else
 
325
    {
 
326
        m_IndexManager.Reset();
 
327
        m_FirstItemProcessed = false;
 
328
        m_FilesParentId = m_pTreeLog->AppendItem(m_pTreeLog->GetRootItem(),
 
329
                wxString::Format(_("=> %s"), findData.GetFindText().c_str()));
 
330
    }
 
331
}
 
332
 
 
333
 
 
334
void ThreadSearchLoggerTree::OnDeleteTreeItem(wxCommandEvent& event)
 
335
{
 
336
    if ( m_ToDeleteItemId.IsOk() )
 
337
    {
 
338
        wxTreeItemId rootId = m_pTreeLog->GetRootItem();
 
339
        wxTreeItemId parentId = m_pTreeLog->GetItemParent(m_ToDeleteItemId);
 
340
        while ( (parentId != rootId) && (m_pTreeLog->GetChildrenCount(parentId, false) == 1) )
 
341
        {
 
342
            m_ToDeleteItemId = parentId;
 
343
            parentId = m_pTreeLog->GetItemParent(m_ToDeleteItemId);
 
344
        }
 
345
        DeleteTreeItem(m_ToDeleteItemId);
 
346
    }
 
347
    event.Skip();
 
348
}
 
349
 
 
350
 
 
351
void ThreadSearchLoggerTree::DeleteTreeItem(wxTreeItemId id)
 
352
{
 
353
    if ( id.IsOk() )
 
354
    {
 
355
        wxWindow* pParent = m_pTreeLog->GetParent();
 
356
        if ( pParent == NULL ) return;
 
357
 
 
358
        // Disconnect events to avoid lots of seleced events
 
359
        DisconnectEvents(pParent);
 
360
        m_pTreeLog->Delete(id);
 
361
        ConnectEvents(pParent);
 
362
 
 
363
        // Select current selected item to refresh code preview
 
364
        wxTreeItemId selectedItemId = m_pTreeLog->GetSelection();
 
365
        if ( selectedItemId.IsOk() )
 
366
        {
 
367
            m_pTreeLog->SelectItem(selectedItemId, true);
 
368
        }
 
369
    }
 
370
}
 
371
 
 
372
 
 
373
void ThreadSearchLoggerTree::OnDeleteAllTreeItems(wxCommandEvent& event)
 
374
{
 
375
    if ( m_ToDeleteItemId.IsOk() )
 
376
    {
 
377
        DeleteTreeItems();
 
378
    }
 
379
}
 
380
 
 
381
 
 
382
void ThreadSearchLoggerTree::DeleteTreeItems()
 
383
{
 
384
    Clear();
 
385
}