Author Topic: Script CB : CallMenu ?  (Read 9253 times)

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Script CB : CallMenu ?
« on: November 15, 2011, 04:33:42 pm »
/ *** 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
« Last Edit: November 15, 2011, 05:36:11 pm by LETARTARE »
CB-13515, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.6
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Re: Script CB : CallMenu ?
« Reply #1 on: November 15, 2011, 05:26:04 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: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Re: Script CB : CallMenu ?
« Reply #2 on: November 15, 2011, 05:31:26 pm »
No, it's an error writting !!
'CallMenu (_T ("/Help/Tips"))' ...
« Last Edit: November 15, 2011, 05:36:38 pm by LETARTARE »
CB-13515, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.6
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Re: Script CB : CallMenu ?
« Reply #3 on: November 15, 2011, 05:44:14 pm »
'CallMenu (_T ("/Help/Tips"))' ...
Did you consider the shortcuts? Namely:
Code
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: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Re: Script CB : CallMenu ?
« Reply #4 on: November 15, 2011, 05:48:05 pm »
I try
Code
CallMenu(_T("/&Help/&Tips"))
but no !
I try
Code
 CallMenu(_T("/&Help/Tips"))
no ...
CB-13515, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.6
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7256
Re: Script CB : CallMenu ?
« Reply #5 on: November 15, 2011, 06:21:15 pm »
Works fine here with
Code
CallMenu(_T("/Help/Tips"))
with english locale, and
Code
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.

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Re: Script CB : CallMenu ?
« Reply #6 on: November 16, 2011, 09:54:55 am »
Quote
/**** Translation by GOOGLE ****/

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")) ;
}
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
}
}

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



« Last Edit: November 16, 2011, 10:45:22 am by LETARTARE »
CB-13515, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.6
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Script CB : CallMenu ?
« Reply #7 on: August 04, 2014, 11:36:40 pm »
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

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Re: Script CB : CallMenu ?
« Reply #8 on: August 05, 2014, 02:17:53 am »
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))

We can write
Quote
menu = "Helps/Tips" or "/Helps/Tips" or "/&Helps/Tips"

1- work
Quote
menu = "Helps/Tips"
menu = "Settings/Editor.."
menu = "File/Open..."
menu = "Search/Find..."
menu = "Plugins/Code profiler..."
...
2- nothing
Quote
menu  = "View/Logs"
menu  = "View/Start page"
...
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
4- crash C:B
Quote
menu = "Build/Select target/Release"
menu = "Help/Plugins/Abbreviations"
...
« Last Edit: August 05, 2014, 02:19:32 am by LETARTARE »
CB-13515, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.6
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Script CB : CallMenu ?
« Reply #9 on: August 12, 2014, 12:44:36 am »
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

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Re: Script CB : CallMenu ?
« Reply #10 on: August 12, 2014, 02:44:24 pm »
Hello @BlueHazzard,
thank you to worry about this problem.
For I do not know further, but I can do testing.
Good job.
CB-13515, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.6
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Script CB : CallMenu ?
« Reply #11 on: August 21, 2014, 11:23:05 pm »
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...

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Re: Script CB : CallMenu ?
« Reply #12 on: August 22, 2014, 06:28:59 pm »
@BlueHazzard
Thank you for your search and I hope that a solution will be found to Win.
Best regards
CB-13515, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.6
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl