Ticket #7051: Deskbar Persist Expanded State 6.diff

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

Made the sExpandedItems list private again. Added a public method AddExpandedItem() to the BarView class that adds a signature to the expanded items list. Call that method anywhere I want to add an item to the sExpandedItems list.

  • src/apps/deskbar/BarApp.cpp

    diff --git src/apps/deskbar/BarApp.cpp src/apps/deskbar/BarApp.cpp
    index 58664f7..ee02685 100644
    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 sig to the expanded items list.
     649    if (fSettings.expandNewTeams)
     650        BarView()->AddExpandedItem(sig);
     651
    648652    int32 subsCount = sSubscribers.CountItems();
    649653    if (subsCount > 0) {
    650654        for (int32 i = 0; i < subsCount; i++) {
  • src/apps/deskbar/BarView.cpp

    diff --git src/apps/deskbar/BarView.cpp src/apps/deskbar/BarView.cpp
    index 6e71956..8a62149 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();
     100
     101    // Add the Tracker to the list of expanded items so that it
     102    // will be expanded on startup.
     103    if (static_cast<TBarApp*>(be_app)->Settings()->expandNewTeams)
     104        AddExpandedItem(kTrackerSignature);
    95105}
    96106
    97107
    TBarView::~TBarView()  
    99109{
    100110    delete fDragMessage;
    101111    delete fCachedTypesList;
     112
     113    // Clean up the expanded items list
     114    while (!sExpandedItems.IsEmpty())
     115        delete static_cast<BString*>(sExpandedItems.RemoveItem((int32)0));
     116    sExpandedItems.MakeEmpty();
    102117}
    103118
    104119
    TBarView::ChangeState(int32 state, bool vertical, bool left, bool top)  
    529544    PlaceTray(vertSwap, leftSwap, screenFrame);
    530545
    531546    // 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     }
     547    SaveExpandedItems();
    549548
    550549    PlaceApplicationBar(screenFrame);
    551550    SizeWindow(screenFrame);
    TBarView::ChangeState(int32 state, bool vertical, bool left, bool top)  
    553552    Window()->UpdateIfNeeded();
    554553
    555554    // 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);
    569                     break;
    570                 }
    571             }
     555    ExpandItems();
     556    Invalidate();
     557}
     558
     559
     560void
     561TBarView::SaveExpandedItems()
     562{
     563    if (!fExpando)
     564        return;
     565
     566    // Get a list of the signatures of expanded apps. Can't use
     567    // team_id because there can be more than one team per application
     568    for (int32 teamIndex = fExpando->CountItems(); teamIndex-- > 0;) {
     569        TTeamMenuItem* teamItem
     570            = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex));
     571        if (teamItem == NULL || teamItem->Signature() == NULL ||
     572            *teamItem->Signature() == '\0')
     573            continue;
     574
     575        if (teamItem->IsExpanded()) {
     576            AddExpandedItem(teamItem->Signature());
    572577        }
     578    }
     579}
     580
    573581
    574         // Clean up expanded signature list.
    575         while (!expandedItems.IsEmpty()) {
    576             delete static_cast<BString*>(expandedItems.RemoveItem((int32)0));
     582void
     583TBarView::ExpandItems()
     584{
     585    if (!fExpando || !fVertical || !Expando()
     586        || !static_cast<TBarApp*>(be_app)->Settings()->superExpando
     587        || sExpandedItems.CountItems() <= 0)
     588        return;
     589
     590    // Start at the 'bottom' of the list working up.
     591    // Prevents being thrown off by expanding items.
     592    for (int32 teamIndex = fExpando->CountItems(); teamIndex-- > 0;) {
     593        TTeamMenuItem* teamItem
     594            = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex));
     595        if (teamItem == NULL || teamItem->Signature() == NULL
     596            || *teamItem->Signature() == '\0')
     597            continue;
     598
     599        for (int32 sigIndex = sExpandedItems.CountItems(); sigIndex-- > 0;) {
     600            BString* itemSig = (BString *)sExpandedItems.ItemAt(sigIndex);
     601
     602            if (itemSig->ICompare(teamItem->Signature()) == 0) {
     603                teamItem->ToggleExpandState(false);
     604                sExpandedItems.RemoveItem(sigIndex);
     605                break;
     606            }
    577607        }
     608    }
     609
     610    // Clean up the expanded items list
     611    while (!sExpandedItems.IsEmpty())
     612        delete static_cast<BString*>(sExpandedItems.RemoveItem((int32)0));
     613    sExpandedItems.MakeEmpty();
    578614
    579         fExpando->SizeWindow();
     615    fExpando->SizeWindow();
     616}
     617
     618void
     619TBarView::AddExpandedItem(const char* signature)
     620{
     621  // If signature is not in the list, add it
     622    bool shouldAdd = true;
     623
     624    for (int32 sigIndex = sExpandedItems.CountItems();
     625        sigIndex-- > 0;) {
     626        BString *itemSig = (BString *)sExpandedItems.ItemAt(sigIndex);
     627        if (itemSig->ICompare(signature) == 0) {
     628            // already in the list, don't add the signature
     629            shouldAdd = false;
     630            break;
     631        }
    580632    }
    581633
    582     Invalidate();
     634    // Add the signature to the list
     635    if (shouldAdd) {
     636        BString *sigToAdd = new BString(signature);
     637        sExpandedItems.AddItem((void *)sigToAdd);
     638    }
    583639}
    584640
    585641
  • src/apps/deskbar/BarView.h

    diff --git src/apps/deskbar/BarView.h src/apps/deskbar/BarView.h
    index 9e165cb..2268fb4 100644
    class TBarView : public BView {  
    141141        TExpandoMenuBar* ExpandoMenuBar() const;
    142142        TBarMenuBar* BarMenuBar() const;
    143143        TDragRegion* DragRegion() const { return fDragRegion; }
    144            
     144        void AddExpandedItem(const char* signature);
     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;
    class TBarView : public BView {  
    177180        uint32 fMaxRecentApps;
    178181
    179182        TTeamMenuItem* fLastDragItem;
     183        static BList sExpandedItems;
    180184};
    181185
    182186