User forums > Using Code::Blocks
Source formatter (line breaks)
The_Immortal:
Oh, guys... I just downloaded the latest version of AStyle (2.03) but have no idea how to involve it into CodeBlocks because there is no *.cbplugin file.
Could you help me please?
Thank you!
stahta01:
--- Quote from: The_Immortal on June 15, 2013, 12:53:38 am ---Oh, guys... I just downloaded the latest version of AStyle (2.03) but have no idea how to involve it into CodeBlocks because there is no *.cbplugin file.
Could you help me please?
Thank you!
--- End quote ---
If you want to convert a single C file at a time; you might wish to try this link
http://jimp03.zxq.net/Downloads.html
It is a GUI that wrap the AStyle; it either that, wait till the CB team integrates it, or learn to use the command line version you downloaded.
Edit2: A second GUI cite http://universalindent.sourceforge.net/
Edit3: You could also patch CB to use the newer AStyle; but, that is beyond my ability, so, I did not think of it, at first.
Edit4: Looks like the CB AStyle version is "2.04 beta" found in file astyle_main.cpp. So, likely just the GUI code needs added to CB to use the feature. If you are good at wxWidgets you might be able to do it. I am still bad at wxWidgets and have no time to learn how to do it.
Tim S.
BlueHazzard:
hello,
i have made a short patch to add this feature:
--- Code: ---Index: astyleconfigdlg.cpp
===================================================================
--- astyleconfigdlg.cpp (revision 9157)
+++ astyleconfigdlg.cpp (working copy)
@@ -41,6 +41,7 @@
EVT_RADIOBUTTON(XRCID("rbLisp"), AstyleConfigDlg::OnStyleChange)
EVT_RADIOBUTTON(XRCID("rbCustom"), AstyleConfigDlg::OnStyleChange)
EVT_BUTTON(XRCID("Preview"), AstyleConfigDlg::OnPreview )
+ EVT_CHECKBOX(XRCID("chkBreakeLines"), AstyleConfigDlg::OnCheckBoxEvt)
END_EVENT_TABLE()
AstyleConfigDlg::AstyleConfigDlg(wxWindow* parent)
@@ -274,6 +275,14 @@
SetStyle(aspsCustom);
}
+void AstyleConfigDlg::OnCheckBoxEvt(wxCommandEvent& event)
+{
+ if(event.IsChecked())
+ XRCCTRL(*this, "txtMaxLineLegth", wxTextCtrl)->Enable();
+ else
+ XRCCTRL(*this, "txtMaxLineLegth", wxTextCtrl)->Disable();
+}
+
void AstyleConfigDlg::OnPreview(wxCommandEvent& WXUNUSED(event))
{
wxString text(XRCCTRL(*this, "txtSample", wxTextCtrl)->GetValue());
@@ -333,7 +342,14 @@
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, "chkAddBrackets", wxCheckBox)->SetValue(cfg->ReadBool(_T("/add_brackets"), false));
+ XRCCTRL(*this, "chkBreakeLines", wxCheckBox)->SetValue(cfg->ReadBool(_T("/break_lines"), false));
+ XRCCTRL(*this, "txtMaxLineLegth", wxTextCtrl)->SetValue(cfg->Read(_T("/max_line_length"), _T("200")));
+ if(XRCCTRL(*this, "chkBreakeLines",wxCheckBox)->GetValue())
+ XRCCTRL(*this, "txtMaxLineLegth", wxTextCtrl)->Enable();
+ else
+ XRCCTRL(*this, "txtMaxLineLegth", wxTextCtrl)->Disable();
+
SetStyle((AStylePredefinedStyle)style);
}
@@ -397,4 +413,6 @@
cfg->Write(_T("/convert_tabs"), XRCCTRL(*this, "chkConvertTabs", wxCheckBox)->GetValue());
cfg->Write(_T("/fill_empty_lines"), XRCCTRL(*this, "chkFillEmptyLines", wxCheckBox)->GetValue());
cfg->Write(_T("/add_brackets"), XRCCTRL(*this, "chkAddBrackets", wxCheckBox)->GetValue());
+ cfg->Write(_T("/break_lines"), XRCCTRL(*this, "chkBreakeLines", wxCheckBox)->GetValue());
+ cfg->Write(_T("/max_line_length"), XRCCTRL(*this, "txtMaxLineLegth", wxTextCtrl)->GetValue());
}
Index: astyleconfigdlg.h
===================================================================
--- astyleconfigdlg.h (revision 9157)
+++ astyleconfigdlg.h (working copy)
@@ -19,6 +19,7 @@
protected:
void OnStyleChange(wxCommandEvent& event);
void OnPreview(wxCommandEvent& event);
+ void OnCheckBoxEvt(wxCommandEvent& event);
virtual wxString GetTitle() const { return _("Source formatter"); }
virtual wxString GetBitmapBaseName() const { return _T("astyle-plugin"); }
Index: formattersettings.cpp
===================================================================
--- formattersettings.cpp (revision 9157)
+++ formattersettings.cpp (working copy)
@@ -126,4 +126,9 @@
formatter.setTabSpaceConversionMode(cfg->ReadBool(_T("/convert_tabs")));
formatter.setEmptyLineFill(cfg->ReadBool(_T("/fill_empty_lines")));
formatter.setAddBracketsMode(cfg->ReadBool(_T("/add_brackets")));
+
+ if(cfg->ReadBool(_T("/break_lines")))
+ formatter.setMaxCodeLength( wxAtoi(cfg->Read(_T("/max_line_length"))));
+ else
+ formatter.setMaxCodeLength(string::npos);
}
Index: resources/configuration.xrc
===================================================================
--- resources/configuration.xrc (revision 9157)
+++ resources/configuration.xrc (working copy)
@@ -381,6 +381,35 @@
<flag>wxTOP|wxALIGN_LEFT|wxALIGN_TOP</flag>
<border>8</border>
</object>
+ <object class="sizeritem">
+ <object class="wxCheckBox" name="chkBreakeLines">
+ <label>Enable Line breaking</label>
+ </object>
+ <flag>wxTOP|wxALIGN_LEFT|wxALIGN_TOP</flag>
+ <border>8</border>
+ </object>
+ <object class="sizeritem">
+ <object class="wxBoxSizer">
+ <object class="sizeritem">
+ <object class="wxStaticText" name="ID_STATICTEXT1">
+ <label>Break lines after (50-200)</label>
+ </object>
+ <flag>wxTOP|wxALIGN_LEFT|wxALIGN_TOP</flag>
+ <border>4</border>
+ </object>
+ <object class="sizeritem">
+ <object class="wxTextCtrl" name="txtMaxLineLegth">
+ <value>200</value>
+ </object>
+ <flag>wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL</flag>
+ <border>8</border>
+ <option>1</option>
+ </object>
+ </object>
+ <flag>wxALIGN_LEFT|wxALIGN_TOP</flag>
+ <border>8</border>
+ <option>1</option>
+ </object>
</object>
<flag>wxALL|wxEXPAND|wxALIGN_LEFT|wxALIGN_TOP</flag>
<border>8</border>
--- End code ---
tested on win7 64bit
not many chages so it should work anywhere. (no boundary checking is performed for max line length value)
greetings
oBFusCATed:
Please post the patch at the project's page on berlios.
MortenMacFly:
--- Quote from: BlueHazzard on June 15, 2013, 02:14:40 pm ---i have made a short patch to add this feature:
--- End quote ---
Thanks for your patch. However, next time please consider to follow or coding guidelines, like format of brackets (i.e. in if-then clauses) and naming of methods: like "OnCheckBoxEvt" does not mean anything; use something as "OnPreview" instead which is easy to understand. This will make is easier for us to integrate proposed functionalities.
Navigation
[0] Message Index
[*] Previous page
Go to full version