1
/***************************************************************
2
* Name: SnipSearchAppMain.cpp
3
* Purpose: Code for Application Frame
8
**************************************************************/
18
#include <wx/filesys.h>
19
#include <wx/fs_zip.h>
20
#include <wx/fs_mem.h>
21
#include <wx/xrc/xmlres.h>
24
#include "cbauibook.h"
27
#include <filefilters.h>
28
#include <cbworkspace.h>
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"
38
#include "snippetsconfig.h"
39
#include "codesnippetswindow.h"
40
#include "seditormanager.h"
41
#include "scbeditor.h"
43
// ----------------------------------------------------------------------------
44
class wxMyFileDropTarget : public wxFileDropTarget
45
// ----------------------------------------------------------------------------
48
wxMyFileDropTarget(ThreadSearchFrame *frame):m_frame(frame){}
49
virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames)
51
if(!m_frame) return false;
52
return m_frame->OnDropFiles(x,y,filenames);
55
ThreadSearchFrame* m_frame;
58
// ----------------------------------------------------------------------------
60
// ----------------------------------------------------------------------------
63
enum wxbuildinfoformat {
66
wxString wxbuildinfo(wxbuildinfoformat format)
68
wxString wxbuild(wxVERSION_STRING);
70
if (format == long_f )
72
#if defined(__WXMSW__)
73
wxbuild << _T("-Windows");
74
#elif defined(__WXMAC__)
75
wxbuild << _T("-Mac");
76
#elif defined(__UNIX__)
77
wxbuild << _T("-Linux");
81
wxbuild << _T("-Unicode build");
83
wxbuild << _T("-ANSI build");
84
#endif // wxUSE_UNICODE
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();
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();
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");
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");
217
// ----------------------------------------------------------------------------
219
// ----------------------------------------------------------------------------
220
BEGIN_EVENT_TABLE(ThreadSearchFrame, wxFrame)
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)
228
EVT_MENU(idFileOpen, ThreadSearchFrame::OnFileOpen)
233
EVT_MENU(idSearchFind, ThreadSearchFrame::OnSearchFind)
234
EVT_MENU(idSearchFindInFiles, ThreadSearchFrame::OnSearchFind)
235
EVT_MENU(idSearchFindNext, ThreadSearchFrame::OnSearchFindNext)
236
EVT_MENU(idSearchFindPrevious, ThreadSearchFrame::OnSearchFindNext)
238
EVT_CODESNIPPETS_NEW_INDEX (wxID_ANY, ThreadSearchFrame::OnCodeSnippetsNewIndex)
242
// ----------------------------------------------------------------------------
243
ThreadSearchFrame::ThreadSearchFrame(wxFrame* appFrame, const wxString& title)
244
// ----------------------------------------------------------------------------
245
: wxFrame(appFrame, -1, title)
247
,m_pProjectsHistory(0)
248
,m_bOnActivateBusy(0)
251
bool ok = InitThreadSearchFrame( appFrame, title);
254
// ----------------------------------------------------------------------------
255
bool ThreadSearchFrame::InitThreadSearchFrame(wxFrame* appFrame, const wxString& title)
256
// ----------------------------------------------------------------------------
258
GetConfig()->SetThreadSearchFrame( this );
263
// create a status bar with some information about the used wxWidgets version
265
SetStatusText(_("CodeSnippets Search"),0);
266
SetStatusText(wxbuildinfo(short_f), 1);
268
InitializeRecentFilesHistory(); // -not used yet-
270
// allocate a separate EditorManager/Notebook
271
if (not GetConfig()->GetEditorManager(this))
273
SEditorManager* m_pEdMan = new SEditorManager(this);
274
GetConfig()->RegisterEditorManager(this, m_pEdMan);
275
}//if GetEditorManager
277
// create ThreadSearch and alter its menu items
278
m_pThreadSearch = new ThreadSearch( this );
279
if ( m_pThreadSearch ) do
281
m_pThreadSearch->ThreadSearch::m_IsAttached = true;
282
m_pThreadSearch->OnAttach();
283
PushEventHandler(m_pThreadSearch);
284
m_pThreadSearch->SetEvtHandlerEnabled( true );
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);
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 );
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);
314
// Catch Destroyed windows
315
Connect( wxEVT_DESTROY,
316
(wxObjectEventFunction) (wxEventFunction)
317
(wxCommandEventFunction) &ThreadSearchFrame::OnWindowDestroy);
319
// Allow filenames to be dropped/opened on ThreadSearchFrame
320
SetDropTarget(new wxMyFileDropTarget(this));
321
GetConfig()->GetEditorManager(this)->GetNotebook()->SetDropTarget(new wxMyFileDropTarget(this));
323
}while(false);//if m_pThreadSearch do
325
return m_pThreadSearch;
327
}//initThreadSearchFrame ctor
328
// ----------------------------------------------------------------------------
329
ThreadSearchFrame::~ThreadSearchFrame()
330
// ----------------------------------------------------------------------------
333
Disconnect( wxEVT_DESTROY,
334
(wxObjectEventFunction) (wxEventFunction)
335
(wxCommandEventFunction) &ThreadSearchFrame::OnWindowDestroy);
337
GetConfig()->SetThreadSearchFrame(0);
339
// ----------------------------------------------------------------------------
340
void ThreadSearchFrame::OnMenuOptions(wxCommandEvent& event)
341
// ----------------------------------------------------------------------------
343
//m_pThreadSearch->m_pThreadSearchView->OnBtnOptionsClick(event);
344
m_pThreadSearch->Configure();
346
// ----------------------------------------------------------------------------
347
void ThreadSearchFrame::OnClose(wxCloseEvent &event)
348
// ----------------------------------------------------------------------------
350
this->Show(false); //avoid fragmented disappearing windows
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);
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);
370
int knt = pEdMan->GetEditorsCount();
371
for ( int i=knt; i>0; --i )
373
ed = (ScbEditor*)pEdMan->GetEditor(i-1);
374
if ( ed ) ed->Close();
379
// reverse splitterwindow switches and reparenting
380
if (m_pThreadSearch){
381
RemoveEventHandler(m_pThreadSearch);
382
m_pThreadSearch->OnRelease(true);
385
// free separate editor manager
386
SEditorManager* m_pEdMan = GetConfig()->GetEditorManager(this);
389
RemoveEventHandler( m_pEdMan ); // *do this or crash @ Destroy()*
391
GetConfig()->RemoveEditorManager((wxFrame*)this);
393
// free ThreadSearch plugin/evtHandler
394
if ( m_pThreadSearch ){
395
delete m_pThreadSearch; // deletes ThreadSearch wxEvtHandler object
399
// release memory in FileLinks array used by ThreadSearch
400
GetConfig()->ClearFileLinksMapArray();
402
//- write the configuation file
403
//- Don't free Manager unless we initialized it. which we didn't.
405
//-GetConfig()->GetSnippetsWindow()->CloseThreadSearchFrame();
409
// ----------------------------------------------------------------------------
410
void ThreadSearchFrame::OnQuit(wxCommandEvent &event)
411
// ----------------------------------------------------------------------------
415
// ----------------------------------------------------------------------------
416
void ThreadSearchFrame::OnAbout(wxCommandEvent &event)
417
// ----------------------------------------------------------------------------
419
wxString msg = wxbuildinfo(long_f);
421
msg << _T("Original ThreadSearch code by Jerome Antoine \n");
422
msg << _T("Ported to CodeSnippets by Pecan Heber \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");
427
msg << _T("Double clicking a CodeSnippets \"Category\" log item \n");
428
msg << _T("simple highlights the item in the index (tree) window. \n");
430
wxMessageBox(msg, _("Welcome to..."));
432
// ----------------------------------------------------------------------------
433
void ThreadSearchFrame::OnSizeWindow(wxSizeEvent &event)
434
// ----------------------------------------------------------------------------
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
440
LOGIT( _T("ThreadSearchFrame::OnSizeWindow"));
444
if (not GetConfig()->GetThreadSearchPlugin() ) return;
445
GetConfig()->GetThreadSearchPlugin()->UserResizingWindow(event);
449
// ----------------------------------------------------------------------------
450
void ThreadSearchFrame::OnSearchFind(wxCommandEvent& event)
451
// ----------------------------------------------------------------------------
454
//Don't search in preview pane, and don't search if no editor is open
455
ScbEditor* sEd = GetConfig()->GetEditorManager(this)->GetBuiltinActiveEditor();
458
if (not ((wxWindow*)(sEd->GetControl()) == wxWindow::FindFocus()))
461
bool bDoMultipleFiles = (event.GetId() == idSearchFindInFiles);
462
if(!bDoMultipleFiles)
464
//-bDoMultipleFiles = !Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
465
bDoMultipleFiles = not GetConfig()->GetEditorManager(this)->GetBuiltinActiveEditor();
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
// ----------------------------------------------------------------------------
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();
479
if (not ((wxWindow*)(sEd->GetControl()) == wxWindow::FindFocus()))
482
bool bNext = !(event.GetId() == idSearchFindPrevious);
483
//-Manager::Get()->GetEditorManager()->FindNext(bNext);
484
GetConfig()->GetEditorManager(this)->FindNext(bNext);
485
} // end of OnSearchFindNext
487
// ----------------------------------------------------------------------------
488
bool ThreadSearchFrame::InitXRCStuff()
489
// ----------------------------------------------------------------------------
491
if (!Manager::LoadResource(_T("resources.zip")))
493
ComplainBadInstall();
498
// ----------------------------------------------------------------------------
499
void ThreadSearchFrame::ComplainBadInstall()
500
// ----------------------------------------------------------------------------
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());
514
// ----------------------------------------------------------------------------
515
void ThreadSearchFrame::CreateMenuBar()
516
// ----------------------------------------------------------------------------
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"));
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"));
531
wxMenu* helpMenu = new wxMenu(_T(""));
532
helpMenu->Append(idMenuAbout, _("&About\tF1"), _("Show info about this application"));
533
mbar->Append(helpMenu, _("&Help"));
537
// ----------------------------------------------------------------------------
538
void ThreadSearchFrame::OnFileOpen(wxCommandEvent& event)
539
// ----------------------------------------------------------------------------
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
546
// ----------------------------------------------------------------------------
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
// ----------------------------------------------------------------------------
559
wxString Filters = FileFilters::GetFilterString();
560
// the value returned by GetIndexForFilterAll() is updated by GetFilterString()
561
int StoredIndex = FileFilters::GetIndexForFilterAll();
563
ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("app"));
568
wxString Filter = mgr->Read(_T("/file_dialogs/file_new_open/filter"));
569
if(!Filter.IsEmpty())
571
FileFilters::GetFilterIndexFromName(Filters, Filter, StoredIndex);
573
Path = mgr->Read(_T("/file_dialogs/file_new_open/directory"), Path);
577
FileFilters::GetFilterIndexFromName(Filters, _("Code::Blocks project files"), StoredIndex);
580
wxFileDialog* dlg = new wxFileDialog(this,
585
wxFD_OPEN | wxFD_MULTIPLE | compatibility::wxHideReadonly);
586
dlg->SetFilterIndex(StoredIndex);
589
if (dlg->ShowModal() == wxID_OK)
591
// store the last used filter and directory
592
// as said : don't do this in case of an 'open project'
595
int Index = dlg->GetFilterIndex();
597
if(FileFilters::GetFilterNameFromIndex(Filters, Index, Filter))
599
mgr->Write(_T("/file_dialogs/file_new_open/filter"), Filter);
601
wxString Test = dlg->GetDirectory();
602
mgr->Write(_T("/file_dialogs/file_new_open/directory"), dlg->GetDirectory());
605
dlg->GetPaths(files);
606
OnDropFiles(0,0,files);
610
} // end of DoOnFileOpen
611
// ----------------------------------------------------------------------------
612
bool ThreadSearchFrame::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& files)
613
// ----------------------------------------------------------------------------
615
bool success = true; // Safe case initialisation
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)
621
FileType ft = FileTypeOf(files[i]);
622
if (ft == ftCodeBlocksWorkspace || ft == ftMSVC6Workspace || ft == ftMSVC7Workspace)
624
foundWorkspace = files[i];
629
if (!foundWorkspace.IsEmpty())
630
success &= OpenGeneric(foundWorkspace);
633
wxBusyCursor useless;
638
for (unsigned int i = 0; i < files.GetCount(); ++i)
639
success &= OpenGeneric(files[i]);
644
// ----------------------------------------------------------------------------
645
bool ThreadSearchFrame::OpenGeneric(const wxString& filename, bool addToHistory)
646
// ----------------------------------------------------------------------------
648
if (filename.IsEmpty())
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();
655
wxFileName fname(filename);
657
fname.SetExt(_T("cbp"));
658
switch(FileTypeOf(filename))
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())
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());
681
////case ftCodeBlocksProject:
683
//// // Make a check whether the project exists in current workspace
684
//// cbProject* prj = Manager::Get()->GetProjectManager()->IsOpen(fname.GetFullPath());
687
//// wxBusyCursor wait; // loading a worspace can take some time -> showhourglass
688
//// return DoOpenProject(filename, addToHistory);
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);
707
return DoOpenFile(filename, addToHistory);
709
// For all other files, ask MIME plugin for a suitable handler
713
////cbMimePlugin* plugin = Manager::Get()->GetPluginManager()->GetMIMEHandlerForFile(filename);
714
////// warn user that "Files extension handler" is disabled
717
//// cbMessageBox(_("Could not open file ") + filename + _(",\nbecause no extension handler could be found."), _("Error"), wxICON_ERROR);
720
////if (plugin->OpenFile(filename) == 0)
722
//// AddToRecentFilesHistory(filename);
726
return DoOpenFile(filename, addToHistory); //(pecan 2008/3/15)
731
// ----------------------------------------------------------------------------
732
bool ThreadSearchFrame::DoOpenFile(const wxString& filename, bool addToHistory)
733
// ----------------------------------------------------------------------------
735
//-if (Manager::Get()->GetEditorManager()->Open(filename))
736
if ( GetConfig()->GetEditorManager(this)->Open(filename))
739
AddToRecentFilesHistory(filename);
744
// ----------------------------------------------------------------------------
745
void ThreadSearchFrame::AddToRecentFilesHistory(const wxString& FileName)
746
// ----------------------------------------------------------------------------
748
wxString filename = FileName;
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)
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);
764
m_pFilesHistory->AddFileToHistory(filename);
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"
770
// c) fill it with the history items
771
// and d) append "Clear history"...
772
wxMenuBar* mbar = GetMenuBar();
775
int pos = mbar->FindMenu(_("&File"));
776
if (pos == wxNOT_FOUND)
778
wxMenu* menu = mbar->GetMenu(pos);
781
wxMenu* recentFiles = 0;
782
wxMenuItem* clear = menu->FindItem(idFileOpenRecentFileClearHistory, &recentFiles);
783
if (clear && recentFiles)
786
recentFiles->Remove(clear);
788
m_pFilesHistory->RemoveMenu(recentFiles);
789
while (recentFiles->GetMenuItemCount())
790
recentFiles->Delete(recentFiles->GetMenuItems()[0]);
792
m_pFilesHistory->UseMenu(recentFiles);
793
m_pFilesHistory->AddFilesToMenu(recentFiles);
795
if (recentFiles->GetMenuItemCount())
796
recentFiles->AppendSeparator();
797
recentFiles->Append(clear);
800
// update start here page
801
////EditorBase* sh = Manager::Get()->GetEditorManager()->GetEditor(g_StartHereTitle);
803
//// ((StartHerePage*)sh)->Reload();
805
// ----------------------------------------------------------------------------
806
void ThreadSearchFrame::InitializeRecentFilesHistory()
807
// ----------------------------------------------------------------------------
809
TerminateRecentFilesHistory();
811
wxMenuBar* mbar = GetMenuBar();
814
int pos = mbar->FindMenu(_("&File"));
815
if (pos != wxNOT_FOUND)
817
m_pFilesHistory = new wxFileHistory(9, wxID_FILE1);
819
wxMenu* menu = mbar->GetMenu(pos);
822
wxMenu* recentFiles = 0;
823
wxMenuItem* clear = menu->FindItem(idFileOpenRecentFileClearHistory, &recentFiles);
826
recentFiles->Remove(clear);
828
wxArrayString files = Manager::Get()->GetConfigManager(_T("app"))->ReadArrayString(_T("/recent_files"));
829
for (int i = (int)files.GetCount() - 1; i >= 0; --i)
831
if(wxFileExists(files[i]))
832
m_pFilesHistory->AddFileToHistory(files[i]);
834
m_pFilesHistory->UseMenu(recentFiles);
835
m_pFilesHistory->AddFilesToMenu(recentFiles);
836
if (recentFiles->GetMenuItemCount())
837
recentFiles->AppendSeparator();
838
recentFiles->Append(clear);
840
wxMenu* recentProjects = 0;
841
clear = menu->FindItem(idFileOpenRecentProjectClearHistory, &recentProjects);
844
m_pProjectsHistory = new wxFileHistory(9, wxID_FILE10);
845
recentProjects->Remove(clear);
847
wxArrayString files = Manager::Get()->GetConfigManager(_T("app"))->ReadArrayString(_T("/recent_projects"));
848
for (int i = (int)files.GetCount() - 1; i >= 0; --i)
850
if(wxFileExists(files[i]))
851
m_pProjectsHistory->AddFileToHistory(files[i]);
853
m_pProjectsHistory->UseMenu(recentProjects);
854
m_pProjectsHistory->AddFilesToMenu(recentProjects);
855
if (recentProjects->GetMenuItemCount())
856
recentProjects->AppendSeparator();
857
recentProjects->Append(clear);
861
// ----------------------------------------------------------------------------
862
void ThreadSearchFrame::TerminateRecentFilesHistory()
863
// ----------------------------------------------------------------------------
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);
872
wxMenuBar* mbar = GetMenuBar();
875
int pos = mbar->FindMenu(_("&File"));
876
if (pos != wxNOT_FOUND)
878
wxMenu* menu = mbar->GetMenu(pos);
881
wxMenu* recentFiles = 0;
882
menu->FindItem(idFileOpenRecentFileClearHistory, &recentFiles);
884
m_pFilesHistory->RemoveMenu(recentFiles);
888
delete m_pFilesHistory;
892
if (m_pProjectsHistory)
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);
899
wxMenuBar* mbar = GetMenuBar();
902
int pos = mbar->FindMenu(_("&File"));
903
if (pos != wxNOT_FOUND)
905
wxMenu* menu = mbar->GetMenu(pos);
908
wxMenu* recentProjects = 0;
909
menu->FindItem(idFileOpenRecentProjectClearHistory, &recentProjects);
911
m_pProjectsHistory->RemoveMenu(recentProjects);
915
delete m_pProjectsHistory;
916
m_pProjectsHistory = 0;
919
// ----------------------------------------------------------------------------
920
void ThreadSearchFrame::OnCodeSnippetsNewIndex(CodeSnippetsEvent& event)
921
// ----------------------------------------------------------------------------
924
LOGIT( _T("ThreadSearchFrame::OnCodeSnippetsNewIndex id[%d]str[%s]"), event.GetSnippetID(), event.GetSnippetString().c_str());
930
// ----------------------------------------------------------------------------
931
void ThreadSearchFrame::OnWindowDestroy(wxEvent& event)
932
// ----------------------------------------------------------------------------
934
// wxEVT_DESTROY entry
936
wxWindow* pWindow = (wxWindow*)(event.GetEventObject());
938
if ( (pWindow) && (pWindow->GetName() == _T("SCIwindow")))
941
LOGIT( _T("ThreadSearchFrame::OnWindowDestroy [%p]"), pWindow);
943
int count = GetConfig()->GetEditorManager(this)->GetEditorsCount();
944
if (count == 1) //closing last window
945
GetConfig()->GetThreadSearchPlugin()->UnsplitThreadSearchWindow();
949
// ----------------------------------------------------------------------------
950
void ThreadSearchFrame::OnFrameActivated(wxActivateEvent& event)
951
// ----------------------------------------------------------------------------
953
// This frame has been activated
955
if ( m_bOnActivateBusy ) {event.Skip();return;}
958
// Check that it's us that got activated
959
if ( event.GetActive() )
962
// Check that CodeSnippets actually has a file open
963
if (not GetConfig()->GetSnippetsWindow() ) break;
964
if (not GetConfig()->GetSnippetsTreeCtrl() ) break;
967
LOGIT( _T("ThreadSearchFrame::OnAppActivate"));
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))
973
//-for (int i = 0; i < GetConfig()->GetEditorManagerCount(); ++i) <--causes loop betwn ThreadSearchFrame and EditSnippetFrame
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
981
// so : idEditorManagerCheckFiles, EditorManager::OnCheckForModifiedFiles just exist for this workaround
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);
989
}while(0); //do only once
991
m_bOnActivateBusy = 0;
995
// ----------------------------------------------------------------------------