Ticket #7051: Deskbar Persist Expanded State 3.diff

File Deskbar Persist Expanded State 3.diff, 5.6 KB (added by jscipione, 13 years ago)

Updated patch after my other style change patches were committed

  • src/apps/deskbar/BarView.cpp

    diff --git src/apps/deskbar/BarView.cpp src/apps/deskbar/BarView.cpp
    index cac3472..7e95133 100644
    const int32 kDefaultRecentAppCount = 10;  
    6868
    6969const int32 kMenuTrackMargin = 20;
    7070
     71BList TBarView::sExpandedItems;
     72
     73
    7174TBarView::TBarView(BRect frame, bool vertical, bool left, bool top,
    7275        bool showInterval, uint32 state, float, bool showTime)
    7376    : BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
    TBarView::TBarView(BRect frame, bool vertical, bool left, bool top,  
    9295    fDragRegion->AddChild(fReplicantTray);
    9396    if (fTrayLocation != 0)
    9497        AddChild(fDragRegion);
     98
     99    sExpandedItems.MakeEmpty();
    95100}
    96101
    97102
    TBarView::~TBarView()  
    99104{
    100105    delete fDragMessage;
    101106    delete fCachedTypesList;
     107
     108    // Clean up the expanded items list
     109    while (!sExpandedItems.IsEmpty())
     110        delete static_cast<BString*>(sExpandedItems.RemoveItem((int32)0));
     111    sExpandedItems.MakeEmpty();
    102112}
    103113
    104114
    TBarView::ChangeState(int32 state, bool vertical, bool left, bool top)  
    453463    PlaceTray(vertSwap, leftSwap, screenFrame);
    454464
    455465    // We need to keep track of what apps are expanded.
    456     BList expandedItems;
    457     BString* signature = NULL;
    458     if (fVertical && Expando()
    459         && static_cast<TBarApp*>(be_app)->Settings()->superExpando) {
    460         // Get a list of the signatures of expanded apps. Can't use
    461         // team_id because there can be more than one team per application
    462         if (fVertical && Expando() && vertical && fExpando) {
    463             for (int index = 0; index < fExpando->CountItems(); index++) {
    464                 TTeamMenuItem* item
    465                     = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(index));
    466                 if (item != NULL && item->IsExpanded()) {
    467                     signature = new BString(item->Signature());
    468                     expandedItems.AddItem((void*)signature);
    469                 }
    470             }
    471         }
    472     }
     466    SaveExpandedItems();
    473467
    474468    PlaceApplicationBar(screenFrame);
    475469    SizeWindow(screenFrame);
    TBarView::ChangeState(int32 state, bool vertical, bool left, bool top)  
    477471    Window()->UpdateIfNeeded();
    478472
    479473    // Re-expand those apps.
    480     if (expandedItems.CountItems() > 0) {
    481         for (int sigIndex = expandedItems.CountItems(); sigIndex-- > 0;) {
    482             signature = static_cast<BString*>(expandedItems.ItemAt(sigIndex));
    483             if (signature == NULL)
    484                 continue;
    485 
    486             // Start at the 'bottom' of the list working up.
    487             // Prevents being thrown off by expanding items.
    488             for (int teamIndex = fExpando->CountItems(); teamIndex-- > 0;) {
    489                 TTeamMenuItem* item
    490                     = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex));
    491                 if (item != NULL && !signature->Compare(item->Signature())) {
    492                     item->ToggleExpandState(false);
     474    ExpandItems();
     475    Invalidate();
     476}
     477
     478
     479void
     480TBarView::SaveExpandedItems()
     481{
     482    if (!fExpando)
     483        return;
     484
     485    // Get a list of the signatures of expanded apps. Can't use
     486    // team_id because there can be more than one team per application
     487    for (int32 teamIndex = fExpando->CountItems(); teamIndex-- > 0;) {
     488        TTeamMenuItem* teamItem
     489            = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex));
     490        if (teamItem == NULL || teamItem->Signature() == NULL ||
     491            *teamItem->Signature() == '\0')
     492            continue;
     493
     494        if (teamItem->IsExpanded()) {
     495            // Expanded, if signature is not in the list add it
     496            bool shouldAdd = true;
     497
     498            for (int32 sigIndex = sExpandedItems.CountItems();
     499                sigIndex-- > 0;) {
     500                BString *signature = (BString *)sExpandedItems.ItemAt(sigIndex);
     501                if (signature->ICompare(teamItem->Signature()) == 0) {
     502                    // already in the list, don't add the signature
     503                    shouldAdd = false;
    493504                    break;
    494505                }
    495506            }
    496         }
    497507
    498         // Clean up expanded signature list.
    499         while (!expandedItems.IsEmpty()) {
    500             delete static_cast<BString*>(expandedItems.RemoveItem((int32)0));
     508            if (shouldAdd) {
     509                // Add the signature to the list
     510                BString* signature = new BString(teamItem->Signature());
     511                sExpandedItems.AddItem((void*)signature);
     512            }
    501513        }
     514    }
     515}
     516
     517
     518void
     519TBarView::ExpandItems()
     520{
     521    if (!fExpando || !fVertical || !Expando()
     522        || !static_cast<TBarApp*>(be_app)->Settings()->superExpando
     523        || sExpandedItems.CountItems() <= 0)
     524        return;
    502525
    503         fExpando->SizeWindow();
     526    // Start at the 'bottom' of the list working up.
     527    // Prevents being thrown off by expanding items.
     528    for (int32 teamIndex = fExpando->CountItems(); teamIndex-- > 0;) {
     529        TTeamMenuItem* teamItem
     530            = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex));
     531        if (teamItem == NULL || teamItem->Signature() == NULL
     532            || *teamItem->Signature() == '\0')
     533            continue;
     534
     535        for (int32 sigIndex = sExpandedItems.CountItems(); sigIndex-- > 0;) {
     536            BString* signature = (BString *)sExpandedItems.ItemAt(sigIndex);
     537
     538            if (signature->ICompare(teamItem->Signature()) == 0) {
     539                teamItem->ToggleExpandState(false);
     540                sExpandedItems.RemoveItem(sigIndex);
     541                break;
     542            }
     543        }
    504544    }
    505545
    506     Invalidate();
     546    // Clean up the expanded items list
     547    while (!sExpandedItems.IsEmpty())
     548        delete static_cast<BString*>(sExpandedItems.RemoveItem((int32)0));
     549    sExpandedItems.MakeEmpty();
     550
     551    fExpando->SizeWindow();
    507552}
    508553
    509554
  • src/apps/deskbar/BarView.h

    diff --git src/apps/deskbar/BarView.h src/apps/deskbar/BarView.h
    index 8f4e5b8..dd0cfd7 100644
    class TBarView : public BView {  
    146146        void PlaceBeMenu();
    147147        void PlaceTray(bool vertSwap, bool leftSwap, BRect screenFrame);
    148148        void PlaceApplicationBar(BRect screenFrame);
     149        void SaveExpandedItems();
     150        void ExpandItems();
    149151
    150152        TBarMenuBar* fBarMenuBar;
    151153        TExpandoMenuBar* fExpando;
    class TBarView : public BView {  
    172174        uint32 fMaxRecentApps;
    173175
    174176        TTeamMenuItem* fLastDragItem;
     177        static BList sExpandedItems;
    175178};
    176179
    177180