Debian Codegraph @

CodeFormatter/FormatterPage.cpp

raw
1 #include "FormatterPage.hpp"
2
3 #include <wx/arrstr.h>
4 #include <wx/tokenzr.h>
5
6 #define UPDATE_TEXT_CB(SETTER_METHOD) \
7 [this](const wxString& label, const wxAny& value) { \
8 wxUnusedVar(label); \
9 wxString str_value; \
10 if(value.GetAs(&str_value)) { \
11 m_cur_formatter->SETTER_METHOD(str_value); \
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 m_cur_formatter->SETTER_METHOD(bool_value); \
21 } \
22 }
23
24 #define UPDATE_LANGS_CB() \
25 [this](const wxString& label, const wxAny& value) { \
26 wxUnusedVar(label); \
27 wxString str_value; \
28 if(value.GetAs(&str_value)) { \
29 m_cur_formatter->SetLanguages(wxStringTokenize(str_value, ";", wxTOKEN_STRTOK)); \
30 } \
31 }
32
33 FormatterPage::FormatterPage(wxWindow* parent)
34 : clPropertiesPage(parent)
35 {
36 }
37
38 FormatterPage::~FormatterPage() {}
39
40 void FormatterPage::Load(std::shared_ptr<GenericFormatter> formatter)
41 {
42 Clear();
43 CHECK_PTR_RET(formatter);
44 m_cur_formatter = formatter;
45
46 AddHeader(m_cur_formatter->GetShortDescription());
47 AddProperty(_("Enabled"), m_cur_formatter->IsEnabled(), UPDATE_BOOL_CB(SetEnabled));
48 AddProperty(_("Format on save?"), m_cur_formatter->IsFormatOnSave(), UPDATE_BOOL_CB(SetFormatOnSave));
49 AddProperty(_("Inplace edit"), m_cur_formatter->IsInplaceFormatter(), UPDATE_BOOL_CB(SetInplaceFormatter));
50 AddProperty(_("Working directory"), m_cur_formatter->GetWorkingDirectory(), UPDATE_TEXT_CB(SetWorkingDirectory));
51 AddPropertyLanguagePicker(_("Supported languages"), m_cur_formatter->GetLanguages(), UPDATE_LANGS_CB());
52 AddProperty(_("Command"), m_cur_formatter->GetCommandWithComments(), UPDATE_TEXT_CB(SetCommandFromString));
53 }
54
55 void FormatterPage::Clear()
56 {
57 clPropertiesPage::Clear();
58 m_cur_formatter = nullptr;
59 }