File: clFileSystemWorkspaceDlg.cpp

package info (click to toggle)
codelite 14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 112,816 kB
  • sloc: cpp: 483,662; ansic: 150,144; php: 9,569; lex: 4,186; python: 3,417; yacc: 2,820; sh: 1,147; makefile: 52; xml: 13
file content (69 lines) | stat: -rw-r--r-- 2,543 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "BuildTargetDlg.h"
#include "ColoursAndFontsManager.h"
#include "FSConfigPage.h"
#include "clFileSystemWorkspace.hpp"
#include "clFileSystemWorkspaceDlg.h"
#include "globals.h"
#include "macros.h"
#include <wx/textdlg.h>
#include <wx/wupdlock.h>

clFileSystemWorkspaceDlg::clFileSystemWorkspaceDlg(wxWindow* parent)
    : clFileSystemWorkspaceDlgBase(parent)
{
    wxWindowUpdateLocker locker(this);
    const auto& configsMap = clFileSystemWorkspace::Get().GetSettings().GetConfigsMap();
    clFileSystemWorkspaceConfig::Ptr_t conf = clFileSystemWorkspace::Get().GetSettings().GetSelectedConfig();
    wxString selConf;
    if(conf) { selConf = conf->GetName(); }
    for(const auto& vt : configsMap) {
        FSConfigPage* page = new FSConfigPage(m_notebook, vt.second);
        m_notebook->AddPage(page, vt.second->GetName(), (selConf == vt.first));
    }
    ::clSetDialogBestSizeAndPosition(this);
}

clFileSystemWorkspaceDlg::~clFileSystemWorkspaceDlg() {}

void clFileSystemWorkspaceDlg::OnOK(wxCommandEvent& event)
{
    for(size_t i = 0; i < m_notebook->GetPageCount(); ++i) {
        FSConfigPage* page = dynamic_cast<FSConfigPage*>(m_notebook->GetPage(i));
        if(!page) { continue; }
        page->Save();
    }

    int sel = m_notebook->GetSelection();
    clFileSystemWorkspace::Get().Save(false);
    clFileSystemWorkspace::Get().GetSettings().SetSelectedConfig(m_notebook->GetPageText(sel));
    clFileSystemWorkspace::Get().Save(true);
    EndModal(wxID_OK);
}

void clFileSystemWorkspaceDlg::OnNewConfig(wxCommandEvent& event)
{
    wxUnusedVar(event);
    wxString name = ::wxGetTextFromUser(_("Name"), _("New configuration"), "Untitled");
    if(name.IsEmpty()) { return; }
    if(clFileSystemWorkspace::Get().GetSettings().AddConfig(name)) {
        clFileSystemWorkspaceConfig::Ptr_t conf = clFileSystemWorkspace::Get().GetSettings().GetConfig(name);
        FSConfigPage* page = new FSConfigPage(m_notebook, conf);
        m_notebook->AddPage(page, name, true);
    }
}

void clFileSystemWorkspaceDlg::OnDeleteConfig(wxCommandEvent& event)
{
    wxWindowUpdateLocker locker(this);
    if(m_notebook->GetSelection() == wxNOT_FOUND) { return; }
    if(m_notebook->GetPageCount() == 1) { return; }
    int sel = m_notebook->GetSelection();
    if(clFileSystemWorkspace::Get().GetSettings().DeleteConfig(m_notebook->GetPageText(sel))) {
        m_notebook->DeletePage(sel);
    }
}

void clFileSystemWorkspaceDlg::OnDeleteConfigUI(wxUpdateUIEvent& event)
{
    event.Enable(m_notebook->GetPageCount() > 1);
}