VirtualBox

Changeset 84635 in vbox


Ignore:
Timestamp:
Jun 2, 2020 11:56:56 AM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Chooser pane: Context-menu stuff cleanup.

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

Legend:

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

    r84625 r84635  
    6363    , m_pMouseHandler(0)
    6464    , m_pKeyboardHandler(0)
    65     , m_pContextMenuGlobal(0)
    66     , m_pContextMenuGroup(0)
    67     , m_pContextMenuMachine(0)
    6865    , m_iCurrentSearchResultIndex(-1)
    6966    , m_iScrollingTokenSize(30)
     
    12351232{
    12361233    /* Context menu for global(s): */
    1237     m_pContextMenuGlobal = new QMenu;
    1238     if (m_pContextMenuGlobal)
     1234    m_menus[UIChooserNodeType_Global] = new QMenu;
     1235    if (QMenu *pMenuGlobal = m_menus.value(UIChooserNodeType_Global))
    12391236    {
    12401237        /* Check if Ext Pack is ready, some of actions my depend on it: */
     
    12431240
    12441241#ifdef VBOX_WS_MAC
    1245         m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_About));
    1246         m_pContextMenuGlobal->addSeparator();
    1247         m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_Preferences));
    1248         m_pContextMenuGlobal->addSeparator();
    1249         m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ImportAppliance));
    1250         m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ExportAppliance));
    1251         m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_NewCloudVM));
     1242        pMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_About));
     1243        pMenuGlobal->addSeparator();
     1244        pMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_Preferences));
     1245        pMenuGlobal->addSeparator();
     1246        pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ImportAppliance));
     1247        pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ExportAppliance));
     1248        pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_NewCloudVM));
    12521249# ifdef VBOX_GUI_WITH_EXTRADATA_MANAGER_UI
    1253         m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowExtraDataManager));
     1250        pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowExtraDataManager));
    12541251# endif
    1255         m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowVirtualMediumManager));
    1256         m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowHostNetworkManager));
     1252        pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowVirtualMediumManager));
     1253        pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowHostNetworkManager));
    12571254        if (fExtPackAccessible)
    1258             m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowCloudProfileManager));
     1255            pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowCloudProfileManager));
    12591256
    12601257#else /* !VBOX_WS_MAC */
    12611258
    1262         m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_Preferences));
    1263         m_pContextMenuGlobal->addSeparator();
    1264         m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ImportAppliance));
    1265         m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ExportAppliance));
    1266         m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_NewCloudVM));
    1267         m_pContextMenuGlobal->addSeparator();
     1259        pMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_Preferences));
     1260        pMenuGlobal->addSeparator();
     1261        pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ImportAppliance));
     1262        pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ExportAppliance));
     1263        pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_NewCloudVM));
     1264        pMenuGlobal->addSeparator();
    12681265# ifdef VBOX_GUI_WITH_EXTRADATA_MANAGER_UI
    1269         m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowExtraDataManager));
     1266        pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowExtraDataManager));
    12701267# endif
    1271         m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowVirtualMediumManager));
    1272         m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowHostNetworkManager));
     1268        pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowVirtualMediumManager));
     1269        pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowHostNetworkManager));
    12731270        if (fExtPackAccessible)
    1274             m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowCloudProfileManager));
     1271            pMenuGlobal->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowCloudProfileManager));
    12751272# ifdef VBOX_GUI_WITH_NETWORK_MANAGER
    1276         m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_NetworkAccessManager));
     1273        pMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_NetworkAccessManager));
    12771274        if (gEDataManager->applicationUpdateEnabled())
    1278             m_pContextMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_CheckForUpdates));
     1275            pMenuGlobal->addAction(actionPool()->action(UIActionIndex_M_Application_S_CheckForUpdates));
    12791276# endif
    12801277#endif /* !VBOX_WS_MAC */
     
    12821279
    12831280    /* Context menu for group(s): */
    1284     m_pContextMenuGroup = new QMenu;
    1285     if (m_pContextMenuGroup)
    1286     {
    1287         m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_New));
    1288         m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Add));
    1289         m_pContextMenuGroup->addSeparator();
    1290         m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Rename));
    1291         m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Remove));
    1292         m_pContextMenuGroup->addMenu(actionPool()->action(UIActionIndexST_M_Group_M_MoveToGroup)->menu());
    1293         m_pContextMenuGroup->addSeparator();
    1294         m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_M_StartOrShow));
    1295         m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_T_Pause));
    1296         m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Reset));
    1297         m_pContextMenuGroup->addMenu(actionPool()->action(UIActionIndexST_M_Group_M_Close)->menu());
    1298         m_pContextMenuGroup->addSeparator();
    1299         m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Discard));
    1300         m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_ShowLogDialog));
    1301         m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Refresh));
    1302         m_pContextMenuGroup->addSeparator();
    1303         m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_ShowInFileManager));
    1304         m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_CreateShortcut));
    1305         m_pContextMenuGroup->addSeparator();
    1306         m_pContextMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Sort));
     1281    m_menus[UIChooserNodeType_Group] = new QMenu;
     1282    if (QMenu *pMenuGroup = m_menus.value(UIChooserNodeType_Group))
     1283    {
     1284        pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_New));
     1285        pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Add));
     1286        pMenuGroup->addSeparator();
     1287        pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Rename));
     1288        pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Remove));
     1289        pMenuGroup->addMenu(actionPool()->action(UIActionIndexST_M_Group_M_MoveToGroup)->menu());
     1290        pMenuGroup->addSeparator();
     1291        pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_M_StartOrShow));
     1292        pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_T_Pause));
     1293        pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Reset));
     1294        pMenuGroup->addMenu(actionPool()->action(UIActionIndexST_M_Group_M_Close)->menu());
     1295        pMenuGroup->addSeparator();
     1296        pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Discard));
     1297        pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_ShowLogDialog));
     1298        pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Refresh));
     1299        pMenuGroup->addSeparator();
     1300        pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_ShowInFileManager));
     1301        pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_CreateShortcut));
     1302        pMenuGroup->addSeparator();
     1303        pMenuGroup->addAction(actionPool()->action(UIActionIndexST_M_Group_S_Sort));
    13071304    }
    13081305
    13091306    /* Context menu for machine(s): */
    1310     m_pContextMenuMachine = new QMenu;
    1311     if (m_pContextMenuMachine)
    1312     {
    1313         m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Settings));
    1314         m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Clone));
    1315         m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Move));
    1316         m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_ExportToOCI));
    1317         m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Remove));
    1318         m_pContextMenuMachine->addMenu(actionPool()->action(UIActionIndexST_M_Machine_M_MoveToGroup)->menu());
    1319         m_pContextMenuMachine->addSeparator();
    1320         m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_M_StartOrShow));
    1321         m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_T_Pause));
    1322         m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Reset));
    1323         m_pContextMenuMachine->addMenu(actionPool()->action(UIActionIndexST_M_Machine_M_Close)->menu());
    1324         m_pContextMenuMachine->addSeparator();
    1325         m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Discard));
    1326         m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_ShowLogDialog));
    1327         m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Refresh));
    1328         m_pContextMenuMachine->addSeparator();
    1329         m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_ShowInFileManager));
    1330         m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_CreateShortcut));
    1331         m_pContextMenuMachine->addSeparator();
    1332         m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_SortParent));
    1333         m_pContextMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_T_Search));
     1307    m_menus[UIChooserNodeType_Machine] = new QMenu;
     1308    if (QMenu *pMenuMachine = m_menus.value(UIChooserNodeType_Machine))
     1309    {
     1310        pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Settings));
     1311        pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Clone));
     1312        pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Move));
     1313        pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_ExportToOCI));
     1314        pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Remove));
     1315        pMenuMachine->addMenu(actionPool()->action(UIActionIndexST_M_Machine_M_MoveToGroup)->menu());
     1316        pMenuMachine->addSeparator();
     1317        pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_M_StartOrShow));
     1318        pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_T_Pause));
     1319        pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Reset));
     1320        pMenuMachine->addMenu(actionPool()->action(UIActionIndexST_M_Machine_M_Close)->menu());
     1321        pMenuMachine->addSeparator();
     1322        pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Discard));
     1323        pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_ShowLogDialog));
     1324        pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_Refresh));
     1325        pMenuMachine->addSeparator();
     1326        pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_ShowInFileManager));
     1327        pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_CreateShortcut));
     1328        pMenuMachine->addSeparator();
     1329        pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_S_SortParent));
     1330        pMenuMachine->addAction(actionPool()->action(UIActionIndexST_M_Machine_T_Search));
    13341331    }
    13351332}
     
    13811378void UIChooserModel::cleanupContextMenu()
    13821379{
    1383     delete m_pContextMenuGlobal;
    1384     m_pContextMenuGlobal = 0;
    1385     delete m_pContextMenuGroup;
    1386     m_pContextMenuGroup = 0;
    1387     delete m_pContextMenuMachine;
    1388     m_pContextMenuMachine = 0;
     1380    qDeleteAll(m_menus);
     1381    m_menus.clear();
    13891382}
    13901383
     
    14091402        case QGraphicsSceneContextMenuEvent::Mouse:
    14101403        {
    1411             /* First of all we should look for an item under cursor: */
     1404            /* Look for an item under cursor: */
    14121405            if (QGraphicsItem *pItem = itemAt(pEvent->scenePos()))
    14131406            {
    1414                 /* If this item of known type? */
    14151407                switch (pItem->type())
    14161408                {
    14171409                    case UIChooserNodeType_Global:
    14181410                    {
    1419                         /* Global context menu for global item cases: */
    1420                         popupContextMenu(UIGraphicsSelectorContextMenuType_Global, pEvent->screenPos());
    1421                         return true;
     1411                        /* Global context menu for all global item cases: */
     1412                        m_menus.value(UIChooserNodeType_Global)->exec(pEvent->screenPos());
     1413                        break;
    14221414                    }
    14231415                    case UIChooserNodeType_Group:
     
    14251417                        /* Get group-item: */
    14261418                        UIChooserItem *pGroupItem = qgraphicsitem_cast<UIChooserItemGroup*>(pItem);
    1427                         /* Make sure thats not root: */
     1419                        /* Don't show context menu for root-item: */
    14281420                        if (pGroupItem->isRoot())
    1429                             return false;
    1430                         /* Is this group-item only the one selected? */
     1421                            break;
     1422                        /* Make sure we have group-item selected exclusively: */
    14311423                        if (selectedItems().contains(pGroupItem) && selectedItems().size() == 1)
    14321424                        {
    14331425                            /* Group context menu in that case: */
    1434                             popupContextMenu(UIGraphicsSelectorContextMenuType_Group, pEvent->screenPos());
    1435                             return true;
     1426                            m_menus.value(UIChooserNodeType_Group)->exec(pEvent->screenPos());
     1427                            break;
    14361428                        }
    14371429                    }
     
    14401432                    {
    14411433                        /* Machine context menu for other Group/Machine cases: */
    1442                         popupContextMenu(UIGraphicsSelectorContextMenuType_Machine, pEvent->screenPos());
    1443                         return true;
     1434                        m_menus.value(UIChooserNodeType_Machine)->exec(pEvent->screenPos());
     1435                        break;
    14441436                    }
    14451437                    default:
     
    14471439                }
    14481440            }
     1441            /* Filter out by default: */
    14491442            return true;
    14501443        }
     
    14541447            if (UIChooserItem *pItem = firstSelectedItem())
    14551448            {
    1456                 /* If this item of known type? */
    14571449                switch (pItem->type())
    14581450                {
    14591451                    case UIChooserNodeType_Global:
    14601452                    {
    1461                         /* Global context menu for global item cases: */
    1462                         popupContextMenu(UIGraphicsSelectorContextMenuType_Machine, pEvent->screenPos());
    1463                         return true;
     1453                        /* Global context menu for all global item cases: */
     1454                        m_menus.value(UIChooserNodeType_Global)->exec(pEvent->screenPos());
     1455                        break;
    14641456                    }
    14651457                    case UIChooserNodeType_Group:
    14661458                    {
    1467                         /* Is this group-item only the one selected? */
     1459                        /* Make sure we have group-item selected exclusively: */
    14681460                        if (selectedItems().size() == 1)
    14691461                        {
    14701462                            /* Group context menu in that case: */
    1471                             popupContextMenu(UIGraphicsSelectorContextMenuType_Group, pEvent->screenPos());
    1472                             return true;
     1463                            m_menus.value(UIChooserNodeType_Group)->exec(pEvent->screenPos());
     1464                            break;
    14731465                        }
    14741466                    }
     
    14771469                    {
    14781470                        /* Machine context menu for other Group/Machine cases: */
    1479                         popupContextMenu(UIGraphicsSelectorContextMenuType_Machine, pEvent->screenPos());
    1480                         return true;
     1471                        m_menus.value(UIChooserNodeType_Machine)->exec(pEvent->screenPos());
     1472                        break;
    14811473                    }
    14821474                    default:
     
    14841476                }
    14851477            }
     1478            /* Filter out by default: */
    14861479            return true;
    14871480        }
     
    14911484    /* Pass others context menu events: */
    14921485    return false;
    1493 }
    1494 
    1495 void UIChooserModel::popupContextMenu(UIGraphicsSelectorContextMenuType enmType, QPoint point)
    1496 {
    1497     /* Which type of context-menu requested? */
    1498     switch (enmType)
    1499     {
    1500         /* For global item? */
    1501         case UIGraphicsSelectorContextMenuType_Global:
    1502         {
    1503             m_pContextMenuGlobal->exec(point);
    1504             break;
    1505         }
    1506         /* For group? */
    1507         case UIGraphicsSelectorContextMenuType_Group:
    1508         {
    1509             m_pContextMenuGroup->exec(point);
    1510             break;
    1511         }
    1512         /* For machine(s)? */
    1513         case UIGraphicsSelectorContextMenuType_Machine:
    1514         {
    1515             m_pContextMenuMachine->exec(point);
    1516             break;
    1517         }
    1518     }
    15191486}
    15201487
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h

    r84625 r84635  
    4545class UIChooserView;
    4646class UIVirtualMachineItem;
    47 
    48 
    49 /** Context-menu types. */
    50 enum UIGraphicsSelectorContextMenuType
    51 {
    52     UIGraphicsSelectorContextMenuType_Global,
    53     UIGraphicsSelectorContextMenuType_Group,
    54     UIGraphicsSelectorContextMenuType_Machine
    55 };
    56 
    5747
    5848/** UIChooserAbstractModel extension used as VM Chooser-pane model.
     
    340330        /** Handles context-menu @a pEvent. */
    341331        bool processContextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent);
    342         /** Popups context-menu of certain @a enmType in specified @a point. */
    343         void popupContextMenu(UIGraphicsSelectorContextMenuType enmType, QPoint point);
    344332    /** @} */
    345333
     
    389377        UIChooserHandlerKeyboard *m_pKeyboardHandler;
    390378
    391         /** Holds the global item context menu instance. */
    392         QMenu *m_pContextMenuGlobal;
    393         /** Holds the group item context menu instance. */
    394         QMenu *m_pContextMenuGroup;
    395         /** Holds the machine item context menu instance. */
    396         QMenu *m_pContextMenuMachine;
     379        /** Holds the map of context-menu instances. */
     380        QMap<UIChooserNodeType, QMenu*>  m_menus;
    397381    /** @} */
    398382
     
    428412};
    429413
    430 
    431414#endif /* !FEQT_INCLUDED_SRC_manager_chooser_UIChooserModel_h */
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