391
391
bool MainBook::SelectPage(wxWindow *win)
393
393
size_t index = m_book->GetPageIndex(win);
394
std::set<wxWindow*>::iterator i = m_detachedTabs.find(win);
394
std::set<wxWindow*>::iterator i = m_detachedTabs.find(win);
396
396
if (index != Notebook::npos) {
397
m_book->SetSelection(index);
398
} else if (i != m_detachedTabs.end()) {
400
} else if (win == NULL) {
401
// OK -- deselecting any page
397
m_book->SetSelection(index);
398
} else if (i != m_detachedTabs.end()) {
400
} else if (win == NULL) {
401
// OK -- deselecting any page
407
407
LEditor *editor = dynamic_cast<LEditor*>(win);
409
// FIXME: move special context-specific menu handling to the Context classes?
410
// it could be done inside the existing ContextXXX::SetActive() method.
411
if (!editor || editor->GetContext()->GetName() != wxT("C++")) {
412
int idx = Frame::Get()->GetMenuBar()->FindMenu(wxT("C++"));
413
if ( idx != wxNOT_FOUND ) {
414
delete Frame::Get()->GetMenuBar()->Remove(idx);
409
// FIXME: move special context-specific menu handling to the Context classes?
410
// it could be done inside the existing ContextXXX::SetActive() method.
411
if (!editor || editor->GetContext()->GetName() != wxT("C++")) {
412
int idx = Frame::Get()->GetMenuBar()->FindMenu(wxT("C++"));
413
if ( idx != wxNOT_FOUND ) {
414
delete Frame::Get()->GetMenuBar()->Remove(idx);
419
419
Frame::Get()->SetFrameTitle(NULL);
420
420
Frame::Get()->SetStatusMessage(wxEmptyString, 2); // clear line & column indicator
421
421
Frame::Get()->SetStatusMessage(wxEmptyString, 3); // clear end-of-line mode indicator
422
422
UpdateNavBar(NULL);
425
if (editor->GetContext()->GetName() == wxT("C++")) {
426
if (Frame::Get()->GetMenuBar()->FindMenu(wxT("C++")) == wxNOT_FOUND) {
427
Frame::Get()->GetMenuBar()->Append(wxXmlResource::Get()->LoadMenu(wxT("editor_right_click")), wxT("C++"));
430
SendCmdEvent(wxEVT_ACTIVE_EDITOR_CHANGED, (IEditor*)editor);
425
if (editor->GetContext()->GetName() == wxT("C++")) {
426
if (Frame::Get()->GetMenuBar()->FindMenu(wxT("C++")) == wxNOT_FOUND) {
427
Frame::Get()->GetMenuBar()->Append(wxXmlResource::Get()->LoadMenu(wxT("editor_right_click")), wxT("C++"));
430
SendCmdEvent(wxEVT_ACTIVE_EDITOR_CHANGED, (IEditor*)editor);
436
436
bool MainBook::DetachPage(wxWindow* win)
440
size_t pos = m_book->GetPageIndex(win);
441
if (pos == Notebook::npos)
443
wxAuiPaneInfo info = wxAuiPaneInfo().Name(m_book->GetPageText(pos)).Caption(m_book->GetPageText(pos))
444
.BestSize(win->GetSize()).Float();
445
m_book->RemovePage(pos, false);
446
Frame::Get()->GetDockingManager().AddPane(win, info);
447
Frame::Get()->GetDockingManager().Update();
448
m_detachedTabs.insert(win);
440
size_t pos = m_book->GetPageIndex(win);
441
if (pos == Notebook::npos)
443
wxAuiPaneInfo info = wxAuiPaneInfo().Name(m_book->GetPageText(pos)).Caption(m_book->GetPageText(pos))
444
.BestSize(win->GetSize()).Float();
445
m_book->RemovePage(pos, false);
446
Frame::Get()->GetDockingManager().AddPane(win, info);
447
Frame::Get()->GetDockingManager().Update();
448
m_detachedTabs.insert(win);
449
wxAuiFloatingFrame *frm = dynamic_cast<wxAuiFloatingFrame*>(win->GetParent());
451
wxAcceleratorTable *acclTable = Frame::Get()->GetAcceleratorTable();
452
((wxFrame*)frm)->SetAcceleratorTable(*acclTable);
452
457
bool MainBook::DockPage(wxWindow* win)
454
std::set<wxWindow*>::iterator i = m_detachedTabs.find(win);
455
if (i == m_detachedTabs.end())
457
m_detachedTabs.erase(i);
458
wxAuiPaneInfo info = Frame::Get()->GetDockingManager().GetPane(win);
459
Frame::Get()->GetDockingManager().DetachPane(win);
460
Frame::Get()->GetDockingManager().Update();
461
m_book->AddPage(win, info.caption);
459
std::set<wxWindow*>::iterator i = m_detachedTabs.find(win);
460
if (i == m_detachedTabs.end())
462
m_detachedTabs.erase(i);
463
wxAuiPaneInfo info = Frame::Get()->GetDockingManager().GetPane(win);
464
Frame::Get()->GetDockingManager().DetachPane(win);
465
Frame::Get()->GetDockingManager().Update();
466
m_book->AddPage(win, info.caption);
465
470
bool MainBook::IsDetached(wxWindow* win)
467
return m_detachedTabs.find(win) != m_detachedTabs.end();
472
return m_detachedTabs.find(win) != m_detachedTabs.end();
470
bool MainBook::UserSelectFiles(std::vector<std::pair<wxFileName,bool> > &files, const wxString &title,
475
bool MainBook::UserSelectFiles(std::vector<std::pair<wxFileName,bool> > &files, const wxString &title,
471
476
const wxString &caption, bool cancellable)
476
FileCheckList dlg(this, wxID_ANY, title);
477
dlg.SetCaption(caption);
479
dlg.SetCancellable(cancellable);
480
bool res = dlg.ShowModal() == wxID_OK;
481
files = dlg.GetFiles();
481
FileCheckList dlg(this, wxID_ANY, title);
482
dlg.SetCaption(caption);
484
dlg.SetCancellable(cancellable);
485
bool res = dlg.ShowModal() == wxID_OK;
486
files = dlg.GetFiles();
485
490
bool MainBook::SaveAll(bool askUser, bool includeUntitled)
487
std::vector<LEditor*> editors;
488
GetAllEditors(editors);
490
std::vector<std::pair<wxFileName, bool> > files;
492
std::vector<LEditor*> editors;
493
GetAllEditors(editors);
495
std::vector<std::pair<wxFileName, bool> > files;
492
497
for (size_t i = 0; i < editors.size(); i++) {
493
498
if (!editors[i]->GetModify())
495
if (!includeUntitled && editors[i]->GetFileName().GetFullPath().StartsWith(wxT("Untitled")))
500
if (!includeUntitled && editors[i]->GetFileName().GetFullPath().StartsWith(wxT("Untitled")))
496
501
continue; //don't save new documents that have not been saved to disk yet
497
files.push_back(std::make_pair(editors[i]->GetFileName(), true));
498
editors[n++] = editors[i];
502
files.push_back(std::make_pair(editors[i]->GetFileName(), true));
503
editors[n++] = editors[i];
502
507
bool res = !askUser || UserSelectFiles(files, wxT("Save Modified Files"),
503
wxT("Some files are modified.\nChoose the files you would like to save."));
505
for (size_t i = 0; i < files.size(); i++) {
506
if (files[i].second) {
507
editors[i]->SaveFile();
508
wxT("Some files are modified.\nChoose the files you would like to save."));
510
for (size_t i = 0; i < files.size(); i++) {
511
if (files[i].second) {
512
editors[i]->SaveFile();
514
519
void MainBook::ReloadExternallyModified()
516
std::vector<LEditor*> editors;
517
GetAllEditors(editors);
519
// filter list of editors for any whose files have been modified
520
std::vector<std::pair<wxFileName, bool> > files;
521
std::vector<LEditor*> editors;
522
GetAllEditors(editors);
524
// filter list of editors for any whose files have been modified
525
std::vector<std::pair<wxFileName, bool> > files;
522
527
for (size_t i = 0; i < editors.size(); i++) {
523
528
time_t diskTime = editors[i]->GetFileLastModifiedTime();
524
529
time_t editTime = editors[i]->GetEditorLastModifiedTime();
525
530
if (diskTime > editTime) {
526
files.push_back(std::make_pair(editors[i]->GetFileName(), !editors[i]->GetModify()));
527
// update editor last mod time so that we don't keep bugging the user over the same file,
528
// unless it gets changed again
529
editors[i]->SetEditorLastModifiedTime(diskTime);
530
editors[n++] = editors[i];
535
UserSelectFiles(files, wxT("Reload Modified Files"),
536
wxT("Files have been modified outside the editor.\nChoose which files you would like to reload."), false);
537
std::vector<wxFileName> filesToRetag;
538
for (size_t i = 0; i < files.size(); i++) {
539
if (files[i].second) {
540
editors[i]->ReloadFile();
541
filesToRetag.push_back(files[i].first);
544
if (!filesToRetag.empty()) {
545
TagsManagerST::Get()->RetagFiles(filesToRetag);
546
SendCmdEvent(wxEVT_FILE_RETAGGED, (void*)&filesToRetag);
531
files.push_back(std::make_pair(editors[i]->GetFileName(), !editors[i]->GetModify()));
532
// update editor last mod time so that we don't keep bugging the user over the same file,
533
// unless it gets changed again
534
editors[i]->SetEditorLastModifiedTime(diskTime);
535
editors[n++] = editors[i];
540
UserSelectFiles(files, wxT("Reload Modified Files"),
541
wxT("Files have been modified outside the editor.\nChoose which files you would like to reload."), false);
542
std::vector<wxFileName> filesToRetag;
543
for (size_t i = 0; i < files.size(); i++) {
544
if (files[i].second) {
545
editors[i]->ReloadFile();
546
filesToRetag.push_back(files[i].first);
549
if (!filesToRetag.empty()) {
550
TagsManagerST::Get()->RetagFiles(filesToRetag);
551
SendCmdEvent(wxEVT_FILE_RETAGGED, (void*)&filesToRetag);
550
555
bool MainBook::ClosePage(wxWindow *page)
553
558
size_t pos = m_book->GetPageIndex(page);
554
559
return pos != Notebook::npos && m_book->DeletePage(pos);
557
562
bool MainBook::CloseAllButThis(wxWindow *page)
559
// TODO: handle case where page is detached
561
size_t pos = m_book->GetPageIndex(page);
562
if (pos != Notebook::npos) {
563
text = m_book->GetPageText(pos);
564
m_book->RemovePage(pos, false);
566
bool res = CloseAll(true);
567
if (pos != Notebook::npos) {
568
m_book->AddPage(page, text, wxNullBitmap, true);
564
// TODO: handle case where page is detached
566
size_t pos = m_book->GetPageIndex(page);
567
if (pos != Notebook::npos) {
568
text = m_book->GetPageText(pos);
569
m_book->RemovePage(pos, false);
571
bool res = CloseAll(true);
572
if (pos != Notebook::npos) {
573
m_book->AddPage(page, text, wxNullBitmap, true);
573
578
bool MainBook::CloseAll(bool cancellable)
575
std::vector<LEditor*> editors;
576
GetAllEditors(editors);
578
// filter list of editors for any that need to be saved
579
std::vector<std::pair<wxFileName, bool> > files;
581
for (size_t i = 0; i < editors.size(); i++) {
582
if (editors[i]->GetModify()) {
583
files.push_back(std::make_pair(editors[i]->GetFileName(), true));
584
editors[n++] = editors[i];
589
if (!UserSelectFiles(files, wxT("Save Modified Files"),
590
wxT("Some files are modified.\nChoose the files you would like to save."), cancellable))
593
for (size_t i = 0; i < files.size(); i++) {
594
if (files[i].second) {
595
editors[i]->SaveFile();
597
editors[i]->SetSavePoint();
601
while (!m_detachedTabs.empty()) {
602
DockPage(*m_detachedTabs.begin());
580
std::vector<LEditor*> editors;
581
GetAllEditors(editors);
583
// filter list of editors for any that need to be saved
584
std::vector<std::pair<wxFileName, bool> > files;
586
for (size_t i = 0; i < editors.size(); i++) {
587
if (editors[i]->GetModify()) {
588
files.push_back(std::make_pair(editors[i]->GetFileName(), true));
589
editors[n++] = editors[i];
594
if (!UserSelectFiles(files, wxT("Save Modified Files"),
595
wxT("Some files are modified.\nChoose the files you would like to save."), cancellable))
598
for (size_t i = 0; i < files.size(); i++) {
599
if (files[i].second) {
600
editors[i]->SaveFile();
602
editors[i]->SetSavePoint();
606
while (!m_detachedTabs.empty()) {
607
DockPage(*m_detachedTabs.begin());
604
609
m_book->DeleteAllPages(true);
608
613
wxString MainBook::GetPageTitle(wxWindow *page)
610
615
size_t selection = m_book->GetPageIndex(page);
611
if (selection != Notebook::npos)
612
return m_book->GetPageText(selection);
613
std::set<wxWindow*>::iterator i = m_detachedTabs.find(page);
614
if (i != m_detachedTabs.end()) {
615
return Frame::Get()->GetDockingManager().GetPane(page).caption;
617
return wxEmptyString;
616
if (selection != Notebook::npos)
617
return m_book->GetPageText(selection);
618
std::set<wxWindow*>::iterator i = m_detachedTabs.find(page);
619
if (i != m_detachedTabs.end()) {
620
return Frame::Get()->GetDockingManager().GetPane(page).caption;
622
return wxEmptyString;
620
625
void MainBook::SetPageTitle ( wxWindow *page, const wxString &name )
623
628
if (selection != Notebook::npos) {
624
629
m_book->SetPageText(selection, name);
626
std::set<wxWindow*>::iterator i = m_detachedTabs.find(page);
627
if (i != m_detachedTabs.end()) {
628
wxAuiManager &mgr = Frame::Get()->GetDockingManager();
629
wxAuiPaneInfo &info = mgr.GetPane(page);
631
info.caption = info.name = name;
632
if (info.frame != NULL) {
633
info.frame->SetTitle(name);
631
std::set<wxWindow*>::iterator i = m_detachedTabs.find(page);
632
if (i != m_detachedTabs.end()) {
633
wxAuiManager &mgr = Frame::Get()->GetDockingManager();
634
wxAuiPaneInfo &info = mgr.GetPane(page);
636
info.caption = info.name = name;
637
if (info.frame != NULL) {
638
info.frame->SetTitle(name);
640
645
void MainBook::ApplySettingsChanges()
642
std::vector<LEditor*> editors;
643
GetAllEditors(editors);
647
std::vector<LEditor*> editors;
648
GetAllEditors(editors);
644
649
for (size_t i = 0; i < editors.size(); i++) {
645
editors[i]->SetSyntaxHighlight(editors[i]->GetContext()->GetName());
650
editors[i]->SetSyntaxHighlight(editors[i]->GetContext()->GetName());
649
654
void MainBook::UnHighlightAll()
651
std::vector<LEditor*> editors;
652
GetAllEditors(editors);
656
std::vector<LEditor*> editors;
657
GetAllEditors(editors);
653
658
for (size_t i = 0; i < editors.size(); i++) {
654
editors[i]->UnHighlightAll();
659
editors[i]->UnHighlightAll();
658
663
void MainBook::DelAllBreakpointMarkers()
660
std::vector<LEditor*> editors;
661
GetAllEditors(editors);
665
std::vector<LEditor*> editors;
666
GetAllEditors(editors);
662
667
for (size_t i = 0; i < editors.size(); i++) {
663
editors[i]->DelAllBreakpointMarkers();
668
editors[i]->DelAllBreakpointMarkers();
667
672
void MainBook::SetViewEOL(bool visible)
669
std::vector<LEditor*> editors;
670
GetAllEditors(editors);
674
std::vector<LEditor*> editors;
675
GetAllEditors(editors);
671
676
for (size_t i = 0; i < editors.size(); i++) {
672
editors[i]->SetViewEOL(visible);
677
editors[i]->SetViewEOL(visible);
676
681
void MainBook::HighlightWord(bool hl)
678
std::vector<LEditor*> editors;
679
GetAllEditors(editors);
683
std::vector<LEditor*> editors;
684
GetAllEditors(editors);
680
685
for (size_t i = 0; i < editors.size(); i++) {
681
editors[i]->HighlightWord(hl);
686
editors[i]->HighlightWord(hl);
685
690
void MainBook::ShowWhitespace(int ws)
687
std::vector<LEditor*> editors;
688
GetAllEditors(editors);
692
std::vector<LEditor*> editors;
693
GetAllEditors(editors);
689
694
for (size_t i = 0; i < editors.size(); i++) {
690
editors[i]->SetViewWhiteSpace(ws);
695
editors[i]->SetViewWhiteSpace(ws);
694
699
void MainBook::UpdateColours()
696
std::vector<LEditor*> editors;
697
GetAllEditors(editors);
701
std::vector<LEditor*> editors;
702
GetAllEditors(editors);
698
703
for (size_t i = 0; i < editors.size(); i++) {
699
editors[i]->UpdateColours();
704
editors[i]->UpdateColours();
703
708
void MainBook::UpdateBreakpoints()
705
std::vector<LEditor*> editors;
706
GetAllEditors(editors);
710
std::vector<LEditor*> editors;
711
GetAllEditors(editors);
707
712
for (size_t i = 0; i < editors.size(); i++) {
708
editors[i]->UpdateBreakpoints();
713
editors[i]->UpdateBreakpoints();