User forums > Using Code::Blocks
Script CB : CallMenu ?
Jenna:
Works fine here with
--- Code: ---CallMenu(_T("/Help/Tips"))
--- End code ---
with english locale, and
--- Code: ---CallMenu(_T("/Hilfe/Tips"))
--- End code ---
with my (default) german locale.
If you have switched internationalization on, some of the strings will be localized (like "Help", "Close", "open" etc.).
You have to use the exact spelling of the menu-entries.
LETARTARE:
--- Quote ---/**** Translation by GOOGLE ****/
--- End quote ---
Thank you for your answers.
I wrote a 'menu.script'
--- Code: ---// menu.script
function main() {
// with english locale
CallMenu(_T("/Help/Tips")) ;
// with my french locale.
CallMenu(_T("/Aide/Astuces")) ;
// with german locale.
CallMenu(_T("/Hilfe/Tips")) ;
}
--- End code ---
called from the command line console script by "main () '
Then I changed 'codeblocks-10.05-release\src\sdk\scripting\bindings\sc_globals.cpp' (with wxWidgets 2.8.11)
--- Code: --- // locate and call a menu from string (e.g. "/Valgrind/Run Valgrind::MemCheck")
void CallMenu(const wxString& menuPath)
{
// -> LETARTARE
gWarningLog (_T("'CallMenu(") + menuPath + _T(")'"));
// <-
// this code is partially based on MenuItemsManager::CreateFromString()
wxMenuBar* mbar = Manager::Get()->GetAppFrame()->GetMenuBar();
wxMenu* menu = 0;
size_t pos = 0;
while (true)
{
// ignore consecutive slashes
while (pos < menuPath.Length() && menuPath.GetChar(pos) == _T('/'))
{
++pos;
}
// find next slash
size_t nextPos = pos;
while (nextPos < menuPath.Length() && menuPath.GetChar(++nextPos) != _T('/'))
;
wxString current = menuPath.Mid(pos, nextPos - pos);
if (current.IsEmpty())
break;
bool isLast = nextPos >= menuPath.Length();
// current holds the current search string
if (!menu) // no menu yet? look in menubar
{
int menuPos = mbar->FindMenu(current);
if (menuPos == wxNOT_FOUND)
break; // failed
else
menu = mbar->GetMenu(menuPos);
}
else
{
if (isLast)
{
int id = menu->FindItem(current);
if (id != wxNOT_FOUND)
{
// --> begin modification : LETARTARE
bool ret;
wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED, id);
#if wxCHECK_VERSION(2, 9, 0)
ret = mbar->GetEventHandler()->ProcessEvent(evt);
if (ret)
gWarningLog (_T("2.9.0 :Process entries '") + menuPath + _T("'") );
else
gErrorLog(_T("2.9.0 : error process entries"));
#else
ret = mbar->ProcessEvent(evt);
if (ret)
gWarningLog (_T(" Process entries '") + menuPath + _T("'"));
else
gErrorLog(_T(" error process entries"));
// <-- end
#endif
// done
}
break;
}
int existing = menu->FindItem(current);
if (existing != wxNOT_FOUND)
menu = menu->GetMenuItems()[existing]->GetSubMenu();
else
break; // failed
}
pos = nextPos; // prepare for next loop
}
}
--- End code ---
Results of the script in the console log
1 - compiled with the sources (French version)
--- Quote ---'CallMenu(/Help/Tips)'
'CallMenu(/Aide/Astuces)'
error process entries
'CallMenu(/Hilfe/Tips)'
--- End quote ---
2 - compiled with the sources (English version)
--- Quote ---'CallMenu(/Help/Tips)'
error process entries
'CallMenu(/Aide/Astuces)'
'CallMenu(/Hilfe/Tips)'
--- End quote ---
3 - from version installed (10.5 rev 6283, unicode wxWidgets 8.2.10) French version
--- Quote ---'CallMenu(/Help/Tips)'
'CallMenu(/Aide/Astuces)'
error process entries
'CallMenu(/Hilfe/Tips)'
--- End quote ---
It seems that 'wxMenuBar-> processEvents (evt)' does not give the desired result.
After that, I do not know ... Maybe a version problem of 'wxWidgets'?
BlueHazzard:
So lets go back here...
I have tested it with my c::b version on github, i don't know the revision...
The name has to be exact, so don't use the &, just CallMenu("Help/Tips") works with my implementation... (but i have support for native strings, so if you are using a "normal" implementation of c::b you can try to use CallMenu(T("Help/Tips")) in the skripting console command line)
sorry for this "incomplete" post, but i just installed my new hardware and there is missing the whole programming thing..
i will future look into this...
greetings
LETARTARE:
Some menus work, others do not, others failed, other crash Code::Blocks !
Tests with svn9778, sdk 1.23.0, wx 2.8
--- Quote ---Syntax ; CallMenu(_T(menu))
--- End quote ---
We can write
--- Quote ---menu = "Helps/Tips" or "/Helps/Tips" or "/&Helps/Tips"
--- End quote ---
1- work
--- Quote ---menu = "Helps/Tips"
menu = "Settings/Editor.."
menu = "File/Open..."
menu = "Search/Find..."
menu = "Plugins/Code profiler..."
...
--- End quote ---
2- nothing
--- Quote ---menu = "View/Logs"
menu = "View/Start page"
...
--- End quote ---
3- failed
--- Quote ---menu = "Project/Add files..." id=864
menu = "Project/Notes..." id=871
menu = "Project/Properties..." id=872
... all Project
menu = "Fortran/Jump..." id=1973
menu = "Build/Build" id=1628
... all Build
--- End quote ---
4- crash C:B
--- Quote ---menu = "Build/Select target/Release"
menu = "Help/Plugins/Abbreviations"
...
--- End quote ---
BlueHazzard:
I finally managed to restore my programing enviroment.
I can confirm your findings. I had not the time to digg deeper, but i think the problem is, that the plugins don't register theyre event handler in a correct form...
The curios thing is that the normal event handling works, but not the custom event creation.
If i find time tomorow i will look into it... It will take its time because debugging event stuff is a pain.
In general i am not really happy with this way over the menus. There should be a native way, like a command manager or all functions are get bound natively to squirell, or something similar...
Greetings.
Ps. Sorry for the errors, but with this mobilephone keyboard, and without spellchecker/dictionary it is a bit difficult for me, to write proper english
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version