News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Script CB : CallMenu ?

Started by LETARTARE, November 15, 2011, 04:33:42 PM

Previous topic - Next topic

LETARTARE

/ *** Translated by GOOGLE  ***/
hello,
I try to use 'CallMenu ()'.
From the script console, I type "CallMenu (_T ("/Help /Tips"))', but nothing happens.
What is the syntax ?.

Best regards.

- OS: Vista Basic Pack 2
          Mingw32 with TDM-GCC 4.4/4.5 Series
- Tools: Code:: Blocks 10.5 rev 6283 with wxWidgets unicode 2.8.10
CB-13834, plugins-sdk-2.25.0 : Collector-2.6.5, AddOnForQt-5.1.2
1- Win7 Business Pack1 64bits : wx-3.2.8, gcc-15.2.0,
2- OpenSuse::Leap-15.6-64bits : wx-3.2.8;gtk3-u, gcc-15.2.0,
=> !! The messages are translated by 'Deepl'

MortenMacFly

Quote from: LETARTARE on November 15, 2011, 04:33:42 PM
CallMenu (_T ("/Help /Tips"))
If the space between Help and the slash (/) is also in your implementation that's why it cannot work.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

LETARTARE

#2
No, it's an error writting !!
'CallMenu (_T ("/Help/Tips"))' ...
CB-13834, plugins-sdk-2.25.0 : Collector-2.6.5, AddOnForQt-5.1.2
1- Win7 Business Pack1 64bits : wx-3.2.8, gcc-15.2.0,
2- OpenSuse::Leap-15.6-64bits : wx-3.2.8;gtk3-u, gcc-15.2.0,
=> !! The messages are translated by 'Deepl'

MortenMacFly

Quote from: LETARTARE on November 15, 2011, 05:31:26 PM
'CallMenu (_T ("/Help/Tips"))' ...
Did you consider the shortcuts? Namely:
CallMenu(_T("/&Help/&Tips"))

(Just a wild guess - I have no access to c::B at the moment...)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

LETARTARE

I try CallMenu(_T("/&Help/&Tips"))
but no !
I try CallMenu(_T("/&Help/Tips"))
no ...
CB-13834, plugins-sdk-2.25.0 : Collector-2.6.5, AddOnForQt-5.1.2
1- Win7 Business Pack1 64bits : wx-3.2.8, gcc-15.2.0,
2- OpenSuse::Leap-15.6-64bits : wx-3.2.8;gtk3-u, gcc-15.2.0,
=> !! The messages are translated by 'Deepl'

Jenna

Works fine here with
CallMenu(_T("/Help/Tips"))
with english locale, and
CallMenu(_T("/Hilfe/Tips"))
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

#6
Quote/**** Translation by GOOGLE ****/

Thank you for your answers.
I wrote a 'menu.script'
// 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")) ;
}

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)

  // 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
}
}


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)'

2 - compiled with the sources (English version)
Quote'CallMenu(/Help/Tips)'
error process entries
'CallMenu(/Aide/Astuces)'
'CallMenu(/Hilfe/Tips)'

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)'

It seems that 'wxMenuBar-> processEvents (evt)' does not give the desired result.
After that, I do not know ... Maybe a version problem of 'wxWidgets'?



CB-13834, plugins-sdk-2.25.0 : Collector-2.6.5, AddOnForQt-5.1.2
1- Win7 Business Pack1 64bits : wx-3.2.8, gcc-15.2.0,
2- OpenSuse::Leap-15.6-64bits : wx-3.2.8;gtk3-u, gcc-15.2.0,
=> !! The messages are translated by 'Deepl'

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

#8
Some menus work, others do not, others failed, other crash Code::Blocks !

Tests  with  svn9778, sdk 1.23.0, wx 2.8

QuoteSyntax ; CallMenu(_T(menu))

We can write
Quotemenu = "Helps/Tips" or "/Helps/Tips" or "/&Helps/Tips"

1- work
Quotemenu = "Helps/Tips"
menu = "Settings/Editor.."
menu = "File/Open..."
menu = "Search/Find..."
menu = "Plugins/Code profiler..."
...
2- nothing
Quotemenu  = "View/Logs"
menu  = "View/Start page"
...
3- failed
Quotemenu = "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
4- crash C:B
Quotemenu = "Build/Select target/Release"
menu = "Help/Plugins/Abbreviations"
...
CB-13834, plugins-sdk-2.25.0 : Collector-2.6.5, AddOnForQt-5.1.2
1- Win7 Business Pack1 64bits : wx-3.2.8, gcc-15.2.0,
2- OpenSuse::Leap-15.6-64bits : wx-3.2.8;gtk3-u, gcc-15.2.0,
=> !! The messages are translated by 'Deepl'

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

LETARTARE

Hello @BlueHazzard,
thank you to worry about this problem.
For I do not know further, but I can do testing.
Good job.
CB-13834, plugins-sdk-2.25.0 : Collector-2.6.5, AddOnForQt-5.1.2
1- Win7 Business Pack1 64bits : wx-3.2.8, gcc-15.2.0,
2- OpenSuse::Leap-15.6-64bits : wx-3.2.8;gtk3-u, gcc-15.2.0,
=> !! The messages are translated by 'Deepl'

BlueHazzard

Hi.. I have looked into it. On linux this bug don't occur, so it possibly is a wxWidgets MSW bug.
The problem is definitely that it doesn't can find the event handler function for the Menu Entry with the given id.. I have tried to manually connect the event handler to the main window,  but it didn't helped. Also calling the event handler of the main window and hoping the event will propagate upwards to the menu event handler didn't worked. I'm not a wxWidgets expert, and debugging event things is a pain, because you don't know in which event handler you are if you step through the code.

So i can't find a solution for this at the moment. If i will find some time, i will look future, but this is really annoying...
Probably the best and most elegant way to fix this bug would be to export every menu call function as squirrel function (the underlying functions, not the event handler).

greetings...

LETARTARE

@BlueHazzard
Thank you for your search and I hope that a solution will be found to Win.
Best regards
CB-13834, plugins-sdk-2.25.0 : Collector-2.6.5, AddOnForQt-5.1.2
1- Win7 Business Pack1 64bits : wx-3.2.8, gcc-15.2.0,
2- OpenSuse::Leap-15.6-64bits : wx-3.2.8;gtk3-u, gcc-15.2.0,
=> !! The messages are translated by 'Deepl'