Ticket #7051: Deskbar Persist Expanded State 7.diff

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

Made sExpandedItems not static and renamed it fExpandedItems. When Deskbar starts, generally at startup, also after a crash or because it was explicitly quit and restarted items are expanded if you set ExpandNewTeams flag. This fixes #4830. Code cleanups abound. Fixed an off-by-one error in trunk when reading in the expanded items list. Axel, please look at this patch I believe that it is now ready to go. One last thing. Use C++ style static_cast rather than C style cast when casting to and from void* in the fExpandedItems BList. Ensure that UpdatePlacement() gets called at least once on startup.

  • src/apps/deskbar/BarApp.cpp

    diff --git src/apps/deskbar/BarApp.cpp src/apps/deskbar/BarApp.cpp
    index 58664f7..9f42ca3 100644
    TBarApp::TBarApp()  
    9595    InitSettings();
    9696    InitIconPreloader();
    9797
     98    fBarWindow = new TBarWindow();
     99
    98100    be_roster->StartWatching(this);
    99101
    100102    gLocalizedNamePreferred
    TBarApp::TBarApp()  
    119121
    120122    fSwitcherMessenger = BMessenger(new TSwitchManager(fSettings.switcherLoc));
    121123
    122     fBarWindow = new TBarWindow();
    123124    fBarWindow->Show();
    124125
     126    // Call UpdatePlacement() after the window is shown because expanded apps
     127    // need to resize the window.
     128    if (fBarWindow->Lock()) {
     129        BarView()->UpdatePlacement();
     130        fBarWindow->Unlock();
     131    }
     132
    125133    // this messenger now targets the barview instead of the
    126134    // statusview so that all additions to the tray
    127135    // follow the same path
    TBarApp::AddTeam(team_id team, uint32 flags, const char* sig, entry_ref* ref)  
    645653
    646654    sBarTeamInfoList.AddItem(barInfo);
    647655
     656    if (fSettings.expandNewTeams)
     657        BarView()->AddExpandedItem(sig);
     658
    648659    int32 subsCount = sSubscribers.CountItems();
    649660    if (subsCount > 0) {
    650661        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..10ec06c 100644
    const int32 kDefaultRecentAppCount = 10;  
    6868
    6969const int32 kMenuTrackMargin = 20;
    7070
     71
    7172TBarView::TBarView(BRect frame, bool vertical, bool left, bool top,
    7273        bool showInterval, uint32 state, float, bool showTime)
    7374    : BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
    TBarView::~TBarView()  
    99100{
    100101    delete fDragMessage;
    101102    delete fCachedTypesList;
     103
     104    RemoveExpandedItems();
    102105}
    103106
    104107
    TBarView::GetPreferredWindowSize(BRect screenFrame, float* width, float* height)  
    405408            windowHeight = screenFrame.bottom;
    406409            windowWidth = fBarMenuBar->Frame().Width();
    407410        } else if (fState == kExpandoState) {
    408             if (fVertical)
     411            if (fVertical) {
    409412                // top left or right
    410413                windowHeight = fExpando->Frame().bottom;
    411             else {
     414            } else {
    412415                // top or bottom, full
    413416                fExpando->CheckItemSizes(0);
    414417                windowHeight = kHModeHeight;
    TBarView::ChangeState(int32 state, bool vertical, bool left, bool top)  
    528531    PlaceBeMenu();
    529532    PlaceTray(vertSwap, leftSwap, screenFrame);
    530533
    531     // 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     }
     534    // Keep track of which apps are expanded
     535    SaveExpandedItems();
    549536
    550537    PlaceApplicationBar(screenFrame);
    551538    SizeWindow(screenFrame);
    552539    PositionWindow(screenFrame);
    553540    Window()->UpdateIfNeeded();
    554541
    555     // 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);
     542    // Re-expand apps
     543    ExpandItems();
     544    Invalidate();
     545}
     546
     547
     548void
     549TBarView::SaveExpandedItems()
     550{
     551    if (fExpando == NULL || fExpando->CountItems() <= 0)
     552        return;
     553
     554    // Get a list of the signatures of expanded apps. Can't use
     555    // team_id because there can be more than one team per application
     556    for (int32 i = 0; i < fExpando->CountItems(); i++) {
     557        TTeamMenuItem* teamItem
     558            = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(i));
     559
     560        if (teamItem != NULL && teamItem->IsExpanded())
     561            AddExpandedItem(teamItem->Signature());
     562    }
     563}
     564
     565
     566void
     567TBarView::RemoveExpandedItems()
     568{
     569    while (!fExpandedItems.IsEmpty())
     570        delete static_cast<BString*>(fExpandedItems.RemoveItem((int32)0));
     571    fExpandedItems.MakeEmpty();
     572}
     573
     574
     575void
     576TBarView::ExpandItems()
     577{
     578    if (fExpando == NULL || !fVertical || !Expando()
     579        || !static_cast<TBarApp*>(be_app)->Settings()->superExpando
     580        || fExpandedItems.CountItems() <= 0)
     581        return;
     582
     583    // Start at the 'bottom' of the list working up.
     584    // Prevents being thrown off by expanding items.
     585    for (int32 i = fExpando->CountItems() - 1; i >= 0; i--) {
     586        TTeamMenuItem* teamItem
     587            = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(i));
     588
     589        if (teamItem != NULL) {
     590            for (int32 j = 0; j < fExpandedItems.CountItems(); j++) {
     591                BString* itemSig =
     592                    static_cast<BString*>(fExpandedItems.ItemAt(j));
     593
     594                if (itemSig->Compare(teamItem->Signature()) == 0) {
     595                    teamItem->ToggleExpandState(false);
    569596                    break;
    570597                }
    571598            }
    572599        }
     600    }
    573601
    574         // Clean up expanded signature list.
    575         while (!expandedItems.IsEmpty()) {
    576             delete static_cast<BString*>(expandedItems.RemoveItem((int32)0));
    577         }
     602    // Clean up the expanded items list
     603    RemoveExpandedItems();
     604
     605    fExpando->SizeWindow();
     606}
     607
     608
     609void
     610TBarView::AddExpandedItem(const char* signature)
     611{
     612    bool shouldAdd = true;
    578613
    579         fExpando->SizeWindow();
     614    for (int32 i = 0; i < fExpandedItems.CountItems(); i++) {
     615        BString *itemSig = static_cast<BString*>(fExpandedItems.ItemAt(i));
     616        if (itemSig->Compare(signature) == 0) {
     617            // already in the list, don't add the signature
     618            shouldAdd = false;
     619            break;
     620        }
    580621    }
    581622
    582     Invalidate();
     623    if (shouldAdd)
     624        fExpandedItems.AddItem(static_cast<void*>(new BString(signature)));
    583625}
    584626
    585627
  • src/apps/deskbar/BarView.h

    diff --git src/apps/deskbar/BarView.h src/apps/deskbar/BarView.h
    index 9e165cb..5939a65 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 RemoveExpandedItems();
     157        void ExpandItems();
    154158
    155159        TBarMenuBar* fBarMenuBar;
    156160        TExpandoMenuBar* fExpando;
    class TBarView : public BView {  
    177181        uint32 fMaxRecentApps;
    178182
    179183        TTeamMenuItem* fLastDragItem;
     184        BList fExpandedItems;
    180185};
    181186
    182187