Menu

#37 Managing menu items

v1.0_(example)
open
nobody
None
1
2021-03-04
2021-02-21
No

Hi,

In hwmake.prg, I use to add items in some submenus.

MENU TITLE _("H&wGui Documentation")
  rgb=0
  for rga=1 to len(tablangage)
       if at("hwgui",tablangage[rga,1]) > 0
               rgb++
               Hwg_DefineMenuItem("&"+tablangage[rga,4],100+rgb,&("{||OpenDoc("+'"'+alltrim(str(rga))+'")'+"}"))
        endif
   next
ENDMENU

In another prg, I tried to add another item, but it failed as it seems it is not possible to manage a menu out of the menu itself.

Hwg_DefineMenuItem("&"+tablangage[nEnd,4],nId,&("{||OpenDoc("+'"'+alltrim(str(nEnd))+'")'+"}"))

It crashes :

Error BASE/1123  Argument error: AADD
Called from AADD(0)
Called from HWG_DEFINEMENUITEM(253)
Called from ADDDOCS(251)
Called from (b)MAIN(670)
Called from ONCOMMAND(370)
Called from (b)HMAINWINDOW(245)
Called from HMAINWINDOW:ONEVENT(339)
Called from HWG_ACTIVATEMAINWINDOW(0)
Called from HMAINWINDOW:ACTIVATE(328)
Called from MAIN(948)

If I include a command MENU of oMakeDlg (where is defined the menu in main(), it doesn't crash anymore, but it doesn't do nothing.
It works for Hwg_DeleteMenuItem() as we must precise the window name where is located the menu.

I see that there is a way to add an item with Hwg_AddMenuItem(), but as there is no parameter to precise the window name, I think it's the same problem as with Hwg_DefineMenuItem(), and also, I don't know the structure of aMenu ... (it would be nice to have it)

Is there a way to modify Hwg_DefineMenuItem() inserting the window name in the parameters, like in Hwg_DeleteMenuItem()

The only way I found for now is to restart hwmake, but it's a little frustating ...

Thanks
A+

Discussion

  • Wilfried Brunken

    Hello Alain,
    with commit r2948 i added a new sample "menumod.prg".
    It is derived from "testxml.prg", but the menu to modify was
    moved into a dialog and also the XML handling was removed.
    Feel free to use this as an template for experiments.
    Post it, if you have modifications.

    For your desire to change a menuitem by caption (string)
    we need new functions:
    At first this function must be created:
    hwg_GetMenuCaption( xWnd, nId )
    <not available="">
    (was in docu, but not realized).
    Needs to call Hwg_FindMenuItem( aMenu, nId, nPos )</not>

    In the next step, a search function must
    go to to the complete menu structure (recursive call's)
    by all id's and compare the string for match.
    Returning the id with match, then the menu item
    can be modified.

    I must spend some time to create and test these functions.

    With regards,
    MNI TNX, 73 es 55 de
    DF7BE, Wilfried

     
  • Aupeix Alain

    Aupeix Alain - 2021-02-28

    Hi Wilfried,

    I had a look to your sample, and I modify a little hwmake source, like this:

    Public aHwGui:={}
    ...
    MENU TITLE _("H&wGui Documentation")
       rgb=0
       for rga=1 to len(tablangage)
           if at("hwgui",tablangage[rga,1]) > 0
                rgb++
                aadd(aHwGui,{"&"+tablangage[rga,4],100+rgb, ;
                     "{||OpenDoc("+'"'+alltrim(str(rga))+'")'+"}"})
                Hwg_DefineMenuItem(aHwGui[len(aHwGui),1], ;
                                   aHwGui[len(aHwGui),2], ;     
                                   &(aHwGui[len(aHwGui),3]))
            endif
        next
    ENDMENU
    

    In another prg, I tried to add another item like this :

    aLang="a"+cProg //aLang=aHwGui for example
    aadd(&aLang,{"&"+cMenu,lid, ;
         "{||OpenDoc("+'"'+alltrim(str(npos))+'")'+"}"})
    Hwg_AddMenuItem(&aLang, cMenu, lid, .F., ;
                    &("{||OpenDoc("+'"'+alltrim(str(npos))+'")'+"}"), ;
                    len(&aLang) )
    hwg_Setmenucaption( oMakeDlg, lid, cMenu )
    

    No more crash, but the item isn't added to aMenu, and not visible immediately, and I have this message in the terminal which can explain the reason (but I'm not able to understand the reason):

    (hwmake:10451): Gtk-CRITICAL **:
        IA__gtk_menu_shell_insert: assertion
        'GTK_IS_MENU_SHELL (menu_shell)' failed
    

    The function hwg_SetMenuCaption() has no effect as hwg_AddMenuItem() fails ...
    When rebooting, as I build the menu from a dbf, it works, but it doesn't solve my problem which is to have the menu updated without restarting hwmake.

    Thanks
    A+

     

    Last edit: Aupeix Alain 2021-02-28
  • Wilfried Brunken

    Hello Alain,
    could you do me a favour ?
    Please take my sample program "menumod.prg". and modify it
    so that the bug appears (this saves time for me, better retrace). Thanks !

    With regards,
    MNI TNX, 73 es 55 de
    DF7BE, Wilfried

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.