Ticket #7051: Deskbar Persist Expanded State 1.diff

File Deskbar Persist Expanded State 1.diff, 5.5 KB (added by jscipione, 14 years ago)

This patch creates a static list of expanded items. When ChangeState() is called the signatures of the expanded items are saved, Deskbar is rebuilt, then the items are re-expanded and the signature is deleted from the list

  • src/apps/deskbar/BarView.cpp

    diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp
    index f113e6a..d14b1df 100644
    a b const int32 kDefaultRecentAppCount = 10;  
    6767
    6868const int32 kMenuTrackMargin = 20;
    6969
     70BList TBarView::sExpandedItems;
     71
     72
    7073TBarView::TBarView(BRect frame, bool vertical, bool left, bool top,
    7174        bool showInterval, uint32 state, float, bool showTime)
    7275    : BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
    TBarView::TBarView(BRect frame, bool vertical, bool left, bool top,  
    9194    fDragRegion->AddChild(fReplicantTray);
    9295    if (fTrayLocation != 0)
    9396        AddChild(fDragRegion);
     97
     98    sExpandedItems.MakeEmpty();
    9499}
    95100
    96101
    TBarView::~TBarView()  
    98103{
    99104    delete fDragMessage;
    100105    delete fCachedTypesList;
     106
     107    // Clean up the expanded items list
     108    while (!sExpandedItems.IsEmpty())
     109        delete static_cast<BString*>(sExpandedItems.RemoveItem((int32)0));
     110    sExpandedItems.MakeEmpty();
    101111}
    102112
    103113
    TBarView::ChangeState(int32 state, bool vertical, bool left, bool top)  
    445455    PlaceTray(vertSwap, leftSwap, screenFrame);
    446456
    447457    // We need to keep track of what apps are expanded.
    448     BList expandedItems;
    449     BString* signature = NULL;
    450     if (fVertical && Expando()
    451         && static_cast<TBarApp*>(be_app)->Settings()->superExpando) {
     458    SaveExpandedItems();
     459
     460    PlaceApplicationBar(screenFrame);
     461    SizeWindow(screenFrame);
     462    PositionWindow(screenFrame);
     463    Window()->UpdateIfNeeded();
     464
     465    // Re-expand those apps.
     466    ExpandItems();
     467    Invalidate();
     468}
     469
     470
     471void
     472TBarView::SaveExpandedItems()
     473{
     474    if (fExpando) {
    452475        // Get a list of the signatures of expanded apps. Can't use
    453476        // team_id because there can be more than one team per application
    454         if (fVertical && Expando() && vertical && fExpando) {
    455             for (int index = 0; index < fExpando->CountItems(); index++) {
    456                 TTeamMenuItem* item
    457                     = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(index));
    458                 if (item != NULL && item->IsExpanded()) {
    459                     signature = new BString(item->Signature());
    460                     expandedItems.AddItem((void*)signature);
     477        for (int32 teamIndex = fExpando->CountItems(); teamIndex-- > 0;) {
     478            TTeamMenuItem* teamItem
     479                = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex));
     480            if (teamItem == NULL || teamItem->Signature() == NULL ||
     481                *teamItem->Signature() == '\0')
     482                continue;
     483
     484            if (teamItem->IsExpanded()) {
     485                // Expanded, if signature is not in the list add it
     486                bool shouldAdd = true;
     487                for (int32 sigIndex = sExpandedItems.CountItems();
     488                    sigIndex-- > 0;) {
     489                    BString *signature =
     490                        (BString *)sExpandedItems.ItemAt(sigIndex);
     491                    if (signature->ICompare(teamItem->Signature()) == 0) {
     492                        // already in the list, don't add the signature
     493                        shouldAdd = false;
     494                        break;
     495                    }
     496                }
     497                if (shouldAdd) {
     498                    // Add the signature to the list
     499                    BString* signature = new BString(teamItem->Signature());
     500                    sExpandedItems.AddItem((void*)signature);
    461501                }
    462502            }
    463503        }
    464504    }
     505}
    465506
    466     PlaceApplicationBar(screenFrame);
    467     SizeWindow(screenFrame);
    468     PositionWindow(screenFrame);
    469     Window()->UpdateIfNeeded();
    470 
    471     // Re-expand those apps.
    472     if (expandedItems.CountItems() > 0) {
    473         for (int sigIndex = expandedItems.CountItems(); sigIndex-- > 0;) {
    474             signature = static_cast<BString*>(expandedItems.ItemAt(sigIndex));
    475             if (signature == NULL)
     507void
     508TBarView::ExpandItems()
     509{
     510    if (fExpando && sExpandedItems.CountItems() > 0 && fVertical && Expando()
     511        && static_cast<TBarApp*>(be_app)->Settings()->superExpando) {
     512        // Start at the 'bottom' of the list working up.
     513        // Prevents being thrown off by expanding items.
     514        for (int32 teamIndex = fExpando->CountItems(); teamIndex-- > 0;) {
     515            TTeamMenuItem* teamItem
     516                = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex));
     517            if (teamItem == NULL || teamItem->Signature() == NULL
     518                || *teamItem->Signature() == '\0')
    476519                continue;
    477520
    478             // Start at the 'bottom' of the list working up.
    479             // Prevents being thrown off by expanding items.
    480             for (int teamIndex = fExpando->CountItems(); teamIndex-- > 0;) {
    481                 TTeamMenuItem* item
    482                     = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex));
    483                 if (item != NULL && !signature->Compare(item->Signature())) {
    484                     item->ToggleExpandState(false);
     521            for (int32 sigIndex = sExpandedItems.CountItems();
     522                sigIndex-- > 0;) {
     523                BString* signature =
     524                    (BString *)sExpandedItems.ItemAt(sigIndex);
     525
     526                if (signature->ICompare(teamItem->Signature()) == 0) {
     527                    teamItem->ToggleExpandState(false);
     528                    sExpandedItems.RemoveItem(sigIndex);
    485529                    break;
    486530                }
    487531            }
    488532        }
    489533
    490         // Clean up expanded signature list.
    491         while (!expandedItems.IsEmpty()) {
    492             delete static_cast<BString*>(expandedItems.RemoveItem((int32)0));
    493         }
     534        // Clean up the expanded items list
     535        while (!sExpandedItems.IsEmpty())
     536            delete static_cast<BString*>(sExpandedItems.RemoveItem((int32)0));
     537        sExpandedItems.MakeEmpty();
    494538
    495539        fExpando->SizeWindow();
    496540    }
    497 
    498     Invalidate();
    499541}
    500542
    501543
  • src/apps/deskbar/BarView.h

    diff --git a/src/apps/deskbar/BarView.h b/src/apps/deskbar/BarView.h
    index a481445..4d29c6c 100644
    a b class TBarView : public BView {  
    145145        void PlaceBeMenu();
    146146        void PlaceTray(bool vertSwap, bool leftSwap, BRect screenFrame);
    147147        void PlaceApplicationBar(BRect screenFrame);
     148        void SaveExpandedItems();
     149        void ExpandItems();
    148150
    149151        TBarMenuBar* fBarMenuBar;
    150152        TExpandoMenuBar* fExpando;
    class TBarView : public BView {  
    171173        uint32 fMaxRecentApps;
    172174
    173175        TTeamMenuItem* fLastDragItem;
     176        static BList sExpandedItems;
    174177};
    175178
    176179