News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

CB Menu modify plugin

Started by anandamu16, February 15, 2017, 01:21:24 PM

Previous topic - Next topic

anandamu16

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.
QuoteAdding 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

\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);

ollydbg

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".
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

anandamu16

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?


anandamu16

Moreover, after installing my plugin, when I tried to uninstall the plugin. Codeblocks crashes away. I didn't get, why that happen?

BlueHazzard

QuoteCodeblocks 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...

Quoteto 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...

yvesdm3000

Quote from: 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?
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
Clang based code completion for Code::Blocks:   [url="http://github.com/yvesdm3000/ClangLib"]http://github.com/yvesdm3000/ClangLib[/url]

anandamu16

QuoteJust 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.next.codeblocks.org/index.php/topic,21745.new.html#new"