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

« back to all changes in this revision

Viewing changes to src/plugins/contrib/ThreadSearch/ThreadSearch.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
 
        #include <wx/xrc/xmlres.h>
14
 
        #include "cbeditor.h"
15
 
        #include "configmanager.h"
16
 
        #include "sdk_events.h"
 
13
    #include <wx/xrc/xmlres.h>
 
14
    #include "cbeditor.h"
 
15
    #include "configmanager.h"
 
16
    #include "sdk_events.h"
17
17
#endif
18
18
 
19
19
#include "cbstyledtextctrl.h"
27
27
// We are using an anonymous namespace so we don't litter the global one.
28
28
namespace
29
29
{
30
 
        PluginRegistrant<ThreadSearch> reg(_T("ThreadSearch"));
 
30
    PluginRegistrant<ThreadSearch> reg(_T("ThreadSearch"));
31
31
}
32
32
 
33
33
// ----------------------------------------------------------------------------
67
67
 
68
68
// events handling
69
69
BEGIN_EVENT_TABLE(ThreadSearch, cbPlugin)
70
 
        // add any events you want to handle here
71
 
        EVT_UPDATE_UI (idMenuViewThreadSearch,   ThreadSearch::OnMnuViewThreadSearchUpdateUI)
72
 
        EVT_MENU      (idMenuViewThreadSearch,   ThreadSearch::OnMnuViewThreadSearch)
73
 
        EVT_UPDATE_UI (idMenuSearchThreadSearch, ThreadSearch::OnMnuSearchThreadSearchUpdateUI)
74
 
        EVT_MENU      (idMenuSearchThreadSearch, ThreadSearch::OnMnuSearchThreadSearch)
75
 
        EVT_MENU      (idMenuCtxThreadSearch,    ThreadSearch::OnCtxThreadSearch)
 
70
    // add any events you want to handle here
 
71
    EVT_UPDATE_UI (idMenuViewThreadSearch,   ThreadSearch::OnMnuViewThreadSearchUpdateUI)
 
72
    EVT_MENU      (idMenuViewThreadSearch,   ThreadSearch::OnMnuViewThreadSearch)
 
73
    EVT_UPDATE_UI (idMenuSearchThreadSearch, ThreadSearch::OnMnuSearchThreadSearchUpdateUI)
 
74
    EVT_MENU      (idMenuSearchThreadSearch, ThreadSearch::OnMnuSearchThreadSearch)
 
75
    EVT_MENU      (idMenuCtxThreadSearch,    ThreadSearch::OnCtxThreadSearch)
76
76
    EVT_MENU      (idMenuEditCopy,           ThreadSearch::OnMnuEditCopy)
77
 
        EVT_UPDATE_UI (idMenuEditCopy,           ThreadSearch::OnMnuEditCopyUpdateUI)
 
77
    EVT_UPDATE_UI (idMenuEditCopy,           ThreadSearch::OnMnuEditCopyUpdateUI)
78
78
    EVT_MENU      (idMenuEditPaste,          ThreadSearch::OnMnuEditPaste)
79
 
        EVT_BUTTON    (idBtnOptions,             ThreadSearch::OnBtnOptionsClick)
80
 
        EVT_BUTTON    (idBtnSearch,              ThreadSearch::OnBtnSearchClick)
 
79
    EVT_TOOL      (idBtnOptions,             ThreadSearch::OnBtnOptionsClick)
 
80
    EVT_TOOL      (idBtnSearch,              ThreadSearch::OnBtnSearchClick)
81
81
    EVT_TEXT_ENTER(idCboSearchExpr,          ThreadSearch::OnCboSearchExprEnter)
82
82
    EVT_TEXT      (idCboSearchExpr,          ThreadSearch::OnCboSearchExprEnter)
83
83
// ---------------------------------------------------------------------------
114
114
 
115
115
// constructor
116
116
ThreadSearch::ThreadSearch()
117
 
                         :m_SearchedWord(wxEmptyString),
118
 
                          m_pThreadSearchView(NULL),
119
 
                          m_pViewManager(NULL),
120
 
                          m_pToolbar(NULL),
121
 
                          m_CtxMenuIntegration(true),
122
 
                          m_UseDefValsForThreadSearch(true),
123
 
                          m_ShowSearchControls(true),
124
 
                          m_ShowDirControls(false),
125
 
                          m_ShowCodePreview(true),
126
 
                          m_LoggerType(ThreadSearchLoggerBase::TypeList),
127
 
                          m_DisplayLogHeaders(true),
128
 
                          m_DrawLogLines(false),
129
 
                          m_pCboSearchExpr(0),
130
 
                          m_SplitterMode(wxSPLIT_VERTICAL),
131
 
                          m_FileSorting(InsertIndexManager::SortByFilePath)
 
117
             :m_SearchedWord(wxEmptyString),
 
118
              m_pThreadSearchView(NULL),
 
119
              m_pViewManager(NULL),
 
120
              m_pToolbar(NULL),
 
121
              m_CtxMenuIntegration(true),
 
122
              m_UseDefValsForThreadSearch(true),
 
123
              m_ShowSearchControls(true),
 
124
              m_ShowDirControls(false),
 
125
              m_ShowCodePreview(true),
 
126
              m_DeletePreviousResults(true),
 
127
              m_LoggerType(ThreadSearchLoggerBase::TypeList),
 
128
              m_DisplayLogHeaders(true),
 
129
              m_DrawLogLines(false),
 
130
              m_pCboSearchExpr(0),
 
131
              m_SplitterMode(wxSPLIT_VERTICAL),
 
132
              m_FileSorting(InsertIndexManager::SortByFilePath)
132
133
{
133
 
        // Make sure our resources are available.
134
 
        // In the generated boilerplate code we have no resources but when
135
 
        // we add some, it will be nice that this code is in place already ;)
136
 
        // ThreadSearch plugin has no resources in zip
137
 
        if(!Manager::LoadResource(_T("ThreadSearch.zip")))
138
 
        {
139
 
                NotifyMissingFile(_T("ThreadSearch.zip"));
140
 
        }
 
134
    // Make sure our resources are available.
 
135
    // In the generated boilerplate code we have no resources but when
 
136
    // we add some, it will be nice that this code is in place already ;)
 
137
    // ThreadSearch plugin has no resources in zip
 
138
    if(!Manager::LoadResource(_T("ThreadSearch.zip")))
 
139
    {
 
140
        NotifyMissingFile(_T("ThreadSearch.zip"));
 
141
    }
141
142
}
142
143
 
143
144
// destructor
147
148
 
148
149
void ThreadSearch::OnAttach()
149
150
{
150
 
        // NOTE: after this function, the inherited member variable
151
 
        // m_IsAttached will be TRUE...
152
 
        // You should check for it in other functions, because if it
153
 
        // is FALSE, it means that the application did *not* "load"
154
 
        // (see: does not need) this plugin...
 
151
    // NOTE: after this function, the inherited member variable
 
152
    // m_IsAttached will be TRUE...
 
153
    // You should check for it in other functions, because if it
 
154
    // is FALSE, it means that the application did *not* "load"
 
155
    // (see: does not need) this plugin...
155
156
 
156
157
    #if LOGGING
157
158
     wxLog::EnableLogging(true);
162
163
     LOGIT( _T("ThreadSearch Plugin Logging Started"));
163
164
    #endif
164
165
 
165
 
        bool showPanel;
166
 
        int  sashPosition;
167
 
        ThreadSearchViewManagerBase::eManagerTypes mgrType;
168
 
        wxArrayString searchPatterns;
169
 
 
170
 
        // Loads configuration from default.conf
171
 
        LoadConfig(showPanel, sashPosition, mgrType, searchPatterns);
172
 
 
173
 
        // Adds window to the manager
174
 
        m_pThreadSearchView = new ThreadSearchView(*this);
175
 
        m_pThreadSearchView->SetSearchHistory(searchPatterns);
176
 
 
177
 
        // Builds manager
178
 
        m_pViewManager = ThreadSearchViewManagerBase::BuildThreadSearchViewManagerBase(m_pThreadSearchView, true, mgrType);
179
 
 
180
 
        // Ensure view is shown or hidden
181
 
        m_pViewManager->ShowView(showPanel);
182
 
 
183
 
        // Sets splitter sash in the middle of the width of the window
184
 
        // and creates columns as it is not managed in ctor on Linux
185
 
        int x, y;
186
 
        m_pThreadSearchView->GetSize(&x, &y);
187
 
        m_pThreadSearchView->SetSashPosition(x/2);
188
 
        m_pThreadSearchView->Update();
 
166
    bool showPanel;
 
167
    int  sashPosition;
 
168
    ThreadSearchViewManagerBase::eManagerTypes mgrType;
 
169
    wxArrayString searchPatterns;
 
170
 
 
171
    // Loads configuration from default.conf
 
172
    LoadConfig(showPanel, sashPosition, mgrType, searchPatterns);
 
173
 
 
174
    // Adds window to the manager
 
175
    m_pThreadSearchView = new ThreadSearchView(*this);
 
176
    m_pThreadSearchView->SetSearchHistory(searchPatterns);
 
177
 
 
178
    // Builds manager
 
179
    m_pViewManager = ThreadSearchViewManagerBase::BuildThreadSearchViewManagerBase(m_pThreadSearchView, true, mgrType);
 
180
 
 
181
    // Ensure view is shown or hidden
 
182
    m_pViewManager->ShowView(showPanel);
 
183
 
 
184
    // Sets splitter sash in the middle of the width of the window
 
185
    // and creates columns as it is not managed in ctor on Linux
 
186
    int x, y;
 
187
    m_pThreadSearchView->GetSize(&x, &y);
 
188
    m_pThreadSearchView->SetSashPosition(x/2);
 
189
    m_pThreadSearchView->Update();
189
190
 
190
191
    // Set the splitter posn from the config
191
192
    if (sashPosition != 0)
192
193
        m_pThreadSearchView->SetSashPosition(sashPosition);
193
194
 
194
 
        // Shows/Hides search widgets on the Messages notebook ThreadSearch panel
195
 
        m_pThreadSearchView->ShowSearchControls(m_ShowSearchControls);
 
195
    // Shows/Hides search widgets on the Messages notebook ThreadSearch panel
 
196
    m_pThreadSearchView->ShowSearchControls(m_ShowSearchControls);
196
197
 
197
 
        // true if it enters in OnRelease for the first time
198
 
        m_OnReleased = false;
 
198
    // true if it enters in OnRelease for the first time
 
199
    m_OnReleased = false;
199
200
}
200
201
 
201
202
void ThreadSearch::OnRelease(bool appShutDown)
202
203
{
203
 
        // do de-initialization for your plugin
204
 
        // if appShutDown is false, the plugin is unloaded because Code::Blocks is being shut down,
205
 
        // which means you must not use any of the SDK Managers
206
 
        // NOTE: after this function, the inherited member variable
207
 
        // m_IsAttached will be FALSE...
 
204
    // do de-initialization for your plugin
 
205
    // if appShutDown is false, the plugin is unloaded because Code::Blocks is being shut down,
 
206
    // which means you must not use any of the SDK Managers
 
207
    // NOTE: after this function, the inherited member variable
 
208
    // m_IsAttached will be FALSE...
208
209
 
209
 
        // --------------------------------------------------------------
210
 
        // Carefull! This routine can be entered consecutive times
211
 
        // --------------------------------------------------------------
212
 
        if ( m_OnReleased ) return;
 
210
    // --------------------------------------------------------------
 
211
    // Carefull! This routine can be entered consecutive times
 
212
    // --------------------------------------------------------------
 
213
    if ( m_OnReleased ) return;
213
214
    m_OnReleased = true;
214
215
 
215
 
        // Removes Thread search menu item from the View menu
216
 
        RemoveMenuItems();
217
 
 
218
 
        m_pToolbar = NULL;
219
 
 
220
 
        if ( m_pThreadSearchView != NULL )
221
 
        {
222
 
                m_pViewManager->RemoveViewFromManager();
223
 
                m_pThreadSearchView->Destroy();
224
 
        }
225
 
 
226
 
        delete m_pViewManager;
227
 
        m_pViewManager = NULL;
 
216
    // Removes Thread search menu item from the View menu
 
217
    RemoveMenuItems();
 
218
 
 
219
    m_pToolbar = 0;
 
220
 
 
221
    if ( m_pThreadSearchView != 0 )
 
222
    {
 
223
        m_pViewManager->RemoveViewFromManager();
 
224
        m_pThreadSearchView->Destroy();
 
225
    }
 
226
 
 
227
    delete m_pViewManager;
 
228
    m_pViewManager = 0;
228
229
}
229
230
 
230
231
 
231
232
void ThreadSearch::OnThreadSearchViewDestruction()
232
233
{
233
 
        // Method is called from view destructor.
234
 
        // Destruction is either made by plugin or
235
 
        // Messages Notebook.
236
 
 
237
 
        // We show code preview to save a consistent
238
 
        // value of splitter sash position.
239
 
        m_pThreadSearchView->ApplySplitterSettings(m_ShowCodePreview, m_SplitterMode);
240
 
 
241
 
        // Saves configuration to default.conf
242
 
        SaveConfig(m_pViewManager->IsViewShown(),
243
 
                           m_pThreadSearchView->GetSashPosition(),
244
 
                           m_pViewManager->GetManagerType(),
245
 
                           m_pThreadSearchView->GetSearchHistory());
246
 
 
247
 
        // Reset of the pointer as view is being deleted
248
 
        m_pThreadSearchView = NULL;
 
234
    // Method is called from view destructor.
 
235
    // Destruction is either made by plugin or
 
236
    // Messages Notebook.
 
237
 
 
238
    // We show code preview to save a consistent
 
239
    // value of splitter sash position.
 
240
    m_pThreadSearchView->ApplySplitterSettings(m_ShowCodePreview, m_SplitterMode);
 
241
 
 
242
    // Saves configuration to default.conf
 
243
    SaveConfig(m_pViewManager->IsViewShown(),
 
244
               m_pThreadSearchView->GetSashPosition(),
 
245
               m_pViewManager->GetManagerType(),
 
246
               m_pThreadSearchView->GetSearchHistory());
 
247
 
 
248
    // Reset of the pointer as view is being deleted
 
249
    m_pThreadSearchView = NULL;
249
250
}
250
251
 
251
252
 
252
253
int ThreadSearch::Configure()
253
254
{
254
 
        if ( !IsAttached() )
255
 
                return -1;
 
255
    if ( !IsAttached() )
 
256
        return -1;
256
257
 
257
 
        // Creates and displays the configuration dialog for the plugin
258
 
        cbConfigurationDialog dlg(Manager::Get()->GetAppWindow(), wxID_ANY, wxT("Thread search"));
259
 
        cbConfigurationPanel* panel = GetConfigurationPanel(&dlg);
260
 
        if (panel)
261
 
        {
262
 
                dlg.AttachConfigurationPanel(panel);
263
 
                PlaceWindow(&dlg);
264
 
                return dlg.ShowModal() == wxID_OK ? 0 : -1;
265
 
        }
266
 
        return -1;
 
258
    // Creates and displays the configuration dialog for the plugin
 
259
    cbConfigurationDialog dlg(Manager::Get()->GetAppWindow(), wxID_ANY, wxT("Thread search"));
 
260
    cbConfigurationPanel* panel = GetConfigurationPanel(&dlg);
 
261
    if (panel)
 
262
    {
 
263
        dlg.AttachConfigurationPanel(panel);
 
264
        PlaceWindow(&dlg);
 
265
        return dlg.ShowModal() == wxID_OK ? 0 : -1;
 
266
    }
 
267
    return -1;
267
268
}
268
269
 
269
270
void ThreadSearch::BuildMenu(wxMenuBar* menuBar)
270
271
{
271
 
        //The application is offering its menubar for your plugin,
272
 
        //to add any menu items you want...
273
 
        //Append any items you need in the menu...
274
 
        //NOTE: Be careful in here... The application's menubar is at your disposal.
275
 
        size_t i;
276
 
        int idx = menuBar->FindMenu(wxT("View"));
277
 
        if (idx != wxNOT_FOUND)
278
 
        {
279
 
                wxMenu* menu = menuBar->GetMenu(idx);
280
 
                wxMenuItemList& items = menu->GetMenuItems();
281
 
 
282
 
                // find the first separator and insert before it
283
 
                for (i = 0; i < items.GetCount(); ++i)
284
 
                {
285
 
                        if (items[i]->IsSeparator())
286
 
                        {
287
 
                                menu->InsertCheckItem(i, idMenuViewThreadSearch, wxT("Thread search"),
288
 
                                                                          wxT("Toggle displaying the 'Thread search' panel"));
289
 
                                break;
290
 
                        }
291
 
                }
292
 
 
293
 
                if ( i == items.GetCount() )
294
 
                {
295
 
                        // not found, just append
296
 
                        menu->AppendCheckItem(idMenuViewThreadSearch, wxT("Thread search"),
297
 
                                                                  wxT("Toggle displaying the 'Thread search' panel"));
298
 
                }
299
 
        }
300
 
 
301
 
        idx = menuBar->FindMenu(wxT("Search"));
302
 
        if (idx != wxNOT_FOUND)
303
 
        {
304
 
                wxMenu* menu = menuBar->GetMenu(idx);
305
 
                wxMenuItemList& items = menu->GetMenuItems();
306
 
 
307
 
                // find the first separator and insert separator + entry before it
308
 
                for (i = 0; i < items.GetCount(); ++i)
309
 
                {
310
 
                        if (items[i]->IsSeparator())
311
 
                        {
312
 
                                menu->Insert(i, idMenuSearchThreadSearch, wxT("Thread search"),
313
 
                                                                wxT("Perform a Threaded search with the current word"));
314
 
                                menu->InsertSeparator(i);
315
 
                                break;
316
 
                        }
317
 
                }
318
 
 
319
 
                if ( i == items.GetCount() )
320
 
                {
321
 
                        // not found, just append
322
 
                        menu->Append(idMenuSearchThreadSearch, wxT("Thread search"),
323
 
                                                        wxT("Perform a Threaded search with the current word"));
324
 
                        menu->AppendSeparator();
325
 
                }
326
 
        }
 
272
    //The application is offering its menubar for your plugin,
 
273
    //to add any menu items you want...
 
274
    //Append any items you need in the menu...
 
275
    //NOTE: Be careful in here... The application's menubar is at your disposal.
 
276
    size_t i;
 
277
    int idx = menuBar->FindMenu(_("&View"));
 
278
    if (idx != wxNOT_FOUND)
 
279
    {
 
280
        wxMenu* menu = menuBar->GetMenu(idx);
 
281
        wxMenuItemList& items = menu->GetMenuItems();
 
282
 
 
283
        // find the first separator and insert before it
 
284
        for (i = 0; i < items.GetCount(); ++i)
 
285
        {
 
286
            if (items[i]->IsSeparator())
 
287
            {
 
288
                menu->InsertCheckItem(i, idMenuViewThreadSearch, _("Thread search"),
 
289
                                      _("Toggle displaying the 'Thread search' panel"));
 
290
                break;
 
291
            }
 
292
        }
 
293
 
 
294
        if ( i == items.GetCount() )
 
295
        {
 
296
            // not found, just append
 
297
            menu->AppendCheckItem(idMenuViewThreadSearch, _("Thread search"),
 
298
                                  _("Toggle displaying the 'Thread search' panel"));
 
299
        }
 
300
    }
 
301
 
 
302
    idx = menuBar->FindMenu(_("Sea&rch"));
 
303
    if (idx != wxNOT_FOUND)
 
304
    {
 
305
        wxMenu* menu = menuBar->GetMenu(idx);
 
306
        wxMenuItemList& items = menu->GetMenuItems();
 
307
 
 
308
        // find the first separator and insert separator + entry before it
 
309
        for (i = 0; i < items.GetCount(); ++i)
 
310
        {
 
311
            if (items[i]->IsSeparator())
 
312
            {
 
313
                menu->Insert(i, idMenuSearchThreadSearch, _("Thread search"),
 
314
                                _("Perform a Threaded search with the current word"));
 
315
                menu->InsertSeparator(i);
 
316
                break;
 
317
            }
 
318
        }
 
319
 
 
320
        if ( i == items.GetCount() )
 
321
        {
 
322
            // not found, just append
 
323
            menu->Append(idMenuSearchThreadSearch, _("Thread search"),
 
324
                            _("Perform a Threaded search with the current word"));
 
325
            menu->AppendSeparator();
 
326
        }
 
327
    }
327
328
}
328
329
 
329
330
void ThreadSearch::RemoveMenuItems()
330
331
{
331
 
        // Removes 'Thread search' item from View and Search menu
332
 
        wxMenuBar* menuBar = Manager::Get()->GetAppFrame()->GetMenuBar();
333
 
        int idx = menuBar->FindMenu(wxT("View"));
334
 
        if (idx != wxNOT_FOUND)
335
 
        {
336
 
                wxMenu* viewMenu = menuBar->GetMenu(idx);
337
 
                if ( viewMenu != NULL )
338
 
                {
339
 
                        viewMenu->Remove(idMenuViewThreadSearch);
340
 
                }
341
 
        }
 
332
    // Removes 'Thread search' item from View and Search menu
 
333
    wxMenuBar* menuBar = Manager::Get()->GetAppFrame()->GetMenuBar();
 
334
    int idx = menuBar->FindMenu(_("&View"));
 
335
    if (idx != wxNOT_FOUND)
 
336
    {
 
337
        wxMenu* viewMenu = menuBar->GetMenu(idx);
 
338
        if ( viewMenu != 0 )
 
339
        {
 
340
            viewMenu->Remove(idMenuViewThreadSearch);
 
341
        }
 
342
    }
342
343
 
343
 
        idx = menuBar->FindMenu(wxT("Search"));
344
 
        if (idx != wxNOT_FOUND)
345
 
        {
346
 
                wxMenu* searchMenu = menuBar->GetMenu(idx);
347
 
                if ( searchMenu != NULL )
348
 
                {
349
 
                        searchMenu->Remove(idMenuSearchThreadSearch);
350
 
                }
351
 
        }
 
344
    idx = menuBar->FindMenu(_("Sea&rch"));
 
345
    if (idx != wxNOT_FOUND)
 
346
    {
 
347
        wxMenu* searchMenu = menuBar->GetMenu(idx);
 
348
        if ( searchMenu != 0 )
 
349
        {
 
350
            searchMenu->Remove(idMenuSearchThreadSearch);
 
351
        }
 
352
    }
352
353
}
353
354
 
354
355
 
355
356
void ThreadSearch::OnMnuViewThreadSearch(wxCommandEvent& event)
356
357
{
357
 
        if ( !IsAttached() )
358
 
                return;
 
358
    if ( !IsAttached() )
 
359
        return;
359
360
 
360
 
        m_pViewManager->ShowView(event.IsChecked());
 
361
    m_pViewManager->ShowView(event.IsChecked());
361
362
}
362
363
 
363
364
 
364
365
void ThreadSearch::OnMnuSearchThreadSearch(wxCommandEvent& event)
365
366
{
366
 
        if ( !IsAttached() )
367
 
                return;
 
367
    if ( !IsAttached() )
 
368
        return;
368
369
 
369
 
        // Need to get the cursor word first and ensure it is consistent.
370
 
        if ( (GetCursorWord(m_SearchedWord) == true) && (m_SearchedWord.IsEmpty() == false) )
371
 
        {
372
 
                // m_SearchedWord is Ok => Search
373
 
                RunThreadSearch(m_SearchedWord, true);
374
 
        }
375
 
        else
376
 
        {
377
 
                // Word is KO, just show the panel
378
 
                m_pViewManager->ShowView(true);
379
 
        }
 
370
    // Need to get the cursor word first and ensure it is consistent.
 
371
    if ( (GetCursorWord(m_SearchedWord) == true) && (m_SearchedWord.IsEmpty() == false) )
 
372
    {
 
373
        // m_SearchedWord is Ok => Search
 
374
        RunThreadSearch(m_SearchedWord, true);
 
375
    }
 
376
    else
 
377
    {
 
378
        // Word is KO, just show the panel
 
379
        m_pViewManager->ShowView(true);
 
380
    }
380
381
}
381
382
 
382
383
 
383
384
void ThreadSearch::OnCtxThreadSearch(wxCommandEvent& event)
384
385
{
385
 
        if ( !IsAttached() )
386
 
                return;
 
386
    if ( !IsAttached() )
 
387
        return;
387
388
 
388
 
        // m_SearchedWord was set in BuildModuleMenu
389
 
        RunThreadSearch(m_SearchedWord, true);
 
389
    // m_SearchedWord was set in BuildModuleMenu
 
390
    RunThreadSearch(m_SearchedWord, true);
390
391
}
391
392
 
392
393
 
393
394
void ThreadSearch::OnMnuViewThreadSearchUpdateUI(wxUpdateUIEvent& event)
394
395
{
395
 
        if ( !IsAttached() )
396
 
                return;
 
396
    if ( !IsAttached() )
 
397
        return;
397
398
 
398
 
        Manager::Get()->GetAppFrame()->GetMenuBar()->Check(idMenuViewThreadSearch, m_pViewManager->IsViewShown());
 
399
    Manager::Get()->GetAppFrame()->GetMenuBar()->Check(idMenuViewThreadSearch, m_pViewManager->IsViewShown());
399
400
}
400
401
 
401
402
 
402
403
void ThreadSearch::OnMnuSearchThreadSearchUpdateUI(wxUpdateUIEvent& event)
403
404
{
404
 
        if ( !IsAttached() )
405
 
                return;
 
405
    if ( !IsAttached() )
 
406
        return;
406
407
 
407
 
        event.Enable(m_pThreadSearchView->IsSearchRunning() == false);
 
408
    event.Enable(m_pThreadSearchView->IsSearchRunning() == false);
408
409
}
409
410
 
410
411
 
411
412
void ThreadSearch::BuildModuleMenu(const ModuleType type, wxMenu* pMenu, const FileTreeData* data)
412
413
{
413
 
        wxMenuItem* pMenuItem = NULL;
414
 
        if (!pMenu || !IsAttached())
415
 
                return;
416
 
 
417
 
        // Triggs editor events if 'Find occurrences' is integrated in context menu
418
 
        if ( (type == mtEditorManager) && (m_CtxMenuIntegration == true) )
419
 
        {
420
 
                // Gets current word
421
 
                if ( GetCursorWord(m_SearchedWord) == true )
422
 
                {
423
 
                        wxString sText = wxT("Find occurrences of: '") + m_SearchedWord + wxT("'");
424
 
 
425
 
                        // Tries to find the 'Find implementation' item to adds the
426
 
                        // 'Find occurrences' item just after or appends it at the end
427
 
                        int dIndex = GetInsertionMenuIndex(pMenu);
428
 
                        if ( dIndex >= 0 )
429
 
                        {
430
 
                                pMenuItem = pMenu->Insert(dIndex, idMenuCtxThreadSearch, sText);
431
 
                        }
432
 
                        else
433
 
                        {
434
 
                                pMenu->AppendSeparator();
435
 
                                pMenuItem = pMenu->Append(idMenuCtxThreadSearch, sText);
436
 
                        }
437
 
 
438
 
                        // Disables item if a threaded search is running
439
 
                        pMenuItem->Enable(!m_pThreadSearchView->IsSearchRunning());
440
 
                }
441
 
        }
 
414
    wxMenuItem* pMenuItem = NULL;
 
415
    if (!pMenu || !IsAttached())
 
416
        return;
 
417
 
 
418
    // Triggs editor events if 'Find occurrences' is integrated in context menu
 
419
    if ( (type == mtEditorManager) && (m_CtxMenuIntegration == true) )
 
420
    {
 
421
        // Gets current word
 
422
        if ( GetCursorWord(m_SearchedWord) == true )
 
423
        {
 
424
            wxString sText = _("Find occurrences of: '") + m_SearchedWord + wxT("'");
 
425
 
 
426
            // Tries to find the 'Find implementation' item to adds the
 
427
            // 'Find occurrences' item just after or appends it at the end
 
428
            int dIndex = GetInsertionMenuIndex(pMenu);
 
429
            if ( dIndex >= 0 )
 
430
            {
 
431
                pMenuItem = pMenu->Insert(dIndex, idMenuCtxThreadSearch, sText);
 
432
            }
 
433
            else
 
434
            {
 
435
                pMenu->AppendSeparator();
 
436
                pMenuItem = pMenu->Append(idMenuCtxThreadSearch, sText);
 
437
            }
 
438
 
 
439
            // Disables item if a threaded search is running
 
440
            pMenuItem->Enable(!m_pThreadSearchView->IsSearchRunning());
 
441
        }
 
442
    }
442
443
}
443
444
 
444
445
 
445
446
int ThreadSearch::GetInsertionMenuIndex(const wxMenu* const pCtxMenu)
446
447
{
447
 
        if ( !IsAttached() )
448
 
                return -1;
 
448
    if ( !IsAttached() )
 
449
        return -1;
449
450
 
450
 
        // Looks after the "Find implementation of:" menu item
451
 
        const wxMenuItemList ItemsList = pCtxMenu->GetMenuItems();
452
 
        for (int i = 0; i < (int)ItemsList.GetCount(); ++i)
453
 
        {
454
 
                if (ItemsList[i]->GetLabel().StartsWith(_T("Find implementation of:")) )
455
 
                {
456
 
                        return ++i;
457
 
                }
458
 
        }
459
 
        return -1;
 
451
    // Looks after the "Find implementation of:" menu item
 
452
    const wxMenuItemList ItemsList = pCtxMenu->GetMenuItems();
 
453
    for (int i = 0; i < (int)ItemsList.GetCount(); ++i)
 
454
    {
 
455
        #if wxCHECK_VERSION(2, 9, 0)
 
456
        if (ItemsList[i]->GetItemLabelText().StartsWith(_("Find implementation of:")) )
 
457
        #else
 
458
        if (ItemsList[i]->GetLabel().StartsWith(_("Find implementation of:")) )
 
459
        #endif
 
460
        {
 
461
            return ++i;
 
462
        }
 
463
    }
 
464
    return -1;
460
465
}
461
466
 
462
467
 
463
468
cbConfigurationPanel* ThreadSearch::GetConfigurationPanel(wxWindow* parent)
464
469
{
465
 
        if ( !IsAttached() )
466
 
                return NULL;
 
470
    if ( !IsAttached() )
 
471
        return NULL;
467
472
 
468
 
        return new ThreadSearchConfPanel(*this, parent);
 
473
    return new ThreadSearchConfPanel(*this, parent);
469
474
}
470
475
 
471
476
 
472
477
void ThreadSearch::Notify()
473
478
{
474
 
        if ( !IsAttached() )
475
 
                return;
 
479
    if ( !IsAttached() )
 
480
        return;
476
481
 
477
 
        m_pThreadSearchView->Update();
478
 
        SaveConfig(m_pViewManager->IsViewShown(),
479
 
                           m_pThreadSearchView->GetSashPosition(),
480
 
                           m_pViewManager->GetManagerType(),
481
 
                           m_pThreadSearchView->GetSearchHistory());
 
482
    m_pThreadSearchView->Update();
 
483
    SaveConfig(m_pViewManager->IsViewShown(),
 
484
               m_pThreadSearchView->GetSashPosition(),
 
485
               m_pViewManager->GetManagerType(),
 
486
               m_pThreadSearchView->GetSearchHistory());
482
487
}
483
488
 
484
489
 
485
490
void ThreadSearch::LoadConfig(bool& showPanel, int& sashPosition,
486
 
                                                          ThreadSearchViewManagerBase::eManagerTypes& mgrType,
487
 
                                                          wxArrayString& searchPatterns)
 
491
                              ThreadSearchViewManagerBase::eManagerTypes& mgrType,
 
492
                              wxArrayString& searchPatterns)
488
493
{
489
 
        if ( !IsAttached() )
490
 
                return;
 
494
    if ( !IsAttached() )
 
495
        return;
491
496
 
492
497
    ConfigManager* pCfg = Manager::Get()->GetConfigManager(_T("ThreadSearch"));
493
498
 
494
 
    m_FindData.SetMatchWord       (pCfg->ReadBool(wxT("/MatchWord"),          true));
495
 
    m_FindData.SetStartWord       (pCfg->ReadBool(wxT("/StartWord"),          false));
496
 
    m_FindData.SetMatchCase       (pCfg->ReadBool(wxT("/MatchCase"),          true));
497
 
    m_FindData.SetRegEx           (pCfg->ReadBool(wxT("/RegEx"),              false));
498
 
    m_FindData.SetHiddenSearch    (pCfg->ReadBool(wxT("/HiddenSearch"),       true));
499
 
    m_FindData.SetRecursiveSearch (pCfg->ReadBool(wxT("/RecursiveSearch"),    true));
500
 
 
501
 
    m_CtxMenuIntegration         = pCfg->ReadBool(wxT("/CtxMenuIntegration"), true);
502
 
    m_UseDefValsForThreadSearch  = pCfg->ReadBool(wxT("/UseDefaultValues"),   true);
503
 
    m_ShowSearchControls         = pCfg->ReadBool(wxT("/ShowSearchControls"), true);
504
 
    m_ShowDirControls            = pCfg->ReadBool(wxT("/ShowDirControls"),    false);
505
 
    m_ShowCodePreview            = pCfg->ReadBool(wxT("/ShowCodePreview"),    true);
506
 
    m_DisplayLogHeaders          = pCfg->ReadBool(wxT("/DisplayLogHeaders"),  true);
507
 
    m_DrawLogLines               = pCfg->ReadBool(wxT("/DrawLogLines"),       false);
508
 
 
509
 
    showPanel                    = pCfg->ReadBool(wxT("/ShowPanel"),          true);
510
 
 
511
 
    m_FindData.SetScope           (pCfg->ReadInt (wxT("/Scope"),              ScopeProjectFiles));
512
 
 
513
 
    m_FindData.SetSearchPath      (pCfg->Read    (wxT("/DirPath"),            wxEmptyString));
514
 
    m_FindData.SetSearchMask      (pCfg->Read    (wxT("/Mask"),               wxT("*.cpp;*.c;*.h")));
515
 
 
516
 
    sashPosition                 = pCfg->ReadInt(wxT("/SplitterPosn"),        0);
517
 
    int splitterMode             = pCfg->ReadInt(wxT("/SplitterMode"),        wxSPLIT_VERTICAL);
 
499
    m_FindData.SetMatchWord       (pCfg->ReadBool(wxT("/MatchWord"),             true));
 
500
    m_FindData.SetStartWord       (pCfg->ReadBool(wxT("/StartWord"),             false));
 
501
    m_FindData.SetMatchCase       (pCfg->ReadBool(wxT("/MatchCase"),             true));
 
502
    m_FindData.SetRegEx           (pCfg->ReadBool(wxT("/RegEx"),                 false));
 
503
    m_FindData.SetHiddenSearch    (pCfg->ReadBool(wxT("/HiddenSearch"),          true));
 
504
    m_FindData.SetRecursiveSearch (pCfg->ReadBool(wxT("/RecursiveSearch"),       true));
 
505
 
 
506
    m_CtxMenuIntegration         = pCfg->ReadBool(wxT("/CtxMenuIntegration"),    true);
 
507
    m_UseDefValsForThreadSearch  = pCfg->ReadBool(wxT("/UseDefaultValues"),      true);
 
508
    m_ShowSearchControls         = pCfg->ReadBool(wxT("/ShowSearchControls"),    true);
 
509
    m_ShowDirControls            = pCfg->ReadBool(wxT("/ShowDirControls"),       false);
 
510
    m_ShowCodePreview            = pCfg->ReadBool(wxT("/ShowCodePreview"),       true);
 
511
    m_DeletePreviousResults      = pCfg->ReadBool(wxT("/DeletePreviousResults"), true);
 
512
    m_DisplayLogHeaders          = pCfg->ReadBool(wxT("/DisplayLogHeaders"),     true);
 
513
    m_DrawLogLines               = pCfg->ReadBool(wxT("/DrawLogLines"),          false);
 
514
 
 
515
    showPanel                    = pCfg->ReadBool(wxT("/ShowPanel"),             true);
 
516
 
 
517
    m_FindData.SetScope           (pCfg->ReadInt (wxT("/Scope"),                 ScopeProjectFiles));
 
518
 
 
519
    m_FindData.SetSearchPath      (pCfg->Read    (wxT("/DirPath"),               wxEmptyString));
 
520
    m_FindData.SetSearchMask      (pCfg->Read    (wxT("/Mask"),                  wxT("*.cpp;*.c;*.h")));
 
521
 
 
522
    sashPosition                 = pCfg->ReadInt(wxT("/SplitterPosn"),           0);
 
523
    int splitterMode             = pCfg->ReadInt(wxT("/SplitterMode"),           wxSPLIT_VERTICAL);
518
524
    m_SplitterMode               = wxSPLIT_VERTICAL;
519
525
    if ( splitterMode == wxSPLIT_HORIZONTAL )
520
526
    {
521
 
        m_SplitterMode = wxSPLIT_HORIZONTAL;
 
527
        m_SplitterMode = wxSPLIT_HORIZONTAL;
522
528
    }
523
529
 
524
 
        int managerType              = pCfg->ReadInt(wxT("/ViewManagerType"),     ThreadSearchViewManagerBase::TypeMessagesNotebook);
525
 
        mgrType                      = ThreadSearchViewManagerBase::TypeMessagesNotebook;
 
530
    int managerType              = pCfg->ReadInt(wxT("/ViewManagerType"),        ThreadSearchViewManagerBase::TypeMessagesNotebook);
 
531
    mgrType                      = ThreadSearchViewManagerBase::TypeMessagesNotebook;
526
532
    if ( managerType == ThreadSearchViewManagerBase::TypeLayout )
527
533
    {
528
 
        mgrType = ThreadSearchViewManagerBase::TypeLayout;
 
534
        mgrType = ThreadSearchViewManagerBase::TypeLayout;
529
535
    }
530
536
 
531
 
        int loggerType               = pCfg->ReadInt(wxT("/LoggerType"),          ThreadSearchLoggerBase::TypeList);
532
 
        m_LoggerType                 = ThreadSearchLoggerBase::TypeList;
 
537
    int loggerType               = pCfg->ReadInt(wxT("/LoggerType"),             ThreadSearchLoggerBase::TypeList);
 
538
    m_LoggerType                 = ThreadSearchLoggerBase::TypeList;
533
539
    if ( loggerType == ThreadSearchLoggerBase::TypeTree )
534
540
    {
535
 
        m_LoggerType = ThreadSearchLoggerBase::TypeTree;
 
541
        m_LoggerType = ThreadSearchLoggerBase::TypeTree;
536
542
    }
537
543
 
538
544
    searchPatterns = pCfg->ReadArrayString(wxT("/SearchPatterns"));
540
546
 
541
547
 
542
548
void ThreadSearch::SaveConfig(bool showPanel, int sashPosition,
543
 
                                                          ThreadSearchViewManagerBase::eManagerTypes mgrType,
544
 
                                                          const wxArrayString& searchPatterns)
 
549
                              ThreadSearchViewManagerBase::eManagerTypes mgrType,
 
550
                              const wxArrayString& searchPatterns)
545
551
{
546
552
    ConfigManager* pCfg = Manager::Get()->GetConfigManager(_T("ThreadSearch"));
547
553
 
548
 
    pCfg->Write(wxT("/MatchWord"),          m_FindData.GetMatchWord());
549
 
    pCfg->Write(wxT("/StartWord"),          m_FindData.GetStartWord());
550
 
    pCfg->Write(wxT("/MatchCase"),          m_FindData.GetMatchCase());
551
 
    pCfg->Write(wxT("/RegEx"),              m_FindData.GetRegEx());
552
 
    pCfg->Write(wxT("/HiddenSearch"),       m_FindData.GetHiddenSearch());
553
 
    pCfg->Write(wxT("/RecursiveSearch"),    m_FindData.GetRecursiveSearch());
554
 
 
555
 
    pCfg->Write(wxT("/CtxMenuIntegration"), m_CtxMenuIntegration);
556
 
    pCfg->Write(wxT("/UseDefaultValues"),   m_UseDefValsForThreadSearch);
557
 
    pCfg->Write(wxT("/ShowSearchControls"), m_ShowSearchControls);
558
 
    pCfg->Write(wxT("/ShowDirControls"),    m_ShowDirControls);
559
 
    pCfg->Write(wxT("/ShowCodePreview"),    m_ShowCodePreview);
560
 
    pCfg->Write(wxT("/DisplayLogHeaders"),  m_DisplayLogHeaders);
561
 
    pCfg->Write(wxT("/DrawLogLines"),       m_DrawLogLines);
562
 
 
563
 
    pCfg->Write(wxT("/ShowPanel"),          showPanel);
564
 
 
565
 
    pCfg->Write(wxT("/Scope"),              m_FindData.GetScope());
566
 
 
567
 
    pCfg->Write(wxT("/DirPath"),            m_FindData.GetSearchPath());
568
 
    pCfg->Write(wxT("/Mask"),               m_FindData.GetSearchMask());
569
 
 
570
 
    pCfg->Write(wxT("/SplitterPosn"),       sashPosition);
571
 
    pCfg->Write(wxT("/SplitterMode"),       (int)m_SplitterMode);
572
 
    pCfg->Write(wxT("/ViewManagerType"),    m_pViewManager->GetManagerType());
573
 
    pCfg->Write(wxT("/LoggerType"),         m_LoggerType);
574
 
    pCfg->Write(wxT("/FileSorting"),        m_FileSorting);
575
 
 
576
 
    pCfg->Write(wxT("/SearchPatterns"),     searchPatterns);
 
554
    pCfg->Write(wxT("/MatchWord"),             m_FindData.GetMatchWord());
 
555
    pCfg->Write(wxT("/StartWord"),             m_FindData.GetStartWord());
 
556
    pCfg->Write(wxT("/MatchCase"),             m_FindData.GetMatchCase());
 
557
    pCfg->Write(wxT("/RegEx"),                 m_FindData.GetRegEx());
 
558
    pCfg->Write(wxT("/HiddenSearch"),          m_FindData.GetHiddenSearch());
 
559
    pCfg->Write(wxT("/RecursiveSearch"),       m_FindData.GetRecursiveSearch());
 
560
 
 
561
    pCfg->Write(wxT("/CtxMenuIntegration"),    m_CtxMenuIntegration);
 
562
    pCfg->Write(wxT("/UseDefaultValues"),      m_UseDefValsForThreadSearch);
 
563
    pCfg->Write(wxT("/ShowSearchControls"),    m_ShowSearchControls);
 
564
    pCfg->Write(wxT("/ShowDirControls"),       m_ShowDirControls);
 
565
    pCfg->Write(wxT("/ShowCodePreview"),       m_ShowCodePreview);
 
566
    pCfg->Write(wxT("/DeletePreviousResults"), m_DeletePreviousResults);
 
567
    pCfg->Write(wxT("/DisplayLogHeaders"),     m_DisplayLogHeaders);
 
568
    pCfg->Write(wxT("/DrawLogLines"),          m_DrawLogLines);
 
569
 
 
570
    pCfg->Write(wxT("/ShowPanel"),             showPanel);
 
571
 
 
572
    pCfg->Write(wxT("/Scope"),                 m_FindData.GetScope());
 
573
 
 
574
    pCfg->Write(wxT("/DirPath"),               m_FindData.GetSearchPath());
 
575
    pCfg->Write(wxT("/Mask"),                  m_FindData.GetSearchMask());
 
576
 
 
577
    pCfg->Write(wxT("/SplitterPosn"),          sashPosition);
 
578
    pCfg->Write(wxT("/SplitterMode"),          (int)m_SplitterMode);
 
579
    pCfg->Write(wxT("/ViewManagerType"),       m_pViewManager->GetManagerType());
 
580
    pCfg->Write(wxT("/LoggerType"),            m_LoggerType);
 
581
    pCfg->Write(wxT("/FileSorting"),           m_FileSorting);
 
582
 
 
583
    pCfg->Write(wxT("/SearchPatterns"),        searchPatterns);
577
584
}
578
585
 
579
586
 
580
587
bool ThreadSearch::BuildToolBar(wxToolBar* toolBar)
581
588
{
582
 
        if ( !IsAttached() || !toolBar )
583
 
                return false;
584
 
 
585
 
        m_pToolbar = toolBar;
586
 
        m_pThreadSearchView->SetToolBar(toolBar);
587
 
 
588
 
        wxString prefix                = ConfigManager::GetDataFolder() + _T("/images/ThreadSearch/");
589
 
        m_pCboSearchExpr               = new wxComboBox    (toolBar, idCboSearchExpr, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN);
590
 
        wxBitmapButton* pBtnSearch     = new wxBitmapButton(toolBar, idBtnSearch, wxBitmap(prefix + wxT("findf.png"), wxBITMAP_TYPE_PNG));
591
 
        wxBitmapButton* pBtnOptions    = new wxBitmapButton(toolBar, idBtnOptions, wxBitmap(prefix + wxT("options.png"), wxBITMAP_TYPE_PNG));
592
 
 
593
 
        m_pCboSearchExpr->SetToolTip(wxT("Text to search"));
594
 
        pBtnSearch->SetToolTip(wxT("Run search"));
595
 
        pBtnOptions->SetToolTip(wxT("Show options window"));
596
 
 
597
 
        pBtnSearch->SetBitmapDisabled(wxBitmap(prefix + wxT("findfdisabled.png"), wxBITMAP_TYPE_PNG));
598
 
        pBtnOptions->SetBitmapDisabled(wxBitmap(prefix + wxT("optionsdisabled.png"), wxBITMAP_TYPE_PNG));
599
 
 
600
 
        toolBar->AddControl(m_pCboSearchExpr);
601
 
        toolBar->AddControl(pBtnSearch);
602
 
        toolBar->AddControl(pBtnOptions);
603
 
 
604
 
        toolBar->Realize();
605
 
        #if wxCHECK_VERSION(2, 8, 0)
606
 
        toolBar->SetInitialSize();
607
 
        #else
608
 
        toolBar->SetBestFittingSize();
609
 
        #endif
610
 
 
611
 
        return true;
 
589
    if ( !IsAttached() || !toolBar )
 
590
        return false;
 
591
 
 
592
    m_pToolbar = toolBar;
 
593
    m_pThreadSearchView->SetToolBar(toolBar);
 
594
 
 
595
    wxString prefix;
 
596
    ConfigManager *cfg = Manager::Get()->GetConfigManager(_T("app"));
 
597
    if (cfg->ReadBool(_T("/environment/toolbar_size"),true))
 
598
    {
 
599
        prefix = ConfigManager::GetDataFolder() + _T("/images/ThreadSearch/16x16/");
 
600
        m_pToolbar->SetToolBitmapSize(wxSize(16,16));
 
601
    }
 
602
    else
 
603
    {
 
604
        prefix = ConfigManager::GetDataFolder() + _T("/images/ThreadSearch/22x22/");
 
605
        m_pToolbar->SetToolBitmapSize(wxSize(22,22));
 
606
    }
 
607
    m_pCboSearchExpr               = new wxComboBox    (toolBar, idCboSearchExpr, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN);
 
608
 
 
609
    m_pCboSearchExpr->SetToolTip(_("Text to search"));
 
610
 
 
611
 
 
612
    toolBar->AddControl(m_pCboSearchExpr);
 
613
    toolBar->AddTool(idBtnSearch,_(""),wxBitmap(prefix + wxT("findf.png"), wxBITMAP_TYPE_PNG),wxBitmap(prefix + wxT("findfdisabled.png"), wxBITMAP_TYPE_PNG),wxITEM_NORMAL,_("Run search")); //Control(pBtnSearch);
 
614
    toolBar->AddTool(idBtnOptions,_(""),wxBitmap(prefix + wxT("options.png"), wxBITMAP_TYPE_PNG),wxBitmap(prefix + wxT("optionsdisabled.png"), wxBITMAP_TYPE_PNG),wxITEM_NORMAL,_("Show options window")); //Control(pBtnSearch);
 
615
 
 
616
    toolBar->Realize();
 
617
    #if wxCHECK_VERSION(2, 8, 0)
 
618
    toolBar->SetInitialSize();
 
619
    #else
 
620
    toolBar->SetBestFittingSize();
 
621
    #endif
 
622
 
 
623
    return true;
612
624
}
613
625
 
614
626
 
615
627
void ThreadSearch::OnBtnOptionsClick(wxCommandEvent &event)
616
628
{
617
 
        if ( !IsAttached() )
618
 
                return;
 
629
    if ( !IsAttached() )
 
630
        return;
619
631
 
620
 
        m_pThreadSearchView->ProcessEvent(event);
 
632
    m_pThreadSearchView->OnBtnOptionsClick(event);
621
633
}
622
634
 
623
635
 
624
636
void ThreadSearch::OnBtnSearchClick(wxCommandEvent &event)
625
637
{
626
 
        if ( !IsAttached() )
627
 
                return;
628
 
 
629
 
        // Behaviour differs if a search is running.
630
 
        if ( m_pThreadSearchView->IsSearchRunning() )
631
 
        {
632
 
                // In this case, user wants to stops search,
633
 
                // we just transmit event
634
 
                m_pThreadSearchView->ProcessEvent(event);
635
 
 
636
 
        }
637
 
        else
638
 
        {
639
 
                // User wants to search for a word.
640
 
                // Forwarding the event would search for the view combo text whereas we want
641
 
                // to look for the toolbar combo text.
642
 
                wxComboBox* pCboBox = static_cast<wxComboBox*>(m_pToolbar->FindControl(idCboSearchExpr));
643
 
                wxASSERT(pCboBox != NULL);
644
 
                RunThreadSearch(pCboBox->GetValue());
645
 
        }
 
638
    if ( !IsAttached() )
 
639
        return;
 
640
 
 
641
    // Behaviour differs if a search is running.
 
642
    if ( m_pThreadSearchView->IsSearchRunning() )
 
643
    {
 
644
        // In this case, user wants to stops search,
 
645
        // we just transmit event
 
646
        m_pThreadSearchView->OnBtnSearchClick(event);
 
647
 
 
648
    }
 
649
    else
 
650
    {
 
651
        // User wants to search for a word.
 
652
        // Forwarding the event would search for the view combo text whereas we want
 
653
        // to look for the toolbar combo text.
 
654
        wxComboBox* pCboBox = static_cast<wxComboBox*>(m_pToolbar->FindControl(idCboSearchExpr));
 
655
        wxASSERT(pCboBox != NULL);
 
656
        RunThreadSearch(pCboBox->GetValue());
 
657
    }
646
658
}
647
659
 
648
660
void ThreadSearch::RunThreadSearch(const wxString& text, bool isCtxSearch/*=false*/)
649
661
{
650
 
        if ( !IsAttached() )
651
 
                return;
652
 
 
653
 
        ThreadSearchFindData findData = m_FindData;
654
 
 
655
 
        // User may prefer to set default options for contextual search
656
 
        if ( (isCtxSearch == true) && (m_UseDefValsForThreadSearch == true) )
657
 
        {
658
 
                findData.SetMatchCase(true);
659
 
                findData.SetMatchWord(true);
660
 
                findData.SetStartWord(false);
661
 
                findData.SetRegEx    (false);
662
 
        }
663
 
 
664
 
        // m_SearchedWord was set in BuildModuleMenu
665
 
        findData.SetFindText(text);
666
 
 
667
 
        // Displays m_pThreadSearchView in manager
668
 
        m_pViewManager->ShowView(true);
669
 
 
670
 
        // Runs the search through a worker thread
671
 
        m_pThreadSearchView->ThreadedSearch(findData);
 
662
    if ( !IsAttached() )
 
663
        return;
 
664
 
 
665
    ThreadSearchFindData findData = m_FindData;
 
666
 
 
667
    // User may prefer to set default options for contextual search
 
668
    if ( (isCtxSearch == true) && (m_UseDefValsForThreadSearch == true) )
 
669
    {
 
670
        findData.SetMatchCase(true);
 
671
        findData.SetMatchWord(true);
 
672
        findData.SetStartWord(false);
 
673
        findData.SetRegEx    (false);
 
674
    }
 
675
 
 
676
    // m_SearchedWord was set in BuildModuleMenu
 
677
    findData.SetFindText(text);
 
678
 
 
679
    // Displays m_pThreadSearchView in manager
 
680
    m_pViewManager->ShowView(true);
 
681
 
 
682
    // Runs the search through a worker thread
 
683
    m_pThreadSearchView->ThreadedSearch(findData);
672
684
}
673
685
 
674
686
 
675
687
void ThreadSearch::OnCboSearchExprEnter(wxCommandEvent &event)
676
688
{
677
 
        if ( !IsAttached() )
678
 
                return;
 
689
    if ( !IsAttached() )
 
690
        return;
679
691
 
680
 
        // Event handler used when user clicks on enter after typing
681
 
        // in combo box text control.
682
 
        // Runs a multi threaded search with combo text
683
 
        wxComboBox* pCboBox = static_cast<wxComboBox*>(m_pToolbar->FindControl(idCboSearchExpr));
684
 
        wxASSERT(pCboBox != NULL);
685
 
        if ( event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER )
 
692
    // Event handler used when user clicks on enter after typing
 
693
    // in combo box text control.
 
694
    // Runs a multi threaded search with combo text
 
695
    wxComboBox* pCboBox = static_cast<wxComboBox*>(m_pToolbar->FindControl(idCboSearchExpr));
 
696
    wxASSERT(pCboBox != NULL);
 
697
    if ( event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER )
686
698
        RunThreadSearch(pCboBox->GetValue());
687
699
}
688
700
 
689
701
 
690
702
void ThreadSearch::ShowToolBar(bool show)
691
703
{
692
 
        if ( !IsAttached() )
693
 
                return;
694
 
 
695
 
        bool isShown = IsWindowReallyShown(m_pToolbar);
696
 
 
697
 
        if ( show != isShown )
698
 
        {
699
 
                CodeBlocksDockEvent evt(show ? cbEVT_SHOW_DOCK_WINDOW : cbEVT_HIDE_DOCK_WINDOW);
700
 
                evt.pWindow = (wxWindow*)m_pToolbar;
701
 
                evt.shown = show;
702
 
                Manager::Get()->ProcessEvent(evt);
703
 
        }
 
704
    if ( !IsAttached() )
 
705
        return;
 
706
 
 
707
    bool isShown = IsWindowReallyShown(m_pToolbar);
 
708
 
 
709
    if ( show != isShown )
 
710
    {
 
711
        CodeBlocksDockEvent evt(show ? cbEVT_SHOW_DOCK_WINDOW : cbEVT_HIDE_DOCK_WINDOW);
 
712
        evt.pWindow = (wxWindow*)m_pToolbar;
 
713
        evt.shown = show;
 
714
        Manager::Get()->ProcessEvent(evt);
 
715
    }
704
716
}
705
717
 
706
718
 
707
719
bool ThreadSearch::IsToolbarVisible()
708
720
{
709
 
        if ( !IsAttached() )
710
 
                return false;
 
721
    if ( !IsAttached() )
 
722
        return false;
711
723
 
712
 
        return IsWindowReallyShown(m_pToolbar);
 
724
    return IsWindowReallyShown(m_pToolbar);
713
725
}
714
726
 
715
727
 
716
728
bool ThreadSearch::GetCursorWord(wxString& sWord)
717
729
{
718
 
        bool wordFound = false;
719
 
        sWord = wxEmptyString;
720
 
 
721
 
        // Gets active editor
722
 
        cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
723
 
        if ( ed != NULL )
724
 
        {
725
 
                cbStyledTextCtrl* control = ed->GetControl();
726
 
 
727
 
                // Gets word under cursor
728
 
                int pos = control->GetCurrentPos();
729
 
                int ws  = control->WordStartPosition(pos, true);
730
 
                int we  = control->WordEndPosition(pos, true);
731
 
                if ( ws < we ) // Avoid empty strings
732
 
                {
733
 
                        // m_SearchedWord will be used if 'Find occurrences' ctx menu is clicked
734
 
                        sWord = control->GetTextRange(ws, we);
735
 
                        wordFound = true;
736
 
                }
737
 
        }
738
 
 
739
 
        return wordFound;
 
730
    bool wordFound = false;
 
731
    sWord = wxEmptyString;
 
732
 
 
733
    // Gets active editor
 
734
    cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
 
735
    if ( ed != NULL )
 
736
    {
 
737
        cbStyledTextCtrl* control = ed->GetControl();
 
738
 
 
739
        // Gets word under cursor
 
740
        int pos = control->GetCurrentPos();
 
741
        int ws  = control->WordStartPosition(pos, true);
 
742
        int we  = control->WordEndPosition(pos, true);
 
743
        if ( ws < we ) // Avoid empty strings
 
744
        {
 
745
            // m_SearchedWord will be used if 'Find occurrences' ctx menu is clicked
 
746
            sWord = control->GetTextRange(ws, we);
 
747
            wordFound = true;
 
748
        }
 
749
    }
 
750
 
 
751
    return wordFound;
740
752
}
741
753
 
742
754
 
743
755
void ThreadSearch::OnMnuEditCopy(wxCommandEvent& event)
744
756
{
745
 
        if ( !IsAttached() )
746
 
        {
747
 
                event.Skip();
748
 
                return;
749
 
        }
 
757
       if ( !IsAttached() )
 
758
    {
 
759
        event.Skip();
 
760
        return;
 
761
    }
750
762
 
751
763
    wxWindow* pFocused = wxWindow::FindFocus();
752
764
 
764
776
        LOGIT( _T("OnMnuEditcopy for m_pThreadSearchView->m_pCboSearchExpr") );
765
777
    }
766
778
    else if ( pFocused == static_cast<wxWindow*>(m_pThreadSearchView->m_pSearchPreview) )
767
 
        {
 
779
    {
768
780
        bool hasSel = m_pThreadSearchView->m_pSearchPreview->GetSelectionStart() != m_pThreadSearchView->m_pSearchPreview->GetSelectionEnd();
769
781
        if (hasSel)
770
782
            m_pThreadSearchView->m_pSearchPreview->Copy();
771
 
                LOGIT( _T("OnMnuEditcopy for m_pSearchPreview") );
772
 
        }
773
 
        else
774
 
        {
775
 
                event.Skip();
776
 
        }
 
783
        LOGIT( _T("OnMnuEditcopy for m_pSearchPreview") );
 
784
    }
 
785
    else
 
786
    {
 
787
        event.Skip();
 
788
    }
777
789
 
778
790
    // If you Skip(), CB main.cpp will wrongly paste your text into the current editor
779
791
    // because CB main.cpp thinks it owns the clipboard.
784
796
 
785
797
void ThreadSearch::OnMnuEditCopyUpdateUI(wxUpdateUIEvent& event)
786
798
{
787
 
        if ( !IsAttached() )
788
 
        {
789
 
                event.Skip(); return;
790
 
        }
 
799
    if ( !IsAttached() )
 
800
    {
 
801
        event.Skip(); return;
 
802
    }
791
803
 
792
 
        wxWindow* pFocused = wxWindow::FindFocus();
 
804
    wxWindow* pFocused = wxWindow::FindFocus();
793
805
    if (not pFocused) return;
794
806
 
795
807
    wxMenuBar* mbar = Manager::Get()->GetAppFrame()->GetMenuBar();
810
822
        //LOGIT( _T("OnMnuEditCopyUpdateUI m_pThreadSearchView->m_pCboSearchExpr") );
811
823
    }
812
824
    else if ( pFocused == static_cast<wxWindow*>(m_pThreadSearchView->m_pSearchPreview) )
813
 
        {
814
 
                hasSel = m_pThreadSearchView->m_pSearchPreview->GetSelectionStart() != m_pThreadSearchView->m_pSearchPreview->GetSelectionEnd();
 
825
    {
 
826
        hasSel = m_pThreadSearchView->m_pSearchPreview->GetSelectionStart() != m_pThreadSearchView->m_pSearchPreview->GetSelectionEnd();
815
827
        //LOGIT( _T("OnMnuEditCopyUpdateUI m_pSearchPreview") );
816
 
        }
 
828
    }
817
829
    if ( hasSel )
818
830
    {
819
 
                mbar->Enable(idMenuEditCopy, hasSel);
 
831
        mbar->Enable(idMenuEditCopy, hasSel);
820
832
        wxToolBar* pMainToolBar = (wxToolBar*) ::wxFindWindowByName(wxT("toolbar"), NULL);
821
833
        if (pMainToolBar) pMainToolBar->EnableTool(idMenuEditCopy, hasSel);
822
834
        return;
841
853
    //      If the window isn't one of ours, we'll event.Skip();
842
854
    // ----------------------------------------------------------------
843
855
 
844
 
        if ( !IsAttached() )
845
 
                { event.Skip(); return; }
 
856
       if ( !IsAttached() )
 
857
        { event.Skip(); return; }
846
858
 
847
859
    if (not m_IsAttached) {event.Skip(); return;}
848
860
 
853
865
//    DBGLOG(wxT("OnMnuEditPaste:Focused[%p][%s]"), pFocused, focusedStr.c_str());
854
866
 
855
867
    // don't allow paste when the following windows have the focus
856
 
        if ( (pFocused == m_pThreadSearchView->m_pSearchPreview) ||
 
868
    if ( (pFocused == m_pThreadSearchView->m_pSearchPreview) ||
857
869
         (pFocused == (wxWindow*)m_pThreadSearchView->m_pLogger) )
858
 
        {
 
870
    {
859
871
        return;
860
 
        }
 
872
    }
861
873
 
862
874
    // if the following window have the focus, own the paste.
863
875
    if ( (pFocused != m_pCboSearchExpr)
864
876
        && (pFocused != m_pThreadSearchView->m_pCboSearchExpr) )
865
877
        { event.Skip(); return;}
866
878
 
867
 
        if (pFocused == m_pCboSearchExpr)
868
 
                m_pCboSearchExpr->Paste();
869
 
        if (pFocused == m_pThreadSearchView->m_pCboSearchExpr)
870
 
                m_pThreadSearchView->m_pCboSearchExpr->Paste();
 
879
    if (pFocused == m_pCboSearchExpr)
 
880
        m_pCboSearchExpr->Paste();
 
881
    if (pFocused == m_pThreadSearchView->m_pCboSearchExpr)
 
882
        m_pThreadSearchView->m_pCboSearchExpr->Paste();
871
883
 
872
884
    // If you Skip(), CB main.cpp will wrongly paste your text into the current editor
873
885
    // because CB main.cpp thinks it owns the clipboard.
878
890
 
879
891
void ThreadSearch::SetManagerType(ThreadSearchViewManagerBase::eManagerTypes mgrType)
880
892
{
881
 
        // Is type different from current one ?
882
 
        if ( mgrType != m_pViewManager->GetManagerType() )
883
 
        {
884
 
                // Get show state and destroy current view manager.
885
 
                bool show(true);
886
 
                if ( m_pViewManager != NULL )
887
 
                {
888
 
                        show = m_pViewManager->IsViewShown();
889
 
                        m_pViewManager->RemoveViewFromManager();
890
 
                        delete m_pViewManager;
891
 
                }
 
893
    // Is type different from current one ?
 
894
    if ( mgrType != m_pViewManager->GetManagerType() )
 
895
    {
 
896
        // Get show state and destroy current view manager.
 
897
        bool show(true);
 
898
        if ( m_pViewManager != NULL )
 
899
        {
 
900
            show = m_pViewManager->IsViewShown();
 
901
            m_pViewManager->RemoveViewFromManager();
 
902
            delete m_pViewManager;
 
903
        }
892
904
 
893
 
                // Create and show new view manager.
894
 
                m_pViewManager = ThreadSearchViewManagerBase::BuildThreadSearchViewManagerBase(m_pThreadSearchView, true, mgrType);
895
 
                m_pViewManager->ShowView(show);
896
 
        }
 
905
        // Create and show new view manager.
 
906
        m_pViewManager = ThreadSearchViewManagerBase::BuildThreadSearchViewManagerBase(m_pThreadSearchView, true, mgrType);
 
907
        m_pViewManager->ShowView(show);
 
908
    }
897
909
}
898
910
 
899
911