Ticket #7051: Deskbar Persist Expanded State 5.diff

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

Add Tracker to the list of expanded items when you create the BarView if the expandNewTeams flag is set. This resolves #4830 in a simple way.

  • src/apps/deskbar/BarApp.cpp

    diff --git a/src/apps/deskbar/BarApp.cpp b/src/apps/deskbar/BarApp.cpp
    index 58664f7..f7bcc1d 100644
    a b TBarApp::AddTeam(team_id team, uint32 flags, const char* sig, entry_ref* ref)  
    645645
    646646    sBarTeamInfoList.AddItem(barInfo);
    647647
     648    // If expandNewTeams is set, add the item to the list of
     649    // expanded items.
     650    if (fSettings.expandNewTeams) {
     651        // Expanded, if signature is not in the list add it
     652        bool shouldAdd = true;
     653
     654        for (int32 sigIndex = BarView()->sExpandedItems.CountItems();
     655            sigIndex-- > 0;) {
     656            BString *signature =
     657                (BString *)BarView()->sExpandedItems.ItemAt(sigIndex);
     658            if (signature->ICompare(sig) == 0) {
     659                // already in the list, don't add the signature
     660                shouldAdd = false;
     661                break;
     662            }
     663        }
     664
     665        if (shouldAdd) {
     666            // Add the signature to the list
     667            BString* signature = new BString(sig);
     668            BarView()->sExpandedItems.AddItem((void *)signature);
     669        }
     670    }
     671
    648672    int32 subsCount = sSubscribers.CountItems();
    649673    if (subsCount > 0) {
    650674        for (int32 i = 0; i < subsCount; i++) {
  • src/apps/deskbar/BarView.cpp

    diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp
    index 6e71956..906365e 100644
    a b 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();
     100    if (static_cast<TBarApp*>(be_app)->Settings()->expandNewTeams) {
     101        // Add the Tracker to the list of expanded items so that it
     102        // will be expanded on startup.
     103        BString* signature = new BString(kTrackerSignature);
     104        sExpandedItems.AddItem((void *)signature);
     105    }
    95106}
    96107
    97108
    TBarView::~TBarView()  
    99110{
    100111    delete fDragMessage;
    101112    delete fCachedTypesList;
     113
     114    // Clean up the expanded items list
     115    while (!sExpandedItems.IsEmpty())
     116        delete static_cast<BString*>(sExpandedItems.RemoveItem((int32)0));
     117    sExpandedItems.MakeEmpty();
    102118}
    103119
    104120
    TBarView::ChangeState(int32 state, bool vertical, bool left, bool top)  
    529545    PlaceTray(vertSwap, leftSwap, screenFrame);
    530546
    531547    // We need to keep track of what apps are expanded.
    532     BList expandedItems;
    533     BString* signature = NULL;
    534     if (fVertical && Expando()
    535         && static_cast<TBarApp*>(be_app)->Settings()->superExpando) {
    536         // Get a list of the signatures of expanded apps. Can't use
    537         // team_id because there can be more than one team per application
    538         if (fVertical && Expando() && vertical && fExpando) {
    539             for (int index = 0; index < fExpando->CountItems(); index++) {
    540                 TTeamMenuItem* item
    541                     = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(index));
    542                 if (item != NULL && item->IsExpanded()) {
    543                     signature = new BString(item->Signature());
    544                     expandedItems.AddItem((void*)signature);
    545                 }
    546             }
    547         }
    548     }
     548    SaveExpandedItems();
    549549
    550550    PlaceApplicationBar(screenFrame);
    551551    SizeWindow(screenFrame);
    TBarView::ChangeState(int32 state, bool vertical, bool left, bool top)  
    553553    Window()->UpdateIfNeeded();
    554554
    555555    // Re-expand those apps.
    556     if (expandedItems.CountItems() > 0) {
    557         for (int sigIndex = expandedItems.CountItems(); sigIndex-- > 0;) {
    558             signature = static_cast<BString*>(expandedItems.ItemAt(sigIndex));
    559             if (signature == NULL)
    560                 continue;
    561 
    562             // Start at the 'bottom' of the list working up.
    563             // Prevents being thrown off by expanding items.
    564             for (int teamIndex = fExpando->CountItems(); teamIndex-- > 0;) {
    565                 TTeamMenuItem* item
    566                     = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex));
    567                 if (item != NULL && !signature->Compare(item->Signature())) {
    568                     item->ToggleExpandState(false);
     556    ExpandItems();
     557    Invalidate();
     558}
     559
     560
     561void
     562TBarView::SaveExpandedItems()
     563{
     564    if (!fExpando)
     565        return;
     566
     567    // Get a list of the signatures of expanded apps. Can't use
     568    // team_id because there can be more than one team per application
     569    for (int32 teamIndex = fExpando->CountItems(); teamIndex-- > 0;) {
     570        TTeamMenuItem* teamItem
     571            = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex));
     572        if (teamItem == NULL || teamItem->Signature() == NULL ||
     573            *teamItem->Signature() == '\0')
     574            continue;
     575
     576        if (teamItem->IsExpanded()) {
     577            // Expanded, if signature is not in the list add it
     578            bool shouldAdd = true;
     579
     580            for (int32 sigIndex = sExpandedItems.CountItems();
     581                sigIndex-- > 0;) {
     582                BString *signature = (BString *)sExpandedItems.ItemAt(sigIndex);
     583                if (signature->ICompare(teamItem->Signature()) == 0) {
     584                    // already in the list, don't add the signature
     585                    shouldAdd = false;
    569586                    break;
    570587                }
    571588            }
    572         }
    573589
    574         // Clean up expanded signature list.
    575         while (!expandedItems.IsEmpty()) {
    576             delete static_cast<BString*>(expandedItems.RemoveItem((int32)0));
     590            if (shouldAdd) {
     591                // Add the signature to the list
     592                BString* signature = new BString(teamItem->Signature());
     593                sExpandedItems.AddItem((void *)signature);
     594            }
    577595        }
     596    }
     597}
    578598
    579         fExpando->SizeWindow();
     599
     600void
     601TBarView::ExpandItems()
     602{
     603    if (!fExpando || !fVertical || !Expando()
     604        || !static_cast<TBarApp*>(be_app)->Settings()->superExpando
     605        || sExpandedItems.CountItems() <= 0)
     606        return;
     607
     608    // Start at the 'bottom' of the list working up.
     609    // Prevents being thrown off by expanding items.
     610    for (int32 teamIndex = fExpando->CountItems(); teamIndex-- > 0;) {
     611        TTeamMenuItem* teamItem
     612            = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex));
     613        if (teamItem == NULL || teamItem->Signature() == NULL
     614            || *teamItem->Signature() == '\0')
     615            continue;
     616
     617        for (int32 sigIndex = sExpandedItems.CountItems(); sigIndex-- > 0;) {
     618            BString* signature = (BString *)sExpandedItems.ItemAt(sigIndex);
     619
     620            if (signature->ICompare(teamItem->Signature()) == 0) {
     621                teamItem->ToggleExpandState(false);
     622                sExpandedItems.RemoveItem(sigIndex);
     623                break;
     624            }
     625        }
    580626    }
    581627
    582     Invalidate();
     628    // Clean up the expanded items list
     629    while (!sExpandedItems.IsEmpty())
     630        delete static_cast<BString*>(sExpandedItems.RemoveItem((int32)0));
     631    sExpandedItems.MakeEmpty();
     632
     633    fExpando->SizeWindow();
    583634}
    584635
    585636
  • src/apps/deskbar/BarView.h

    diff --git a/src/apps/deskbar/BarView.h b/src/apps/deskbar/BarView.h
    index 9e165cb..158b28d 100644
    a b class TBarView : public BView {  
    141141        TExpandoMenuBar* ExpandoMenuBar() const;
    142142        TBarMenuBar* BarMenuBar() const;
    143143        TDragRegion* DragRegion() const { return fDragRegion; }
    144            
     144        static BList sExpandedItems;
     145
    145146    private:
    146147        friend class TBeMenu;
    147148        friend class PreferencesWindow;
    class TBarView : public BView {  
    151152        void PlaceBeMenu();
    152153        void PlaceTray(bool vertSwap, bool leftSwap, BRect screenFrame);
    153154        void PlaceApplicationBar(BRect screenFrame);
     155        void SaveExpandedItems();
     156        void ExpandItems();
    154157
    155158        TBarMenuBar* fBarMenuBar;
    156159        TExpandoMenuBar* fExpando;