Ticket #7051: Deskbar Persist Expanded State 2.diff

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

Fix style issues in patch, take out non-related style changed, those are already fixed in #7052

  • src/apps/deskbar/BarView.cpp

    diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp
    index 53dfeec..db3078f 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)  
    451461    PlaceTray(vertSwap, leftSwap, screenFrame);
    452462
    453463    // We need to keep track of what apps are expanded.
    454     BList expandedItems;
    455     BString* signature = NULL;
    456     if (fVertical && Expando()
    457         && static_cast<TBarApp*>(be_app)->Settings()->superExpando) {
    458         // Get a list of the signatures of expanded apps. Can't use
    459         // team_id because there can be more than one team per application
    460         if (fVertical && Expando() && vertical && fExpando) {
    461             for (int index = 0; index < fExpando->CountItems(); index++) {
    462                 TTeamMenuItem* item
    463                     = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(index));
    464                 if (item != NULL && item->IsExpanded()) {
    465                     signature = new BString(item->Signature());
    466                     expandedItems.AddItem((void*)signature);
    467                 }
    468             }
    469         }
    470     }
     464    SaveExpandedItems();
    471465
    472466    PlaceApplicationBar(screenFrame);
    473467    SizeWindow(screenFrame);
    TBarView::ChangeState(int32 state, bool vertical, bool left, bool top)  
    475469    Window()->UpdateIfNeeded();
    476470
    477471    // Re-expand those apps.
    478     if (expandedItems.CountItems() > 0) {
    479         for (int sigIndex = expandedItems.CountItems(); sigIndex-- > 0;) {
    480             signature = static_cast<BString*>(expandedItems.ItemAt(sigIndex));
    481             if (signature == NULL)
    482                 continue;
    483 
    484             // Start at the 'bottom' of the list working up.
    485             // Prevents being thrown off by expanding items.
    486             for (int teamIndex = fExpando->CountItems(); teamIndex-- > 0;) {
    487                 TTeamMenuItem* item
    488                     = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex));
    489                 if (item != NULL && !signature->Compare(item->Signature())) {
    490                     item->ToggleExpandState(false);
     472    ExpandItems();
     473    Invalidate();
     474}
     475
     476
     477void
     478TBarView::SaveExpandedItems()
     479{
     480    if (!fExpando)
     481        return;
     482
     483    // Get a list of the signatures of expanded apps. Can't use
     484    // team_id because there can be more than one team per application
     485    for (int32 teamIndex = fExpando->CountItems(); teamIndex-- > 0;) {
     486        TTeamMenuItem* teamItem
     487            = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex));
     488        if (teamItem == NULL || teamItem->Signature() == NULL ||
     489            *teamItem->Signature() == '\0')
     490            continue;
     491
     492        if (teamItem->IsExpanded()) {
     493            // Expanded, if signature is not in the list add it
     494            bool shouldAdd = true;
     495            for (int32 sigIndex = sExpandedItems.CountItems();
     496                sigIndex-- > 0;) {
     497                BString *signature = (BString *)sExpandedItems.ItemAt(sigIndex);
     498                if (signature->ICompare(teamItem->Signature()) == 0) {
     499                    // already in the list, don't add the signature
     500                    shouldAdd = false;
    491501                    break;
    492502                }
    493503            }
     504            if (shouldAdd) {
     505                // Add the signature to the list
     506                BString* signature = new BString(teamItem->Signature());
     507                sExpandedItems.AddItem((void*)signature);
     508            }
    494509        }
     510    }
     511}
    495512
    496         // Clean up expanded signature list.
    497         while (!expandedItems.IsEmpty()) {
    498             delete static_cast<BString*>(expandedItems.RemoveItem((int32)0));
    499         }
    500513
    501         fExpando->SizeWindow();
     514void
     515TBarView::ExpandItems()
     516{
     517    if (!fExpando || !fVertical || !Expando()
     518        || !static_cast<TBarApp*>(be_app)->Settings()->superExpando
     519        || sExpandedItems.CountItems() <= 0)
     520        return;
     521
     522    // Start at the 'bottom' of the list working up.
     523    // Prevents being thrown off by expanding items.
     524    for (int32 teamIndex = fExpando->CountItems(); teamIndex-- > 0;) {
     525        TTeamMenuItem* teamItem
     526            = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex));
     527        if (teamItem == NULL || teamItem->Signature() == NULL
     528            || *teamItem->Signature() == '\0')
     529            continue;
     530
     531        for (int32 sigIndex = sExpandedItems.CountItems(); sigIndex-- > 0;) {
     532            BString* signature = (BString *)sExpandedItems.ItemAt(sigIndex);
     533
     534            if (signature->ICompare(teamItem->Signature()) == 0) {
     535                teamItem->ToggleExpandState(false);
     536                sExpandedItems.RemoveItem(sigIndex);
     537                break;
     538            }
     539        }
    502540    }
    503541
    504     Invalidate();
     542    // Clean up the expanded items list
     543    while (!sExpandedItems.IsEmpty())
     544        delete static_cast<BString*>(sExpandedItems.RemoveItem((int32)0));
     545    sExpandedItems.MakeEmpty();
     546
     547    fExpando->SizeWindow();
    505548}
    506549
    507550
  • 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