How To Use/set Visible Attribute In Menu-items

PrJlndni

Member
Good day Masters,

I would like to ask your expertise on MENU and SUB-MENU Widgets.
I have a menu-item in my sub-menu that I do not want to show in my menu.
I am using OpenEdge 11.8 and running it via Putty.

I am currently working on the following:
[]
Code:
DEFINE SUB-Menu maint000
    Menu-ITEM online          LABEL "O&n-line dBase "
    Menu-ITEM offline         LABEL "O&ff-line dBASE"
    Menu-ITEM archive         LABEL "Archive Data   "
    MENU-ITEM m_Search        LABEL "Search         "  ACCELERATOR "PF3".
   
  DEFINE Menu m_mainMenu MenuBAR DCOLOR 3
    SUB-Menu maint000      LABEL "       &MAINTENANCE       "
   Menu-ITEM Menu-exit       LABEL "            E&XIT           ".

  MENU-ITEM m_Search:VISIBLE = false.
  Menu-ITEM online:SENSITIVE = YES.
  CURRENT-WINDOW:MenuBAR = Menu m_mainMenu:HANDLE.
  CURRENT-WINDOW:VISIBLE = TRUE.
  CURRENT-WINDOW:SENSITIVE = TRUE.

  ON CHOOSE OF MENU-ITEM m_Search IN MENU maint000 MESSAGE 1 VIEW-AS ALERT-BOX.

My problem here is this:
Code:
 MENU-ITEM m_Search:VISIBLE = false.

Upon compiling, it doesn't have an error, but then when I run it in putty this error appears:
**VISIBLE is not a setable attribute for MENU-ITEM archive. (4052)

According to knowledgebase notes, VISIBLE Attributes can be used in menu widgets. Please help.
Thank you so much in advance Masters.


Regards,

PrJlndni
 

Osborne

Active Member
You can change what menus to have at runtime, so the solutions are either to create dynamically or duplicate the static ones and the duplicate does not contain m_Search:
Code:
DEFINE VARIABLE vHideSearch AS LOGICAL INITIAL TRUE NO-UNDO.

DEFINE SUB-Menu maint000
   Menu-ITEM online  LABEL "O&n-line dBase "
   Menu-ITEM offline  LABEL "O&ff-line dBASE"
   Menu-ITEM archive  LABEL "Archive Data  "
   MENU-ITEM m_Search  LABEL "Search  "  ACCELERATOR "PF3".

DEFINE Menu m_mainMenu MenuBAR DCOLOR 3
   SUB-Menu maint000  LABEL "  &MAINTENANCE  "
   Menu-ITEM Menu-exit  LABEL "  E&XIT  ".

DEFINE SUB-Menu maint000_2
   Menu-ITEM online_2  LABEL "O&n-line dBase "
   Menu-ITEM offline_2  LABEL "O&ff-line dBASE"
   Menu-ITEM archive_2  LABEL "Archive Data  ".

DEFINE Menu m_mainMenu_2 MenuBAR DCOLOR 3
   SUB-Menu maint000_2  LABEL "  &MAINTENANCE  "
   Menu-ITEM Menu-exit_2  LABEL "  E&XIT  ".

ON CHOOSE OF MENU-ITEM m_Search IN MENU maint000 MESSAGE 1 VIEW-AS ALERT-BOX.

Menu-ITEM online:SENSITIVE = YES.
CURRENT-WINDOW:MenuBAR = Menu m_mainMenu:HANDLE.
CURRENT-WINDOW:VISIBLE = TRUE.
CURRENT-WINDOW:SENSITIVE = TRUE.

IF vHideSearch THEN
   ASSIGN Menu-ITEM online_2:SENSITIVE = YES
   CURRENT-WINDOW:MenuBAR = Menu m_mainMenu_2:HANDLE.

WAIT-FOR ENDKEY, WINDOW-CLOSE OF CURRENT-WINDOW.
 

Fabio

New Member
I did a flexible and dynamic solution for your menus.

Feel free to change anything.

Best regards,

Code:
/* -------------------------------------------------------------------------- */

DEF VAR hMainMenu      AS HANDLE NO-UNDO.

DEF TEMP-TABLE tt-menu NO-UNDO
  FIELD men-key        AS CHAR
  FIELD men-label      AS CHAR
  FIELD men-parent-key AS CHAR
  FIELD men-is-visible AS LOG INITIAL TRUE.

/* -------------------------------------------------------------------------- */

PROCEDURE AddMenu:

  DEF INPUT PARAM cLabel     AS CHAR NO-UNDO.
  DEF INPUT PARAM cKey       AS CHAR NO-UNDO.
  DEF INPUT PARAM cParentKey AS CHAR NO-UNDO.
  DEF INPUT PARAM lIsVisible AS LOG  NO-UNDO.

  CREATE tt-menu.
  ASSIGN tt-menu.men-key        = cKey
         tt-menu.men-label      = cLabel
         tt-menu.men-parent-key = cParentKey
         tt-menu.men-is-visible = lIsVisible.

END.

/* -------------------------------------------------------------------------- */

PROCEDURE InsertItem:

  DEF INPUT PARAM hParent AS HANDLE NO-UNDO.
  DEF INPUT PARAM cKey    AS CHAR   NO-UNDO.
  DEF INPUT PARAM cLabel  AS CHAR   NO-UNDO.

  DEF VAR hMenuItem AS HANDLE NO-UNDO.

  CREATE MENU-ITEM hMenuItem
    ASSIGN PARENT = hParent
             NAME = cKey
            LABEL = cLabel
    TRIGGERS:
      ON CHOOSE PERSISTENT RUN MenuItemChoose IN THIS-PROCEDURE (hMenuItem:NAME).
    END TRIGGERS.

END.

/* -------------------------------------------------------------------------- */

PROCEDURE MenuItemChoose:

  DEF INPUT PARAM cMenuItemName AS CHAR NO-UNDO.

  IF cMenuItemName = 'show-search' THEN
    RUN SetVisibility('search', TRUE).
  ELSE IF cMenuItemName = 'hide-search' THEN
    RUN SetVisibility('search', FALSE).

END.

/* -------------------------------------------------------------------------- */

PROCEDURE BuildMenu:

  DEF INPUT PARAM hParent    AS HANDLE NO-UNDO.
  DEF INPUT PARAM cParentKey AS CHAR NO-UNDO.

  DEF VAR hSubMenu           AS HANDLE NO-UNDO.

  DEF BUFFER bf-tt-menu      FOR tt-menu.

  FOR EACH tt-menu
     WHERE tt-menu.men-parent-key = cParentKey
       AND tt-menu.men-is-visible NO-LOCK:

    IF CAN-FIND(FIRST bf-tt-menu WHERE bf-tt-menu.men-parent-key = tt-menu.men-key) THEN DO:
      CREATE SUB-MENU hSubMenu
        ASSIGN PARENT = hParent
                 NAME = tt-menu.men-key
                LABEL = tt-menu.men-label.
      RUN BuildMenu(hSubMenu, tt-menu.men-key).
    END.
    ELSE DO:
      RUN InsertItem(hParent, tt-menu.men-key, tt-menu.men-label).
    END.

  END.

END.

/* -------------------------------------------------------------------------- */

PROCEDURE StartMenu:

  CREATE MENU hMainMenu.
  RUN BuildMenu(hMainMenu, ?).
  CURRENT-WINDOW:MENUBAR = hMainMenu:HANDLE.

END.

/* -------------------------------------------------------------------------- */

PROCEDURE SetVisibility:

  DEF INPUT PARAM cKey     AS CHAR NO-UNDO.
  DEF INPUT PARAM lIsVisible AS LOG NO-UNDO.

  FIND tt-menu WHERE tt-menu.men-key = cKey NO-ERROR.
  IF AVAIL tt-menu THEN
    ASSIGN tt-menu.men-is-visible = lIsVisible.

  RUN StartMenu.

END.

/* -------------------------------------------------------------------------- */

RUN AddMenu('&MAINTENANCE'     , 'maintenance'     , ?            , TRUE ).
RUN AddMenu('O&n-line dBase'   , 'on-line-dbase'   , 'maintenance', TRUE ).
RUN AddMenu('O&ff-line dBASE'  , 'off-line-dbase'  , 'maintenance', TRUE ).
RUN AddMenu('Archive Data'     , 'archive-data'    , 'maintenance', TRUE ).
RUN AddMenu('Search'           , 'search'          , 'maintenance', FALSE).
                                                  
RUN AddMenu('E&XIT'            , 'exit'            , ?            , TRUE ).
                                                  
RUN AddMenu('&SHOW SEARCH'     , 'show-search'     , ?            , TRUE ).
                                                  
RUN AddMenu('&HIDE SEARCH'     , 'hide-search'     , ?            , TRUE ).
                                                  
RUN AddMenu('&OTHER'           , 'other'           , ?            , TRUE ).
RUN AddMenu('Other 1'          , 'other-1'         , 'other'      , TRUE ).
RUN AddMenu('Other 2'          , 'other-2'         , 'other'      , TRUE ).
RUN AddMenu('Other 2.1'        , 'other-2-1'       , 'other-2'    , TRUE ).
RUN AddMenu('Other 2.2'        , 'other-2-2'       , 'other-2'    , TRUE ).
RUN AddMenu('Other 3'          , 'other-3'         , 'other'      , TRUE ).

RUN StartMenu.

CURRENT-WINDOW:VISIBLE = TRUE.
WAIT-FOR ENDKEY, WINDOW-CLOSE OF CURRENT-WINDOW.

/* -------------------------------------------------------------------------- */
 
Top