Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: anandamu16 on February 15, 2017, 01:21:24 pm

Title: CB Menu modify plugin
Post by: anandamu16 on February 15, 2017, 01:21:24 pm
Hi,

I am trying to create a plugin to add an extra menu item in codeblocks.
Is there any guide, I can refer?

I referred this article, http://wiki.codeblocks.org/index.php/Creating_a_Plug-in_which_modifies_CB's_Menus
But its outdated and giving errors on using the api mentioned. Is there any updated one?

I tried to build the menu plugin following the above link, but I struck into submenu part.
Quote
Adding a submenu
Let's take our manipulation of the menu 1 step further. Let's create a submenu, which has its own entries. Since a submenu is nothing more then a menu, we first need to create a new menu object; this new object has to live as long as the plug-in itself, so it can not be a local variable, it needs to be stored in the class itself. Therefor we added the member m_SubMenu1, initialized to NULL, and released during the destructor. We will allocate it now :

       m_SubMenu1 = new wxMenu();
And we append this new menu to our EditMenu :

       EditMenu->Append(idSubMenu1, _("SubMenu1"), m_SubMenu1);

Build Log

Code
\Users\zbcqcm\Documents\Codeblocks_SVN\MenuPlugin\MenuPlugin.cpp -o .objs\MenuPlugin.o
mingw32-g++.exe -shared   -Wl,--dll -LC:\zbcqcm\codeblocks_svn_code\code\src\devel -LC:\wxMSW-2.8.12\wxMSW-2.8.12\lib\gcc_dll -LC:\wxMSW-2.8.12\wxMSW-2.8.12\lib\gcc_dll -L"C:\Program Files (x86)\CodeBlocks" .objs\MenuPlugin.o  -o MenuPlugin.dll -mthreads  -lcodeblocks -lwxmsw28u
C:\Users\zbcqcm\Documents\Codeblocks_SVN\MenuPlugin\MenuPlugin.cpp: In member function 'virtual void MenuPlugin::BuildMenu(wxMenuBar*)':
C:\Users\zbcqcm\Documents\Codeblocks_SVN\MenuPlugin\MenuPlugin.cpp:79:5: error: 'm_SubMenu1' was not declared in this scope
     m_SubMenu1 = new wxMenu();
     ^
C:\Users\zbcqcm\Documents\Codeblocks_SVN\MenuPlugin\MenuPlugin.cpp:80:22: error: 'idSubMenu1' was not declared in this scope
     EditMenu->Append(idSubMenu1, _("SubMenu1"), m_SubMenu1);
Title: Re: CB Menu modify plugin
Post by: ollydbg on February 15, 2017, 02:57:25 pm
Code
error: 'm_SubMenu1' was not declared in this scope
In C++, to use a member variable, you have to define it first, then use it.  :)  This is the same reason of the error about "idSubMenu1".
Title: Re: CB Menu modify plugin
Post by: anandamu16 on February 16, 2017, 07:28:41 am
Thanks, and sorry for asking such a dumb question



Some things I noticed, that varies from the CB's Menu plugin article are: Instead of using "messagemanager.h" we have to use "logmanager.h" as I guess messagemanager.h is no more available in codeblocks. And so as subsequent commands will get modify in Event handler functions. Maybe, someone can update the document.

Some doubts I had, may be if anyone can answer.
- Do I need to learn creating wxwidget project... to add a separate window for my plugin Menu entry or configuring wxsmith will be enough.? If wxsmith is enough, then when we can use wxwidget?

Title: Re: CB Menu modify plugin
Post by: anandamu16 on February 16, 2017, 08:14:18 am
Moreover, after installing my plugin, when I tried to uninstall the plugin. Codeblocks crashes away. I didn't get, why that happen?
Title: Re: CB Menu modify plugin
Post by: BlueHazzard on February 16, 2017, 03:30:23 pm
Quote
Codeblocks crashes away. I didn't get, why that happen?
you have to debug it to get a backtrace... If your plugin project is set up correctly you simply can hit the debugger button and it should launch codeblocks and you can debug all things like a normal program...

Quote
to add a separate window for my plugin Menu entry or configuring wxsmith will be enough.?
You can add awxSmith dialog by simply wxSmith->Add Dialog... this should work fine.. maybe you have to set the paths to wxWidgets for the compiler and linker...
Title: Re: CB Menu modify plugin
Post by: yvesdm3000 on February 16, 2017, 08:56:41 pm
Moreover, after installing my plugin, when I tried to uninstall the plugin. Codeblocks crashes away. I didn't get, why that happen?
Why don't you try something simpler than a plugin? One easily runs into some issue where a developer needs a lot of experience to solve it...
Just a wxWidgets based app alone sounds like a big enough challenge for you...

Yves
Title: Re: CB Menu modify plugin
Post by: anandamu16 on February 17, 2017, 08:17:26 am
Quote
Just a wxWidgets based app alone sounds like a big enough challenge for you...

I tried to create a wxwidget application for a smooth start, but I got the error. Check "http://forums.codeblocks.org/index.php/topic,21745.new.html#new"