Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 4dda012fe7a08b77f6f10ba26cffe6e6b9e382a5 @xuhdev xuhdev committed Jan 26, 2012
Showing with 362 additions and 0 deletions.
  1. +11 −0 .editorconfig
  2. +164 −0 CBEditorConfig.cpp
  3. +90 −0 CBEditorConfig.hpp
  4. +44 −0 README.md
  5. +39 −0 editorconfig-codeblocks_unix.cbp
  6. +14 −0 manifest.xml
@@ -0,0 +1,11 @@
+[*]
+end_of_line = lf
+indent_style = space
+
+[*.xml]
+indent_size = 2
+
+[*.cpp]
+indent_size = 4
+[*.hpp]
+indent_size = 4
@@ -0,0 +1,164 @@
+#include <sdk.h> // Code::Blocks SDK
+#include <configurationpanel.h>
+#include <editormanager.h>
+#include <manager.h>
+#include "cbeditor.h"
+#include "cbstyledtextctrl.h"
+#include "CBEditorConfig.hpp"
+#include <wx/msgdlg.h>
+#include <editorconfig/editorconfig.h>
+
+// Register the plugin with Code::Blocks.
+// We are using an anonymous namespace so we don't litter the global one.
+namespace
+{
+ PluginRegistrant<CBEditorConfig> reg(_T("CBEditorConfig"));
+}
+
+// constructor
+CBEditorConfig::CBEditorConfig()
+{
+ // Make sure our resources are available.
+ // In the generated boilerplate code we have no resources but when
+ // we add some, it will be nice that this code is in place already ;)
+ if (!Manager::LoadResource(_T("CBEditorConfig.zip"))) {
+ NotifyMissingFile(_T("CBEditorConfig.zip"));
+ }
+}
+
+// destructor
+CBEditorConfig::~CBEditorConfig()
+{
+}
+
+void CBEditorConfig::OnAttach()
+{
+ // do initialization
+
+ // register event
+ Manager::Get()->RegisterEventSink(cbEVT_EDITOR_OPEN,
+ new cbEventFunctor<CBEditorConfig, CodeBlocksEvent>(this,
+ &CBEditorConfig::OnEditorOpen));
+}
+
+void CBEditorConfig::LoadConfig(const wxString& fileName)
+{
+ editorconfig_handle eh = editorconfig_handle_init();
+
+ /* start parsing */
+ int err_num;
+ if ((err_num = editorconfig_parse(fileName.ToAscii(), eh)) != 0 &&
+ /* Ignore full path error, whose error code is
+ * EDITORCONFIG_PARSE_NOT_FULL_PATH */
+ err_num != EDITORCONFIG_PARSE_NOT_FULL_PATH) {
+ wxString err_msg;
+ err_msg << wxT("EditorConfig Error: ") << err_num;
+ wxMessageDialog(NULL, err_msg, wxT("EditorConfig"), wxOK);
+ editorconfig_handle_destroy(eh);
+ return;
+ }
+
+ // apply the settings
+
+ struct
+ {
+ const char* indent_style;
+ int indent_size;
+ int tab_width;
+ const char* end_of_line;
+ } ecConf; // obtained EditorConfig settings will be here
+
+ int name_value_count = editorconfig_handle_get_name_value_count(eh);
+
+ // get settings
+ for (int i = 0; i < name_value_count; ++i) {
+ const char* name;
+ const char* value;
+
+ editorconfig_handle_get_name_value(eh, i, &name, &value);
+
+ if (!strcmp(name, "indent_style"))
+ ecConf.indent_style = value;
+ else if (!strcmp(name, "tab_width"))
+ ecConf.tab_width = atoi(value);
+ else if (!strcmp(name, "indent_size"))
+ ecConf.indent_size = atoi(value);
+ else if (!strcmp(name, "end_of_line"))
+ ecConf.end_of_line = value;
+ }
+
+ // get the cbEditor and cbStyledTextCtrl
+ cbEditor *ed =
+ Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
+ cbStyledTextCtrl* control = ed->GetControl();
+
+ if (ecConf.indent_style) {
+ if (!strcmp(ecConf.indent_style, "tab"))
+ control->SetUseTabs(true);
+ else if (!strcmp(ecConf.indent_style, "space"))
+ control->SetUseTabs(false);
+ }
+ if (ecConf.indent_size > 0) {
+ control->SetIndent(ecConf.indent_size);
+
+ // We set the tab width here, so that this could be overrided then
+ // if ecConf.tab_wdith > 0
+ control->SetTabWidth(ecConf.indent_size);
+ }
+
+ if (ecConf.tab_width > 0)
+ control->SetTabWidth(ecConf.indent_size);
+
+ // set eol
+ if (ecConf.end_of_line) {
+ if (!strcmp(ecConf.end_of_line, "lf"))
+ control->SetEOLMode(wxSCI_EOL_LF);
+ else if (!strcmp(ecConf.end_of_line, "crlf"))
+ control->SetEOLMode(wxSCI_EOL_CRLF);
+ else if (!strcmp(ecConf.end_of_line, "cr"))
+ control->SetEOLMode(wxSCI_EOL_CR);
+ }
+
+ editorconfig_handle_destroy(eh);
+}
+
+void CBEditorConfig::OnEditorOpen(CodeBlocksEvent& event)
+{
+ LoadConfig(event.GetEditor()->GetFilename());
+}
+
+void CBEditorConfig::OnRelease(bool /* appShutDown */)
+{
+}
+
+int CBEditorConfig::Configure()
+{
+ return 0;
+}
+
+int CBEditorConfig::GetConfigurationPriority() const
+{
+ return 50;
+}
+
+int CBEditorConfig::GetConfigurationGroup() const
+{
+ return cgUnknown;
+}
+
+void CBEditorConfig::BuildMenu(wxMenuBar* /*menuBar*/)
+{
+ return;
+}
+
+void CBEditorConfig::BuildModuleMenu(const ModuleType /*type*/,
+ wxMenu* /*menu*/,
+ const FileTreeData* /*data*/)
+{
+ return;
+}
+
+bool CBEditorConfig::BuildToolBar(wxToolBar* /*toolBar*/)
+{
+ return false;
+}
@@ -0,0 +1,90 @@
+#ifndef CBEDITORCONFIG_HPP_INCLUDED
+#define CBEDITORCONFIG_HPP_INCLUDED
+
+// For compilers that support precompilation, includes <wx/wx.h>
+#include <wx/wxprec.h>
+
+#ifndef WX_PRECOMP
+ #include <wx/wx.h>
+#endif
+
+#include <cbplugin.h> // for "class cbToolPlugin"
+
+class CBEditorConfig : public cbPlugin
+{
+public:
+ /** Constructor. */
+ CBEditorConfig();
+ /** Destructor. */
+ virtual ~CBEditorConfig();
+
+ /** Invoke configuration dialog. */
+ virtual int Configure();
+
+ /** Return the plugin's configuration priority.
+ * This is a number (default is 50) that is used to sort plugins
+ * in configuration dialogs. Lower numbers mean the plugin's
+ * configuration is put higher in the list.
+ */
+ virtual int GetConfigurationPriority() const;
+
+ /** Return the configuration group for this plugin. Default is cgUnknown.
+ * Notice that you can logically OR more than one configuration groups,
+ * so you could set it, for example, as "cgCompiler | cgContribPlugin".
+ */
+ virtual int GetConfigurationGroup() const;
+
+ /** Return plugin's configuration panel.
+ * @param parent The parent window.
+ * @return A pointer to the plugin's cbConfigurationPanel. It is deleted by the caller.
+ */
+ virtual cbConfigurationPanel* GetConfigurationPanel(wxWindow* parent){ return 0; }
+
+ /** Return plugin's configuration panel for projects.
+ * The panel returned from this function will be added in the project's
+ * configuration dialog.
+ * @param parent The parent window.
+ * @param project The project that is being edited.
+ * @return A pointer to the plugin's cbConfigurationPanel. It is deleted by the caller.
+ */
+ virtual cbConfigurationPanel* GetProjectConfigurationPanel(wxWindow* parent, cbProject* project){ return 0; }
+
+protected:
+ /** Any descendent plugin should override this virtual method and
+ * perform any necessary initialization. This method is called by
+ * Code::Blocks (PluginManager actually) when the plugin has been
+ * loaded and should attach in Code::Blocks. When Code::Blocks
+ * starts up, it finds and <em>loads</em> all plugins but <em>does
+ * not</em> activate (attaches) them. It then activates all plugins
+ * that the user has selected to be activated on start-up.\n
+ * This means that a plugin might be loaded but <b>not</b> activated...\n
+ * Think of this method as the actual constructor...
+ */
+ virtual void OnAttach();
+
+ /** Any descendent plugin should override this virtual method and
+ * perform any necessary de-initialization. This method is called by
+ * Code::Blocks (PluginManager actually) when the plugin has been
+ * loaded, attached and should de-attach from Code::Blocks.\n
+ * Think of this method as the actual destructor...
+ * @param appShutDown If true, the application is shutting down. In this
+ * case *don't* use Manager::Get()->Get...() functions or the
+ * behaviour is undefined...
+ */
+ virtual void OnRelease(bool appShutDown);
+
+ virtual void BuildMenu(wxMenuBar* /*menuBar*/);
+ virtual void BuildModuleMenu(const ModuleType /*type*/,
+ wxMenu* /*menu*/,
+ const FileTreeData* /*data*/ = 0);
+ virtual bool BuildToolBar(wxToolBar* /*toolBar*/);
+
+private:
+ /** Called when the editor opens a new file
+ */
+ void OnEditorOpen(CodeBlocksEvent& event);
+
+ void LoadConfig(const wxString& fileName);
+};
+
+#endif // CBEDITORCONFIG_HPP_INCLUDED
@@ -0,0 +1,44 @@
+# EditorConfig Code::Blocks Plugin
+
+This is an [EditorConfig][] plugin for [Code::Blocks][].
+
+## Installation
+
+### Install from Source
+
+Before installation, you must have both [Code::Blocks][] installed.
+
+1. Download the [EditorConfig core][] and follow the instructions in the README
+ and INSTALL files to compile and install it.
+
+2. Download the [EditorConfig plugin for Code::Blocks][CBEditorConfig] and
+ extract it.
+
+3. Use Code::Blocks to open the Code::Blocks project file:
+ `editorconfig-codeblocks_unix.cbp`. To do this, launch Code::Blocks, click
+ menu `File->Open...`, and select `editorconfig-codeblocks_unix.cbp` in the
+ popped up file dialog.
+
+4. Click menu `Build->Build` to compile the plugin.
+
+5. Click menu `Plugins->Manage Plugins...`, then click on the `Install new`
+ button. In the popped up file dialog, select the built
+ `CBEditorConfig.cbplugin` file.
+
+## Supported properties
+
+The EditorConfig Code::Blocks plugin supports the following EditorConfig
+[properties][]:
+
+* indent_style
+* indent_size
+* tab_width
+* end_of_line
+* root (only used by EditorConfig core)
+
+
+[CBEditorConfig]: https://github.com/editorconfig/editorconfig-codeblocks
+[CodeBlocks]: http://www.codeblocks.org
+[EditorConfig]: http://editorconfig.org
+[EditorConfig core]: https://github.com/editorconfig/editorconfig
+[properties]: http://editorconfig.org/#supported-properties
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_project_file>
+ <FileVersion major="1" minor="6" />
+ <Project>
+ <Option title="editorconfig-codeblocks" />
+ <Option pch_mode="2" />
+ <Option compiler="gcc" />
+ <Build>
+ <Target title="default">
+ <Option output="CBEditorConfig" prefix_auto="1" extension_auto="1" />
+ <Option type="3" />
+ <Option compiler="gcc" />
+ <Option host_application="codeblocks" />
+ <Compiler>
+ <Add option="-g" />
+ <Add option="`pkg-config --cflags codeblocks`" />
+ <Add option="`wx-config --cflags`" />
+ <Add option="-fPIC" />
+ </Compiler>
+ <Linker>
+ <Add option="`pkg-config --libs codeblocks`" />
+ <Add option="`wx-config --libs`" />
+ <Add option="-leditorconfig" />
+ </Linker>
+ <ExtraCommands>
+ <Add after="zip -j9 CBEditorConfig.zip manifest.xml" />
+ <Add after="zip -j9 CBEditorConfig.cbplugin CBEditorConfig.so CBEditorConfig.zip" />
+ </ExtraCommands>
+ </Target>
+ </Build>
+ <Unit filename="CBEditorConfig.cpp" />
+ <Unit filename="CBEditorConfig.hpp" />
+ <Unit filename="manifest.xml" />
+ <Extensions>
+ <code_completion />
+ <debugger />
+ </Extensions>
+ </Project>
+</CodeBlocks_project_file>
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_plugin_manifest_file>
+ <SdkVersion major="1" minor="11" release="12" />
+ <Plugin name="CBEditorConfig">
+ <Value title="EditorConfig plugin for Code::Blocks" />
+ <Value version="0.1" />
+ <Value description="EditorConfig plugin for Code::Blocks" />
+ <Value author="EditorConfig Team" />
+ <Value authorEmail="" />
+ <Value authorWebsite="http://editorconfig.org" />
+ <Value thanksTo="" />
+ <Value license="Simplified BSD License" />
+ </Plugin>
+</CodeBlocks_plugin_manifest_file>

0 comments on commit 4dda012

Please sign in to comment.