Debian Codegraph @

DebugAdapterClient/DapSettingsPage.cpp

raw
1 #include "DapSettingsPage.hpp"
2
3 #define UPDATE_TEXT_CB(SETTER_METHOD) \
4 [this](const wxString& label, const wxAny& value) { \
5 wxUnusedVar(label); \
6 wxString str_value; \
7 if(value.GetAs(&str_value)) { \
8 DapEntry d; \
9 m_store.Get(m_entry.GetName(), &d); \
10 d.SETTER_METHOD(str_value); \
11 m_store.Set(d); \
12 } \
13 }
14
15 #define UPDATE_BOOL_CB(SETTER_METHOD) \
16 [this](const wxString& label, const wxAny& value) { \
17 wxUnusedVar(label); \
18 bool bool_value; \
19 if(value.GetAs(&bool_value)) { \
20 DapEntry d; \
21 m_store.Get(m_entry.GetName(), &d); \
22 d.SETTER_METHOD(bool_value); \
23 m_store.Set(d); \
24 } \
25 }
26
27 DapSettingsPage::DapSettingsPage(wxWindow* win, clDapSettingsStore& store, const DapEntry& entry)
28 : clPropertiesPage(win)
29 , m_store(store)
30 , m_entry(entry)
31 {
32 AddHeader(_("General"));
33 AddProperty(_("Command"), m_entry.GetCommand(), UPDATE_TEXT_CB(SetCommand));
34 AddProperty(_("Connection string"), m_entry.GetConnectionString(), UPDATE_TEXT_CB(SetConnectionString));
35
36 const std::vector<wxString> launch_choices = { "Launch", "Attach" };
37 wxString launch_type = entry.GetLaunchType() == DapLaunchType::LAUNCH ? "Launch" : "Attach";
38 AddProperty(_("Launch type"), launch_choices, launch_type, [this](const wxString& label, const wxAny& value) {
39 wxUnusedVar(label);
40 wxString value_str;
41 if(value.GetAs(&value_str)) {
42 DapEntry d;
43 m_store.Get(m_entry.GetName(), &d);
44 if(value_str == "Launch") {
45 d.SetLaunchType(DapLaunchType::LAUNCH);
46 } else {
47 d.SetLaunchType(DapLaunchType::ATTACH);
48 }
49 m_store.Set(d);
50 }
51 });
52
53 AddHeader(_("File path options"));
54 AddProperty(_("Use relative paths"), m_entry.UseRelativePath(), UPDATE_BOOL_CB(SetUseRelativePath));
55
56 #ifdef __WXMSW__
57 AddProperty(_("Use forward slash"), m_entry.UseForwardSlash(), UPDATE_BOOL_CB(SetUseForwardSlash));
58 AddProperty(_("Use volume"), m_entry.UseVolume(), UPDATE_BOOL_CB(SetUseVolume));
59 #endif
60
61 AddHeader(_("Environment variables"));
62 AddProperty(_("Server environment"), m_entry.GetEnvironment(), UPDATE_TEXT_CB(SetEnvironment));
63
64 const std::vector<wxString> format_choices = { "List", "Dictionary", "None" };
65 int sel = wxNOT_FOUND;
66 switch(m_entry.GetEnvFormat()) {
67 case dap::EnvFormat::LIST:
68 sel = 0;
69 break;
70 case dap::EnvFormat::DICTIONARY:
71 sel = 1;
72 break;
73 case dap::EnvFormat::NONE:
74 sel = 2;
75 break;
76 }
77
78 AddProperty(_("Environment format"), format_choices, sel, [this](const wxString& label, const wxAny& value) {
79 wxUnusedVar(label);
80 wxString value_str;
81 if(value.GetAs(&value_str)) {
82 DapEntry d;
83 m_store.Get(m_entry.GetName(), &d);
84 if(value_str == "List") {
85 d.SetEnvFormat(dap::EnvFormat::LIST);
86 } else if(value_str == "Dictionary") {
87 d.SetEnvFormat(dap::EnvFormat::DICTIONARY);
88 } else {
89 d.SetEnvFormat(dap::EnvFormat::NONE);
90 }
91 m_store.Set(d);
92 }
93 });
94 }
95
96 DapSettingsPage::~DapSettingsPage() {}