VirtualBox

Ignore:
Timestamp:
Apr 16, 2021 10:56:37 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
143855
Message:

FE/Qt: bugref:8161: A bit of rework for Chooser pane; Saving last chosen item instantly on change to avoid doing that on app shutdown; This is tricky cause we have to avoid saving in unwanted cases.

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

    r88102 r88560  
    6262    , m_pMouseHandler(0)
    6363    , m_pKeyboardHandler(0)
     64    , m_fSelectionSaveAllowed(false)
    6465    , m_iCurrentSearchResultIndex(-1)
    6566    , m_iScrollingTokenSize(30)
     
    8283    /* Build tree for main root: */
    8384    buildTreeForMainRoot();
    84     /* Load last selected-item: */
    85     loadLastSelectedItem();
     85    /* Load settings: */
     86    loadSettings();
    8687}
    8788
    8889void UIChooserModel::deinit()
    8990{
    90     /* Save last selected-item: */
    91     saveLastSelectedItem();
     91    /* Clean tree for main root: */
     92    clearTreeForMainRoot();
    9293
    9394    /* Call to base-class: */
     
    188189        pItem->setSelected(true);
    189190        pItem->update();
     191    }
     192
     193    /* Should the selection changes be saved? */
     194    if (m_fSelectionSaveAllowed)
     195    {
     196        /* Acquire first selected item: */
     197        UIChooserItem *pFirstSelectedItem = m_selectedItems.value(0);
     198        /* If this item is of machine type: */
     199        if (   pFirstSelectedItem
     200            && pFirstSelectedItem->type() == UIChooserNodeType_Machine)
     201        {
     202            /* Cast to machine item: */
     203            UIChooserItemMachine *pMachineItem = pFirstSelectedItem->toMachineItem();
     204            /* If this machine item is of cloud type =>
     205             * Choose the parent (profile) group item as the last one selected: */
     206            if (   pMachineItem
     207                && (   pMachineItem->cacheType() == UIVirtualMachineItemType_CloudFake
     208                    || pMachineItem->cacheType() == UIVirtualMachineItemType_CloudReal))
     209                pFirstSelectedItem = pMachineItem->parentItem();
     210        }
     211        /* Save last selected-item: */
     212        gEDataManager->setSelectorWindowLastItemChosen(pFirstSelectedItem ? pFirstSelectedItem->definition() : QString());
    190213    }
    191214
     
    15461569}
    15471570
    1548 void UIChooserModel::loadLastSelectedItem()
     1571void UIChooserModel::loadSettings()
    15491572{
    15501573    /* Load last selected-item (choose first if unable to load): */
    15511574    setSelectedItem(gEDataManager->selectorWindowLastItemChosen());
    15521575    makeSureAtLeastOneItemSelected();
    1553 }
    1554 
    1555 void UIChooserModel::saveLastSelectedItem()
    1556 {
    1557     /* Acquire first selected item: */
    1558     UIChooserItem *pFirstSelectedItem = firstSelectedItem();
    1559     /* If this item is of machine type: */
    1560     if (   pFirstSelectedItem
    1561         && pFirstSelectedItem->type() == UIChooserNodeType_Machine)
    1562     {
    1563         /* Cast to machine item: */
    1564         UIChooserItemMachine *pMachineItem = pFirstSelectedItem->toMachineItem();
    1565         AssertPtrReturnVoid(pMachineItem);
    1566         /* If this machine item is of cloud type: */
    1567         if (   pMachineItem->cacheType() == UIVirtualMachineItemType_CloudFake
    1568             || pMachineItem->cacheType() == UIVirtualMachineItemType_CloudReal)
    1569         {
    1570             /* Choose the parent (profile) group item as the last one selected: */
    1571             pFirstSelectedItem = pMachineItem->parentItem();
    1572         }
    1573     }
    1574     /* Save last selected-item: */
    1575     gEDataManager->setSelectorWindowLastItemChosen(pFirstSelectedItem ? pFirstSelectedItem->definition() : QString());
    15761576}
    15771577
     
    17611761}
    17621762
     1763void UIChooserModel::clearTreeForMainRoot()
     1764{
     1765    /* Forbid to save selection changes: */
     1766    m_fSelectionSaveAllowed = false;
     1767
     1768    /* Cleanup tree if exists: */
     1769    delete m_pRoot;
     1770    m_pRoot = 0;
     1771}
     1772
    17631773void UIChooserModel::buildTreeForMainRoot(bool fPreserveSelection /* = false */)
    17641774{
     
    17781788            selectedItemDefinitions << pSelectedItem->definition();
    17791789
    1780     /* Cleanup previous tree if exists: */
    1781     delete m_pRoot;
    1782     m_pRoot = 0;
     1790    /* Clean tree for main root: */
     1791    clearTreeForMainRoot();
    17831792
    17841793    /* Build whole tree for invisible root item: */
     
    18131822    if (view() && view()->isSearchWidgetVisible())
    18141823        view()->redoSearch();
     1824
     1825    /* Allow to save selection changes: */
     1826    m_fSelectionSaveAllowed = true;
    18151827}
    18161828
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h

    r87102 r88560  
    360360        /** Prepares connections. */
    361361        void prepareConnections();
    362         /** Loads last selected-items. */
    363         void loadLastSelectedItem();
    364 
    365         /** Saves last selected-items. */
    366         void saveLastSelectedItem();
     362        /** Loads settings. */
     363        void loadSettings();
     364
    367365        /** Cleanups connections. */
    368366        void cleanupConnections();
     
    399397    /** @name Children stuff.
    400398      * @{ */
     399        /** Clears tree for main root. */
     400        void clearTreeForMainRoot();
    401401        /** [Re]builds tree for main root, preserves selection if requested. */
    402402        void buildTreeForMainRoot(bool fPreserveSelection = false);
     
    440440        /** Holds the current-item reference. */
    441441        QPointer<UIChooserItem>  m_pCurrentItem;
     442
     443        /** Holds whether selection save allowed. */
     444        bool  m_fSelectionSaveAllowed;
    442445    /** @} */
    443446
Note: See TracChangeset for help on using the changeset viewer.

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