~quadrispro/codelite/trunk

« back to all changes in this revision

Viewing changes to LiteEditor/mainbook.cpp

  • Committer: eranif
  • Date: 2008-12-05 05:59:40 UTC
  • Revision ID: svn-v4:9da81c78-c036-0410-9e1f-a2b0375e4b5a:trunk:2507
- Accelerators are now working properly for detached *floating* panes

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "manager.h"
29
29
#include "custom_tabcontainer.h"
30
30
#include "close_all_dlg.h"
31
 
#include "filechecklist.h"
 
31
#include "filechecklist.h"
32
32
#include "mainbook.h"
33
33
 
34
34
MainBook::MainBook(wxWindow *parent)
35
 
    : wxPanel       (parent)
36
 
    , m_navBar      (NULL)
37
 
        , m_book        (NULL)
38
 
        , m_quickFindBar(NULL)
39
 
    , m_currentPage (NULL)
 
35
                : wxPanel       (parent)
 
36
                , m_navBar      (NULL)
 
37
                , m_book        (NULL)
 
38
                , m_quickFindBar(NULL)
 
39
                , m_currentPage (NULL)
40
40
{
41
41
        CreateGuiControls();
42
42
        ConnectEvents();
69
69
        m_book->Connect(wxEVT_COMMAND_BOOK_PAGE_CLOSING,  NotebookEventHandler(MainBook::OnPageClosing),  NULL, this);
70
70
        m_book->Connect(wxEVT_COMMAND_BOOK_PAGE_CLOSED,   NotebookEventHandler(MainBook::OnPageClosed),   NULL, this);
71
71
 
72
 
    wxTheApp->Connect(wxEVT_AUI_PANE_CLOSE, wxAuiManagerEventHandler(MainBook::OnPaneClosed), NULL, this);
73
 
    
 
72
        wxTheApp->Connect(wxEVT_AUI_PANE_CLOSE, wxAuiManagerEventHandler(MainBook::OnPaneClosed), NULL, this);
 
73
 
74
74
        wxTheApp->Connect(wxEVT_WORKSPACE_LOADED,  wxCommandEventHandler(MainBook::OnWorkspaceLoaded),    NULL, this);
75
75
        wxTheApp->Connect(wxEVT_PROJ_FILE_ADDED,   wxCommandEventHandler(MainBook::OnProjectFileAdded),   NULL, this);
76
76
        wxTheApp->Connect(wxEVT_PROJ_FILE_REMOVED, wxCommandEventHandler(MainBook::OnProjectFileRemoved), NULL, this);
89
89
 
90
90
void MainBook::OnFocus(wxFocusEvent &e)
91
91
{
92
 
    if (!SelectPage(dynamic_cast<wxWindow*>(e.GetEventObject()))) {
93
 
        e.Skip();
94
 
    }
 
92
        if (!SelectPage(dynamic_cast<wxWindow*>(e.GetEventObject()))) {
 
93
                e.Skip();
 
94
        }
95
95
}
96
96
 
97
 
void MainBook::OnPaneClosed(wxAuiManagerEvent &e) 
 
97
void MainBook::OnPaneClosed(wxAuiManagerEvent &e)
98
98
{
99
 
    if (!DockPage(e.GetPane()->window)) {
100
 
        e.Skip();
101
 
    }
 
99
        if (!DockPage(e.GetPane()->window)) {
 
100
                e.Skip();
 
101
        }
102
102
}
103
103
 
104
104
void MainBook::OnPageClosing(NotebookEvent &e)
115
115
 
116
116
void MainBook::OnPageClosed(NotebookEvent &e)
117
117
{
118
 
    SelectPage(m_book->GetCurrentPage());
 
118
        SelectPage(m_book->GetCurrentPage());
119
119
 
120
120
        // any editors left open?
121
121
        LEditor *editor = NULL;
122
122
        for (size_t i = 0; i < m_book->GetPageCount() && editor == NULL; i++) {
123
123
                editor = dynamic_cast<LEditor*>(m_book->GetPage(i));
124
124
        }
125
 
    for (std::set<wxWindow*>::iterator i = m_detachedTabs.begin(); i != m_detachedTabs.end() && editor == NULL; i++) {
126
 
        editor = dynamic_cast<LEditor*>(*i);
127
 
    }
 
125
        for (std::set<wxWindow*>::iterator i = m_detachedTabs.begin(); i != m_detachedTabs.end() && editor == NULL; i++) {
 
126
                editor = dynamic_cast<LEditor*>(*i);
 
127
        }
128
128
        if (editor == NULL) {
129
129
                SendCmdEvent(wxEVT_ALL_EDITORS_CLOSED);
130
 
        ShowQuickBar(false);
 
130
                ShowQuickBar(false);
131
131
        }
132
132
}
133
133
 
197
197
        case wxCANCEL:
198
198
                return false;
199
199
        }
200
 
        
 
200
 
201
201
        return true; // to avoid compiler warnings
202
202
}
203
203
 
223
223
 
224
224
void MainBook::SaveSession(SessionEntry &session)
225
225
{
226
 
    std::vector<LEditor*> editors;
227
 
    GetAllEditors(editors);
228
 
    
 
226
        std::vector<LEditor*> editors;
 
227
        GetAllEditors(editors);
 
228
 
229
229
        session.SetSelectedTab(0);
230
230
        std::vector<TabInfo> vTabInfoArr;
231
231
        for (size_t i = 0; i < editors.size(); i++) {
270
270
                        }
271
271
                }
272
272
        }
273
 
    SelectPage(m_book->GetPage(sel));
 
273
        SelectPage(m_book->GetPage(sel));
274
274
}
275
275
 
276
276
LEditor *MainBook::GetActiveEditor()
280
280
 
281
281
void MainBook::GetAllEditors(std::vector<LEditor*> &editors)
282
282
{
283
 
    editors.clear();
284
 
    for (size_t i = 0; i < m_book->GetPageCount(); i++) {
285
 
        LEditor *editor = dynamic_cast<LEditor*>(m_book->GetPage(i));
286
 
        if (editor) {
287
 
            editors.push_back(editor);
288
 
        }
289
 
    }
290
 
    for (std::set<wxWindow*>::iterator i = m_detachedTabs.begin(); i != m_detachedTabs.end(); i++) {
291
 
        LEditor *editor = dynamic_cast<LEditor*>(*i);
292
 
        if (editor) {
293
 
            editors.push_back(editor);
294
 
        }
295
 
    }
 
283
        editors.clear();
 
284
        for (size_t i = 0; i < m_book->GetPageCount(); i++) {
 
285
                LEditor *editor = dynamic_cast<LEditor*>(m_book->GetPage(i));
 
286
                if (editor) {
 
287
                        editors.push_back(editor);
 
288
                }
 
289
        }
 
290
        for (std::set<wxWindow*>::iterator i = m_detachedTabs.begin(); i != m_detachedTabs.end(); i++) {
 
291
                LEditor *editor = dynamic_cast<LEditor*>(*i);
 
292
                if (editor) {
 
293
                        editors.push_back(editor);
 
294
                }
 
295
        }
296
296
}
297
297
 
298
298
LEditor *MainBook::FindEditor(const wxString &fileName)
302
302
                if (editor && editor->GetFileName().GetFullPath() == fileName)
303
303
                        return editor;
304
304
        }
305
 
    for (std::set<wxWindow*>::iterator i = m_detachedTabs.begin(); i != m_detachedTabs.end(); i++) {
306
 
        LEditor *editor = dynamic_cast<LEditor*>(*i);
307
 
        if (editor && editor->GetFileName().GetFullPath() == fileName)
308
 
            return editor;
309
 
    }
 
305
        for (std::set<wxWindow*>::iterator i = m_detachedTabs.begin(); i != m_detachedTabs.end(); i++) {
 
306
                LEditor *editor = dynamic_cast<LEditor*>(*i);
 
307
                if (editor && editor->GetFileName().GetFullPath() == fileName)
 
308
                        return editor;
 
309
        }
310
310
        return NULL;
311
311
}
312
312
 
316
316
                if (m_book->GetPageText(i) == text)
317
317
                        return m_book->GetPage(i);
318
318
        }
319
 
    for (std::set<wxWindow*>::iterator i = m_detachedTabs.begin(); i != m_detachedTabs.end(); i++) {
320
 
        if (Frame::Get()->GetDockingManager().GetPane(*i).caption == text)
321
 
            return *i;
322
 
    }
 
319
        for (std::set<wxWindow*>::iterator i = m_detachedTabs.begin(); i != m_detachedTabs.end(); i++) {
 
320
                if (Frame::Get()->GetDockingManager().GetPane(*i).caption == text)
 
321
                        return *i;
 
322
        }
323
323
        return NULL;
324
324
}
325
325
 
371
371
                if (GetActiveEditor() == editor) {
372
372
                        editor->SetActive();
373
373
                } else {
374
 
            SelectPage(editor);
 
374
                        SelectPage(editor);
375
375
                }
376
376
                ManagerST::Get()->AddToRecentlyOpenedFiles(fileName.GetFullPath());
377
377
        }
383
383
{
384
384
        if (m_book->GetPageIndex(win) != Notebook::npos || m_detachedTabs.find(win) != m_detachedTabs.end())
385
385
                return false;
386
 
    win->Connect(wxEVT_SET_FOCUS, wxFocusEventHandler(MainBook::OnFocus), NULL, this);
 
386
        win->Connect(wxEVT_SET_FOCUS, wxFocusEventHandler(MainBook::OnFocus), NULL, this);
387
387
        m_book->AddPage(win, text, bmp, selected);
388
388
        return true;
389
389
}
391
391
bool MainBook::SelectPage(wxWindow *win)
392
392
{
393
393
        size_t index = m_book->GetPageIndex(win);
394
 
    std::set<wxWindow*>::iterator i = m_detachedTabs.find(win);
395
 
    
 
394
        std::set<wxWindow*>::iterator i = m_detachedTabs.find(win);
 
395
 
396
396
        if (index != Notebook::npos) {
397
 
        m_book->SetSelection(index);
398
 
    } else  if (i != m_detachedTabs.end()) {
399
 
        // anything to do?
400
 
    } else if (win == NULL) {
401
 
        // OK -- deselecting any page
402
 
    } else
403
 
        return false;
404
 
        
405
 
    m_currentPage = win;
 
397
                m_book->SetSelection(index);
 
398
        } else  if (i != m_detachedTabs.end()) {
 
399
                // anything to do?
 
400
        } else if (win == NULL) {
 
401
                // OK -- deselecting any page
 
402
        } else
 
403
                return false;
 
404
 
 
405
        m_currentPage = win;
406
406
 
407
407
        LEditor *editor = dynamic_cast<LEditor*>(win);
408
 
    
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);
415
 
        }
416
 
    }
417
 
    
 
408
 
 
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);
 
415
                }
 
416
        }
 
417
 
418
418
        if (!editor) {
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);
423
423
        } else {
424
 
        editor->SetActive();
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++"));
428
 
            }
429
 
        }
430
 
        SendCmdEvent(wxEVT_ACTIVE_EDITOR_CHANGED, (IEditor*)editor);
431
 
    }
 
424
                editor->SetActive();
 
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++"));
 
428
                        }
 
429
                }
 
430
                SendCmdEvent(wxEVT_ACTIVE_EDITOR_CHANGED, (IEditor*)editor);
 
431
        }
432
432
 
433
 
    return true;
 
433
        return true;
434
434
}
435
435
 
436
436
bool MainBook::DetachPage(wxWindow* win)
437
437
{
438
 
    if (IsDetached(win))
439
 
        return true;
440
 
    size_t pos = m_book->GetPageIndex(win);
441
 
    if (pos == Notebook::npos)
442
 
        return false;
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
 
    return true;
 
438
        if (IsDetached(win))
 
439
                return true;
 
440
        size_t pos = m_book->GetPageIndex(win);
 
441
        if (pos == Notebook::npos)
 
442
                return false;
 
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());
 
450
        if (frm) {
 
451
                wxAcceleratorTable *acclTable = Frame::Get()->GetAcceleratorTable();
 
452
                ((wxFrame*)frm)->SetAcceleratorTable(*acclTable);
 
453
        }
 
454
        return true;
450
455
}
451
456
 
452
457
bool MainBook::DockPage(wxWindow* win)
453
458
{
454
 
    std::set<wxWindow*>::iterator i = m_detachedTabs.find(win);
455
 
    if (i == m_detachedTabs.end())
456
 
        return false;
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);
462
 
    return true;
 
459
        std::set<wxWindow*>::iterator i = m_detachedTabs.find(win);
 
460
        if (i == m_detachedTabs.end())
 
461
                return false;
 
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);
 
467
        return true;
463
468
}
464
469
 
465
470
bool MainBook::IsDetached(wxWindow* win)
466
471
{
467
 
    return m_detachedTabs.find(win) != m_detachedTabs.end();
 
472
        return m_detachedTabs.find(win) != m_detachedTabs.end();
468
473
}
469
474
 
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)
472
477
{
473
 
    if (files.empty())
474
 
        return true;
475
 
                
476
 
    FileCheckList dlg(this, wxID_ANY, title);
477
 
    dlg.SetCaption(caption);
478
 
    dlg.SetFiles(files);
479
 
    dlg.SetCancellable(cancellable);
480
 
    bool res = dlg.ShowModal() == wxID_OK;
481
 
    files = dlg.GetFiles();
482
 
    return res;
 
478
        if (files.empty())
 
479
                return true;
 
480
 
 
481
        FileCheckList dlg(this, wxID_ANY, title);
 
482
        dlg.SetCaption(caption);
 
483
        dlg.SetFiles(files);
 
484
        dlg.SetCancellable(cancellable);
 
485
        bool res = dlg.ShowModal() == wxID_OK;
 
486
        files = dlg.GetFiles();
 
487
        return res;
483
488
}
484
489
 
485
490
bool MainBook::SaveAll(bool askUser, bool includeUntitled)
486
491
{
487
 
    std::vector<LEditor*> editors;
488
 
    GetAllEditors(editors);
489
 
    
490
 
    std::vector<std::pair<wxFileName, bool> > files;
491
 
    size_t n = 0;
 
492
        std::vector<LEditor*> editors;
 
493
        GetAllEditors(editors);
 
494
 
 
495
        std::vector<std::pair<wxFileName, bool> > files;
 
496
        size_t n = 0;
492
497
        for (size_t i = 0; i < editors.size(); i++) {
493
498
                if (!editors[i]->GetModify())
494
499
                        continue;
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];
499
504
        }
500
 
    editors.resize(n);
501
 
    
 
505
        editors.resize(n);
 
506
 
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."));
504
 
    if (res) {
505
 
        for (size_t i = 0; i < files.size(); i++) {
506
 
            if (files[i].second) {
507
 
                editors[i]->SaveFile();               
508
 
            }
509
 
        }
510
 
    }
 
508
                                               wxT("Some files are modified.\nChoose the files you would like to save."));
 
509
        if (res) {
 
510
                for (size_t i = 0; i < files.size(); i++) {
 
511
                        if (files[i].second) {
 
512
                                editors[i]->SaveFile();
 
513
                        }
 
514
                }
 
515
        }
511
516
        return res;
512
517
}
513
518
 
514
519
void MainBook::ReloadExternallyModified()
515
520
{
516
 
    std::vector<LEditor*> editors;
517
 
    GetAllEditors(editors);
518
 
    
519
 
    // filter list of editors for any whose files have been modified
520
 
    std::vector<std::pair<wxFileName, bool> > files;
521
 
    size_t n = 0;
 
521
        std::vector<LEditor*> editors;
 
522
        GetAllEditors(editors);
 
523
 
 
524
        // filter list of editors for any whose files have been modified
 
525
        std::vector<std::pair<wxFileName, bool> > files;
 
526
        size_t n = 0;
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];
531
 
        }
532
 
        }
533
 
    editors.resize(n);
534
 
    
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);
542
 
        }
543
 
    }
544
 
    if (!filesToRetag.empty()) {
545
 
        TagsManagerST::Get()->RetagFiles(filesToRetag);
546
 
        SendCmdEvent(wxEVT_FILE_RETAGGED, (void*)&filesToRetag);
547
 
    }
 
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];
 
536
                }
 
537
        }
 
538
        editors.resize(n);
 
539
 
 
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);
 
547
                }
 
548
        }
 
549
        if (!filesToRetag.empty()) {
 
550
                TagsManagerST::Get()->RetagFiles(filesToRetag);
 
551
                SendCmdEvent(wxEVT_FILE_RETAGGED, (void*)&filesToRetag);
 
552
        }
548
553
}
549
554
 
550
555
bool MainBook::ClosePage(wxWindow *page)
551
556
{
552
 
    DockPage(page);
 
557
        DockPage(page);
553
558
        size_t pos = m_book->GetPageIndex(page);
554
559
        return pos != Notebook::npos && m_book->DeletePage(pos);
555
560
}
556
561
 
557
562
bool MainBook::CloseAllButThis(wxWindow *page)
558
563
{
559
 
    // TODO: handle case where page is detached
560
 
    wxString text;
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);
565
 
    }
566
 
    bool res = CloseAll(true);
567
 
    if (pos != Notebook::npos) {
568
 
        m_book->AddPage(page, text, wxNullBitmap, true);
569
 
    }
570
 
    return res;
 
564
        // TODO: handle case where page is detached
 
565
        wxString text;
 
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);
 
570
        }
 
571
        bool res = CloseAll(true);
 
572
        if (pos != Notebook::npos) {
 
573
                m_book->AddPage(page, text, wxNullBitmap, true);
 
574
        }
 
575
        return res;
571
576
}
572
577
 
573
578
bool MainBook::CloseAll(bool cancellable)
574
579
{
575
 
    std::vector<LEditor*> editors;
576
 
    GetAllEditors(editors);
577
 
    
578
 
    // filter list of editors for any that need to be saved
579
 
    std::vector<std::pair<wxFileName, bool> > files;
580
 
    size_t n = 0;
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];
585
 
        }
586
 
    }
587
 
    editors.resize(n);
588
 
    
589
 
    if (!UserSelectFiles(files, wxT("Save Modified Files"),
590
 
                         wxT("Some files are modified.\nChoose the files you would like to save."), cancellable))
591
 
        return false;
592
 
        
593
 
    for (size_t i = 0; i < files.size(); i++) {
594
 
        if (files[i].second) {
595
 
            editors[i]->SaveFile();
596
 
        } else {
597
 
            editors[i]->SetSavePoint();
598
 
        }
599
 
    }
600
 
    
601
 
    while (!m_detachedTabs.empty()) {
602
 
        DockPage(*m_detachedTabs.begin());
603
 
    }
 
580
        std::vector<LEditor*> editors;
 
581
        GetAllEditors(editors);
 
582
 
 
583
        // filter list of editors for any that need to be saved
 
584
        std::vector<std::pair<wxFileName, bool> > files;
 
585
        size_t n = 0;
 
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];
 
590
                }
 
591
        }
 
592
        editors.resize(n);
 
593
 
 
594
        if (!UserSelectFiles(files, wxT("Save Modified Files"),
 
595
                             wxT("Some files are modified.\nChoose the files you would like to save."), cancellable))
 
596
                return false;
 
597
 
 
598
        for (size_t i = 0; i < files.size(); i++) {
 
599
                if (files[i].second) {
 
600
                        editors[i]->SaveFile();
 
601
                } else {
 
602
                        editors[i]->SetSavePoint();
 
603
                }
 
604
        }
 
605
 
 
606
        while (!m_detachedTabs.empty()) {
 
607
                DockPage(*m_detachedTabs.begin());
 
608
        }
604
609
        m_book->DeleteAllPages(true);
605
 
    return true;
 
610
        return true;
606
611
}
607
612
 
608
613
wxString MainBook::GetPageTitle(wxWindow *page)
609
614
{
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;
616
 
    }
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;
 
621
        }
 
622
        return wxEmptyString;
618
623
}
619
624
 
620
625
void MainBook::SetPageTitle ( wxWindow *page, const wxString &name )
623
628
        if (selection != Notebook::npos) {
624
629
                m_book->SetPageText(selection, name);
625
630
        }
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);
630
 
        if (info.IsOk()) {
631
 
            info.caption = info.name = name;
632
 
            if (info.frame != NULL) {
633
 
                info.frame->SetTitle(name);
634
 
            }
635
 
            mgr.Update();
636
 
        }
637
 
    }
 
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);
 
635
                if (info.IsOk()) {
 
636
                        info.caption = info.name = name;
 
637
                        if (info.frame != NULL) {
 
638
                                info.frame->SetTitle(name);
 
639
                        }
 
640
                        mgr.Update();
 
641
                }
 
642
        }
638
643
}
639
644
 
640
645
void MainBook::ApplySettingsChanges()
641
646
{
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());
646
651
        }
647
652
}
648
653
 
649
654
void MainBook::UnHighlightAll()
650
655
{
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();
655
660
        }
656
661
}
657
662
 
658
663
void MainBook::DelAllBreakpointMarkers()
659
664
{
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();
664
669
        }
665
670
}
666
671
 
667
672
void MainBook::SetViewEOL(bool visible)
668
673
{
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);
673
678
        }
674
679
}
675
680
 
676
681
void MainBook::HighlightWord(bool hl)
677
682
{
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);
682
687
        }
683
688
}
684
689
 
685
690
void MainBook::ShowWhitespace(int ws)
686
691
{
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);
691
696
        }
692
697
}
693
698
 
694
699
void MainBook::UpdateColours()
695
700
{
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();
700
705
        }
701
706
}
702
707
 
703
708
void MainBook::UpdateBreakpoints()
704
709
{
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();
709
714
        }
710
715
}