VirtualBox

Changeset 91669 in vbox for trunk


Ignore:
Timestamp:
Oct 11, 2021 6:11:33 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
147396
Message:

FE/Qt: UIFilePathSelector: Bugfixes for r147128 and few commits before; Recent list separator position should be dynamical since presence of ResetId item is dynamical as well; We should compare old and new paths with native-separators taken into account; When changing to recent list item, we should switch to Path item back early otherwise lineEdit will contain stale data.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIFilePathSelector.cpp

    r91445 r91669  
    6060    , m_enmMode(Mode_Folder)
    6161    , m_strInitialPath(QDir::current().absolutePath())
     62    , m_fResetEnabled(true)
    6263    , m_fEditable(true)
    6364    , m_fModified(false)
     
    6667    , m_fToolTipOverriden(false)
    6768    , m_pCopyAction(new QAction(this))
     69    , m_iRecentListSeparatorPosition(ResetId + 1)
    6870    , m_enmRecentMediaListType(UIMediumDeviceType_Invalid)
    6971{
     
    154156void UIFilePathSelector::setResetEnabled(bool fEnabled)
    155157{
     158    /* Cache requested state: */
     159    m_fResetEnabled = fEnabled;
     160
     161    /* Update recent list separator position: */
     162    m_iRecentListSeparatorPosition = fEnabled ? ResetId + 1 : ResetId;
     163
    156164    if (!fEnabled && count() - 1 == ResetId)
    157165        removeItem(ResetId);
     
    344352void UIFilePathSelector::onActivated(int iIndex)
    345353{
    346     switch (iIndex)
    347     {
    348         case SelectId:
    349         {
    350             selectPath();
    351             break;
    352         }
    353         case ResetId:
    354         {
    355             if (m_strDefaultPath.isEmpty())
    356                 changePath(QString());
    357             else
    358                 changePath(m_strDefaultPath);
    359             break;
    360         }
    361         default:
    362         {
    363             if (iIndex >= RecentListSeparator)
    364             {
    365                 changePath(itemText(iIndex));
    366                 update();
    367             }
    368             break;
    369         }
    370     }
     354    /* Since the presence of ResetId and position of recent list separator
     355     * are dynamical now, we should control condition more carefully: */
     356    if (iIndex == SelectId)
     357        selectPath();
     358    else if (m_fResetEnabled && iIndex == ResetId)
     359    {
     360        if (m_strDefaultPath.isEmpty())
     361            changePath(QString());
     362        else
     363            changePath(m_strDefaultPath);
     364    }
     365    else if (iIndex >= m_iRecentListSeparatorPosition)
     366    {
     367        /* Switch back to Path item early, lineEdit() in refreshText()
     368         * should be related to this exactly item: */
     369        setCurrentIndex(PathId);
     370        changePath(itemText(iIndex));
     371    }
     372
    371373    setCurrentIndex(PathId);
    372374    setFocus();
     
    390392                                    bool fRefreshText /* = true */)
    391393{
    392     const QString strOldPath = m_strPath;
     394    const QString strOldPath = QDir::toNativeSeparators(m_strPath);
    393395    setPath(strPath, fRefreshText);
    394396    if (!m_fModified && m_strPath != strOldPath)
     
    613615{
    614616    /* Remove the recent media list from the end of the combo: */
    615     while (count() >= static_cast<int>(RecentListSeparator))
    616     {
     617    while (count() >= m_iRecentListSeparatorPosition)
    617618        removeItem(count() - 1);
    618     }
    619619
    620620
     
    641641        return;
    642642
    643     insertSeparator(RecentListSeparator);
     643    insertSeparator(m_iRecentListSeparatorPosition);
    644644    foreach (const QString strPath, recentMedia)
    645645        addItem(strPath);
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIFilePathSelector.h

    r91445 r91669  
    6666        PathId = 0,
    6767        SelectId,
    68         ResetId,
    69         RecentListSeparator
     68        ResetId
    7069    };
    7170
     
    205204    QString  m_strNoneToolTipFocused;
    206205
     206    /** Holds whether editor has Reset action. */
     207    bool     m_fResetEnabled;
     208
    207209    /** Holds whether the path is editable. */
    208210    bool     m_fEditable;
     
    224226    QString m_strDefaultPath;
    225227
     228    /** Holds the recent list separator position. */
     229    int                 m_iRecentListSeparatorPosition;
    226230    /** Holds whether medium type for recent media list. If it is UIMediumDeviceType_Invalid the recent list is not shown. */
    227231    UIMediumDeviceType  m_enmRecentMediaListType;
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