VirtualBox

Changeset 84537 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
May 26, 2020 11:50:47 AM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Make sure menu update handlers called after menus were updated from the action-pool side; That's a common approach designed for the UIActionPool interface.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/manager
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp

    r84536 r84537  
    365365}
    366366
     367void UIVirtualBoxManager::sltHandleMenuPrepare(int iIndex, QMenu *pMenu)
     368{
     369    /* Update if there is update-handler: */
     370    if (m_menuUpdateHandlers.contains(iIndex))
     371        (this->*(m_menuUpdateHandlers.value(iIndex)))(pMenu);
     372}
     373
    367374void UIVirtualBoxManager::sltOpenVirtualMediumManagerWindow()
    368375{
     
    13771384}
    13781385
    1379 void UIVirtualBoxManager::sltGroupCloseMenuAboutToShow()
    1380 {
    1381     /* Get selected items: */
    1382     QList<UIVirtualMachineItem*> items = currentItems();
    1383     AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n"));
    1384 
    1385     actionPool()->action(UIActionIndexST_M_Group_M_Close_S_Shutdown)->setEnabled(isActionEnabled(UIActionIndexST_M_Group_M_Close_S_Shutdown, items));
    1386 }
    1387 
    1388 void UIVirtualBoxManager::sltMachineCloseMenuAboutToShow()
    1389 {
    1390     /* Get selected items: */
    1391     QList<UIVirtualMachineItem*> items = currentItems();
    1392     AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n"));
    1393 
    1394     actionPool()->action(UIActionIndexST_M_Machine_M_Close_S_Shutdown)->setEnabled(isActionEnabled(UIActionIndexST_M_Machine_M_Close_S_Shutdown, items));
    1395 }
    1396 
    13971386void UIVirtualBoxManager::prepare()
    13981387{
     
    14771466    /* Create action-pool: */
    14781467    m_pActionPool = UIActionPool::create(UIActionPoolType_Manager);
     1468
     1469    /* Prepare menu update-handlers: */
     1470    m_menuUpdateHandlers[UIActionIndexST_M_Group_M_Close] = &UIVirtualBoxManager::updateMenuGroupClose;
     1471    m_menuUpdateHandlers[UIActionIndexST_M_Machine_M_Close] = &UIVirtualBoxManager::updateMenuMachineClose;
    14791472
    14801473    /* Build menu-bar: */
     
    15491542    connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigSessionStateChange,
    15501543            this, &UIVirtualBoxManager::sltHandleStateChange);
     1544
     1545    /* General action-pool connections: */
     1546    connect(actionPool(), &UIActionPool::sigNotifyAboutMenuPrepare, this, &UIVirtualBoxManager::sltHandleMenuPrepare);
    15511547
    15521548    /* 'File' menu connections: */
     
    16631659
    16641660    /* 'Group/Close' menu connections: */
    1665     connect(actionPool()->action(UIActionIndexST_M_Group_M_Close)->menu(), &UIMenu::aboutToShow,
    1666             this, &UIVirtualBoxManager::sltGroupCloseMenuAboutToShow);
    16671661    connect(actionPool()->action(UIActionIndexST_M_Group_M_Close_S_Detach), &UIAction::triggered,
    16681662            this, &UIVirtualBoxManager::sltPerformDetachMachineUI);
     
    16751669
    16761670    /* 'Machine/Close' menu connections: */
    1677     connect(actionPool()->action(UIActionIndexST_M_Machine_M_Close)->menu(), &UIMenu::aboutToShow,
    1678             this, &UIVirtualBoxManager::sltMachineCloseMenuAboutToShow);
    16791671    connect(actionPool()->action(UIActionIndexST_M_Machine_M_Close_S_Detach), &UIAction::triggered,
    16801672            this, &UIVirtualBoxManager::sltPerformDetachMachineUI);
     
    19051897        }
    19061898    }
     1899}
     1900
     1901void UIVirtualBoxManager::updateMenuGroupClose(QMenu *)
     1902{
     1903    /* Get selected items: */
     1904    QList<UIVirtualMachineItem*> items = currentItems();
     1905    AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n"));
     1906
     1907    actionPool()->action(UIActionIndexST_M_Group_M_Close_S_Shutdown)->setEnabled(isActionEnabled(UIActionIndexST_M_Group_M_Close_S_Shutdown, items));
     1908}
     1909
     1910void UIVirtualBoxManager::updateMenuMachineClose(QMenu *)
     1911{
     1912    /* Get selected items: */
     1913    QList<UIVirtualMachineItem*> items = currentItems();
     1914    AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n"));
     1915
     1916    actionPool()->action(UIActionIndexST_M_Machine_M_Close_S_Shutdown)->setEnabled(isActionEnabled(UIActionIndexST_M_Machine_M_Close_S_Shutdown, items));
    19071917}
    19081918
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.h

    r84518 r84537  
    4949    Q_OBJECT;
    5050
     51    /** Pointer to menu update-handler for this class: */
     52    typedef void (UIVirtualBoxManager::*MenuUpdateHandler)(QMenu *pMenu);
     53
    5154signals:
    5255
     
    142145        /** Handles CVirtualBox event about state change for machine with @a uID. */
    143146        void sltHandleStateChange(const QUuid &uID);
     147    /** @} */
     148
     149    /** @name Action-pool stuff.
     150      * @{ */
     151        /** Handle menu prepare. */
     152        void sltHandleMenuPrepare(int iIndex, QMenu *pMenu);
    144153    /** @} */
    145154
     
    266275        /** Handles call to toggle machine search widget visibility to be @a fVisible. */
    267276        void sltPerformMachineSearchWidgetVisibilityToggling(bool fVisible);
    268 
    269         /** Handles call to show group Close menu. */
    270         void sltGroupCloseMenuAboutToShow();
    271         /** Handles call to show machine Close menu. */
    272         void sltMachineCloseMenuAboutToShow();
    273277    /** @} */
    274278
     
    339343    /** @name Action update stuff.
    340344      * @{ */
     345        /** Updates 'Group' : 'Close' menu. */
     346        void updateMenuGroupClose(QMenu *pMenu);
     347        /** Updates 'Machine' : 'Close' menu. */
     348        void updateMenuMachineClose(QMenu *pMenu);
     349
    341350        /** Performs update of actions visibility. */
    342351        void updateActionsVisibility();
     
    386395    /** Holds the action-pool instance. */
    387396    UIActionPool *m_pActionPool;
     397    /** Holds the map of menu update-handlers. */
     398    QMap<int, MenuUpdateHandler> m_menuUpdateHandlers;
    388399
    389400    /** Holds the Virtual Media Manager window instance. */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette