Menu

[r1967]: / trunk / src / plugins / astyle / dlgformattersettings.cpp  Maximize  Restore  History

Download this file

192 lines (173 with data), 6.7 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
#include "dlgformattersettings.h"
#include <wx/radiobut.h>
#include <wx/checkbox.h>
#include <wx/combobox.h>
#include <wx/spinctrl.h>
#include <wx/xrc/xmlres.h>
dlgFormatterSettings::dlgFormatterSettings(wxWindow *dlg)
: m_dlg(dlg)
{
//ctor
}
dlgFormatterSettings::~dlgFormatterSettings()
{
//dtor
}
void dlgFormatterSettings::ApplyTo(astyle::ASFormatter& formatter)
{
int style = 0;
if (XRCCTRL(*m_dlg, "rbAnsi", wxRadioButton)->GetValue())
style = 0;
else if (XRCCTRL(*m_dlg, "rbKr", wxRadioButton)->GetValue())
style = 1;
else if (XRCCTRL(*m_dlg, "rbLinux", wxRadioButton)->GetValue())
style = 2;
else if (XRCCTRL(*m_dlg, "rbGNU", wxRadioButton)->GetValue())
style = 3;
else if (XRCCTRL(*m_dlg, "rbJava", wxRadioButton)->GetValue())
style = 4;
else if (XRCCTRL(*m_dlg, "rbCustom", wxRadioButton)->GetValue())
style = 5;
switch(style)
{
case 0: // ansi
formatter.bracketIndent = false;
formatter.indentLength = 4;
formatter.indentString = " ";
formatter.bracketFormatMode = astyle::BREAK_MODE;
formatter.classIndent = false;
formatter.switchIndent = false;
formatter.namespaceIndent = true;
formatter.blockIndent = false;
formatter.breakBlocks = false;
formatter.breakElseIfs = false;
formatter.padOperators = false;
formatter.padParen = false;
formatter.breakOneLineStatements = true;
formatter.breakOneLineBlocks = true;
break;
case 1: // K&R
formatter.bracketIndent = false;
formatter.indentLength = 4;
formatter.indentString = " ";
formatter.bracketFormatMode = astyle::ATTACH_MODE;
formatter.classIndent = false;
formatter.switchIndent = false;
formatter.namespaceIndent = true;
formatter.blockIndent = false;
formatter.breakBlocks = false;
formatter.breakElseIfs = false;
formatter.padOperators = false;
formatter.padParen = false;
formatter.breakOneLineStatements = true;
formatter.breakOneLineBlocks = true;
break;
case 2: // Linux
formatter.bracketIndent = false;
formatter.indentLength = 8;
formatter.indentString = " ";
formatter.bracketFormatMode = astyle::BDAC_MODE;
formatter.classIndent = false;
formatter.switchIndent = false;
formatter.namespaceIndent = true;
formatter.blockIndent = false;
formatter.breakBlocks = false;
formatter.breakElseIfs = false;
formatter.padOperators = false;
formatter.padParen = false;
formatter.breakOneLineStatements = true;
formatter.breakOneLineBlocks = true;
break;
case 3: // GNU
formatter.blockIndent = true;
formatter.bracketIndent = false;
formatter.indentLength = 2;
formatter.indentString = " ";
formatter.bracketFormatMode = astyle::BREAK_MODE;
formatter.classIndent = false;
formatter.switchIndent = false;
formatter.namespaceIndent = false;
formatter.breakBlocks = false;
formatter.breakElseIfs = false;
formatter.padOperators = false;
formatter.padParen = false;
formatter.breakOneLineStatements = true;
formatter.breakOneLineBlocks = true;
break;
case 4: // Java
formatter.sourceStyle = astyle::STYLE_JAVA;
formatter.modeSetManually = true;
formatter.bracketIndent = false;
formatter.indentLength = 4;
formatter.indentString = " ";
formatter.bracketFormatMode = astyle::ATTACH_MODE;
formatter.switchIndent = false;
formatter.blockIndent = false;
formatter.breakBlocks = false;
formatter.breakElseIfs = false;
formatter.padOperators = false;
formatter.padParen = false;
formatter.breakOneLineStatements = true;
formatter.breakOneLineBlocks = true;
break;
default: // Custom
{
bool value;
int spaceNum = XRCCTRL(*m_dlg, "spnIndentation", wxSpinCtrl)->GetValue();
formatter.modeSetManually = false;
formatter.indentLength = spaceNum;
if (XRCCTRL(*m_dlg, "chkUseTab", wxCheckBox)->GetValue())
{
formatter.indentString = '\t';
}
else
{
formatter.indentString = string(spaceNum, ' ');
}
value = XRCCTRL(*m_dlg, "chkForceUseTabs", wxCheckBox)->GetValue();
if (value)
{
formatter.indentString = '\t';
formatter.forceTabIndent = true;
}
else
{
formatter.forceTabIndent = false;
}
formatter.convertTabs2Space = XRCCTRL(*m_dlg, "chkConvertTabs", wxCheckBox)->GetValue();
formatter.emptyLineIndent = XRCCTRL(*m_dlg, "chkFillEmptyLines", wxCheckBox)->GetValue();
formatter.classIndent = XRCCTRL(*m_dlg, "chkIndentClasses", wxCheckBox)->GetValue();
formatter.switchIndent = XRCCTRL(*m_dlg, "chkIndentSwitches", wxCheckBox)->GetValue();
formatter.caseIndent = XRCCTRL(*m_dlg, "chkIndentCase", wxCheckBox)->GetValue();
formatter.bracketIndent = XRCCTRL(*m_dlg, "chkIndentBrackets", wxCheckBox)->GetValue();
formatter.blockIndent = XRCCTRL(*m_dlg, "chkIndentBlocks", wxCheckBox)->GetValue();
formatter.namespaceIndent = XRCCTRL(*m_dlg, "chkIndentNamespaces", wxCheckBox)->GetValue();
formatter.labelIndent = XRCCTRL(*m_dlg, "chkIndentLabels", wxCheckBox)->GetValue();
formatter.preprocessorIndent = XRCCTRL(*m_dlg, "chkIndentPreprocessor", wxCheckBox)->GetValue();
wxString breakType = XRCCTRL(*m_dlg, "cmbBreakType", wxComboBox)->GetValue();
if (breakType == _T("Break"))
{
formatter.bracketFormatMode = astyle::BREAK_MODE;
}
else if (breakType == _T("Attach"))
{
formatter.bracketFormatMode = astyle::ATTACH_MODE;
}
else if (breakType == _T("Linux"))
{
formatter.bracketFormatMode = astyle::BDAC_MODE;
}
else
{
formatter.bracketFormatMode = astyle::NONE_MODE;
}
formatter.breakBlocks = XRCCTRL(*m_dlg, "chkBreakBlocks", wxCheckBox)->GetValue();
formatter.breakElseIfs = XRCCTRL(*m_dlg, "chkBreakElseIfs", wxCheckBox)->GetValue();
formatter.padOperators = XRCCTRL(*m_dlg, "chkPadOperators", wxCheckBox)->GetValue();
formatter.padParen = XRCCTRL(*m_dlg, "chkPadParens", wxCheckBox)->GetValue();
formatter.breakOneLineStatements = !XRCCTRL(*m_dlg, "chkKeepComplex", wxCheckBox)->GetValue();
formatter.breakOneLineBlocks = !XRCCTRL(*m_dlg, "chkKeepBlocks", wxCheckBox)->GetValue();
break;
}
}
}