Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: cacb on July 13, 2021, 10:32:33 am

Title: Execute plugin after saving C:B workspace?
Post by: cacb on July 13, 2021, 10:32:33 am
I have lots of Code::Blocks workspaces and I am considering exporting information found in them into "another format" (it doesn't matter what that is at this point).

I could write a completely separate tool to read C::B workspace and project files, but maybe a better idea is to write some form of C::B plugin that would always execute when a workspace is saved. I have been trying to read up on plugins from the Wiki, and there is useful information there, but it isn't clear to me how to make the plugin do its thing after saving a workspace. Is there some list of C::B events that a plugin can react to to achieve that?

For the sake of simplicity, let's assume there is no need for a plugin GUI. All that is needed is access to the workspace & project information + some event to trigger execution after saving the workspace.

Any suggestions?
Title: Re: Execute plugin after saving C:B workspace?
Post by: Miguel Gimenez on July 13, 2021, 11:23:09 am
You can use the rndgen plugin as starting point, changing cbEVT_EDITOR_BEFORE_SAVE to cbEVT_WORKSPACE_CLOSING_BEGIN (or similar, see sdk_events.h)
Title: Re: Execute plugin after saving C:B workspace?
Post by: cacb on July 13, 2021, 12:32:35 pm
Thank you, that was indeed a useful reply. I can see it is one of the contrib plugins.

Through your reply I also discovered
https://wiki.codeblocks.org/index.php/Code::Blocks_SDK_events

I will see what this means. I guess you need to use the same wxWidgets  in plugins that was used for building C::B, and that will be ok for me on Linux, as I build C::B from source there. Under Windows probably not, as I use exclusively Nightly Builds of C::B there, and wxWidgets compiled with MSVC. So most likely such a plugin would be Linux only.

In any case, I might give it a try. Thanks!
Title: Re: Execute plugin after saving C:B workspace?
Post by: Miguel Gimenez on July 13, 2021, 01:19:51 pm
The list of events in the wiki is incomplete (cbEVT_PROJECT_FILE_RENAMED is missing), but currently it can't be edited.
Title: Re: Execute plugin after saving C:B workspace?
Post by: cacb on July 13, 2021, 11:30:23 pm
I have played around a bit with this under Kubuntu 20.04, and the plugin events seem to work quite nicely. I found that cbEVT_COMPILER_FINISHED is another good candidate. Thanks for the help.

If I can get the plugin to do something useful I will put it on github and mention it here.
Title: Re: Execute plugin after saving C:B workspace?
Post by: cacb on July 15, 2021, 02:30:23 pm
I have managed to get my plugin to work, more or less (a number of rough edges still).  It runs just after build (cbEVT_COMPILER_FINISHED) which is nice in many ways.  But I can now see that I have hard coded a couple of things that should be user configurable, so I have a couple of questions:

As I understand it, the "settings" for a plugin is accessed in C::B via Tools -> Plugins if the plugin has created a dialog for it in its GetConfigurationPanel() overload. Is that correct?

If I have such a dialog with settings that should persist also after closing and restarting Code::Blocks, where would I store those values? In a normal application I would perhaps use wxConfig for that, but how does this work for a Code::Blocks plugin? Is maybe the correct way to use Manager::Get()->GetConfigManager("MyPluginName") and obtain a ConfigManager* where I simply use standard primitives like Read/Write in much the same way as for wxConfig?
Title: Re: Execute plugin after saving C:B workspace?
Post by: Miguel Gimenez on July 15, 2021, 04:05:18 pm
You can use the tidycmt plugin as reference, it uses these two methods to show/save settings:

Code
cbConfigurationPanel* TidyCmt::GetConfigurationPanel(wxWindow* parent)
void TidyCmt::ConfigurePlugin(const TidyCmtConfig& tcc)

and a custom panel derived from cbConfigurationPanel (TidyCmtSettingsWrapper).
Title: Re: Execute plugin after saving C:B workspace?
Post by: cacb on July 15, 2021, 09:20:22 pm
Thank you, that is useful. However, on Windows I have tidycmt enabled but I can't find where its show/save settings is displayed in the C::B gui. It does not show in the Plugins menu and I can't find it anywhere else either (settings). To be usable as a reference I need to see it working.

What I hope to do is
1. Make my plugin be listed in the Plugins Menu and when I select it, a settings dialog show up (similar to Symbols Table Plugin maybe).
2. Make it add a menu entry in the File menu (e.g. File -> Export ) where it would perform the same operation without requiring a Compilation

So far I have figured out that only plugins of type "ptTool" show up in the Plugins menu, but I can't make it a cbToolPlugin because I think that hides things I need to do for # 2 (I could be wrong). I tried to make my plugin return type "pTool" and that made it show up in the Plugins Menu, but it crashed when I clicked it since it doesn't return a dialog at present.

Would implementing ConfigurePlugin using a wrapper like TidyCmt::GetConfigurationPanel solve that? I can't figure this bit out since I never saw the tidycmt gui, and I think I need a dialog, not a panel.

EDIT: I finally found that the tidycmt panel GUI is very well hidden in Project -> Properties  as "EditorConfig options" tab far to the right. So now I know where it is.  But this is not the kind of feature I want to duplicate.  I think I want the same as a cbToolPlugin but where the BuildMenu function is not hidden as it is in cbToolPlugin
Title: Re: Execute plugin after saving C:B workspace?
Post by: Miguel Gimenez on July 15, 2021, 10:41:46 pm
I see it under Settings -> Editor -> tidycmt. The panel you supply will be shown inside the Settings window.