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

« back to all changes in this revision

Viewing changes to src/plugins/contrib/codesnippets/Search/ThreadSearchFrame.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:
 
1
/***************************************************************
 
2
 * Name:      SnipSearchAppMain.cpp
 
3
 * Purpose:   Code for Application Frame
 
4
 * Author:    Pecan ()
 
5
 * Created:   2008-02-27
 
6
 * Copyright: Pecan ()
 
7
 * License:
 
8
 **************************************************************/
 
9
 
 
10
#ifdef WX_PRECOMP
 
11
#include "wx_pch.h"
 
12
#endif
 
13
 
 
14
#ifdef __BORLANDC__
 
15
#pragma hdrstop
 
16
#endif //__BORLANDC__
 
17
 
 
18
#include <wx/filesys.h>
 
19
#include <wx/fs_zip.h>
 
20
#include <wx/fs_mem.h>
 
21
#include <wx/xrc/xmlres.h>
 
22
#include <wx/dnd.h>
 
23
#include <wx/utils.h>
 
24
#include "cbauibook.h"
 
25
 
 
26
 
 
27
#include <filefilters.h>
 
28
#include <cbworkspace.h>
 
29
 
 
30
#include "ThreadSearchFrame.h"
 
31
#include "ThreadSearch.h"
 
32
#include "ThreadSearchView.h"
 
33
#include "editormanager.h"
 
34
#include "scbeditor.h"
 
35
#include "personalitymanager.h"
 
36
#include "configmanager.h"
 
37
#include "version.h"
 
38
#include "snippetsconfig.h"
 
39
#include "codesnippetswindow.h"
 
40
#include "seditormanager.h"
 
41
#include "scbeditor.h"
 
42
 
 
43
// ----------------------------------------------------------------------------
 
44
class wxMyFileDropTarget : public wxFileDropTarget
 
45
// ----------------------------------------------------------------------------
 
46
{
 
47
public:
 
48
    wxMyFileDropTarget(ThreadSearchFrame *frame):m_frame(frame){}
 
49
    virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames)
 
50
    {
 
51
        if(!m_frame) return false;
 
52
        return m_frame->OnDropFiles(x,y,filenames);
 
53
    }
 
54
private:
 
55
    ThreadSearchFrame* m_frame;
 
56
};
 
57
 
 
58
// ----------------------------------------------------------------------------
 
59
namespace
 
60
// ----------------------------------------------------------------------------
 
61
{
 
62
    //helper functions
 
63
    enum wxbuildinfoformat {
 
64
        short_f, long_f };
 
65
 
 
66
    wxString wxbuildinfo(wxbuildinfoformat format)
 
67
    {
 
68
        wxString wxbuild(wxVERSION_STRING);
 
69
 
 
70
        if (format == long_f )
 
71
        {
 
72
            #if defined(__WXMSW__)
 
73
                    wxbuild << _T("-Windows");
 
74
            #elif defined(__WXMAC__)
 
75
                    wxbuild << _T("-Mac");
 
76
            #elif defined(__UNIX__)
 
77
                    wxbuild << _T("-Linux");
 
78
            #endif
 
79
 
 
80
            #if wxUSE_UNICODE
 
81
                    wxbuild << _T("-Unicode build");
 
82
            #else
 
83
                    wxbuild << _T("-ANSI build");
 
84
            #endif // wxUSE_UNICODE
 
85
        }
 
86
 
 
87
        return wxbuild;
 
88
    }
 
89
 
 
90
    int wxID_FILE10 = wxNewId();
 
91
    int wxID_FILE11 = wxNewId();
 
92
    int wxID_FILE12 = wxNewId();
 
93
    int wxID_FILE13 = wxNewId();
 
94
    int wxID_FILE14 = wxNewId();
 
95
    int wxID_FILE15 = wxNewId();
 
96
    int wxID_FILE16 = wxNewId();
 
97
    int wxID_FILE17 = wxNewId();
 
98
    int wxID_FILE18 = wxNewId();
 
99
    int wxID_FILE19 = wxNewId();
 
100
 
 
101
////    int idToolNew = XRCID("idToolNew");
 
102
////    int idFileNew = XRCID("idFileNew");
 
103
////    int idFileNewEmpty = XRCID("idFileNewEmpty");
 
104
////    int idFileNewProject = XRCID("idFileNewProject");
 
105
////    int idFileNewTarget = XRCID("idFileNewTarget");
 
106
////    int idFileNewFile = XRCID("idFileNewFile");
 
107
////    int idFileNewCustom = XRCID("idFileNewCustom");
 
108
////    int idFileNewUser = XRCID("idFileNewUser");
 
109
    int idFileOpen = XRCID("idFileOpen");
 
110
////    int idFileReopen = XRCID("idFileReopen");
 
111
    int idFileOpenRecentFileClearHistory = XRCID("idFileOpenRecentFileClearHistory");
 
112
    int idFileOpenRecentProjectClearHistory = XRCID("idFileOpenRecentProjectClearHistory");
 
113
////    int idFileImportProjectDevCpp = XRCID("idFileImportProjectDevCpp");
 
114
////    int idFileImportProjectMSVC = XRCID("idFileImportProjectMSVC");
 
115
////    int idFileImportProjectMSVCWksp = XRCID("idFileImportProjectMSVCWksp");
 
116
////    int idFileImportProjectMSVS = XRCID("idFileImportProjectMSVS");
 
117
////    int idFileImportProjectMSVSWksp = XRCID("idFileImportProjectMSVSWksp");
 
118
////    int idFileSave = XRCID("idFileSave");
 
119
////    int idFileSaveAs = XRCID("idFileSaveAs");
 
120
////    int idFileSaveAllFiles = XRCID("idFileSaveAllFiles");
 
121
////    int idFileSaveProject = XRCID("idFileSaveProject");
 
122
////    int idFileSaveProjectAs = XRCID("idFileSaveProjectAs");
 
123
////    int idFileSaveProjectAllProjects = XRCID("idFileSaveProjectAllProjects");
 
124
////    int idFileSaveProjectTemplate = XRCID("idFileSaveProjectTemplate");
 
125
////    int idFileOpenDefWorkspace = XRCID("idFileOpenDefWorkspace");
 
126
////    int idFileSaveWorkspace = XRCID("idFileSaveWorkspace");
 
127
////    int idFileSaveWorkspaceAs = XRCID("idFileSaveWorkspaceAs");
 
128
////    int idFileSaveAll = XRCID("idFileSaveAll");
 
129
////    int idFileCloseWorkspace = XRCID("idFileCloseWorkspace");
 
130
////    int idFileClose = XRCID("idFileClose");
 
131
////    int idFileCloseAll = XRCID("idFileCloseAll");
 
132
////    int idFileCloseProject = XRCID("idFileCloseProject");
 
133
////    int idFileCloseAllProjects = XRCID("idFileCloseAllProjects");
 
134
////    int idFilePrintSetup = XRCID("idFilePrintSetup");
 
135
////    int idFilePrint = XRCID("idFilePrint");
 
136
////    int idFileExit = XRCID("idFileExit");
 
137
////    int idFileNext = wxNewId();
 
138
////    int idFilePrev = wxNewId();
 
139
////
 
140
////    int idEditUndo = XRCID("idEditUndo");
 
141
////    int idEditRedo = XRCID("idEditRedo");
 
142
////    int idEditCopy = XRCID("idEditCopy");
 
143
////    int idEditCut = XRCID("idEditCut");
 
144
////    int idEditPaste = XRCID("idEditPaste");
 
145
////    int idEditSwapHeaderSource = XRCID("idEditSwapHeaderSource");
 
146
////    int idEditGotoMatchingBrace = XRCID("idEditGotoMatchingBrace");
 
147
////    int idEditHighlightMode = XRCID("idEditHighlightMode");
 
148
////    int idEditHighlightModeText = XRCID("idEditHighlightModeText");
 
149
////    int idEditBookmarks = XRCID("idEditBookmarks");
 
150
////    int idEditBookmarksToggle = XRCID("idEditBookmarksToggle");
 
151
////    int idEditBookmarksPrevious = XRCID("idEditBookmarksPrevious");
 
152
////    int idEditBookmarksNext = XRCID("idEditBookmarksNext");
 
153
////    int idEditFolding = XRCID("idEditFolding");
 
154
////    int idEditFoldAll = XRCID("idEditFoldAll");
 
155
////    int idEditUnfoldAll = XRCID("idEditUnfoldAll");
 
156
////    int idEditToggleAllFolds = XRCID("idEditToggleAllFolds");
 
157
////    int idEditFoldBlock = XRCID("idEditFoldBlock");
 
158
////    int idEditUnfoldBlock = XRCID("idEditUnfoldBlock");
 
159
////    int idEditToggleFoldBlock = XRCID("idEditToggleFoldBlock");
 
160
////    int idEditEOLMode = XRCID("idEditEOLMode");
 
161
////    int idEditEOLCRLF = XRCID("idEditEOLCRLF");
 
162
////    int idEditEOLCR = XRCID("idEditEOLCR");
 
163
////    int idEditEOLLF = XRCID("idEditEOLLF");
 
164
////    int idEditEncoding = XRCID("idEditEncoding");
 
165
////    int idEditEncodingDefault = XRCID("idEditEncodingDefault");
 
166
////    int idEditEncodingUseBom = XRCID("idEditEncodingUseBom");
 
167
////    int idEditEncodingAscii = XRCID("idEditEncodingAscii");
 
168
////    int idEditEncodingUtf7 = XRCID("idEditEncodingUtf7");
 
169
////    int idEditEncodingUtf8 = XRCID("idEditEncodingUtf8");
 
170
////    int idEditEncodingUnicode = XRCID("idEditEncodingUnicode");
 
171
////    int idEditEncodingUtf16 = XRCID("idEditEncodingUtf16");
 
172
////    int idEditEncodingUtf32 = XRCID("idEditEncodingUtf32");
 
173
////    int idEditEncodingUnicode16BE = XRCID("idEditEncodingUnicode16BE");
 
174
////    int idEditEncodingUnicode16LE = XRCID("idEditEncodingUnicode16LE");
 
175
////    int idEditEncodingUnicode32BE = XRCID("idEditEncodingUnicode32BE");
 
176
////    int idEditEncodingUnicode32LE = XRCID("idEditEncodingUnicode32LE");
 
177
////    int idEditSpecialCommands = XRCID("idEditSpecialCommands");
 
178
////    int idEditSpecialCommandsMovement = XRCID("idEditSpecialCommandsMovement");
 
179
////    int idEditParaUp = XRCID("idEditParaUp");
 
180
////    int idEditParaUpExtend = XRCID("idEditParaUpExtend");
 
181
////    int idEditParaDown = XRCID("idEditParaDown");
 
182
////    int idEditParaDownExtend = XRCID("idEditParaDownExtend");
 
183
////    int idEditWordPartLeft = XRCID("idEditWordPartLeft");
 
184
////    int idEditWordPartLeftExtend = XRCID("idEditWordPartLeftExtend");
 
185
////    int idEditWordPartRight = XRCID("idEditWordPartRight");
 
186
////    int idEditWordPartRightExtend = XRCID("idEditWordPartRightExtend");
 
187
////    int idEditSpecialCommandsZoom = XRCID("idEditSpecialCommandsZoom");
 
188
////    int idEditZoomIn = XRCID("idEditZoomIn");
 
189
////    int idEditZoomOut = XRCID("idEditZoomOut");
 
190
////    int idEditZoomReset = XRCID("idEditZoomReset");
 
191
////    int idEditSpecialCommandsLine = XRCID("idEditSpecialCommandsLine");
 
192
////    int idEditLineCut = XRCID("idEditLineCut");
 
193
////    int idEditLineDelete = XRCID("idEditLineDelete");
 
194
////    int idEditLineDuplicate = XRCID("idEditLineDuplicate");
 
195
////    int idEditLineTranspose = XRCID("idEditLineTranspose");
 
196
////    int idEditLineCopy = XRCID("idEditLineCopy");
 
197
////    int idEditLinePaste = XRCID("idEditLinePaste");
 
198
////    int idEditSpecialCommandsCase = XRCID("idEditSpecialCommandsCase");
 
199
////    int idEditUpperCase = XRCID("idEditUpperCase");
 
200
////    int idEditLowerCase = XRCID("idEditLowerCase");
 
201
////    int idEditSelectAll = XRCID("idEditSelectAll");
 
202
////    int idEditCommentSelected = XRCID("idEditCommentSelected");
 
203
////    int idEditUncommentSelected = XRCID("idEditUncommentSelected");
 
204
////    int idEditToggleCommentSelected = XRCID("idEditToggleCommentSelected");
 
205
////    int idEditStreamCommentSelected = XRCID("idEditStreamCommentSelected");
 
206
////    int idEditBoxCommentSelected = XRCID("idEditBoxCommentSelected");
 
207
////    int idEditAutoComplete = XRCID("idEditAutoComplete");
 
208
////
 
209
    int idSearchFind = XRCID("idSearchFind");
 
210
    int idSearchFindInFiles = XRCID("idSearchFindInFiles");
 
211
    int idSearchFindNext = XRCID("idSearchFindNext");
 
212
    int idSearchFindPrevious = XRCID("idSearchFindPrevious");
 
213
////    int idSearchReplace = XRCID("idSearchReplace");
 
214
////    int idSearchReplaceInFiles = XRCID("idSearchReplaceInFiles");
 
215
////    int idSearchGotoLine = XRCID("idSearchGotoLine");
 
216
}
 
217
// ----------------------------------------------------------------------------
 
218
//      Events Table
 
219
// ----------------------------------------------------------------------------
 
220
BEGIN_EVENT_TABLE(ThreadSearchFrame, wxFrame)
 
221
 
 
222
    EVT_ACTIVATE(         ThreadSearchFrame::OnFrameActivated)
 
223
    EVT_SIZE(             ThreadSearchFrame::OnSizeWindow)
 
224
    EVT_CLOSE(            ThreadSearchFrame::OnClose)
 
225
    EVT_MENU(idMenuQuit,  ThreadSearchFrame::OnQuit)
 
226
    EVT_MENU(idMenuAbout, ThreadSearchFrame::OnAbout)
 
227
    // File
 
228
    EVT_MENU(idFileOpen,  ThreadSearchFrame::OnFileOpen)
 
229
 
 
230
    // Edit
 
231
 
 
232
    // Search/Find
 
233
    EVT_MENU(idSearchFind,          ThreadSearchFrame::OnSearchFind)
 
234
    EVT_MENU(idSearchFindInFiles,   ThreadSearchFrame::OnSearchFind)
 
235
    EVT_MENU(idSearchFindNext,      ThreadSearchFrame::OnSearchFindNext)
 
236
    EVT_MENU(idSearchFindPrevious,  ThreadSearchFrame::OnSearchFindNext)
 
237
 
 
238
    EVT_CODESNIPPETS_NEW_INDEX (wxID_ANY,    ThreadSearchFrame::OnCodeSnippetsNewIndex)
 
239
 
 
240
END_EVENT_TABLE()
 
241
 
 
242
// ----------------------------------------------------------------------------
 
243
ThreadSearchFrame::ThreadSearchFrame(wxFrame* appFrame, const wxString& title)
 
244
// ----------------------------------------------------------------------------
 
245
    : wxFrame(appFrame, -1, title)
 
246
      ,m_pFilesHistory(0)
 
247
      ,m_pProjectsHistory(0)
 
248
      ,m_bOnActivateBusy(0)
 
249
      ,m_pThreadSearch(0)
 
250
{
 
251
    bool ok = InitThreadSearchFrame( appFrame, title);
 
252
    wxUnusedVar(ok);
 
253
}
 
254
// ----------------------------------------------------------------------------
 
255
bool ThreadSearchFrame::InitThreadSearchFrame(wxFrame* appFrame, const wxString& title)
 
256
// ----------------------------------------------------------------------------
 
257
{
 
258
    GetConfig()->SetThreadSearchFrame( this );
 
259
 
 
260
    // create a menu bar
 
261
    CreateMenuBar();
 
262
 
 
263
    // create a status bar with some information about the used wxWidgets version
 
264
    CreateStatusBar(2);
 
265
    SetStatusText(_("CodeSnippets Search"),0);
 
266
    SetStatusText(wxbuildinfo(short_f), 1);
 
267
 
 
268
    InitializeRecentFilesHistory(); // -not used yet-
 
269
 
 
270
    // allocate a separate EditorManager/Notebook
 
271
    if (not GetConfig()->GetEditorManager(this))
 
272
    {
 
273
        SEditorManager* m_pEdMan = new SEditorManager(this);
 
274
        GetConfig()->RegisterEditorManager(this, m_pEdMan);
 
275
    }//if GetEditorManager
 
276
 
 
277
    // create ThreadSearch and alter its menu items
 
278
    m_pThreadSearch = new ThreadSearch( this );
 
279
    if (  m_pThreadSearch ) do
 
280
    {
 
281
        m_pThreadSearch->ThreadSearch::m_IsAttached = true;
 
282
        m_pThreadSearch->OnAttach();
 
283
        PushEventHandler(m_pThreadSearch);
 
284
        m_pThreadSearch->SetEvtHandlerEnabled( true );
 
285
 
 
286
        // add View and Search menu items
 
287
        wxMenuBar* pMenuBar = this->GetMenuBar();
 
288
        wxMenu* pMenuView = new wxMenu();
 
289
        //-wxMenu* pMenuSearch = pMenuBar->GetMenu( pMenuBar->FindMenu(_T("Search")));
 
290
        pMenuBar->Insert( 1, pMenuView, _T("View"));
 
291
        //-pMenuBar->Insert( 2, pMenuSearch, _T("Search"));
 
292
        m_pThreadSearch->BuildMenu( pMenuBar );
 
293
        // Change 'View/ThreadSearch' to 'View/Options'
 
294
        int idOptionsThreadSearch = pMenuBar->FindMenuItem(_T("View"),_T("Snippets search"));
 
295
        if (idOptionsThreadSearch not_eq wxNOT_FOUND)
 
296
        {   pMenuBar->SetLabel( idOptionsThreadSearch, _T("Options...") );
 
297
            m_pThreadSearch->Connect(idOptionsThreadSearch, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(ThreadSearchFrame::OnMenuOptions), NULL, this);
 
298
        }
 
299
 
 
300
        // create tool bar and hide it (avoids bar reference crashes)
 
301
        wxToolBar* pToolBar = new wxToolBar(this, -1);
 
302
        if (  m_pThreadSearch )
 
303
            m_pThreadSearch->BuildToolBar( pToolBar );
 
304
        pToolBar->Hide();
 
305
 
 
306
        // move frame to last know frame position
 
307
        ConfigManager* pCfg = Manager::Get()->GetConfigManager(_T("SnippetsSearch"));
 
308
        int xPos = pCfg->ReadInt( wxT("/FramePosX"), 120);
 
309
        int yPos = pCfg->ReadInt( wxT("/FramePosY"), 60);
 
310
        int width = pCfg->ReadInt( wxT("/FrameWidth"), 120);
 
311
        int height = pCfg->ReadInt( wxT("/FrameHeight"), 60);
 
312
        SetSize( xPos, yPos, width, height);
 
313
 
 
314
        // Catch Destroyed windows
 
315
        Connect( wxEVT_DESTROY,
 
316
            (wxObjectEventFunction) (wxEventFunction)
 
317
            (wxCommandEventFunction) &ThreadSearchFrame::OnWindowDestroy);
 
318
 
 
319
        // Allow filenames to be dropped/opened on ThreadSearchFrame
 
320
        SetDropTarget(new wxMyFileDropTarget(this));
 
321
        GetConfig()->GetEditorManager(this)->GetNotebook()->SetDropTarget(new wxMyFileDropTarget(this));
 
322
 
 
323
    }while(false);//if m_pThreadSearch do
 
324
 
 
325
    return m_pThreadSearch;
 
326
 
 
327
}//initThreadSearchFrame ctor
 
328
// ----------------------------------------------------------------------------
 
329
ThreadSearchFrame::~ThreadSearchFrame()
 
330
// ----------------------------------------------------------------------------
 
331
{
 
332
    //dtor
 
333
    Disconnect( wxEVT_DESTROY,
 
334
        (wxObjectEventFunction) (wxEventFunction)
 
335
        (wxCommandEventFunction) &ThreadSearchFrame::OnWindowDestroy);
 
336
 
 
337
    GetConfig()->SetThreadSearchFrame(0);
 
338
}
 
339
// ----------------------------------------------------------------------------
 
340
void ThreadSearchFrame::OnMenuOptions(wxCommandEvent& event)
 
341
// ----------------------------------------------------------------------------
 
342
{
 
343
    //m_pThreadSearch->m_pThreadSearchView->OnBtnOptionsClick(event);
 
344
    m_pThreadSearch->Configure();
 
345
}
 
346
// ----------------------------------------------------------------------------
 
347
void ThreadSearchFrame::OnClose(wxCloseEvent &event)
 
348
// ----------------------------------------------------------------------------
 
349
{
 
350
    this->Show(false);  //avoid fragmented disappearing windows
 
351
 
 
352
    // memorize current ThreadSearchFrame position
 
353
    ConfigManager* pCfg = Manager::Get()->GetConfigManager(_T("SnippetsSearch"));
 
354
    int xPos, yPos, width, height;
 
355
    GetPosition(&xPos,&yPos);
 
356
    GetSize(&width,&height);
 
357
    pCfg->Write(wxT("/FramePosX"), xPos );
 
358
    pCfg->Write(wxT("/FramePosY"), yPos);
 
359
    pCfg->Write(wxT("/FrameWidth"), width);
 
360
    pCfg->Write(wxT("/FrameHeight"), height);
 
361
 
 
362
    //-if (GetConfig()->IsApplication())
 
363
    {   // we have to close all open editors or we'll crash
 
364
        // in wxAuiNoteBook::GetPageCount(). EditoManager call wxAuiNotebook
 
365
        // to close 'em, but wxAuiNotebook has alread been deleted by
 
366
        // wxWidgets Destory().
 
367
        SEditorManager* pEdMan = GetConfig()->GetEditorManager(this);
 
368
        if (pEdMan)
 
369
        {   ScbEditor* ed;
 
370
            int knt = pEdMan->GetEditorsCount();
 
371
            for ( int i=knt; i>0; --i )
 
372
            {
 
373
                ed = (ScbEditor*)pEdMan->GetEditor(i-1);
 
374
                if ( ed ) ed->Close();
 
375
            }
 
376
        }
 
377
    }//if
 
378
 
 
379
    // reverse splitterwindow switches and reparenting
 
380
    if (m_pThreadSearch){
 
381
        RemoveEventHandler(m_pThreadSearch);
 
382
        m_pThreadSearch->OnRelease(true);
 
383
    }
 
384
 
 
385
    // free separate editor manager
 
386
    SEditorManager* m_pEdMan = GetConfig()->GetEditorManager(this);
 
387
    if ( m_pEdMan )
 
388
    {
 
389
        RemoveEventHandler( m_pEdMan ); // *do this or crash @ Destroy()*
 
390
        delete m_pEdMan;
 
391
        GetConfig()->RemoveEditorManager((wxFrame*)this);
 
392
    }
 
393
    // free ThreadSearch plugin/evtHandler
 
394
    if ( m_pThreadSearch ){
 
395
        delete m_pThreadSearch; // deletes ThreadSearch wxEvtHandler object
 
396
        m_pThreadSearch = 0;
 
397
    }
 
398
 
 
399
    // release memory in FileLinks array used by ThreadSearch
 
400
    GetConfig()->ClearFileLinksMapArray();
 
401
 
 
402
    //- write the configuation file
 
403
    //- Don't free Manager unless we initialized it. which we didn't.
 
404
    //-Manager::Free();
 
405
    //-GetConfig()->GetSnippetsWindow()->CloseThreadSearchFrame();
 
406
 
 
407
    Destroy();
 
408
}
 
409
// ----------------------------------------------------------------------------
 
410
void ThreadSearchFrame::OnQuit(wxCommandEvent &event)
 
411
// ----------------------------------------------------------------------------
 
412
{
 
413
    wxWindow::Close();
 
414
}
 
415
// ----------------------------------------------------------------------------
 
416
void ThreadSearchFrame::OnAbout(wxCommandEvent &event)
 
417
// ----------------------------------------------------------------------------
 
418
{
 
419
    wxString msg = wxbuildinfo(long_f);
 
420
    msg << _T("\n\n");
 
421
    msg << _T("Original ThreadSearch code by Jerome Antoine \n");
 
422
        msg << _T("Ported to CodeSnippets by Pecan Heber \n");
 
423
    msg << _T("\n");
 
424
        msg << _T("Click Log item once to display snippet in preview window. \n");
 
425
        msg << _T("Double click Log item to display in editor window. \n");
 
426
    msg << _T("\n");
 
427
        msg << _T("Double clicking a CodeSnippets \"Category\" log item \n");
 
428
        msg << _T("simple highlights the item in the index (tree) window. \n");
 
429
 
 
430
    wxMessageBox(msg, _("Welcome to..."));
 
431
}
 
432
// ----------------------------------------------------------------------------
 
433
void ThreadSearchFrame::OnSizeWindow(wxSizeEvent &event)
 
434
// ----------------------------------------------------------------------------
 
435
{
 
436
    // On the first resizing of the frame, the editor notebook splitter sash
 
437
    // is getting put back in the middle of the window, not where the user
 
438
    // placed it.
 
439
    #if defined(LOGGING)
 
440
    LOGIT( _T("ThreadSearchFrame::OnSizeWindow"));
 
441
    #endif
 
442
 
 
443
    event.Skip();
 
444
    if (not GetConfig()->GetThreadSearchPlugin() ) return;
 
445
    GetConfig()->GetThreadSearchPlugin()->UserResizingWindow(event);
 
446
    event.Skip();
 
447
    return;
 
448
}
 
449
// ----------------------------------------------------------------------------
 
450
void ThreadSearchFrame::OnSearchFind(wxCommandEvent& event)
 
451
// ----------------------------------------------------------------------------
 
452
{
 
453
    //(pecan 2008/7/20)
 
454
    //Don't search in preview pane, and don't search if no editor is open
 
455
    ScbEditor* sEd = GetConfig()->GetEditorManager(this)->GetBuiltinActiveEditor();
 
456
    if (not sEd)
 
457
        return;
 
458
    if (not ((wxWindow*)(sEd->GetControl()) == wxWindow::FindFocus()))
 
459
        return;
 
460
 
 
461
    bool bDoMultipleFiles = (event.GetId() == idSearchFindInFiles);
 
462
    if(!bDoMultipleFiles)
 
463
    {
 
464
        //-bDoMultipleFiles = !Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
 
465
        bDoMultipleFiles = not GetConfig()->GetEditorManager(this)->GetBuiltinActiveEditor();
 
466
    }
 
467
    //-Manager::Get()->GetEditorManager()->ShowFindDialog(false, bDoMultipleFiles);
 
468
    GetConfig()->GetEditorManager(this)->ShowFindDialog(false, false);
 
469
}// end of OnSearchFind
 
470
// ----------------------------------------------------------------------------
 
471
void ThreadSearchFrame::OnSearchFindNext(wxCommandEvent& event)
 
472
// ----------------------------------------------------------------------------
 
473
{
 
474
    //(pecan 2008/7/20) FullSearch
 
475
    //Don't search in preview pane, and don't search if no editor is open
 
476
    ScbEditor* sEd = GetConfig()->GetEditorManager(this)->GetBuiltinActiveEditor();
 
477
    if (not sEd)
 
478
        return;
 
479
    if (not ((wxWindow*)(sEd->GetControl()) == wxWindow::FindFocus()))
 
480
        return;
 
481
 
 
482
    bool bNext = !(event.GetId() == idSearchFindPrevious);
 
483
    //-Manager::Get()->GetEditorManager()->FindNext(bNext);
 
484
    GetConfig()->GetEditorManager(this)->FindNext(bNext);
 
485
} // end of OnSearchFindNext
 
486
 
 
487
// ----------------------------------------------------------------------------
 
488
bool ThreadSearchFrame::InitXRCStuff()
 
489
// ----------------------------------------------------------------------------
 
490
{
 
491
    if (!Manager::LoadResource(_T("resources.zip")))
 
492
        {
 
493
                ComplainBadInstall();
 
494
                return false;
 
495
        }
 
496
    return true;
 
497
}
 
498
// ----------------------------------------------------------------------------
 
499
void ThreadSearchFrame::ComplainBadInstall()
 
500
// ----------------------------------------------------------------------------
 
501
{
 
502
    wxString msg;
 
503
    msg.Printf(_T("Cannot find resources...\n"
 
504
        "%s was configured to be installed in '%s'.\n"
 
505
        "Please use the command-line switch '--prefix' or "
 
506
        "set the CODEBLOCKS_DATA_DIR environment variable "
 
507
        "to point where %s is installed,\n"
 
508
        "or try re-installing the application..."),
 
509
        _T("CodeSnippetsApp"),
 
510
        ConfigManager::ReadDataPath().c_str(),
 
511
        wxTheApp->GetAppName().c_str());
 
512
    cbMessageBox(msg);
 
513
}
 
514
// ----------------------------------------------------------------------------
 
515
void ThreadSearchFrame::CreateMenuBar()
 
516
// ----------------------------------------------------------------------------
 
517
{
 
518
    // create a menu bar
 
519
    wxMenuBar* mbar = new wxMenuBar();
 
520
    wxMenu* fileMenu = new wxMenu(_T(""));
 
521
    fileMenu->Append(idFileOpen, _("&Open...\tCtrl-O"), _("Open file"));
 
522
    fileMenu->Append(idMenuQuit, _("&Quit\tAlt-F4"), _("Quit the application"));
 
523
    mbar->Append(fileMenu, _("&File"));
 
524
 
 
525
    wxMenu* searchMenu = new wxMenu(_T(""));
 
526
    searchMenu->Append(idSearchFind, _("&Find...\tCtrl-F"), _("Find"));
 
527
    searchMenu->Append(idSearchFindNext, _("Find &Next\tCtrl-N"), _("Find Next"));
 
528
    searchMenu->Append(idSearchFindPrevious, _("Find &Previous\tShift-Ctrl-N"), _("Find Previous"));
 
529
    mbar->Append(searchMenu, _("&Search"));
 
530
 
 
531
    wxMenu* helpMenu = new wxMenu(_T(""));
 
532
    helpMenu->Append(idMenuAbout, _("&About\tF1"), _("Show info about this application"));
 
533
    mbar->Append(helpMenu, _("&Help"));
 
534
 
 
535
    SetMenuBar(mbar);
 
536
}
 
537
// ----------------------------------------------------------------------------
 
538
void ThreadSearchFrame::OnFileOpen(wxCommandEvent& event)
 
539
// ----------------------------------------------------------------------------
 
540
{
 
541
    if (not GetConfig()->GetThreadSearchPlugin() ) return;
 
542
    GetConfig()->GetThreadSearchPlugin()->SplitThreadSearchWindow();
 
543
    DoOnFileOpen(false); // through file menu (not sure if we are opening a project)
 
544
} // end of OnFileOpen
 
545
 
 
546
// ----------------------------------------------------------------------------
 
547
// DoOnFileOpen:
 
548
// in case we are opening a project (bProject == true) we do not want to interfere
 
549
// with 'last type of files' (probably the call was open (existing) project on the
 
550
// start here page --> so we know it's a project --> set the filter accordingly
 
551
// but as said don't force the 'last used type of files' to change, that should
 
552
// only change when an open file is carried out (so (source) file <---> project (file) )
 
553
// TODO : when regular file open and user manually sets filter to project files --> will change
 
554
//      the last type : is that expected behaviour ???
 
555
// ----------------------------------------------------------------------------
 
556
void ThreadSearchFrame::DoOnFileOpen(bool bProject)
 
557
// ----------------------------------------------------------------------------
 
558
{
 
559
    wxString Filters = FileFilters::GetFilterString();
 
560
    // the value returned by GetIndexForFilterAll() is updated by GetFilterString()
 
561
    int StoredIndex = FileFilters::GetIndexForFilterAll();
 
562
    wxString Path;
 
563
    ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("app"));
 
564
    if(mgr)
 
565
    {
 
566
        if(!bProject)
 
567
        {
 
568
            wxString Filter = mgr->Read(_T("/file_dialogs/file_new_open/filter"));
 
569
            if(!Filter.IsEmpty())
 
570
            {
 
571
                FileFilters::GetFilterIndexFromName(Filters, Filter, StoredIndex);
 
572
            }
 
573
            Path = mgr->Read(_T("/file_dialogs/file_new_open/directory"), Path);
 
574
        }
 
575
        else
 
576
        {
 
577
            FileFilters::GetFilterIndexFromName(Filters, _("Code::Blocks project files"), StoredIndex);
 
578
        }
 
579
    }
 
580
    wxFileDialog* dlg = new wxFileDialog(this,
 
581
                            _("Open file"),
 
582
                            Path,
 
583
                            wxEmptyString,
 
584
                            Filters,
 
585
                            wxFD_OPEN | wxFD_MULTIPLE | compatibility::wxHideReadonly);
 
586
    dlg->SetFilterIndex(StoredIndex);
 
587
 
 
588
    PlaceWindow(dlg);
 
589
    if (dlg->ShowModal() == wxID_OK)
 
590
    {
 
591
        // store the last used filter and directory
 
592
        // as said : don't do this in case of an 'open project'
 
593
        if(mgr && !bProject)
 
594
        {
 
595
            int Index = dlg->GetFilterIndex();
 
596
            wxString Filter;
 
597
            if(FileFilters::GetFilterNameFromIndex(Filters, Index, Filter))
 
598
            {
 
599
                mgr->Write(_T("/file_dialogs/file_new_open/filter"), Filter);
 
600
            }
 
601
            wxString Test = dlg->GetDirectory();
 
602
            mgr->Write(_T("/file_dialogs/file_new_open/directory"), dlg->GetDirectory());
 
603
        }
 
604
        wxArrayString files;
 
605
        dlg->GetPaths(files);
 
606
        OnDropFiles(0,0,files);
 
607
    }
 
608
 
 
609
    dlg->Destroy();
 
610
} // end of DoOnFileOpen
 
611
// ----------------------------------------------------------------------------
 
612
bool ThreadSearchFrame::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& files)
 
613
// ----------------------------------------------------------------------------
 
614
{
 
615
    bool success = true; // Safe case initialisation
 
616
 
 
617
    // first check to see if a workspace is passed. If so, only this will be loaded
 
618
    wxString foundWorkspace;
 
619
    for (unsigned int i = 0; i < files.GetCount(); ++i)
 
620
    {
 
621
        FileType ft = FileTypeOf(files[i]);
 
622
        if (ft == ftCodeBlocksWorkspace || ft == ftMSVC6Workspace || ft == ftMSVC7Workspace)
 
623
        {
 
624
            foundWorkspace = files[i];
 
625
            break;
 
626
        }
 
627
    }
 
628
 
 
629
    if (!foundWorkspace.IsEmpty())
 
630
      success &= OpenGeneric(foundWorkspace);
 
631
    else
 
632
    {
 
633
        wxBusyCursor useless;
 
634
        wxPaintEvent e;
 
635
        ProcessEvent(e);
 
636
 
 
637
        Freeze();
 
638
        for (unsigned int i = 0; i < files.GetCount(); ++i)
 
639
          success &= OpenGeneric(files[i]);
 
640
        Thaw();
 
641
    }
 
642
    return success;
 
643
}
 
644
// ----------------------------------------------------------------------------
 
645
bool ThreadSearchFrame::OpenGeneric(const wxString& filename, bool addToHistory)
 
646
// ----------------------------------------------------------------------------
 
647
{
 
648
    if (filename.IsEmpty())
 
649
        return false;
 
650
 
 
651
    // Split the window to show notebook and file panel //(pecan 2008/5/19)
 
652
    if (not GetConfig()->GetThreadSearchPlugin() ) return false;
 
653
    GetConfig()->GetThreadSearchPlugin()->SplitThreadSearchWindow();
 
654
 
 
655
    wxFileName fname(filename);
 
656
    fname.ClearExt();
 
657
    fname.SetExt(_T("cbp"));
 
658
    switch(FileTypeOf(filename))
 
659
    {
 
660
        //
 
661
        // Workspace
 
662
        //
 
663
        ////case ftCodeBlocksWorkspace:
 
664
        ////    // verify that it's not the same as the one already open
 
665
        ////    if (filename != Manager::Get()->GetProjectManager()->GetWorkspace()->GetFilename() &&
 
666
        ////        DoCloseCurrentWorkspace())
 
667
        ////    {
 
668
        ////        wxBusyCursor wait; // loading a worspace can take some time -> showhourglass
 
669
        ////        bool ret = Manager::Get()->GetProjectManager()->LoadWorkspace(filename);
 
670
        ////        if (ret && addToHistory)
 
671
        ////            AddToRecentProjectsHistory(Manager::Get()->GetProjectManager()->GetWorkspace()->GetFilename());
 
672
        ////        return ret;
 
673
        ////    }
 
674
        ////    else
 
675
        ////        return false;
 
676
        ////    break;
 
677
 
 
678
        //
 
679
        // Project
 
680
        //
 
681
        ////case ftCodeBlocksProject:
 
682
        ////{
 
683
        ////    // Make a check whether the project exists in current workspace
 
684
        ////    cbProject* prj = Manager::Get()->GetProjectManager()->IsOpen(fname.GetFullPath());
 
685
        ////    if (!prj)
 
686
        ////    {
 
687
        ////        wxBusyCursor wait; // loading a worspace can take some time -> showhourglass
 
688
        ////        return DoOpenProject(filename, addToHistory);
 
689
        ////    }
 
690
        ////    else
 
691
        ////    {
 
692
        ////        // NOTE (Morten#1#): A message here will prevent batch-builds from working and is shown sometimes even if correct
 
693
        ////        Manager::Get()->GetProjectManager()->SetProject(prj, false);
 
694
        ////        return true;
 
695
        ////    }
 
696
        ////}
 
697
 
 
698
        //
 
699
        // Source files
 
700
        //
 
701
        case ftHeader:
 
702
            // fallthrough
 
703
 
 
704
        case ftSource:
 
705
            // fallthrough
 
706
        case ftResource:
 
707
            return DoOpenFile(filename, addToHistory);
 
708
        //
 
709
        // For all other files, ask MIME plugin for a suitable handler
 
710
        //
 
711
        default:
 
712
        {
 
713
            ////cbMimePlugin* plugin = Manager::Get()->GetPluginManager()->GetMIMEHandlerForFile(filename);
 
714
            ////// warn user that "Files extension handler" is disabled
 
715
            ////if (!plugin)
 
716
            ////{
 
717
            ////    cbMessageBox(_("Could not open file ") + filename + _(",\nbecause no extension handler could be found."), _("Error"), wxICON_ERROR);
 
718
            ////    return false;
 
719
            ////}
 
720
            ////if (plugin->OpenFile(filename) == 0)
 
721
            ////{
 
722
            ////    AddToRecentFilesHistory(filename);
 
723
            ////    return true;
 
724
            ////}
 
725
            ////return false;
 
726
            return DoOpenFile(filename, addToHistory); //(pecan 2008/3/15)
 
727
        }//default
 
728
    }
 
729
    return true;
 
730
}
 
731
// ----------------------------------------------------------------------------
 
732
bool ThreadSearchFrame::DoOpenFile(const wxString& filename, bool addToHistory)
 
733
// ----------------------------------------------------------------------------
 
734
{
 
735
    //-if (Manager::Get()->GetEditorManager()->Open(filename))
 
736
    if ( GetConfig()->GetEditorManager(this)->Open(filename))
 
737
    {
 
738
        if (addToHistory)
 
739
            AddToRecentFilesHistory(filename);
 
740
        return true;
 
741
    }
 
742
    return false;
 
743
}
 
744
// ----------------------------------------------------------------------------
 
745
void ThreadSearchFrame::AddToRecentFilesHistory(const wxString& FileName)
 
746
// ----------------------------------------------------------------------------
 
747
{
 
748
    wxString filename = FileName;
 
749
#ifdef __WXMSW__
 
750
    // for windows, look for case-insensitive matches
 
751
    // if found, don't add it
 
752
    wxString low = filename.Lower();
 
753
    for (size_t i = 0; i < m_pFilesHistory->GetCount(); ++i)
 
754
    {
 
755
        if (low == m_pFilesHistory->GetHistoryFile(i).Lower())
 
756
        {    // it exists, set filename to the existing name, so it can become
 
757
            // the most recent one
 
758
            filename = m_pFilesHistory->GetHistoryFile(i);
 
759
            break;
 
760
        }
 
761
    }
 
762
#endif
 
763
 
 
764
    m_pFilesHistory->AddFileToHistory(filename);
 
765
 
 
766
    // because we append "clear history" menu to the end of the list,
 
767
    // each time we must add a history item we have to:
 
768
    // a) remove "Clear history"
 
769
    // b) clear the menu
 
770
    // c) fill it with the history items
 
771
    // and d) append "Clear history"...
 
772
    wxMenuBar* mbar = GetMenuBar();
 
773
    if (!mbar)
 
774
        return;
 
775
    int pos = mbar->FindMenu(_("&File"));
 
776
    if (pos == wxNOT_FOUND)
 
777
        return;
 
778
    wxMenu* menu = mbar->GetMenu(pos);
 
779
    if (!menu)
 
780
        return;
 
781
    wxMenu* recentFiles = 0;
 
782
    wxMenuItem* clear = menu->FindItem(idFileOpenRecentFileClearHistory, &recentFiles);
 
783
    if (clear && recentFiles)
 
784
    {
 
785
        // a)
 
786
        recentFiles->Remove(clear);
 
787
        // b)
 
788
        m_pFilesHistory->RemoveMenu(recentFiles);
 
789
        while (recentFiles->GetMenuItemCount())
 
790
            recentFiles->Delete(recentFiles->GetMenuItems()[0]);
 
791
        // c)
 
792
        m_pFilesHistory->UseMenu(recentFiles);
 
793
        m_pFilesHistory->AddFilesToMenu(recentFiles);
 
794
        // d)
 
795
        if (recentFiles->GetMenuItemCount())
 
796
            recentFiles->AppendSeparator();
 
797
        recentFiles->Append(clear);
 
798
    }
 
799
 
 
800
    // update start here page
 
801
    ////EditorBase* sh = Manager::Get()->GetEditorManager()->GetEditor(g_StartHereTitle);
 
802
    ////if (sh)
 
803
    ////    ((StartHerePage*)sh)->Reload();
 
804
}
 
805
// ----------------------------------------------------------------------------
 
806
void ThreadSearchFrame::InitializeRecentFilesHistory()
 
807
// ----------------------------------------------------------------------------
 
808
{
 
809
    TerminateRecentFilesHistory();
 
810
 
 
811
    wxMenuBar* mbar = GetMenuBar();
 
812
    if (!mbar)
 
813
        return;
 
814
    int pos = mbar->FindMenu(_("&File"));
 
815
    if (pos != wxNOT_FOUND)
 
816
    {
 
817
        m_pFilesHistory = new wxFileHistory(9, wxID_FILE1);
 
818
 
 
819
        wxMenu* menu = mbar->GetMenu(pos);
 
820
        if (!menu)
 
821
            return;
 
822
        wxMenu* recentFiles = 0;
 
823
        wxMenuItem* clear = menu->FindItem(idFileOpenRecentFileClearHistory, &recentFiles);
 
824
        if (recentFiles)
 
825
        {
 
826
            recentFiles->Remove(clear);
 
827
 
 
828
            wxArrayString files = Manager::Get()->GetConfigManager(_T("app"))->ReadArrayString(_T("/recent_files"));
 
829
            for (int i = (int)files.GetCount() - 1; i >= 0; --i)
 
830
            {
 
831
                if(wxFileExists(files[i]))
 
832
                    m_pFilesHistory->AddFileToHistory(files[i]);
 
833
            }
 
834
            m_pFilesHistory->UseMenu(recentFiles);
 
835
            m_pFilesHistory->AddFilesToMenu(recentFiles);
 
836
            if (recentFiles->GetMenuItemCount())
 
837
                recentFiles->AppendSeparator();
 
838
            recentFiles->Append(clear);
 
839
        }
 
840
        wxMenu* recentProjects = 0;
 
841
        clear = menu->FindItem(idFileOpenRecentProjectClearHistory, &recentProjects);
 
842
        if (recentProjects)
 
843
        {
 
844
            m_pProjectsHistory = new wxFileHistory(9, wxID_FILE10);
 
845
            recentProjects->Remove(clear);
 
846
 
 
847
            wxArrayString files = Manager::Get()->GetConfigManager(_T("app"))->ReadArrayString(_T("/recent_projects"));
 
848
            for (int i = (int)files.GetCount() - 1; i >= 0; --i)
 
849
            {
 
850
                if(wxFileExists(files[i]))
 
851
                    m_pProjectsHistory->AddFileToHistory(files[i]);
 
852
            }
 
853
            m_pProjectsHistory->UseMenu(recentProjects);
 
854
            m_pProjectsHistory->AddFilesToMenu(recentProjects);
 
855
            if (recentProjects->GetMenuItemCount())
 
856
                recentProjects->AppendSeparator();
 
857
            recentProjects->Append(clear);
 
858
        }
 
859
    }
 
860
}
 
861
// ----------------------------------------------------------------------------
 
862
void ThreadSearchFrame::TerminateRecentFilesHistory()
 
863
// ----------------------------------------------------------------------------
 
864
{
 
865
    if (m_pFilesHistory)
 
866
    {
 
867
        wxArrayString files;
 
868
        for (unsigned int i = 0; i < m_pFilesHistory->GetCount(); ++i)
 
869
            files.Add(m_pFilesHistory->GetHistoryFile(i));
 
870
        Manager::Get()->GetConfigManager(_T("app"))->Write(_T("/recent_files"), files);
 
871
 
 
872
        wxMenuBar* mbar = GetMenuBar();
 
873
        if (mbar)
 
874
        {
 
875
            int pos = mbar->FindMenu(_("&File"));
 
876
            if (pos != wxNOT_FOUND)
 
877
            {
 
878
                wxMenu* menu = mbar->GetMenu(pos);
 
879
                if (menu)
 
880
                {
 
881
                    wxMenu* recentFiles = 0;
 
882
                    menu->FindItem(idFileOpenRecentFileClearHistory, &recentFiles);
 
883
                    if (recentFiles)
 
884
                        m_pFilesHistory->RemoveMenu(recentFiles);
 
885
                }
 
886
            }
 
887
        }
 
888
        delete m_pFilesHistory;
 
889
        m_pFilesHistory = 0;
 
890
    }
 
891
 
 
892
    if (m_pProjectsHistory)
 
893
    {
 
894
        wxArrayString files;
 
895
        for (unsigned int i = 0; i < m_pProjectsHistory->GetCount(); ++i)
 
896
            files.Add(m_pProjectsHistory->GetHistoryFile(i));
 
897
        Manager::Get()->GetConfigManager(_T("app"))->Write(_T("/recent_projects"), files);
 
898
 
 
899
        wxMenuBar* mbar = GetMenuBar();
 
900
        if (mbar)
 
901
        {
 
902
            int pos = mbar->FindMenu(_("&File"));
 
903
            if (pos != wxNOT_FOUND)
 
904
            {
 
905
                wxMenu* menu = mbar->GetMenu(pos);
 
906
                if (menu)
 
907
                {
 
908
                    wxMenu* recentProjects = 0;
 
909
                    menu->FindItem(idFileOpenRecentProjectClearHistory, &recentProjects);
 
910
                    if (recentProjects)
 
911
                        m_pProjectsHistory->RemoveMenu(recentProjects);
 
912
                }
 
913
            }
 
914
        }
 
915
        delete m_pProjectsHistory;
 
916
        m_pProjectsHistory = 0;
 
917
    }
 
918
}
 
919
// ----------------------------------------------------------------------------
 
920
void ThreadSearchFrame::OnCodeSnippetsNewIndex(CodeSnippetsEvent& event)
 
921
// ----------------------------------------------------------------------------
 
922
{
 
923
    #if defined(LOGGING)
 
924
    LOGIT( _T("ThreadSearchFrame::OnCodeSnippetsNewIndex id[%d]str[%s]"), event.GetSnippetID(), event.GetSnippetString().c_str());
 
925
    #endif
 
926
 
 
927
    event.Skip();
 
928
    return;
 
929
}
 
930
// ----------------------------------------------------------------------------
 
931
void ThreadSearchFrame::OnWindowDestroy(wxEvent& event)
 
932
// ----------------------------------------------------------------------------
 
933
{
 
934
    // wxEVT_DESTROY entry
 
935
 
 
936
    wxWindow* pWindow = (wxWindow*)(event.GetEventObject());
 
937
 
 
938
    if ( (pWindow) && (pWindow->GetName() == _T("SCIwindow")))
 
939
    {
 
940
        #ifdef LOGGING
 
941
         LOGIT( _T("ThreadSearchFrame::OnWindowDestroy [%p]"), pWindow);
 
942
        #endif //LOGGING
 
943
        int count = GetConfig()->GetEditorManager(this)->GetEditorsCount();
 
944
        if (count == 1) //closing last window
 
945
            GetConfig()->GetThreadSearchPlugin()->UnsplitThreadSearchWindow();
 
946
    }
 
947
    event.Skip();
 
948
}//OnWindowClose
 
949
// ----------------------------------------------------------------------------
 
950
void ThreadSearchFrame::OnFrameActivated(wxActivateEvent& event)
 
951
// ----------------------------------------------------------------------------
 
952
{
 
953
    // This frame has been activated
 
954
 
 
955
    if ( m_bOnActivateBusy ) {event.Skip();return;}
 
956
    ++m_bOnActivateBusy;
 
957
 
 
958
    // Check that it's us that got activated
 
959
    if ( event.GetActive() )
 
960
      do { //only once
 
961
 
 
962
        // Check that CodeSnippets actually has a file open
 
963
        if (not GetConfig()->GetSnippetsWindow() )  break;
 
964
        if (not GetConfig()->GetSnippetsTreeCtrl() ) break;
 
965
 
 
966
        #if defined(LOGGING)
 
967
        LOGIT( _T("ThreadSearchFrame::OnAppActivate"));
 
968
        #endif
 
969
        //-if  ( (GetConfig()->GetEditorManagerCount() ) <--causes loop betwn ThreadSearchFrame and EditSnippetFrame
 
970
        if  ( (GetConfig()->GetEditorManager(this) )
 
971
              && (Manager::Get()->GetConfigManager(_T("app"))->ReadBool(_T("/environment/check_modified_files"), true))
 
972
            )
 
973
            //-for (int i = 0; i < GetConfig()->GetEditorManagerCount(); ++i) <--causes loop betwn ThreadSearchFrame and EditSnippetFrame
 
974
            {
 
975
                // for some reason a mouse up event doesnt make it into scintilla (scintilla bug)
 
976
                // therefor the workaournd is not to directly call the editorManager, but
 
977
                // take a detour through an event
 
978
                // the bug is when the file has been offered to reload, no matter what answer you
 
979
                // give the mouse is in a selecting mode, adding/removing things to it's selection as you
 
980
                // move it around
 
981
                // so : idEditorManagerCheckFiles, EditorManager::OnCheckForModifiedFiles just exist for this workaround
 
982
 
 
983
                // If SEditorManager belongs to this frame, check for modified files
 
984
                wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED, idSEditorManagerCheckFiles);
 
985
                //-wxPostEvent(GetConfig()->GetEditorManager(i), evt);
 
986
                wxPostEvent(GetConfig()->GetEditorManager(this), evt);
 
987
                //-GetConfig()->GetEditorManager(i)->ProcessEvent( evt);
 
988
            }
 
989
    }while(0); //do only once
 
990
 
 
991
    m_bOnActivateBusy = 0;
 
992
    event.Skip();
 
993
    return;
 
994
}
 
995
// ----------------------------------------------------------------------------