|
| 1 | +/*************************************************************** |
| 2 | + * Name: PreservePermissions |
| 3 | + * Purpose: Code::Blocks plugin |
| 4 | + * Author: Damien Moore (damienlmoore@gmail.com) |
| 5 | + * Created: 2014-03-29 |
| 6 | + * Copyright: Damien Moore |
| 7 | + * License: GPL |
| 8 | + **************************************************************/ |
| 9 | + |
| 10 | +#ifndef PERMISSIONS_PRESERVER_H_INCLUDED |
| 11 | +#define PERMISSIONS_PRESERVER_H_INCLUDED |
| 12 | + |
| 13 | +// For compilers that support precompilation, includes <wx/wx.h> |
| 14 | +#include <wx/wxprec.h> |
| 15 | + |
| 16 | +#ifndef WX_PRECOMP |
| 17 | + #include <wx/wx.h> |
| 18 | +#endif |
| 19 | + |
| 20 | +#include <cbplugin.h> // for "class cbPlugin" |
| 21 | + |
| 22 | +#include <sys/stat.h> |
| 23 | + |
| 24 | + |
| 25 | +class PermissionsPreserver : public cbPlugin |
| 26 | +{ |
| 27 | + public: |
| 28 | + /** Constructor. */ |
| 29 | + PermissionsPreserver(); |
| 30 | + /** Destructor. */ |
| 31 | + virtual ~PermissionsPreserver(); |
| 32 | + |
| 33 | + |
| 34 | + /** This method is called by Code::Blocks and is used by the plugin |
| 35 | + * to add any menu items it needs on Code::Blocks's menu bar.\n |
| 36 | + * It is a pure virtual method that needs to be implemented by all |
| 37 | + * plugins. If the plugin does not need to add items on the menu, |
| 38 | + * just do nothing ;) |
| 39 | + * @param menuBar the wxMenuBar to create items in |
| 40 | + */ |
| 41 | + virtual void BuildMenu(wxMenuBar* menuBar){} |
| 42 | + |
| 43 | + /** This method is called by Code::Blocks core modules (EditorManager, |
| 44 | + * ProjectManager etc) and is used by the plugin to add any menu |
| 45 | + * items it needs in the module's popup menu. For example, when |
| 46 | + * the user right-clicks on a project file in the project tree, |
| 47 | + * ProjectManager prepares a popup menu to display with context |
| 48 | + * sensitive options for that file. Before it displays this popup |
| 49 | + * menu, it asks all attached plugins (by asking PluginManager to call |
| 50 | + * this method), if they need to add any entries |
| 51 | + * in that menu. This method is called.\n |
| 52 | + * If the plugin does not need to add items in the menu, |
| 53 | + * just do nothing ;) |
| 54 | + * @param type the module that's preparing a popup menu |
| 55 | + * @param menu pointer to the popup menu |
| 56 | + * @param data pointer to FileTreeData object (to access/modify the file tree) |
| 57 | + */ |
| 58 | + virtual void BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data = 0){} |
| 59 | + |
| 60 | + /** This method is called by Code::Blocks and is used by the plugin |
| 61 | + * to add any toolbar items it needs on Code::Blocks's toolbar.\n |
| 62 | + * It is a pure virtual method that needs to be implemented by all |
| 63 | + * plugins. If the plugin does not need to add items on the toolbar, |
| 64 | + * just do nothing ;) |
| 65 | + * @param toolBar the wxToolBar to create items on |
| 66 | + * @return The plugin should return true if it needed the toolbar, false if not |
| 67 | + */ |
| 68 | + virtual bool BuildToolBar(wxToolBar* toolBar){ return false; } |
| 69 | + protected: |
| 70 | + /** Any descendent plugin should override this virtual method and |
| 71 | + * perform any necessary initialization. This method is called by |
| 72 | + * Code::Blocks (PluginManager actually) when the plugin has been |
| 73 | + * loaded and should attach in Code::Blocks. When Code::Blocks |
| 74 | + * starts up, it finds and <em>loads</em> all plugins but <em>does |
| 75 | + * not</em> activate (attaches) them. It then activates all plugins |
| 76 | + * that the user has selected to be activated on start-up.\n |
| 77 | + * This means that a plugin might be loaded but <b>not</b> activated...\n |
| 78 | + * Think of this method as the actual constructor... |
| 79 | + */ |
| 80 | + virtual void OnAttach(); |
| 81 | + |
| 82 | + /** Any descendent plugin should override this virtual method and |
| 83 | + * perform any necessary de-initialization. This method is called by |
| 84 | + * Code::Blocks (PluginManager actually) when the plugin has been |
| 85 | + * loaded, attached and should de-attach from Code::Blocks.\n |
| 86 | + * Think of this method as the actual destructor... |
| 87 | + * @param appShutDown If true, the application is shutting down. In this |
| 88 | + * case *don't* use Manager::Get()->Get...() functions or the |
| 89 | + * behaviour is undefined... |
| 90 | + */ |
| 91 | + virtual void OnRelease(bool appShutDown); |
| 92 | + private: |
| 93 | + void OnEditorBeforeSave(CodeBlocksEvent& event); |
| 94 | + void OnEditorSave(CodeBlocksEvent& event); |
| 95 | + wxString m_filename; |
| 96 | + mode_t m_permissions; |
| 97 | + |
| 98 | +}; |
| 99 | + |
| 100 | +#endif // PERMISSIONS_PRESERVER_H_INCLUDED |
0 commit comments