VirtualBox

Changeset 52558 in vbox


Ignore:
Timestamp:
Sep 1, 2014 5:02:01 PM (10 years ago)
Author:
vboxsync
Message:

FE/Qt: Mac OS X: Runtime UI: Menu-bar editor: Properly update 'Application' menu.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPool.cpp

    r52555 r52558  
    422422};
    423423
     424#ifdef RT_OS_DARWIN
     425class UIActionMenuApplication : public UIActionMenu
     426{
     427    Q_OBJECT;
     428
     429public:
     430
     431    UIActionMenuApplication(UIActionPool *pParent)
     432        : UIActionMenu(pParent)
     433    {
     434        menu()->setConsumable(true);
     435        retranslateUi();
     436    }
     437
     438protected:
     439
     440    /** Returns action extra-data ID. */
     441    virtual int extraDataID() const { return UIExtraDataMetaDefs::RuntimeMenuType_Application; }
     442    /** Returns action extra-data key. */
     443    virtual QString extraDataKey() const { return gpConverter->toInternalString(UIExtraDataMetaDefs::RuntimeMenuType_Application); }
     444
     445    void retranslateUi()
     446    {
     447        setName(QApplication::translate("UIActionPool", "&VirtualBox"));
     448    }
     449};
     450
     451class UIActionSimplePerformClose : public UIActionSimple
     452{
     453    Q_OBJECT;
     454
     455public:
     456
     457    UIActionSimplePerformClose(UIActionPool *pParent)
     458        : UIActionSimple(pParent, ":/exit_16px.png")
     459    {
     460        setMenuRole(QAction::QuitRole);
     461    }
     462
     463protected:
     464
     465    /** Returns action extra-data ID. */
     466    virtual int extraDataID() const { return UIExtraDataMetaDefs::MenuApplicationActionType_Close; }
     467    /** Returns action extra-data key. */
     468    virtual QString extraDataKey() const { return gpConverter->toInternalString(UIExtraDataMetaDefs::MenuApplicationActionType_Close); }
     469
     470    QString shortcutExtraDataID() const
     471    {
     472        return QString("Close");
     473    }
     474
     475    QKeySequence defaultShortcut(UIActionPoolType) const
     476    {
     477        return QKeySequence("Q");
     478    }
     479
     480    void retranslateUi()
     481    {
     482        setName(QApplication::translate("UIActionPool", "&Close..."));
     483        setStatusTip(QApplication::translate("UIActionPool", "Close the virtual machine"));
     484    }
     485};
     486#endif /* RT_OS_DARWIN */
     487
    424488class UIActionMenuHelp : public UIActionMenu
    425489{
     
    743807{
    744808    m_restrictedActionsMenuApplication[level] = restriction;
    745     m_invalidations << UIActionIndex_Menu_Help;
     809    m_invalidations << UIActionIndex_M_Application;
    746810}
    747811#endif /* Q_WS_MAC */
     
    781845{
    782846    /* Create various actions: */
    783     m_pool[UIActionIndex_Simple_Preferences] = new UIActionSimplePreferences(this);
    784847    m_pool[UIActionIndex_Simple_LogDialog] = new UIActionSimpleLogDialog(this);
     848
     849#ifdef RT_OS_DARWIN
     850    /* Create 'Application' actions: */
     851    m_pool[UIActionIndex_M_Application] = new UIActionMenuApplication(this);
     852    m_pool[UIActionIndex_M_Application_S_About] = new UIActionSimpleAbout(this);
     853    m_pool[UIActionIndex_M_Application_S_Preferences] = new UIActionSimplePreferences(this);
     854    m_pool[UIActionIndex_M_Application_S_Close] = new UIActionSimplePerformClose(this);
     855#endif /* RT_OS_DARWIN */
    785856
    786857    /* Create 'Help' actions: */
     
    793864    m_pool[UIActionIndex_Simple_CheckForUpdates] = new UIActionSimpleCheckForUpdates(this);
    794865#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
     866#ifndef RT_OS_DARWIN
    795867    m_pool[UIActionIndex_Simple_About] = new UIActionSimpleAbout(this);
     868    m_pool[UIActionIndex_Simple_Preferences] = new UIActionSimplePreferences(this);
     869#endif /* !RT_OS_DARWIN */
    796870
    797871    /* Prepare update-handlers for known menus: */
     872#ifdef RT_OS_DARWIN
     873    m_menuUpdateHandlers[UIActionIndex_M_Application].ptf = &UIActionPool::updateMenuApplication;
     874#endif /* RT_OS_DARWIN */
    798875    m_menuUpdateHandlers[UIActionIndex_Menu_Help].ptf = &UIActionPool::updateMenuHelp;
    799876
     
    879956}
    880957
     958#ifdef RT_OS_DARWIN
     959void UIActionPool::updateMenuApplication()
     960{
     961    /* Get corresponding menu: */
     962    UIMenu *pMenu = action(UIActionIndex_M_Application)->menu();
     963    AssertReturnVoid(pMenu && pMenu->isConsumable());
     964    /* Clear contents: */
     965    if (!pMenu->isConsumed())
     966        pMenu->clear();
     967
     968    /* 'About' action: */
     969    const bool fAllowToShowActionAbout = isAllowedInMenuApplication(UIExtraDataMetaDefs::MenuApplicationActionType_About);
     970    action(UIActionIndex_M_Application_S_About)->setEnabled(fAllowToShowActionAbout);
     971    action(UIActionIndex_M_Application_S_About)->setVisible(fAllowToShowActionAbout);
     972    if (!pMenu->isConsumed())
     973    {
     974        pMenu->addAction(action(UIActionIndex_M_Application_S_About));
     975        connect(action(UIActionIndex_M_Application_S_About), SIGNAL(triggered()),
     976                &msgCenter(), SLOT(sltShowHelpAboutDialog()), Qt::UniqueConnection);
     977    }
     978
     979    /* Only for Runtime pool: */
     980    if (type() == UIActionPoolType_Runtime)
     981    {
     982        /* 'Preferences' action: */
     983        const bool fAllowToShowActionPreferences = isAllowedInMenuApplication(UIExtraDataMetaDefs::MenuApplicationActionType_Preferences);
     984        action(UIActionIndex_M_Application_S_Preferences)->setEnabled(fAllowToShowActionPreferences);
     985        action(UIActionIndex_M_Application_S_Preferences)->setVisible(fAllowToShowActionPreferences);
     986        if (!pMenu->isConsumed())
     987            pMenu->addAction(action(UIActionIndex_M_Application_S_Preferences));
     988    }
     989
     990    /* Close action: */
     991    const bool fAllowToShowActionClose = isAllowedInMenuApplication(UIExtraDataMetaDefs::MenuApplicationActionType_Close);
     992    action(UIActionIndex_M_Application_S_Close)->setEnabled(fAllowToShowActionClose);
     993    if (!pMenu->isConsumed())
     994        pMenu->addAction(action(UIActionIndex_M_Application_S_Close));
     995
     996    /* Mark menu as valid: */
     997    m_invalidations.remove(UIActionIndex_M_Application);
     998}
     999#endif /* RT_OS_DARWIN */
     1000
    8811001void UIActionPool::updateMenuHelp()
    8821002{
     
    9811101
    9821102
     1103#ifndef RT_OS_DARWIN
    9831104    /* 'About' action: */
    984     const bool fAllowToShowActionAbout =
    985 #ifdef Q_WS_MAC
    986         isAllowedInMenuApplication(UIExtraDataMetaDefs::MenuApplicationActionType_About);
    987 #else /* !Q_WS_MAC */
    988         isAllowedInMenuHelp(UIExtraDataMetaDefs::MenuHelpActionType_About);
    989 #endif /* Q_WS_MAC */
     1105    const bool fAllowToShowActionAbout = isAllowedInMenuHelp(UIExtraDataMetaDefs::MenuHelpActionType_About);
    9901106    action(UIActionIndex_Simple_About)->setEnabled(fAllowToShowActionAbout);
    9911107    if (fAllowToShowActionAbout)
     
    10001116    {
    10011117        /* 'Preferences' action: */
    1002         const bool fAllowToShowActionPreferences =
    1003 #ifdef Q_WS_MAC
    1004             isAllowedInMenuApplication(UIExtraDataMetaDefs::MenuApplicationActionType_Preferences);
    1005 #else /* !Q_WS_MAC */
    1006             isAllowedInMenuHelp(UIExtraDataMetaDefs::MenuHelpActionType_Preferences);
    1007 #endif /* Q_WS_MAC */
     1118        const bool fAllowToShowActionPreferences = isAllowedInMenuHelp(UIExtraDataMetaDefs::MenuHelpActionType_Preferences);
    10081119        action(UIActionIndex_Simple_Preferences)->setEnabled(fAllowToShowActionPreferences);
    10091120        if (fAllowToShowActionPreferences)
    10101121            pMenu->addAction(action(UIActionIndex_Simple_Preferences));
    10111122    }
     1123#endif /* !RT_OS_DARWIN */
    10121124
    10131125
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPool.h

    r52555 r52558  
    5353{
    5454    /* Various actions: */
    55     UIActionIndex_Simple_Preferences,
    5655    UIActionIndex_Simple_LogDialog,
     56
     57#ifdef RT_OS_DARWIN
     58    /* 'Application' menu actions: */
     59    UIActionIndex_M_Application,
     60    UIActionIndex_M_Application_S_About,
     61    UIActionIndex_M_Application_S_Preferences,
     62    UIActionIndex_M_Application_S_Close,
     63#endif /* RT_OS_DARWIN */
    5764
    5865    /* 'Help' menu actions: */
     
    6572    UIActionIndex_Simple_CheckForUpdates,
    6673#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
     74#ifndef RT_OS_DARWIN
    6775    UIActionIndex_Simple_About,
     76    UIActionIndex_Simple_Preferences,
     77#endif /* !RT_OS_DARWIN */
    6878
    6979    /* Maximum index: */
     
    402412    /** Update menus routine. */
    403413    virtual void updateMenus() = 0;
     414#ifdef RT_OS_DARWIN
     415    /** Update 'Application' menu routine. */
     416    virtual void updateMenuApplication();
     417#endif /* RT_OS_DARWIN */
    404418    /** Update 'Help' menu routine. */
    405419    virtual void updateMenuHelp();
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIActionPoolRuntime.cpp

    r52478 r52558  
    524524};
    525525
     526#ifndef RT_OS_DARWIN
    526527class UIActionSimplePerformClose : public UIActionSimple
    527528{
     
    539540
    540541    /** Returns action extra-data ID. */
    541     virtual int extraDataID() const
    542     {
    543 #ifdef Q_WS_MAC
    544         return UIExtraDataMetaDefs::MenuApplicationActionType_Close;
    545 #else /* !Q_WS_MAC */
    546         return UIExtraDataMetaDefs::RuntimeMenuMachineActionType_Close;
    547 #endif /* !Q_WS_MAC */
    548     }
    549     /** Returns action extra-data key. */
    550     virtual QString extraDataKey() const
    551     {
    552 #ifdef Q_WS_MAC
    553         return gpConverter->toInternalString(UIExtraDataMetaDefs::MenuApplicationActionType_Close);
    554 #else /* !Q_WS_MAC */
    555         return gpConverter->toInternalString(UIExtraDataMetaDefs::RuntimeMenuMachineActionType_Close);
    556 #endif /* !Q_WS_MAC */
    557     }
     542    virtual int extraDataID() const { return UIExtraDataMetaDefs::RuntimeMenuMachineActionType_Close;}
     543    /** Returns action extra-data key. */
     544    virtual QString extraDataKey() const { return gpConverter->toInternalString(UIExtraDataMetaDefs::RuntimeMenuMachineActionType_Close);}
    558545
    559546    QString shortcutExtraDataID() const
     
    573560    }
    574561};
     562#endif /* !RT_OS_DARWIN */
    575563
    576564class UIActionMenuView : public UIActionMenu
     
    17891777    m_pool[UIActionIndexRT_M_Machine_S_Shutdown] = new UIActionSimplePerformShutdown(this);
    17901778    m_pool[UIActionIndexRT_M_Machine_S_PowerOff] = new UIActionSimplePerformPowerOff(this);
     1779#ifndef RT_OS_DARWIN
    17911780    m_pool[UIActionIndexRT_M_Machine_S_Close] = new UIActionSimplePerformClose(this);
     1781#endif /* !RT_OS_DARWIN */
    17921782
    17931783    /* 'View' actions: */
     
    19801970    m_mainMenus.clear();
    19811971
     1972#ifdef RT_OS_DARWIN
     1973    /* 'Application' menu: */
     1974    action(UIActionIndex_M_Application)->setVisible(false);
     1975    m_mainMenus << action(UIActionIndex_M_Application)->menu();
     1976    updateMenuApplication();
     1977#endif /* RT_OS_DARWIN */
     1978
    19821979    /* 'Machine' menu: */
    19831980    const bool fAllowToShowMenuMachine = isAllowedInMenuBar(UIExtraDataMetaDefs::RuntimeMenuType_Machine);
     
    22022199
    22032200
     2201#ifndef Q_WS_MAC
    22042202    /* Close action: */
    2205     const bool fAllowToShowActionClose =
    2206 #ifdef Q_WS_MAC
    2207         isAllowedInMenuApplication(UIExtraDataMetaDefs::MenuApplicationActionType_Close);
    2208 #else /* !Q_WS_MAC */
    2209         isAllowedInMenuMachine(UIExtraDataMetaDefs::RuntimeMenuMachineActionType_Close);
    2210 #endif /* !Q_WS_MAC */
     2203    const bool fAllowToShowActionClose = isAllowedInMenuMachine(UIExtraDataMetaDefs::RuntimeMenuMachineActionType_Close);
    22112204    pMenu->addAction(action(UIActionIndexRT_M_Machine_S_Close));
    22122205    action(UIActionIndexRT_M_Machine_S_Close)->setEnabled(fAllowToShowActionClose);
     2206#endif /* !Q_WS_MAC */
    22132207
    22142208
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIActionPoolRuntime.h

    r52478 r52558  
    5858    UIActionIndexRT_M_Machine_S_Shutdown,
    5959    UIActionIndexRT_M_Machine_S_PowerOff,
     60#ifndef RT_OS_DARWIN
    6061    UIActionIndexRT_M_Machine_S_Close,
     62#endif /* !RT_OS_DARWIN */
    6163
    6264    /* 'View' menu actions: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r52516 r52558  
    925925    connect(actionPool()->action(UIActionIndexRT_M_Machine_S_PowerOff), SIGNAL(triggered()),
    926926            this, SLOT(sltPowerOff()));
     927#ifdef RT_OS_DARWIN
     928    connect(actionPool()->action(UIActionIndex_M_Application_S_Close), SIGNAL(triggered()),
     929            this, SLOT(sltClose()));
     930#else /* !RT_OS_DARWIN */
    927931    connect(actionPool()->action(UIActionIndexRT_M_Machine_S_Close), SIGNAL(triggered()),
    928932            this, SLOT(sltClose()));
     933#endif /* !RT_OS_DARWIN */
    929934
    930935    /* 'View' actions connections: */
     
    966971
    967972    /* 'Help' actions connections: */
     973#ifdef RT_OS_DARWIN
     974    connect(actionPool()->action(UIActionIndex_M_Application_S_Preferences), SIGNAL(triggered()),
     975            this, SLOT(sltShowGlobalPreferences()), Qt::UniqueConnection);
     976#else /* !RT_OS_DARWIN */
    968977    connect(actionPool()->action(UIActionIndex_Simple_Preferences), SIGNAL(triggered()),
    969978            this, SLOT(sltShowGlobalPreferences()), Qt::UniqueConnection);
     979#endif /* !RT_OS_DARWIN */
    970980}
    971981
     
    22392249        return;
    22402250
     2251#ifdef RT_OS_DARWIN
     2252    /* Check that we do NOT handling that already: */
     2253    if (actionPool()->action(UIActionIndex_M_Application_S_Preferences)->data().toBool())
     2254        return;
     2255    /* Remember that we handling that already: */
     2256    actionPool()->action(UIActionIndex_M_Application_S_Preferences)->setData(true);
     2257#else /* !RT_OS_DARWIN */
    22412258    /* Check that we do NOT handling that already: */
    22422259    if (actionPool()->action(UIActionIndex_Simple_Preferences)->data().toBool())
     
    22442261    /* Remember that we handling that already: */
    22452262    actionPool()->action(UIActionIndex_Simple_Preferences)->setData(true);
     2263#endif /* !RT_OS_DARWIN */
    22462264
    22472265    /* Create and execute global settings window: */
     
    22522270        delete pDialog;
    22532271
     2272#ifdef RT_OS_DARWIN
     2273    /* Remember that we do NOT handling that already: */
     2274    actionPool()->action(UIActionIndex_M_Application_S_Preferences)->setData(false);
     2275#else /* !RT_OS_DARWIN */
    22542276    /* Remember that we do NOT handling that already: */
    22552277    actionPool()->action(UIActionIndex_Simple_Preferences)->setData(false);
     2278#endif /* !RT_OS_DARWIN */
    22562279}
    22572280
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMenuBarEditorWindow.cpp

    r52557 r52558  
    474474    AssertPtrReturnVoid(pMenu);
    475475    {
    476         prepareCopiedAction(pMenu, actionPool()->action(UIActionIndex_Simple_About));
    477         prepareCopiedAction(pMenu, actionPool()->action(UIActionIndex_Simple_Preferences));
     476        prepareCopiedAction(pMenu, actionPool()->action(UIActionIndex_M_Application_S_About));
     477        prepareCopiedAction(pMenu, actionPool()->action(UIActionIndex_M_Application_S_Preferences));
    478478    }
    479479}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r52472 r52558  
    12801280    m_pMenuBar->clear();
    12811281    foreach (QMenu *pMenu, actionPool()->menus())
    1282         m_pMenuBar->addMenu(pMenu);
     1282    {
     1283        UIMenu *pMenuUI = qobject_cast<UIMenu*>(pMenu);
     1284        if (!pMenuUI->isConsumable() || !pMenuUI->isConsumed())
     1285            m_pMenuBar->addMenu(pMenuUI);
     1286        if (pMenuUI->isConsumable() && !pMenuUI->isConsumed())
     1287            pMenuUI->setConsumed(true);
     1288    }
    12831289}
    12841290#endif /* Q_WS_MAC */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r52472 r52558  
    3232/* Forward declarations: */
    3333class QMenu;
    34 class QMenuBar;
    3534class UIFrameBuffer;
    3635class UIMachine;
     
    4140class CNetworkAdapter;
    4241class CMediumAttachment;
    43 #ifndef Q_WS_MAC
     42#ifdef Q_WS_MAC
     43class QMenuBar;
     44#else /* !Q_WS_MAC */
    4445class QIcon;
    45 class QMenuBar;
    4646#endif /* !Q_WS_MAC */
    4747
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineWindowFullscreen.cpp

    r52515 r52558  
    235235    connect(m_pMiniToolBar, SIGNAL(sigExitAction()),
    236236            actionPool()->action(UIActionIndexRT_M_View_T_Fullscreen), SLOT(trigger()));
     237#ifdef RT_OS_DARWIN
     238    connect(m_pMiniToolBar, SIGNAL(sigCloseAction()),
     239            actionPool()->action(UIActionIndex_M_Application_S_Close), SLOT(trigger()));
     240#else /* !RT_OS_DARWIN */
    237241    connect(m_pMiniToolBar, SIGNAL(sigCloseAction()),
    238242            actionPool()->action(UIActionIndexRT_M_Machine_S_Close), SLOT(trigger()));
     243#endif /* !RT_OS_DARWIN */
    239244    connect(m_pMiniToolBar, SIGNAL(sigNotifyAboutFocusStolen()), this, SLOT(sltRevokeFocus()));
    240245}
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp

    r52215 r52558  
    321321void UISelectorWindow::sltShowPreferencesDialog()
    322322{
     323#ifdef RT_OS_DARWIN
     324    /* Check that we do NOT handling that already: */
     325    if (actionPool()->action(UIActionIndex_M_Application_S_Preferences)->data().toBool())
     326        return;
     327    /* Remember that we handling that already: */
     328    actionPool()->action(UIActionIndex_M_Application_S_Preferences)->setData(true);
     329#else /* !RT_OS_DARWIN */
    323330    /* Check that we do NOT handling that already: */
    324331    if (actionPool()->action(UIActionIndex_Simple_Preferences)->data().toBool())
     
    326333    /* Remember that we handling that already: */
    327334    actionPool()->action(UIActionIndex_Simple_Preferences)->setData(true);
     335#endif /* !RT_OS_DARWIN */
    328336
    329337    /* Don't show the inaccessible warning
     
    335343    dialog.execute();
    336344
     345#ifdef RT_OS_DARWIN
     346    /* Remember that we do NOT handling that already: */
     347    actionPool()->action(UIActionIndex_M_Application_S_Preferences)->setData(false);
     348#else /* !RT_OS_DARWIN */
    337349    /* Remember that we do NOT handling that already: */
    338350    actionPool()->action(UIActionIndex_Simple_Preferences)->setData(false);
     351#endif /* !RT_OS_DARWIN */
    339352}
    340353
     
    11461159    pMenu->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowExtraDataManager));
    11471160#endif /* DEBUG */
     1161#ifdef RT_OS_DARWIN
     1162    pMenu->addAction(actionPool()->action(UIActionIndex_M_Application_S_Preferences));
     1163#else /* !RT_OS_DARWIN */
    11481164    pMenu->addAction(actionPool()->action(UIActionIndex_Simple_Preferences));
     1165#endif /* !RT_OS_DARWIN */
    11491166#ifndef Q_WS_MAC
    11501167    pMenu->addSeparator();
     
    13671384    connect(actionPool()->action(UIActionIndexST_M_File_S_ShowExtraDataManager), SIGNAL(triggered()), this, SLOT(sltOpenExtraDataManagerWindow()));
    13681385#endif /* DEBUG */
     1386#ifdef RT_OS_DARWIN
     1387    connect(actionPool()->action(UIActionIndex_M_Application_S_Preferences), SIGNAL(triggered()), this, SLOT(sltShowPreferencesDialog()));
     1388#else /* !RT_OS_DARWIN */
    13691389    connect(actionPool()->action(UIActionIndex_Simple_Preferences), SIGNAL(triggered()), this, SLOT(sltShowPreferencesDialog()));
     1390#endif /* !RT_OS_DARWIN */
    13701391    connect(actionPool()->action(UIActionIndexST_M_File_S_Close), SIGNAL(triggered()), this, SLOT(sltPerformExit()));
    13711392
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