VirtualBox

Changeset 84461 in vbox for trunk/src


Ignore:
Timestamp:
May 22, 2020 1:31:42 PM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Chooser pane cleanup: Move group disband action trigger handling to proper place in UIVirtualBoxManager class; A bit of rework for corresponding functionality.

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

Legend:

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

    r84217 r84461  
    630630{
    631631    alert(0, MessageType_Error,
    632           tr("<p>You are trying to move machine <nobr><b>%1</b></nobr> "
    633              "to group <nobr><b>%2</b></nobr> which already have sub-group <nobr><b>%1</b></nobr>.</p>"
    634              "<p>Please resolve this name-conflict and try again.</p>")
     632          tr("<p>You are trying to move machine <nobr><b>%1</b></nobr> to group "
     633             "<nobr><b>%2</b></nobr> which already have another item with the same name.</p>"
     634             "<p>Please resolve this name conflict and try again.</p>")
    635635             .arg(strCollisionName, strGroupName));
    636636}
     
    639639{
    640640    return questionBinary(0, MessageType_Question,
    641                           tr("<p>You are trying to move group <nobr><b>%1</b></nobr> "
    642                              "to group <nobr><b>%2</b></nobr> which already have another item with the same name.</p>"
     641                          tr("<p>You are trying to move group <nobr><b>%1</b></nobr> to group "
     642                             "<nobr><b>%2</b></nobr> which already have another item with the same name.</p>"
    643643                             "<p>Would you like to automatically rename it?</p>")
    644644                             .arg(strName, strGroupName),
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp

    r84456 r84461  
    605605}
    606606
     607void UIVirtualBoxManager::sltDisbandGroup()
     608{
     609    m_pWidget->disbandGroup();
     610}
     611
    607612void UIVirtualBoxManager::sltOpenMachineSettingsDialog(QString strCategory /* = QString() */,
    608613                                                       QString strControl /* = QString() */,
     
    15151520    connect(actionPool()->action(UIActionIndexST_M_Group_S_Rename), &UIAction::triggered,
    15161521            this, &UIVirtualBoxManager::sltOpenGroupNameEditor);
     1522    connect(actionPool()->action(UIActionIndexST_M_Group_S_Remove), &UIAction::triggered,
     1523            this, &UIVirtualBoxManager::sltDisbandGroup);
    15171524    connect(actionPool()->action(UIActionIndexST_M_Group_M_StartOrShow), &UIAction::triggered,
    15181525            this, &UIVirtualBoxManager::sltPerformStartOrShowMachine);
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.h

    r84456 r84461  
    190190        /** Handles call to open group name editor. */
    191191        void sltOpenGroupNameEditor();
     192        /** Handles call to disband group. */
     193        void sltDisbandGroup();
    192194
    193195        /** Handles call to open Machine Settings dialog.
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManagerWidget.cpp

    r84456 r84461  
    114114{
    115115    m_pPaneChooser->openGroupNameEditor();
     116}
     117
     118void UIVirtualBoxManagerWidget::disbandGroup()
     119{
     120    m_pPaneChooser->disbandGroup();
    116121}
    117122
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManagerWidget.h

    r84456 r84461  
    137137        /** Opens group name editor. */
    138138        void openGroupNameEditor();
     139        /** Disbands group. */
     140        void disbandGroup();
    139141        /** Performs group sorting. */
    140142        void performGroupSorting();
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooser.cpp

    r84456 r84461  
    111111    AssertPtrReturnVoid(model());
    112112    model()->startEditingSelectedGroupItemName();
     113}
     114
     115void UIChooser::disbandGroup()
     116{
     117    AssertPtrReturnVoid(model());
     118    model()->disbandSelectedGroupItem();
    113119}
    114120
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooser.h

    r84456 r84461  
    131131        /** Opens group name editor. */
    132132        void openGroupNameEditor();
     133        /** Disbands group. */
     134        void disbandGroup();
    133135        /** Performs group sorting. */
    134136        void performGroupSorting();
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp

    r84456 r84461  
    565565}
    566566
     567void UIChooserModel::disbandSelectedGroupItem()
     568{
     569    /* Only for single selected group: */
     570    if (!isSingleGroupSelected())
     571        return;
     572
     573    /* Check if we have collisions with our potential siblings: */
     574    UIChooserItem *pCurrentItem = currentItem();
     575    UIChooserNode *pCurrentNode = pCurrentItem->node();
     576    UIChooserItem *pParentItem = pCurrentItem->parentItem();
     577    UIChooserNode *pParentNode = pParentItem->node();
     578    QList<UIChooserNode*> childrenToBeRenamed;
     579    foreach (UIChooserNode *pChildNode, pCurrentNode->nodes())
     580    {
     581        const QString strChildName = pChildNode->name();
     582        UIChooserNode *pCollisionSibling = 0;
     583        foreach (UIChooserNode *pSiblingNode, pParentNode->nodes())
     584            if (pSiblingNode != pCurrentNode && pSiblingNode->name() == strChildName)
     585            {
     586                pCollisionSibling = pSiblingNode;
     587                break;
     588            }
     589        if (pCollisionSibling)
     590        {
     591            switch (pChildNode->type())
     592            {
     593                case UIChooserNodeType_Machine:
     594                {
     595                    msgCenter().cannotResolveCollisionAutomatically(strChildName, pParentNode->name());
     596                    return;
     597                }
     598                case UIChooserNodeType_Group:
     599                {
     600                    if (!msgCenter().confirmAutomaticCollisionResolve(strChildName, pParentNode->name()))
     601                        return;
     602                    childrenToBeRenamed << pChildNode;
     603                    break;
     604                }
     605                default:
     606                    break;
     607            }
     608        }
     609    }
     610
     611    /* Copy all the children into our parent: */
     612    QList<UIChooserItem*> ungroupedItems;
     613    foreach (UIChooserNode *pNode, pCurrentNode->nodes())
     614    {
     615        switch (pNode->type())
     616        {
     617            case UIChooserNodeType_Group:
     618            {
     619                UIChooserNodeGroup *pGroupNode = new UIChooserNodeGroup(pParentNode,
     620                                                                        pNode->toGroupNode(),
     621                                                                        pParentNode->nodes().size());
     622                UIChooserItemGroup *pGroupItem = new UIChooserItemGroup(pParentItem, pGroupNode);
     623                if (childrenToBeRenamed.contains(pNode))
     624                    pGroupNode->setName(uniqueGroupName(pParentNode));
     625                ungroupedItems << pGroupItem;
     626                break;
     627            }
     628            case UIChooserNodeType_Machine:
     629            {
     630                UIChooserNodeMachine *pMachineNode = new UIChooserNodeMachine(pParentNode,
     631                                                                              pNode->toMachineNode(),
     632                                                                              pParentNode->nodes().size());
     633                UIChooserItemMachine *pMachineItem = new UIChooserItemMachine(pParentItem, pMachineNode);
     634                ungroupedItems << pMachineItem;
     635                break;
     636            }
     637            default:
     638                break;
     639        }
     640    }
     641
     642    /* Delete current group: */
     643    delete pCurrentNode;
     644
     645    /* And update model: */
     646    updateTreeForMainRoot();
     647    if (!ungroupedItems.isEmpty())
     648    {
     649        setSelectedItems(ungroupedItems);
     650        setCurrentItem(firstSelectedItem());
     651    }
     652    else
     653    {
     654        setSelectedItem(navigationItems().first());
     655        emit sigSelectionInvalidated();
     656    }
     657    saveGroups();
     658}
     659
    567660void UIChooserModel::startOrShowSelectedItems()
    568661{
     
    819912}
    820913
    821 void UIChooserModel::sltUngroupSelectedGroup()
    822 {
    823     /* Check if action is enabled: */
    824     if (!actionPool()->action(UIActionIndexST_M_Group_S_Remove)->isEnabled())
    825         return;
    826 
    827     /* Make sure current-item is of group type! */
    828     AssertMsg(currentItem()->type() == UIChooserNodeType_Group, ("This is not group-item!"));
    829 
    830     /* Check if we have collisions with our siblings: */
    831     UIChooserItem *pCurrentItem = currentItem();
    832     UIChooserNode *pCurrentNode = pCurrentItem->node();
    833     UIChooserItem *pParentItem = pCurrentItem->parentItem();
    834     UIChooserNode *pParentNode = pParentItem->node();
    835     QList<UIChooserNode*> siblings = pParentNode->nodes();
    836     QList<UIChooserNode*> toBeRenamed;
    837     QList<UIChooserNode*> toBeRemoved;
    838     foreach (UIChooserNode *pNode, pCurrentNode->nodes())
    839     {
    840         QString strItemName = pNode->name();
    841         UIChooserNode *pCollisionSibling = 0;
    842         foreach (UIChooserNode *pSibling, siblings)
    843             if (pSibling != pCurrentNode && pSibling->name() == strItemName)
    844                 pCollisionSibling = pSibling;
    845         if (pCollisionSibling)
    846         {
    847             if (pNode->type() == UIChooserNodeType_Machine)
    848             {
    849                 if (pCollisionSibling->type() == UIChooserNodeType_Machine)
    850                     toBeRemoved << pNode;
    851                 else if (pCollisionSibling->type() == UIChooserNodeType_Group)
    852                 {
    853                     msgCenter().cannotResolveCollisionAutomatically(strItemName, pParentNode->name());
    854                     return;
    855                 }
    856             }
    857             else if (pNode->type() == UIChooserNodeType_Group)
    858             {
    859                 if (msgCenter().confirmAutomaticCollisionResolve(strItemName, pParentNode->name()))
    860                     toBeRenamed << pNode;
    861                 else
    862                     return;
    863             }
    864         }
    865     }
    866 
    867     /* Copy all the children into our parent: */
    868     QList<UIChooserItem*> copiedItems;
    869     foreach (UIChooserNode *pNode, pCurrentNode->nodes())
    870     {
    871         if (toBeRemoved.contains(pNode))
    872             continue;
    873         switch (pNode->type())
    874         {
    875             case UIChooserNodeType_Group:
    876             {
    877                 UIChooserNodeGroup *pGroupNode = new UIChooserNodeGroup(pParentNode,
    878                                                                         pNode->toGroupNode(),
    879                                                                         pParentNode->nodes().size());
    880                 UIChooserItemGroup *pGroupItem = new UIChooserItemGroup(pParentItem, pGroupNode);
    881                 if (toBeRenamed.contains(pNode))
    882                     pGroupNode->setName(uniqueGroupName(pParentNode));
    883                 copiedItems << pGroupItem;
    884                 break;
    885             }
    886             case UIChooserNodeType_Machine:
    887             {
    888                 UIChooserNodeMachine *pMachineNode = new UIChooserNodeMachine(pParentNode,
    889                                                                               pNode->toMachineNode(),
    890                                                                               pParentNode->nodes().size());
    891                 UIChooserItemMachine *pMachineItem = new UIChooserItemMachine(pParentItem, pMachineNode);
    892                 copiedItems << pMachineItem;
    893                 break;
    894             }
    895             default:
    896                 break;
    897         }
    898     }
    899 
    900     /* Delete current group: */
    901     delete pCurrentNode;
    902 
    903     /* And update model: */
    904     updateTreeForMainRoot();
    905     if (!copiedItems.isEmpty())
    906     {
    907         setSelectedItems(copiedItems);
    908         setCurrentItem(firstSelectedItem());
    909     }
    910     else
    911     {
    912         setSelectedItem(navigationItems().first());
    913         emit sigSelectionInvalidated();
    914     }
    915     saveGroups();
    916 }
    917 
    918914void UIChooserModel::sltCreateNewMachine()
    919915{
     
    13721368    connect(actionPool()->action(UIActionIndexST_M_Machine_S_New), &UIAction::triggered,
    13731369            this, &UIChooserModel::sltCreateNewMachine);
    1374     connect(actionPool()->action(UIActionIndexST_M_Group_S_Remove), &UIAction::triggered,
    1375             this, &UIChooserModel::sltUngroupSelectedGroup);
    13761370    connect(actionPool()->action(UIActionIndexST_M_Machine_S_Remove), &UIAction::triggered,
    13771371            this, &UIChooserModel::sltRemoveSelectedMachine);
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h

    r84456 r84461  
    215215        /** Starts editing selected group item name. */
    216216        void startEditingSelectedGroupItemName();
     217        /** Disbands selected group item. */
     218        void disbandSelectedGroupItem();
    217219        /** Starts or shows selected items. */
    218220        void startOrShowSelectedItems();
     
    290292    /** @name Children stuff.
    291293      * @{ */
    292         /** Handles group destroy request. */
    293         void sltUngroupSelectedGroup();
    294 
    295294        /** Handles create new machine request. */
    296295        void sltCreateNewMachine();
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