Thanks to visit codestin.com
Credit goes to sourceforge.net

Menu

[r1960]: / trunk / src / plugins / astyle / astyleconfigdlg.cpp  Maximize  Restore  History

Download this file

223 lines (193 with data), 10.2 kB

  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
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#include <sdk.h>
#include "astyleconfigdlg.h"
#include <configmanager.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
#include <wx/font.h>
#include <wx/radiobut.h>
#include <wx/checkbox.h>
#include <wx/textctrl.h>
#include <wx/combobox.h>
#include <wx/spinctrl.h>
#include "dlgformattersettings.h"
#include <string>
BEGIN_EVENT_TABLE(AstyleConfigDlg, wxPanel)
EVT_RADIOBUTTON(XRCID("rbAnsi"), AstyleConfigDlg::OnStyleChange)
EVT_RADIOBUTTON(XRCID("rbKr"), AstyleConfigDlg::OnStyleChange)
EVT_RADIOBUTTON(XRCID("rbLinux"), AstyleConfigDlg::OnStyleChange)
EVT_RADIOBUTTON(XRCID("rbGNU"), AstyleConfigDlg::OnStyleChange)
EVT_RADIOBUTTON(XRCID("rbJava"), AstyleConfigDlg::OnStyleChange)
EVT_RADIOBUTTON(XRCID("rbCustom"), AstyleConfigDlg::OnStyleChange)
EVT_BUTTON(XRCID("Preview"), AstyleConfigDlg::OnPreview)
END_EVENT_TABLE()
AstyleConfigDlg::AstyleConfigDlg(wxWindow* parent)
{
//ctor
wxXmlResource::Get()->LoadPanel(this, parent, _T("dlgAstyleConfig"));
wxFont font(10, wxMODERN, wxNORMAL, wxNORMAL);
XRCCTRL(*this, "txtSample", wxTextCtrl)->SetFont(font);
LoadSettings();
}
AstyleConfigDlg::~AstyleConfigDlg()
{
//dtor
}
void AstyleConfigDlg::SetStyle(AStylePredefinedStyle style)
{
wxString sample;
switch (style)
{
case aspsAnsi:
sample = _T("namespace foospace\n{\n int Foo()\n {\n if (isBar)\n {\n bar();\n return 1;\n }\n else\n return 0;\n }\n}");
XRCCTRL(*this, "rbAnsi", wxRadioButton)->SetValue(true);
break;
case aspsKr:
sample = _T("namespace foospace {\n int Foo() {\n if (isBar) {\n bar();\n return 1;\n } else\n return 0;\n }\n}");
XRCCTRL(*this, "rbKr", wxRadioButton)->SetValue(true);
break;
case aspsLinux:
sample = _T("namespace foospace\n{\n int Foo()\n {\n if (isBar) {\n bar();\n return 1;\n } else\n return 0;\n }\n}");
XRCCTRL(*this, "rbLinux", wxRadioButton)->SetValue(true);
break;
case aspsGnu:
sample = _T("namespace foospace\n {\n int Foo()\n {\n if (isBar)\n {\n bar();\n return 1;\n }\n else\n return 0;\n }\n}");
XRCCTRL(*this, "rbGNU", wxRadioButton)->SetValue(true);
break;
case aspsJava:
sample = _T("namespace foospace {\n int Foo() {\n if (isBar) {\n bar();\n return 1;\n } else\n return 0;\n }\n}");
XRCCTRL(*this, "rbJava", wxRadioButton)->SetValue(true);
break;
default:
XRCCTRL(*this, "rbCustom", wxRadioButton)->SetValue(true);
break;
}
bool en = style != aspsCustom;
if (!sample.IsEmpty())
{
XRCCTRL(*this, "txtSample", wxTextCtrl)->SetValue(sample);
}
// disable/enable checkboxes based on style
XRCCTRL(*this, "spnIndentation", wxSpinCtrl)->Enable(!en);
XRCCTRL(*this, "chkUseTab", wxCheckBox)->Enable(!en);
XRCCTRL(*this, "chkForceUseTabs", wxCheckBox)->Enable(!en);
XRCCTRL(*this, "chkConvertTabs", wxCheckBox)->Enable(!en);
XRCCTRL(*this, "chkFillEmptyLines", wxCheckBox)->Enable(!en);
XRCCTRL(*this, "chkIndentClasses", wxCheckBox)->Enable(!en);
XRCCTRL(*this, "chkIndentSwitches", wxCheckBox)->Enable(!en);
XRCCTRL(*this, "chkIndentCase", wxCheckBox)->Enable(!en);
XRCCTRL(*this, "chkIndentBrackets", wxCheckBox)->Enable(!en);
XRCCTRL(*this, "chkIndentBlocks", wxCheckBox)->Enable(!en);
XRCCTRL(*this, "chkIndentNamespaces", wxCheckBox)->Enable(!en);
XRCCTRL(*this, "chkIndentLabels", wxCheckBox)->Enable(!en);
XRCCTRL(*this, "chkIndentPreprocessor", wxCheckBox)->Enable(!en);
XRCCTRL(*this, "cmbBreakType", wxComboBox)->Enable(!en);
XRCCTRL(*this, "chkBreakBlocks", wxCheckBox)->Enable(!en);
XRCCTRL(*this, "chkBreakElseIfs", wxCheckBox)->Enable(!en);
XRCCTRL(*this, "chkPadOperators", wxCheckBox)->Enable(!en);
XRCCTRL(*this, "chkPadParens", wxCheckBox)->Enable(!en);
XRCCTRL(*this, "chkKeepComplex", wxCheckBox)->Enable(!en);
XRCCTRL(*this, "chkKeepBlocks", wxCheckBox)->Enable(!en);
}
void AstyleConfigDlg::OnStyleChange(wxCommandEvent& event)
{
if (event.GetId() == XRCID("rbAnsi"))
SetStyle(aspsAnsi);
else if (event.GetId() == XRCID("rbKr"))
SetStyle(aspsKr);
else if (event.GetId() == XRCID("rbLinux"))
SetStyle(aspsLinux);
else if (event.GetId() == XRCID("rbGNU"))
SetStyle(aspsGnu);
else if (event.GetId() == XRCID("rbJava"))
SetStyle(aspsJava);
else if (event.GetId() == XRCID("rbCustom"))
SetStyle(aspsCustom);
}
void AstyleConfigDlg::OnPreview(wxCommandEvent& WXUNUSED(event))
{
std::string text(XRCCTRL(*this, "txtSample", wxTextCtrl)->GetValue().mb_str());
wxString formattedText;
astyle::ASFormatter formatter;
// load settings
dlgFormatterSettings settings(this);
settings.ApplyTo(formatter);
if (text.size() && *text.rbegin() != '\r' && *text.rbegin() != '\n')
{
text += '\n';
}
istringstream iter(text);
formatter.init(iter);
while (formatter.hasMoreLines())
{
formattedText << _U(formatter.nextLine().c_str());
if (formatter.hasMoreLines())
{
formattedText << _T('\n');
}
}
XRCCTRL(*this, "txtSample", wxTextCtrl)->SetValue(formattedText);
}
void AstyleConfigDlg::LoadSettings()
{
ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("astyle"));
int style = cfg->ReadInt(_T("/style"), 0);
XRCCTRL(*this, "spnIndentation", wxSpinCtrl)->SetValue(cfg->ReadInt(_T("/indentation"), 4));
XRCCTRL(*this, "chkUseTab", wxCheckBox)->SetValue(cfg->ReadBool(_T("/use_tabs"), false));
XRCCTRL(*this, "chkForceUseTabs", wxCheckBox)->SetValue(cfg->ReadBool(_T("/force_tabs"), false));
XRCCTRL(*this, "chkConvertTabs", wxCheckBox)->SetValue(cfg->ReadBool(_T("/convert_tabs"), false));
XRCCTRL(*this, "chkFillEmptyLines", wxCheckBox)->SetValue(cfg->ReadBool(_T("/fill_empty_lines"), false));
XRCCTRL(*this, "chkIndentClasses", wxCheckBox)->SetValue(cfg->ReadBool(_T("/indent_classes"), false));
XRCCTRL(*this, "chkIndentSwitches", wxCheckBox)->SetValue(cfg->ReadBool(_T("/indent_switches"), false));
XRCCTRL(*this, "chkIndentCase", wxCheckBox)->SetValue(cfg->ReadBool(_T("/indent_case"), false));
XRCCTRL(*this, "chkIndentBrackets", wxCheckBox)->SetValue(cfg->ReadBool(_T("/indent_brackets"), false));
XRCCTRL(*this, "chkIndentBlocks", wxCheckBox)->SetValue(cfg->ReadBool(_T("/indent_blocks"), false));
XRCCTRL(*this, "chkIndentNamespaces", wxCheckBox)->SetValue(cfg->ReadBool(_T("/indent_namespaces"), false));
XRCCTRL(*this, "chkIndentLabels", wxCheckBox)->SetValue(cfg->ReadBool(_T("/indent_labels"), false));
XRCCTRL(*this, "chkIndentPreprocessor", wxCheckBox)->SetValue(cfg->ReadBool(_T("/indent_preprocessor"), false));
XRCCTRL(*this, "cmbBreakType", wxComboBox)->SetValue(cfg->Read(_T("/break_type"), _T("None")));
XRCCTRL(*this, "chkBreakBlocks", wxCheckBox)->SetValue(cfg->ReadBool(_T("/break_blocks"), false));
XRCCTRL(*this, "chkBreakElseIfs", wxCheckBox)->SetValue(cfg->ReadBool(_T("/break_elseifs"), false));
XRCCTRL(*this, "chkPadOperators", wxCheckBox)->SetValue(cfg->ReadBool(_T("/pad_operators"), false));
XRCCTRL(*this, "chkPadParens", wxCheckBox)->SetValue(cfg->ReadBool(_T("/pad_parentheses"), false));
XRCCTRL(*this, "chkKeepComplex", wxCheckBox)->SetValue(cfg->ReadBool(_T("/keep_complex"), false));
XRCCTRL(*this, "chkKeepBlocks", wxCheckBox)->SetValue(cfg->ReadBool(_T("/keep_blocks"), false));
SetStyle((AStylePredefinedStyle)style);
}
void AstyleConfigDlg::SaveSettings()
{
ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("astyle"));
int style = 0;
if (XRCCTRL(*this, "rbAnsi", wxRadioButton)->GetValue())
style = 0;
else if (XRCCTRL(*this, "rbKr", wxRadioButton)->GetValue())
style = 1;
else if (XRCCTRL(*this, "rbLinux", wxRadioButton)->GetValue())
style = 2;
else if (XRCCTRL(*this, "rbGNU", wxRadioButton)->GetValue())
style = 3;
else if (XRCCTRL(*this, "rbJava", wxRadioButton)->GetValue())
style = 4;
else if (XRCCTRL(*this, "rbCustom", wxRadioButton)->GetValue())
style = 5;
cfg->Write(_T("/style"), style);
cfg->Write(_T("/indentation"), XRCCTRL(*this, "spnIndentation", wxSpinCtrl)->GetValue());
cfg->Write(_T("/use_tabs"), XRCCTRL(*this, "chkUseTab", wxCheckBox)->GetValue());
cfg->Write(_T("/force_tabs"), XRCCTRL(*this, "chkForceUseTabs", wxCheckBox)->GetValue());
cfg->Write(_T("/convert_tabs"), XRCCTRL(*this, "chkConvertTabs", wxCheckBox)->GetValue());
cfg->Write(_T("/fill_empty_lines"), XRCCTRL(*this, "chkFillEmptyLines", wxCheckBox)->GetValue());
cfg->Write(_T("/indent_classes"), XRCCTRL(*this, "chkIndentClasses", wxCheckBox)->GetValue());
cfg->Write(_T("/indent_switches"), XRCCTRL(*this, "chkIndentSwitches", wxCheckBox)->GetValue());
cfg->Write(_T("/indent_case"), XRCCTRL(*this, "chkIndentCase", wxCheckBox)->GetValue());
cfg->Write(_T("/indent_brackets"), XRCCTRL(*this, "chkIndentBrackets", wxCheckBox)->GetValue());
cfg->Write(_T("/indent_blocks"), XRCCTRL(*this, "chkIndentBlocks", wxCheckBox)->GetValue());
cfg->Write(_T("/indent_namespaces"), XRCCTRL(*this, "chkIndentNamespaces", wxCheckBox)->GetValue());
cfg->Write(_T("/indent_labels"), XRCCTRL(*this, "chkIndentLabels", wxCheckBox)->GetValue());
cfg->Write(_T("/indent_preprocessor"), XRCCTRL(*this, "chkIndentPreprocessor", wxCheckBox)->GetValue());
cfg->Write(_T("/break_type"), XRCCTRL(*this, "cmbBreakType", wxComboBox)->GetValue());
cfg->Write(_T("/break_blocks"), XRCCTRL(*this, "chkBreakBlocks", wxCheckBox)->GetValue());
cfg->Write(_T("/break_elseifs"), XRCCTRL(*this, "chkBreakElseIfs", wxCheckBox)->GetValue());
cfg->Write(_T("/pad_operators"), XRCCTRL(*this, "chkPadOperators", wxCheckBox)->GetValue());
cfg->Write(_T("/pad_parentheses"), XRCCTRL(*this, "chkPadParens", wxCheckBox)->GetValue());
cfg->Write(_T("/keep_complex"), XRCCTRL(*this, "chkKeepComplex", wxCheckBox)->GetValue());
cfg->Write(_T("/keep_blocks"), XRCCTRL(*this, "chkKeepBlocks", wxCheckBox)->GetValue());
}